Skip to content

Commit 0206c33

Browse files
committed
rename var.identifier to var.name + enable array tests
1 parent 59760a8 commit 0206c33

File tree

6 files changed

+94
-91
lines changed

6 files changed

+94
-91
lines changed

docs/AST.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ be any expression in general, an expression can also be a pattern.
988988

989989
**Properties**
990990

991-
- `identifier` **([String](#string) \| [Node](#node))**
991+
- `name` **([String](#string) \| [Node](#node))**
992992
- `byref` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
993993

994994
# While

src/ast/variable.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
44
* @url http://glayzzle.com
55
*/
6-
6+
"use strict";
77
var Expr = require('./expression');
88
var KIND = 'variable';
99

@@ -12,12 +12,12 @@ var KIND = 'variable';
1212
* be any expression in general, an expression can also be a pattern.
1313
* @constructor Variable
1414
* @extends {Expression}
15-
* @property {String|Node} identifier
15+
* @property {String|Node} name
1616
* @property {boolean} byref
1717
*/
18-
var Variable = Expr.extends(function Variable(identifier, byref, location) {
18+
var Variable = Expr.extends(function Variable(name, byref, location) {
1919
Expr.apply(this, [KIND, location]);
20-
this.identifier = identifier;
20+
this.name = name;
2121
this.byref = byref || false;
2222
});
2323

test/arrayTests.js

Lines changed: 84 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
var should = require("should");
22
var parser = require('../src/index');
33

4-
/*describe('Array without keys', function() {
4+
describe('Array without keys', function() {
55

66
describe('of strings', function () {
77
// Get result from parser
88
var ast = parser.parseEval('array("item1", "item2", "item3")');
99

1010
it('should be of type array', function () {
11-
ast[1][0][0].should.be.exactly("array");
11+
ast.children[0].kind.should.be.exactly("array");
1212
});
1313

1414
it('should have correct number of items', function () {
15-
ast[1][0][1].length.should.be.exactly(3);
15+
ast.children[0].items.length.should.be.exactly(3);
1616
});
1717

1818
it('should have correct item types and values', function () {
19-
ast[1][0][1][0].value[0].should.be.exactly("string");
20-
ast[1][0][1][0].value[1].should.be.exactly("item1");
19+
ast.children[0].items[0].value.kind.should.be.exactly("string");
20+
ast.children[0].items[0].value.value.should.be.exactly("item1");
2121

22-
ast[1][0][1][1].value[0].should.be.exactly("string");
23-
ast[1][0][1][1].value[1].should.be.exactly("item2");
22+
ast.children[0].items[1].value.kind.should.be.exactly("string");
23+
ast.children[0].items[1].value.value.should.be.exactly("item2");
2424

25-
ast[1][0][1][2].value[0].should.be.exactly("string");
26-
ast[1][0][1][2].value[1].should.be.exactly("item3");
25+
ast.children[0].items[2].value.kind.should.be.exactly("string");
26+
ast.children[0].items[2].value.value.should.be.exactly("item3");
2727
});
2828
});
2929

@@ -32,22 +32,22 @@ var parser = require('../src/index');
3232
var ast = parser.parseEval('array(1, 2.5, 0x1000)');
3333

3434
it('should be of type array', function () {
35-
ast[1][0][0].should.be.exactly("array");
35+
ast.children[0].kind.should.be.exactly("array");
3636
});
3737

3838
it('should have correct number of items', function () {
39-
ast[1][0][1].length.should.be.exactly(3);
39+
ast.children[0].items.length.should.be.exactly(3);
4040
});
4141

4242
it('should have correct item types and values', function () {
43-
ast[1][0][1][0].value[0].should.be.exactly("number");
44-
ast[1][0][1][0].value[1].should.be.exactly('1');
43+
ast.children[0].items[0].value.kind.should.be.exactly("number");
44+
ast.children[0].items[0].value.value.should.be.exactly('1');
4545

46-
ast[1][0][1][1].value[0].should.be.exactly("number");
47-
ast[1][0][1][1].value[1].should.be.exactly('2.5');
46+
ast.children[0].items[1].value.kind.should.be.exactly("number");
47+
ast.children[0].items[1].value.value.should.be.exactly('2.5');
4848

49-
ast[1][0][1][2].value[0].should.be.exactly("number");
50-
ast[1][0][1][2].value[1].should.be.exactly('0x1000');
49+
ast.children[0].items[2].value.kind.should.be.exactly("number");
50+
ast.children[0].items[2].value.value.should.be.exactly('0x1000');
5151
});
5252
});
5353

@@ -56,25 +56,25 @@ var parser = require('../src/index');
5656
var ast = parser.parseEval('array(1, "item2", 3, "item4")');
5757

5858
it('should be of type array', function () {
59-
ast[1][0][0].should.be.exactly("array");
59+
ast.children[0].kind.should.be.exactly("array");
6060
});
6161

6262
it('should have correct number of items', function () {
63-
ast[1][0][1].length.should.be.exactly(4);
63+
ast.children[0].items.length.should.be.exactly(4);
6464
});
6565

6666
it('should have correct item types and values', function () {
67-
ast[1][0][1][0].value[0].should.be.exactly("number");
68-
ast[1][0][1][0].value[1].should.be.exactly('1');
67+
ast.children[0].items[0].value.kind.should.be.exactly("number");
68+
ast.children[0].items[0].value.value.should.be.exactly('1');
6969

70-
ast[1][0][1][1].value[0].should.be.exactly("string");
71-
ast[1][0][1][1].value[1].should.be.exactly("item2");
70+
ast.children[0].items[1].value.kind.should.be.exactly("string");
71+
ast.children[0].items[1].value.value.should.be.exactly("item2");
7272

73-
ast[1][0][1][2].value[0].should.be.exactly("number");
74-
ast[1][0][1][2].value[1].should.be.exactly('3');
73+
ast.children[0].items[2].value.kind.should.be.exactly("number");
74+
ast.children[0].items[2].value.value.should.be.exactly('3');
7575

76-
ast[1][0][1][3].value[0].should.be.exactly("string");
77-
ast[1][0][1][3].value[1].should.be.exactly("item4");
76+
ast.children[0].items[3].value.kind.should.be.exactly("string");
77+
ast.children[0].items[3].value.value.should.be.exactly("item4");
7878
});
7979
});
8080

@@ -83,22 +83,22 @@ var parser = require('../src/index');
8383
var ast = parser.parseEval('array($obj1, $obj2, $obj3)');
8484

8585
it('should be of type array', function () {
86-
ast[1][0][0].should.be.exactly("array");
86+
ast.children[0].kind.should.be.exactly("array");
8787
});
8888

8989
it('should have correct number of items', function () {
90-
ast[1][0][1].length.should.be.exactly(3);
90+
ast.children[0].items.length.should.be.exactly(3);
9191
});
9292

9393
it('should have correct item types and values', function () {
94-
ast[1][0][1][0].value[0].should.be.exactly("var");
95-
ast[1][0][1][0].value[1].should.be.exactly("$obj1");
94+
ast.children[0].items[0].value.kind.should.be.exactly("variable");
95+
ast.children[0].items[0].value.name.should.be.exactly("$obj1");
9696

97-
ast[1][0][1][1].value[0].should.be.exactly("var");
98-
ast[1][0][1][1].value[1].should.be.exactly("$obj2");
97+
ast.children[0].items[1].value.kind.should.be.exactly("variable");
98+
ast.children[0].items[1].value.name.should.be.exactly("$obj2");
9999

100-
ast[1][0][1][2].value[0].should.be.exactly("var");
101-
ast[1][0][1][2].value[1].should.be.exactly("$obj3");
100+
ast.children[0].items[2].value.kind.should.be.exactly("variable");
101+
ast.children[0].items[2].value.name.should.be.exactly("$obj3");
102102
});
103103
});
104104

@@ -108,50 +108,77 @@ var parser = require('../src/index');
108108
var ast = parser.parseEval('[new foo(), new stdClass(), new bar()]');
109109

110110
it('should be of type array', function () {
111-
ast[1][0][0].should.be.exactly("array");
111+
ast.children[0].kind.should.be.exactly("array");
112112
});
113113

114114
it('should have correct number of items', function () {
115-
ast[1][0][1].length.should.be.exactly(3);
115+
ast.children[0].items.length.should.be.exactly(3);
116116
});
117117

118118
it('should have correct item types and values', function () {
119-
ast[1][0][1][0].value[0].should.be.exactly("new");
120-
ast[1][0][1][0].value[1][0].should.be.exactly("ns");
121-
ast[1][0][1][0].value[1][1][0].should.be.exactly("foo");
119+
ast.children[0].items[0].value.kind.should.be.exactly("new");
120+
ast.children[0].items[0].value.what.name.should.be.exactly("foo");
122121

123-
ast[1][0][1][1].value[0].should.be.exactly("new");
124-
ast[1][0][1][1].value[1][0].should.be.exactly("ns");
125-
ast[1][0][1][1].value[1][1][0].should.be.exactly("stdClass");
122+
ast.children[0].items[1].value.kind.should.be.exactly("new");
123+
ast.children[0].items[1].value.what.name.should.be.exactly("stdClass");
126124

127-
ast[1][0][1][2].value[0].should.be.exactly("new");
128-
ast[1][0][1][2].value[1][0].should.be.exactly("ns");
129-
ast[1][0][1][2].value[1][1][0].should.be.exactly("bar");
125+
ast.children[0].items[2].value.kind.should.be.exactly("new");
126+
ast.children[0].items[2].value.what.name.should.be.exactly("bar");
130127
});
131128
});
132129

133130
describe('of arrays', function () {
134131
// Get result from parser
135-
var ast = parser.parseEval('array(array("item1", "item2"), array("item3", "item4"), array("item5", "item6"))');
132+
var ast = parser.parseEval([
133+
'array(',
134+
' array("item1", "item2"),',
135+
' array("item3", "item4"),',
136+
' array("item5", "item6")',
137+
')'
138+
].join('\n'));
136139

137140
it('should be of type array', function () {
138-
ast[1][0][0].should.be.exactly("array");
141+
ast.children[0].kind.should.be.exactly("array");
139142
});
140143

141144
it('should have correct number of items', function () {
142-
ast[1][0][1].length.should.be.exactly(3);
145+
ast.children[0].items.length.should.be.exactly(3);
143146
});
144147

145148
it('should have correct item types and values', function () {
146-
ast[1][0][1][0].value[0].should.be.exactly("array");
147-
ast[1][0][1][0].value[1].should.be.match([{ key: false, value: ["string", "item1"] }, { key: false, value: ["string", "item2"] }]);
148-
149-
ast[1][0][1][1].value[0].should.be.exactly("array");
150-
ast[1][0][1][1].value[1].should.be.match([{ key: false, value: ["string", "item3"] }, { key: false, value: ["string", "item4"] }]);
149+
ast.children[0].items[0].value.kind.should.be.exactly("array");
150+
ast.children[0].items[0].value.items.length.should.be.exactly(2);
151+
ast.children[0].items[0].value.items[0].value.value.should.be.exactly("item1");
152+
ast.children[0].items[0].value.items[1].value.value.should.be.exactly("item2");
153+
154+
ast.children[0].items[1].value.kind.should.be.exactly("array");
155+
ast.children[0].items[1].value.items.length.should.be.exactly(2);
156+
ast.children[0].items[1].value.items[0].value.value.should.be.exactly("item3");
157+
ast.children[0].items[1].value.items[1].value.value.should.be.exactly("item4");
158+
159+
ast.children[0].items[2].value.kind.should.be.exactly("array");
160+
ast.children[0].items[2].value.items.length.should.be.exactly(2);
161+
ast.children[0].items[2].value.items[0].value.value.should.be.exactly("item5");
162+
ast.children[0].items[2].value.items[1].value.value.should.be.exactly("item6");
163+
});
164+
});
151165

152-
ast[1][0][1][2].value[0].should.be.exactly("array");
153-
ast[1][0][1][2].value[1].should.be.match([{ key: false, value: ["string", "item5"] }, { key: false, value: ["string", "item6"] }]);
166+
describe('mixed tests / coverage', function() {
167+
it('test short form / keys', function() {
168+
var ast = parser.parseEval('[0 => &$foo, $bar => "foobar"];');
169+
ast.children[0].items.length.should.be.exactly(2);
170+
ast.children[0].shortForm.should.be.exactly(true);
171+
ast.children[0].items[0].key.kind.should.be.exactly('number');
172+
ast.children[0].items[0].value.kind.should.be.exactly('variable');
173+
ast.children[0].items[0].value.byref.should.be.exactly(true);
174+
ast.children[0].items[0].value.name.should.be.exactly('$foo');
175+
ast.children[0].items[0].value.byref.should.be.exactly(true);
176+
ast.children[0].items[1].key.kind.should.be.exactly('variable');
177+
ast.children[0].items[1].key.name.should.be.exactly('$bar');
178+
ast.children[0].items[1].key.byref.should.be.exactly(false);
154179
});
180+
155181
});
156182

157-
});*/
183+
184+
});

test/astTests.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,6 @@ describe('Test AST structure', function() {
2626
// @todo
2727
});
2828

29-
30-
31-
it('test arrays', function() {
32-
var ast;
33-
34-
ast = parser.parseEval('\n\narray(\n\t"item1",\n\t"item2",\n\t"item3");\n\n');
35-
ast.children[0].kind.should.be.exactly('array');
36-
ast.children[0].shortForm.should.be.exactly(false);
37-
ast.children[0].items.length.should.be.exactly(3);
38-
ast.children[0].items[0].kind.should.be.exactly('entry');
39-
40-
ast = parser.parseEval('[0 => &$foo, $bar => "foobar"];');
41-
ast.children[0].items.length.should.be.exactly(2);
42-
ast.children[0].shortForm.should.be.exactly(true);
43-
ast.children[0].items[0].key.kind.should.be.exactly('number');
44-
ast.children[0].items[0].value.kind.should.be.exactly('variable');
45-
ast.children[0].items[0].value.byref.should.be.exactly(true);
46-
ast.children[0].items[0].value.identifier.should.be.exactly('$foo');
47-
ast.children[0].items[0].value.byref.should.be.exactly(true);
48-
ast.children[0].items[1].key.kind.should.be.exactly('variable');
49-
ast.children[0].items[1].key.identifier.should.be.exactly('$bar');
50-
ast.children[0].items[1].key.byref.should.be.exactly(false);
51-
});
52-
5329
it('test inline', function() {
5430
var ast = parser.parseCode('Hello <?php echo "World"; ?> !');
5531
ast.children[0].kind.should.be.exactly('inline');

test/loopTests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ describe('Test loops statements (for, while)', function() {
6767
});
6868
it('test init args', function() {
6969
ast.children[0].init.length.should.be.exactly(2);
70-
ast.children[0].init[0].left.identifier.should.be.exactly('$i');
71-
ast.children[0].init[1].left.identifier.should.be.exactly('$b');
70+
ast.children[0].init[0].left.name.should.be.exactly('$i');
71+
ast.children[0].init[1].left.name.should.be.exactly('$b');
7272
ast.children[1].init.length.should.be.exactly(0);
7373
});
7474
it('check test args', function() {
@@ -105,7 +105,7 @@ describe('Test loops statements (for, while)', function() {
105105
it('test source', function() {
106106
ast.children[0].source.kind.should.be.exactly('variable');
107107
ast.children[0].source.byref.should.be.exactly(true);
108-
ast.children[0].source.identifier.should.be.exactly('$foo');
108+
ast.children[0].source.name.should.be.exactly('$foo');
109109
ast.children[1].source.kind.should.be.exactly('array');
110110
ast.children[1].source.items.length.should.be.exactly(2);
111111
});
@@ -116,7 +116,7 @@ describe('Test loops statements (for, while)', function() {
116116
});
117117
it('test value', function() {
118118
ast.children[0].value.kind.should.be.exactly('variable');
119-
ast.children[0].value.identifier.should.be.exactly('$v');
119+
ast.children[0].value.name.should.be.exactly('$v');
120120
ast.children[1].value.kind.should.be.exactly('array');
121121
ast.children[1].value.shortForm.should.be.exactly(true);
122122
});

test/statementTests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('Test statements', function() {
3737
ast.children[0].catches[0].what[0].name.should.be.exactly('FooError');
3838
ast.children[0].catches[0].what[1].name.should.be.exactly('BarError');
3939
ast.children[0].catches[0].variable.kind.should.be.exactly('variable');
40-
ast.children[0].catches[0].variable.identifier.should.be.exactly('$err');
40+
ast.children[0].catches[0].variable.name.should.be.exactly('$err');
4141
ast.children[0].always.kind.should.be.exactly('block');
4242
});
4343
});

0 commit comments

Comments
 (0)