-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
66 lines (51 loc) · 1.57 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const { test } = require("tapzero");
const { parse, serialize } = require(".");
test("parse double quotes and nulls", (t) => {
let result = [...parse('("(""(""""(,)"""")"")")')];
t.deepEqual(result, ['("(""(,)"")")']);
result = [...parse(result[0])];
t.deepEqual(result, ['("(,)")']);
result = [...parse(result[0])];
t.deepEqual(result, ["(,)"]);
result = [...parse(result[0])];
t.deepEqual(result, [null, null]);
t.deepEqual([...parse("()")], [null]);
});
test("parse backslashes", (t) => {
let result = [
...parse(
'("(""(""""(""""""""\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"""""""")"""")"")")'
),
];
t.deepEqual(result, ['("(""(""""\\\\\\\\\\\\\\\\"""")"")")']);
result = [...parse(result[0])];
t.deepEqual(result, ['("(""\\\\\\\\"")")']);
result = [...parse(result[0])];
t.deepEqual(result, ['("\\\\")']);
result = [...parse(result[0])];
t.deepEqual(result, ["\\"]);
});
test("parse null input returns empty", (t) => {
t.deepEqual([...parse(null)], []);
});
test("serialize returns null on empty input", (t) => {
t.equal(serialize([]), null);
});
test("serialze escapes double quotes and backslashes by doulbling", (t) => {
t.equal(serialize(['"', "\\"]), '("""","\\\\")');
});
test("serialze quotes commas, whitespaces, parentesis, double quotes and backslashes", (t) => {
t.equal(serialize(["1", " ", '"', ")", "\\"]), '(1," ","""",")","\\\\")');
});
test("serialze iterable", (t) => {
t.equal(
serialize(
(function* () {
yield "1";
yield null;
yield "3";
})()
),
"(1,,3)"
);
});