-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
50 lines (46 loc) · 1.48 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var encode = require('./encode')
var decode = require('./decode')
var assert = console.assert
var o, i = {
string: 'ẕ̢͒͛͗ͪ̓ḁ̢͑͆̌̍̎ͨ͘l̶̜̖͍̞ͨͫ͑̽̀̑̓͂͞g̷͖̜̤̬͖ͪo͑͌͐̐̐̌̍ͣ̀͏̥̻̹',
positive: 42,
negative: -42,
float: 4.2,
bigint: 42n,
boolean: true,
array: [123, { some: 'thing' }],
typed: new Uint8Array([4, 5, 6]),
undef: void 0,
nil: null
}
o = transform(i)
assert(o.string === i.string)
assert(o.positive === i.positive)
assert(o.negative === i.negative)
assert(parseFloat(o.float) === i.float)
assert(BigInt(o.bigint) === i.bigint)
assert(Boolean(o.boolean) === i.boolean)
assert(o.array[0] === i.array[0])
assert(o.array[1].some === i.array[1].some)
assert(o.typed[0] === i.typed[0])
assert(o.typed[1] === i.typed[1])
assert(o.typed[2] === i.typed[2])
assert(o.typed[3] === i.typed[3])
assert(o.typed[4] === i.typed[4])
assert(o.typed[5] === i.typed[5])
assert(o.undef === 0)
assert(o.nil === 0)
assert(transform(i.string) === i.string)
assert(transform(i.positive) === i.positive)
assert(transform(i.negative) === i.negative)
assert(parseFloat(transform(i.float)) === i.float)
assert(BigInt(transform(i.bigint)) === i.bigint)
assert(Boolean(transform(i.boolean)) === i.boolean)
assert(transform(i.array)[0] === i.array[0])
assert(transform(i.array)[1].some === i.array[1].some)
assert(transform(i.typed)[0] === i.typed[0])
assert(transform(i.undef) === 0)
assert(transform(i.nil) === 0)
function transform (val) {
return decode(encode(val))
}