UNPKG

897 BJavaScriptView Raw
1
2var bytewise = require('../')
3var bytewiseHex = require('../hex')
4var typewise = require('typewise')
5var test = require('tape')
6var bops = require('bops')
7
8var example = [
9 null,
10 0.304958230,
11 true,
12 4,
13 'hello',
14 ['foo', 'bar', 'baz'],
15 {whatever: true},
16 //this breaks
17 // {k: 'X', b: true}
18].sort(typewise.compare)
19
20test('sorts with same order when encoded', function (t) {
21
22 var sorted =
23 example
24 .map(bytewise.encode)
25 .sort(bytewise.compare)
26 .map(bytewise.decode)
27
28 t.equal(
29 bops.to(bytewise.encode(sorted),'hex'),
30 bops.to(bytewise.encode(example),'hex')
31 )
32
33 t.end()
34})
35
36test('sorts with same order when hex encoded', function (t) {
37
38 var sorted =
39 example
40 .map(bytewiseHex.encode)
41 .sort()
42 .map(bytewiseHex.decode)
43
44 t.equal(
45 bops.to(bytewise.encode(sorted),'hex'),
46 bops.to(bytewise.encode(example),'hex')
47 )
48 t.end()
49})
50
51