1 |
3a515b92
|
cagy
|
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
2 |
|
|
var B = require('../').Buffer
|
3 |
|
|
var test = require('tape')
|
4 |
|
|
|
5 |
|
|
test('buffer.compare', function (t) {
|
6 |
|
|
var b = new B(1).fill('a')
|
7 |
|
|
var c = new B(1).fill('c')
|
8 |
|
|
var d = new B(2).fill('aa')
|
9 |
|
|
|
10 |
|
|
t.equal(b.compare(c), -1)
|
11 |
|
|
t.equal(c.compare(d), 1)
|
12 |
|
|
t.equal(d.compare(b), 1)
|
13 |
|
|
t.equal(b.compare(d), -1)
|
14 |
|
|
|
15 |
|
|
// static method
|
16 |
|
|
t.equal(B.compare(b, c), -1)
|
17 |
|
|
t.equal(B.compare(c, d), 1)
|
18 |
|
|
t.equal(B.compare(d, b), 1)
|
19 |
|
|
t.equal(B.compare(b, d), -1)
|
20 |
|
|
t.end()
|
21 |
|
|
})
|
22 |
|
|
|
23 |
|
|
test('buffer.compare argument validation', function (t) {
|
24 |
|
|
t.throws(function () {
|
25 |
|
|
var b = new B(1)
|
26 |
|
|
B.compare(b, 'abc')
|
27 |
|
|
})
|
28 |
|
|
|
29 |
|
|
t.throws(function () {
|
30 |
|
|
var b = new B(1)
|
31 |
|
|
B.compare('abc', b)
|
32 |
|
|
})
|
33 |
|
|
|
34 |
|
|
t.throws(function () {
|
35 |
|
|
var b = new B(1)
|
36 |
|
|
b.compare('abc')
|
37 |
|
|
})
|
38 |
|
|
t.end()
|
39 |
|
|
})
|
40 |
|
|
|
41 |
|
|
test('buffer.equals', function (t) {
|
42 |
|
|
var b = new B(5).fill('abcdf')
|
43 |
|
|
var c = new B(5).fill('abcdf')
|
44 |
|
|
var d = new B(5).fill('abcde')
|
45 |
|
|
var e = new B(6).fill('abcdef')
|
46 |
|
|
|
47 |
|
|
t.ok(b.equals(c))
|
48 |
|
|
t.ok(!c.equals(d))
|
49 |
|
|
t.ok(!d.equals(e))
|
50 |
|
|
t.end()
|
51 |
|
|
})
|
52 |
|
|
|
53 |
|
|
test('buffer.equals argument validation', function (t) {
|
54 |
|
|
t.throws(function () {
|
55 |
|
|
var b = new B(1)
|
56 |
|
|
b.equals('abc')
|
57 |
|
|
})
|
58 |
|
|
t.end()
|
59 |
|
|
})
|