summaryrefslogtreecommitdiff
path: root/test/parallel/test-buffer-compare.js
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2016-08-23 14:16:45 -0700
committerJames M Snell <jasnell@gmail.com>2016-08-26 07:15:31 -0700
commit7053922c1a76ac56ef245923ec171b01cd90d2f4 (patch)
tree0464984232c835fe6e1d3ac2b429bdaaf77a6cbe /test/parallel/test-buffer-compare.js
parentb3e7ac2605c18c041293cd3ab892c963e1145176 (diff)
downloadandroid-node-v8-7053922c1a76ac56ef245923ec171b01cd90d2f4.tar.gz
android-node-v8-7053922c1a76ac56ef245923ec171b01cd90d2f4.tar.bz2
android-node-v8-7053922c1a76ac56ef245923ec171b01cd90d2f4.zip
test: clean up / refactor buffer tests, remove duplication
Remove duplication of buffer tests, separate out into separate files, update and cleanup code, move to using strictEqual where possible. PR-URL: https://github.com/nodejs/node/pull/8256 Reviewed-By: Michaƫl Zasso <mic.besace@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-compare.js')
-rw-r--r--test/parallel/test-buffer-compare.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/parallel/test-buffer-compare.js b/test/parallel/test-buffer-compare.js
new file mode 100644
index 0000000000..c0db39a6e3
--- /dev/null
+++ b/test/parallel/test-buffer-compare.js
@@ -0,0 +1,30 @@
+'use strict';
+
+require('../common');
+const assert = require('assert');
+
+const b = Buffer.alloc(1, 'a');
+const c = Buffer.alloc(1, 'c');
+const d = Buffer.alloc(2, 'aa');
+
+assert.strictEqual(b.compare(c), -1);
+assert.strictEqual(c.compare(d), 1);
+assert.strictEqual(d.compare(b), 1);
+assert.strictEqual(b.compare(d), -1);
+assert.strictEqual(b.compare(b), 0);
+
+assert.strictEqual(Buffer.compare(b, c), -1);
+assert.strictEqual(Buffer.compare(c, d), 1);
+assert.strictEqual(Buffer.compare(d, b), 1);
+assert.strictEqual(Buffer.compare(b, d), -1);
+assert.strictEqual(Buffer.compare(c, c), 0);
+
+assert.strictEqual(Buffer.compare(Buffer.alloc(0), Buffer.alloc(0)), 0);
+assert.strictEqual(Buffer.compare(Buffer.alloc(0), Buffer.alloc(1)), -1);
+assert.strictEqual(Buffer.compare(Buffer.alloc(1), Buffer.alloc(0)), 1);
+
+assert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'));
+
+assert.throws(() => Buffer.compare('abc', Buffer.alloc(1)));
+
+assert.throws(() => Buffer.alloc(1).compare('abc'));