-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
38 lines (35 loc) · 1.25 KB
/
index.test.ts
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
import { describe, test, expect } from "@jest/globals";
import { parse } from "./index";
describe("parse", () => {
test.each<{ text: string; expected: any }>`
text | expected
${`[]`} | ${[]}
${`[[[]]]`} | ${[[[]]]}
${`[1,2,3]`} | ${[1, 2, 3]}
${`\"aaa\"`} | ${"aaa"}
${`{ "key": 123 }`} | ${{ key: 123 }}
${`{ "key1": { "key2": 123 } }`} | ${{ key1: { key2: 123 } }}
${`123`} | ${123}
${`-123`} | ${-123}
${`123.01`} | ${123.01}
${`123e1`} | ${1230}
${`123E-1`} | ${12.3}
${`true`} | ${true}
${`false`} | ${false}
${`null`} | ${null}
`("expected $expected when $text is passed", ({ text, expected }) => {
expect(parse(text)).toStrictEqual(expected);
});
test.each<{ text: string }>`
text
${`[`}
${`[[]`}
${`[]]`}
${`{`}
${`{{}`}
${`{}}`}
${`01`}
`("thrown an exception when $text is passed", ({ text }) => {
expect(() => parse(text)).toThrowError();
});
});