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