Skip to content

Commit 62e3880

Browse files
committed
added match statement support and supporting tests
1 parent c0e1f5c commit 62e3880

File tree

2 files changed

+242
-6
lines changed

2 files changed

+242
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`match can be parsed 1`] = `
4+
Program {
5+
"children": Array [
6+
ExpressionStatement {
7+
"expression": Assign {
8+
"kind": "assign",
9+
"left": Variable {
10+
"curly": false,
11+
"kind": "variable",
12+
"name": "test",
13+
},
14+
"operator": "=",
15+
"right": Match {
16+
"body": Array [
17+
MatchEntry {
18+
"keys": Array [
19+
Boolean {
20+
"kind": "boolean",
21+
"raw": "true",
22+
"value": true,
23+
},
24+
],
25+
"kind": "matchentry",
26+
"value": String {
27+
"isDoubleQuote": false,
28+
"kind": "string",
29+
"raw": "'yes'",
30+
"unicode": false,
31+
"value": "yes",
32+
},
33+
},
34+
MatchEntry {
35+
"keys": Array [
36+
Boolean {
37+
"kind": "boolean",
38+
"raw": "false",
39+
"value": false,
40+
},
41+
],
42+
"kind": "matchentry",
43+
"value": String {
44+
"isDoubleQuote": false,
45+
"kind": "string",
46+
"raw": "'no'",
47+
"unicode": false,
48+
"value": "no",
49+
},
50+
},
51+
MatchEntry {
52+
"keys": Array [
53+
DefaultKeyword {
54+
"kind": "defaultkeyword",
55+
"raw": "default",
56+
},
57+
],
58+
"kind": "matchentry",
59+
"value": NullKeyword {
60+
"kind": "nullkeyword",
61+
"raw": "null",
62+
},
63+
},
64+
],
65+
"kind": "match",
66+
"test": Variable {
67+
"curly": false,
68+
"kind": "variable",
69+
"name": "a",
70+
},
71+
},
72+
},
73+
"kind": "expressionstatement",
74+
},
75+
],
76+
"errors": Array [],
77+
"kind": "program",
78+
}
79+
`;
80+
81+
exports[`match can have lhs, functions 1`] = `
82+
Program {
83+
"children": Array [
84+
ExpressionStatement {
85+
"expression": Assign {
86+
"kind": "assign",
87+
"left": Variable {
88+
"curly": false,
89+
"kind": "variable",
90+
"name": "test",
91+
},
92+
"operator": "=",
93+
"right": Match {
94+
"body": Array [
95+
MatchEntry {
96+
"keys": Array [
97+
Call {
98+
"arguments": Array [
99+
Variable {
100+
"curly": false,
101+
"kind": "variable",
102+
"name": "a",
103+
},
104+
],
105+
"kind": "call",
106+
"what": Name {
107+
"kind": "name",
108+
"name": "test",
109+
"resolution": "uqn",
110+
},
111+
},
112+
Call {
113+
"arguments": Array [
114+
Variable {
115+
"curly": false,
116+
"kind": "variable",
117+
"name": "b",
118+
},
119+
],
120+
"kind": "call",
121+
"what": Name {
122+
"kind": "name",
123+
"name": "abc",
124+
"resolution": "uqn",
125+
},
126+
},
127+
],
128+
"kind": "matchentry",
129+
"value": String {
130+
"isDoubleQuote": false,
131+
"kind": "string",
132+
"raw": "'yes'",
133+
"unicode": false,
134+
"value": "yes",
135+
},
136+
},
137+
MatchEntry {
138+
"keys": Array [
139+
DefaultKeyword {
140+
"kind": "defaultkeyword",
141+
"raw": "default",
142+
},
143+
],
144+
"kind": "matchentry",
145+
"value": NullKeyword {
146+
"kind": "nullkeyword",
147+
"raw": "null",
148+
},
149+
},
150+
],
151+
"kind": "match",
152+
"test": Boolean {
153+
"kind": "boolean",
154+
"raw": "true",
155+
"value": true,
156+
},
157+
},
158+
},
159+
"kind": "expressionstatement",
160+
},
161+
],
162+
"errors": Array [],
163+
"kind": "program",
164+
}
165+
`;
166+
167+
exports[`match can have multiple values 1`] = `
168+
Program {
169+
"children": Array [
170+
ExpressionStatement {
171+
"expression": Assign {
172+
"kind": "assign",
173+
"left": Variable {
174+
"curly": false,
175+
"kind": "variable",
176+
"name": "test",
177+
},
178+
"operator": "=",
179+
"right": Match {
180+
"body": Array [
181+
MatchEntry {
182+
"keys": Array [
183+
Number {
184+
"kind": "number",
185+
"value": "0",
186+
},
187+
Number {
188+
"kind": "number",
189+
"value": "1",
190+
},
191+
Number {
192+
"kind": "number",
193+
"value": "2",
194+
},
195+
Number {
196+
"kind": "number",
197+
"value": "3",
198+
},
199+
],
200+
"kind": "matchentry",
201+
"value": Call {
202+
"arguments": Array [],
203+
"kind": "call",
204+
"what": Name {
205+
"kind": "name",
206+
"name": "run",
207+
"resolution": "uqn",
208+
},
209+
},
210+
},
211+
MatchEntry {
212+
"keys": Array [
213+
DefaultKeyword {
214+
"kind": "defaultkeyword",
215+
"raw": "default",
216+
},
217+
],
218+
"kind": "matchentry",
219+
"value": NullKeyword {
220+
"kind": "nullkeyword",
221+
"raw": "null",
222+
},
223+
},
224+
],
225+
"kind": "match",
226+
"test": Name {
227+
"kind": "name",
228+
"name": "trye",
229+
"resolution": "uqn",
230+
},
231+
},
232+
},
233+
"kind": "expressionstatement",
234+
},
235+
],
236+
"errors": Array [],
237+
"kind": "program",
238+
}
239+
`;

test/snapshot/match.test.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ describe("match", () => {
99
default => null,
1010
};
1111
`);
12-
console.log(ast.children[0].expression.right.body);
13-
// expect (ast).toMatchSnapshot();
12+
expect(ast).toMatchSnapshot();
1413
});
1514

1615
it("can have lhs, functions", () => {
@@ -20,8 +19,7 @@ describe("match", () => {
2019
default => null,
2120
};
2221
`);
23-
console.log(ast.children[0].expression.right.body);
24-
// expect (ast).toMatchSnapshot();
22+
expect(ast).toMatchSnapshot();
2523
});
2624

2725
it("can have multiple values", () => {
@@ -31,7 +29,6 @@ describe("match", () => {
3129
default => null,
3230
};
3331
`);
34-
console.log(ast.children[0].expression.right.body);
35-
// expect (ast).toMatchSnapshot();
32+
expect(ast).toMatchSnapshot();
3633
});
3734
});

0 commit comments

Comments
 (0)