Skip to content

Commit fc128e4

Browse files
committed
glayzzle#205 - add tests to cover the use case
1 parent e39268b commit fc128e4

File tree

2 files changed

+238
-0
lines changed

2 files changed

+238
-0
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`byref call result 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": "a",
13+
},
14+
"operator": "=",
15+
"right": Call {
16+
"arguments": Array [
17+
ByRef {
18+
"kind": "byref",
19+
"what": Variable {
20+
"curly": false,
21+
"kind": "variable",
22+
"name": "b",
23+
},
24+
},
25+
],
26+
"kind": "call",
27+
"what": ClassReference {
28+
"kind": "classreference",
29+
"name": "foo",
30+
"resolution": "uqn",
31+
},
32+
},
33+
},
34+
"kind": "expressionstatement",
35+
},
36+
],
37+
"errors": Array [],
38+
"kind": "program",
39+
}
40+
`;
41+
42+
exports[`byref function definition 1`] = `
43+
Program {
44+
"children": Array [
45+
_Function {
46+
"arguments": Array [
47+
Parameter {
48+
"byref": true,
49+
"kind": "parameter",
50+
"name": Identifier {
51+
"kind": "identifier",
52+
"name": "bar",
53+
},
54+
"nullable": false,
55+
"type": null,
56+
"value": null,
57+
"variadic": false,
58+
},
59+
],
60+
"body": Block {
61+
"children": Array [],
62+
"kind": "block",
63+
},
64+
"byref": true,
65+
"kind": "function",
66+
"name": Identifier {
67+
"kind": "identifier",
68+
"name": "foo",
69+
},
70+
"nullable": false,
71+
"type": null,
72+
},
73+
],
74+
"errors": Array [],
75+
"kind": "program",
76+
}
77+
`;
78+
79+
exports[`byref new class 1`] = `
80+
Program {
81+
"children": Array [
82+
ExpressionStatement {
83+
"expression": Assign {
84+
"kind": "assign",
85+
"left": Variable {
86+
"curly": false,
87+
"kind": "variable",
88+
"name": "a",
89+
},
90+
"operator": "=",
91+
"right": New {
92+
"arguments": Array [],
93+
"kind": "new",
94+
"what": ClassReference {
95+
"kind": "classreference",
96+
"name": "foo",
97+
"resolution": "uqn",
98+
},
99+
},
100+
},
101+
"kind": "expressionstatement",
102+
},
103+
],
104+
"errors": Array [],
105+
"kind": "program",
106+
}
107+
`;
108+
109+
exports[`byref offset lookup 1`] = `
110+
Program {
111+
"children": Array [
112+
ExpressionStatement {
113+
"expression": OffsetLookup {
114+
"kind": "offsetlookup",
115+
"offset": ByRef {
116+
"kind": "byref",
117+
"what": Variable {
118+
"curly": false,
119+
"kind": "variable",
120+
"name": "bar",
121+
},
122+
},
123+
"what": Variable {
124+
"curly": false,
125+
"kind": "variable",
126+
"name": "foo",
127+
},
128+
},
129+
"kind": "expressionstatement",
130+
},
131+
],
132+
"errors": Array [],
133+
"kind": "program",
134+
}
135+
`;
136+
137+
exports[`byref return statement 1`] = `
138+
Program {
139+
"children": Array [
140+
Return {
141+
"expr": ByRef {
142+
"kind": "byref",
143+
"what": Variable {
144+
"curly": false,
145+
"kind": "variable",
146+
"name": "foo",
147+
},
148+
},
149+
"kind": "return",
150+
},
151+
],
152+
"errors": Array [],
153+
"kind": "program",
154+
}
155+
`;
156+
157+
exports[`byref static lookup 1`] = `
158+
Program {
159+
"children": Array [
160+
ExpressionStatement {
161+
"expression": ByRef {
162+
"kind": "byref",
163+
"what": StaticLookup {
164+
"kind": "staticlookup",
165+
"offset": Variable {
166+
"curly": false,
167+
"kind": "variable",
168+
"name": "bar",
169+
},
170+
"what": ClassReference {
171+
"kind": "classreference",
172+
"name": "foo",
173+
"resolution": "uqn",
174+
},
175+
},
176+
},
177+
"kind": "expressionstatement",
178+
},
179+
],
180+
"errors": Array [],
181+
"kind": "program",
182+
}
183+
`;
184+
185+
exports[`byref variable 1`] = `
186+
Program {
187+
"children": Array [
188+
ExpressionStatement {
189+
"expression": ByRef {
190+
"kind": "byref",
191+
"what": Variable {
192+
"curly": false,
193+
"kind": "variable",
194+
"name": "foo",
195+
},
196+
},
197+
"kind": "expressionstatement",
198+
},
199+
],
200+
"errors": Array [],
201+
"kind": "program",
202+
}
203+
`;

test/snapshot/byref.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const parser = require('../main');
2+
3+
describe('byref', () => {
4+
it('variable', () => {
5+
expect(parser.parseEval('&$foo;')).toMatchSnapshot();
6+
});
7+
it('static lookup', () => {
8+
expect(parser.parseEval('&foo::$bar;')).toMatchSnapshot();
9+
});
10+
it('offset lookup', () => {
11+
expect(parser.parseEval('$foo[&$bar];')).toMatchSnapshot();
12+
});
13+
it('new class', () => {
14+
15+
expect(
16+
parser.parseEval('$a =& new foo();', {
17+
parser: {
18+
php7: false
19+
}
20+
}
21+
)).toMatchSnapshot();
22+
expect(() => {
23+
parser.parseEval('$a =& new foo();');
24+
}).toThrow('Parse Error : syntax error, unexpected \'new\' (T_NEW) on line 1');
25+
});
26+
it('call result', () => {
27+
expect(parser.parseEval('$a =& foo( &$b );')).toMatchSnapshot();
28+
});
29+
it('return statement', () => {
30+
expect(parser.parseEval('return &$foo;')).toMatchSnapshot();
31+
});
32+
it('function definition', () => {
33+
expect(parser.parseEval('function &foo( &$bar ) { }')).toMatchSnapshot();
34+
});
35+
});

0 commit comments

Comments
 (0)