1
1
var should = require ( "should" ) ;
2
2
var parser = require ( '../src/index' ) ;
3
3
4
- /* describe('Array without keys', function() {
4
+ describe ( 'Array without keys' , function ( ) {
5
5
6
6
describe ( 'of strings' , function ( ) {
7
7
// Get result from parser
8
8
var ast = parser . parseEval ( 'array("item1", "item2", "item3")' ) ;
9
9
10
10
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" ) ;
12
12
} ) ;
13
13
14
14
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 ) ;
16
16
} ) ;
17
17
18
18
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" ) ;
21
21
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" ) ;
24
24
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" ) ;
27
27
} ) ;
28
28
} ) ;
29
29
@@ -32,22 +32,22 @@ var parser = require('../src/index');
32
32
var ast = parser . parseEval ( 'array(1, 2.5, 0x1000)' ) ;
33
33
34
34
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" ) ;
36
36
} ) ;
37
37
38
38
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 ) ;
40
40
} ) ;
41
41
42
42
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' ) ;
45
45
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' ) ;
48
48
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' ) ;
51
51
} ) ;
52
52
} ) ;
53
53
@@ -56,25 +56,25 @@ var parser = require('../src/index');
56
56
var ast = parser . parseEval ( 'array(1, "item2", 3, "item4")' ) ;
57
57
58
58
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" ) ;
60
60
} ) ;
61
61
62
62
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 ) ;
64
64
} ) ;
65
65
66
66
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' ) ;
69
69
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" ) ;
72
72
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' ) ;
75
75
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" ) ;
78
78
} ) ;
79
79
} ) ;
80
80
@@ -83,22 +83,22 @@ var parser = require('../src/index');
83
83
var ast = parser . parseEval ( 'array($obj1, $obj2, $obj3)' ) ;
84
84
85
85
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" ) ;
87
87
} ) ;
88
88
89
89
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 ) ;
91
91
} ) ;
92
92
93
93
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" ) ;
96
96
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" ) ;
99
99
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" ) ;
102
102
} ) ;
103
103
} ) ;
104
104
@@ -108,50 +108,77 @@ var parser = require('../src/index');
108
108
var ast = parser . parseEval ( '[new foo(), new stdClass(), new bar()]' ) ;
109
109
110
110
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" ) ;
112
112
} ) ;
113
113
114
114
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 ) ;
116
116
} ) ;
117
117
118
118
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" ) ;
122
121
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" ) ;
126
124
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" ) ;
130
127
} ) ;
131
128
} ) ;
132
129
133
130
describe ( 'of arrays' , function ( ) {
134
131
// 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' ) ) ;
136
139
137
140
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" ) ;
139
142
} ) ;
140
143
141
144
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 ) ;
143
146
} ) ;
144
147
145
148
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
+ } ) ;
151
165
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 ) ;
154
179
} ) ;
180
+
155
181
} ) ;
156
182
157
- });*/
183
+
184
+ } ) ;
0 commit comments