-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
parser.test.js
62 lines (54 loc) · 1.37 KB
/
parser.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
const {
transformJsStringToMermaidString,
transformJsStringToJsAst
} = require(".");
describe("parser", () => {
test("return", () => {
expect(
transformJsStringToJsAst("function f(x){return 5;}")
).toMatchSnapshot();
});
test("return", () => {
expect(
transformJsStringToJsAst("function f(x){const a = 5;}")
).toMatchSnapshot();
});
test("if else", () => {
expect(
transformJsStringToJsAst(
"function f(x){if(x===5){return 0}else{return 1}}"
)
).toMatchSnapshot();
});
test("if else", () => {
expect(
transformJsStringToJsAst(
"function f(x){if(x===5){return 0}else if(x===6){return 1}else {return 2}}"
)
).toMatchSnapshot();
});
test("switch", () => {
expect(
transformJsStringToJsAst(
"function f(x){switch(x){case 1:return 2; default: break;}return 3;}"
)
).toMatchSnapshot();
});
test("switch", () => {
expect(
transformJsStringToJsAst(
`(x)=>{switch(x){case 0: return 1;case 2:{const a=1;return 3;};default: return 4}}`
)
).toMatchSnapshot();
});
test("yield", () => {
expect(
transformJsStringToJsAst("function* f(x){yield 5;}")
).toMatchSnapshot();
});
test("const yield", () => {
expect(
transformJsStringToJsAst("function* f(x){const a = yield 5;}")
).toMatchSnapshot();
});
});