1 |
|
2 | var bytewise = require('../')
|
3 | var bytewiseHex = require('../hex')
|
4 | var typewise = require('typewise')
|
5 | var test = require('tape')
|
6 | var bops = require('bops')
|
7 |
|
8 | var example = [
|
9 | null,
|
10 | 0.304958230,
|
11 | true,
|
12 | 4,
|
13 | 'hello',
|
14 | ['foo', 'bar', 'baz'],
|
15 | {whatever: true},
|
16 |
|
17 |
|
18 | ].sort(typewise.compare)
|
19 |
|
20 | test('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 |
|
36 | test('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 |
|