Skip to content
This repository
Newer
Older
100644 749 lines (603 sloc) 26.857 kb
05eedb5e »
2010-01-25 initial add
1 // Copyright 2010 Todd Ditchendorf
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #import "TDJavaScriptParserTest.h"
16
17 @implementation TDJavaScriptParserTest
18
19 - (void)setUp {
32bd9bfa »
2010-04-07 cleaning up factory method return types. adding twitter state test.
20 jsp = (TDJavaScriptParser *)[TDJavaScriptParser parser];
05eedb5e »
2010-01-25 initial add
21 }
22
23
24 - (void)tearDown {
25
26 }
27
28
29 - (void)testStmtParser {
30 s = @";";
31 jsp.tokenizer.string = s;
32 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
33 res = [jsp.stmtParser bestMatchFor:a];
34 TDEqualObjects([res description], @"[;];^");
35
36 s = @"{}";
37 jsp.tokenizer.string = s;
38 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
39 res = [jsp.stmtParser bestMatchFor:a];
40 TDEqualObjects([res description], @"[{, }]{/}^");
41 }
42
43
44 - (void)testFunctionParser {
45 s = @"function";
46 jsp.tokenizer.string = s;
47 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
48 res = [jsp.functionParser bestMatchFor:a];
49 TDEqualObjects([res description], @"[function]function^");
50 }
51
52
53 - (void)testIdentifierParser {
54 s = @"foo";
55 jsp.tokenizer.string = s;
56 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
57 res = [jsp.identifierParser bestMatchFor:a];
58 TDEqualObjects([res description], @"[foo]foo^");
59 }
60
61
62 - (void)testParamListOptParserParser {
63 s = @"a, b";
64 jsp.tokenizer.string = s;
65 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
66 res = [jsp.paramListOptParser bestMatchFor:a];
67 TDEqualObjects([res description], @"[a, ,, b]a/,/b^");
68 }
69
70
71 - (void)testCompoundStmtParserParser {
72 s = @"{}";
73 jsp.tokenizer.string = s;
74 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
75 res = [jsp.compoundStmtParser bestMatchFor:a];
76 TDEqualObjects([res description], @"[{, }]{/}^");
77 }
78
79
80 - (void)testFuncParser {
81 s = @"function foo(a, b) {}";
82 jsp.tokenizer.string = s;
83 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
84 res = [jsp.funcParser bestMatchFor:a];
85 TDEqualObjects([res description], @"[function, foo, (, a, ,, b, ), {, }]function/foo/(/a/,/b/)/{/}^");
86
87 s = @"function foo(a, b) { return a + b; }";
88 jsp.tokenizer.string = s;
89 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
90 res = [jsp.funcParser bestMatchFor:a];
91 TDEqualObjects([res description], @"[function, foo, (, a, ,, b, ), {, return, a, +, b, ;, }]function/foo/(/a/,/b/)/{/return/a/+/b/;/}^");
92
93 s = @"function foo(a, b) { a++; b--; return a + b; }";
94 jsp.tokenizer.string = s;
95 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
96 res = [jsp.funcParser bestMatchFor:a];
97 TDEqualObjects([res description], @"[function, foo, (, a, ,, b, ), {, a, ++, ;, b, --, ;, return, a, +, b, ;, }]function/foo/(/a/,/b/)/{/a/++/;/b/--/;/return/a/+/b/;/}^");
98
99 s = @"function foo(a, b) { a++; b--; return a + b; }";
100 jsp.tokenizer.string = s;
101 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
102 res = [jsp.elementParser bestMatchFor:a];
103 TDEqualObjects([res description], @"[function, foo, (, a, ,, b, ), {, a, ++, ;, b, --, ;, return, a, +, b, ;, }]function/foo/(/a/,/b/)/{/a/++/;/b/--/;/return/a/+/b/;/}^");
104 }
105
106
107 - (void)testBitwiseOrExprParser {
108 s = @"true";
109 jsp.tokenizer.string = s;
110 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
111 res = [jsp.bitwiseOrExprParser bestMatchFor:a];
112 TDEqualObjects([res description], @"[true]true^");
113 }
114
115
116 - (void)testAndBitwiseOrExprParser {
117 s = @"&& true";
118 jsp.tokenizer.string = s;
119 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
120 res = [jsp.andBitwiseOrExprParser bestMatchFor:a];
121 TDEqualObjects([res description], @"[&&, true]&&/true^");
122 }
123
124
125 - (void)testParamListParser {
126 s = @"baz, bat";
127 jsp.tokenizer.string = s;
128 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
129 res = [jsp.paramListParser bestMatchFor:a];
130 TDEqualObjects([res description], @"[baz, ,, bat]baz/,/bat^");
131
132 s = @"foo,bar,c_str";
133 jsp.tokenizer.string = s;
134 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
135 res = [jsp.paramListParser bestMatchFor:a];
136 TDEqualObjects([res description], @"[foo, ,, bar, ,, c_str]foo/,/bar/,/c_str^");
137
138 s = @"_x, __y";
139 jsp.tokenizer.string = s;
140 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
141 res = [jsp.paramListParser bestMatchFor:a];
142 TDEqualObjects([res description], @"[_x, ,, __y]_x/,/__y^");
143 }
144
145
146 - (void)testCommaIdentifierParser {
147 s = @", foo";
148 jsp.tokenizer.string = s;
149 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
150 res = [jsp.commaIdentifierParser bestMatchFor:a];
151 TDEqualObjects([res description], @"[,, foo],/foo^");
152
153 s = @" ,bar";
154 jsp.tokenizer.string = s;
155 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
156 res = [jsp.commaIdentifierParser bestMatchFor:a];
157 TDEqualObjects([res description], @"[,, bar],/bar^");
158 }
159
160
161 - (void)testBreakStmtParser {
162 s = @"break;";
163 jsp.tokenizer.string = s;
164 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
165 res = [jsp.breakStmtParser bestMatchFor:a];
166 TDEqualObjects([res description], @"[break, ;]break/;^");
167 }
168
169
170 - (void)testContinueStmtParser {
171 s = @"continue;";
172 jsp.tokenizer.string = s;
173 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
174 res = [jsp.continueStmtParser bestMatchFor:a];
175 TDEqualObjects([res description], @"[continue, ;]continue/;^");
176 }
177
178
179 - (void)testAssignmentOpParser {
180 s = @"=";
181 jsp.tokenizer.string = s;
182 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
183 res = [jsp.assignmentOpParser bestMatchFor:a];
184 TDEqualObjects([res description], @"[=]=^");
185
186 s = @"*=";
187 jsp.tokenizer.string = s;
188 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
189 res = [jsp.assignmentOpParser bestMatchFor:a];
190 TDEqualObjects([res description], @"[*=]*=^");
191
192 s = @"%=";
193 jsp.tokenizer.string = s;
194 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
195 res = [jsp.assignmentOpParser bestMatchFor:a];
196 TDEqualObjects([res description], @"[%=]%=^");
197
198 s = @">>>=";
199 jsp.tokenizer.string = s;
200 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
201 res = [jsp.assignmentOpParser bestMatchFor:a];
202 TDEqualObjects([res description], @"[>>>=]>>>=^");
203 }
204
205
206 - (void)testRelationalOpParser {
207 s = @"<=";
208 jsp.tokenizer.string = s;
209 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
210 res = [jsp.relationalOpParser bestMatchFor:a];
211 TDEqualObjects([res description], @"[<=]<=^");
212
213 s = @"instanceof";
214 jsp.tokenizer.string = s;
215 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
216 res = [jsp.relationalOpParser bestMatchFor:a];
217 TDEqualObjects([res description], @"[instanceof]instanceof^");
218 }
219
220
221 - (void)testEqualityOpParser {
222 s = @"==";
223 jsp.tokenizer.string = s;
224 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
225 res = [jsp.equalityOpParser bestMatchFor:a];
226 TDEqualObjects([res description], @"[==]==^");
227
228 s = @"!==";
229 jsp.tokenizer.string = s;
230 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
231 res = [jsp.equalityOpParser bestMatchFor:a];
232 TDEqualObjects([res description], @"[!==]!==^");
233
234 s = @"===";
235 jsp.tokenizer.string = s;
236 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
237 res = [jsp.equalityOpParser bestMatchFor:a];
238 TDEqualObjects([res description], @"[===]===^");
239 }
240
241
242 - (void)testForParenParser {
243 s = @"for (";
244 jsp.tokenizer.string = s;
245 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
246 res = [jsp.forParenParser bestMatchFor:a];
247 TDEqualObjects([res description], @"[for, (]for/(^");
248
249 s = @"for(";
250 jsp.tokenizer.string = s;
251 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
252 res = [jsp.forParenParser bestMatchFor:a];
253 TDEqualObjects([res description], @"[for, (]for/(^");
254 }
255
256
257 - (void)testExprOptParser {
258 s = @"true";
259 jsp.tokenizer.string = s;
260 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
261 res = [jsp.exprOptParser bestMatchFor:a];
262 TDEqualObjects([res description], @"[true]true^");
263 }
264
265
266 - (void)testForBeginParenStmtParser {
267 s = @"for(1";
268 jsp.tokenizer.string = s;
269 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
270 res = [jsp.forBeginParser bestMatchFor:a];
271 TDEqualObjects([res description], @"[for, (, 1]for/(/1^");
272
273 s = @";";
274 jsp.tokenizer.string = s;
275 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
276 res = [jsp.semiParser bestMatchFor:a];
277 TDEqualObjects([res description], @"[;];^");
278
279 s = @"3<2";
280 jsp.tokenizer.string = s;
281 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
282 res = [jsp.exprOptParser bestMatchFor:a];
283 TDEqualObjects([res description], @"[3, <, 2]3/</2^");
284
285 s = @"1";
286 jsp.tokenizer.string = s;
287 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
288 res = [jsp.exprOptParser bestMatchFor:a];
289 TDEqualObjects([res description], @"[1]1^");
290
291 s = @")";
292 jsp.tokenizer.string = s;
293 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
294 res = [jsp.closeParenParser bestMatchFor:a];
295 TDEqualObjects([res description], @"[)])^");
296
297 s = @"{}";
298 jsp.tokenizer.string = s;
299 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
300 res = [jsp.stmtParser bestMatchFor:a];
301 TDEqualObjects([res description], @"[{, }]{/}^");
302
303 s = @"for(1; 3<2; 1) {}";
304 jsp.tokenizer.string = s;
305 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
306 res = [jsp.forBeginStmtParser bestMatchFor:a];
307 TDEqualObjects([res description], @"[for, (, 1, ;, 3, <, 2, ;, 1, ), {, }]for/(/1/;/3/</2/;/1/)/{/}^");
308
309 s = @"for(1; 3<2; 1) {}";
310 jsp.tokenizer.string = s;
311 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
312 res = [jsp bestMatchFor:a];
313 TDEqualObjects([res description], @"[for, (, 1, ;, 3, <, 2, ;, 1, ), {, }]for/(/1/;/3/</2/;/1/)/{/}^");
314
315 s = @"for(var i = 0; true; true) {}";
316 jsp.tokenizer.string = s;
317 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
318 res = [jsp.forBeginStmtParser bestMatchFor:a];
319 TDEqualObjects([res description], @"[for, (, var, i, =, 0, ;, true, ;, true, ), {, }]for/(/var/i/=/0/;/true/;/true/)/{/}^");
320 }
321
322
323 - (void)testUndefinedParser {
324 s = @"undefined";
325 jsp.tokenizer.string = s;
326 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
327 res = [jsp.undefinedParser bestMatchFor:a];
328 TDEqualObjects([res description], @"[undefined]undefined^");
329 }
330
331
332 - (void)testNullParser {
333 s = @"null";
334 jsp.tokenizer.string = s;
335 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
336 res = [jsp.nullParser bestMatchFor:a];
337 TDEqualObjects([res description], @"[null]null^");
338 }
339
340
341 - (void)testFalseParser {
342 s = @"false";
343 jsp.tokenizer.string = s;
344 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
345 res = [jsp.falseParser bestMatchFor:a];
346 TDEqualObjects([res description], @"[false]false^");
347 }
348
349
350 - (void)testTrueParser {
351 s = @"true";
352 jsp.tokenizer.string = s;
353 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
354 res = [jsp.trueParser bestMatchFor:a];
355 TDEqualObjects([res description], @"[true]true^");
356 }
357
358
359 - (void)testNumberParser {
360 s = @"47.2";
361 jsp.tokenizer.string = s;
362 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
363 res = [jsp.numberParser bestMatchFor:a];
364 TDEqualObjects([res description], @"[47.2]47.2^");
365
366 s = @"-0.20";
367 jsp.tokenizer.string = s;
368 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
369 res = [jsp.numberParser bestMatchFor:a];
370 TDEqualObjects([res description], @"[-0.20]-0.20^");
371
372 s = @"-0.20e6";
373 jsp.tokenizer.string = s;
374 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
375 res = [jsp.numberParser bestMatchFor:a];
376 TDEqualObjects([res description], @"[-0.20e6]-0.20e6^");
377 }
378
379
380 - (void)testStringParser {
381 s = @"'foo'";
382 jsp.tokenizer.string = s;
383 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
384 res = [jsp.stringParser bestMatchFor:a];
385 TDEqualObjects([res description], @"['foo']'foo'^");
386 }
387
388
389 - (void)testFoo {
390 s = @"function() {}";
391 jsp.tokenizer.string = s;
392 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
393 res = [jsp.funcLiteralParser bestMatchFor:a];
394 TDEqualObjects([res description], @"[function, (, ), {, }]function/(/)/{/}^");
395
396 s = @"function() {}";
397 jsp.tokenizer.string = s;
398 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
399 res = [jsp.primaryExprParser bestMatchFor:a];
400 TDEqualObjects([res description], @"[function, (, ), {, }]function/(/)/{/}^");
401
402 s = @"var foo =function(a, b) {return a+b;};";
403 jsp.tokenizer.string = s;
404 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
405 res = [jsp bestMatchFor:a];
406 TDEqualObjects([res description], @"[var, foo, =, function, (, a, ,, b, ), {, return, a, +, b, ;, }, ;]var/foo/=/function/(/a/,/b/)/{/return/a/+/b/;/}/;^");
407
408 s = @"var foo = 'bar';";
409 jsp.tokenizer.string = s;
410 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
411 res = [jsp bestMatchFor:a];
412 TDEqualObjects([res description], @"[var, foo, =, 'bar', ;]var/foo/=/'bar'/;^");
413
414 s = @"foo = 'bar';";
415 jsp.tokenizer.string = s;
416 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
417 res = [jsp bestMatchFor:a];
418 TDEqualObjects([res description], @"[foo, =, 'bar', ;]foo/=/'bar'/;^");
419 }
420
421
422 - (void)testWhileLoop {
423 s = @"while(true) {alert(i++);}";
424 jsp.tokenizer.string = s;
425 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
426 res = [jsp bestMatchFor:a];
427 TDEqualObjects([res description], @"[while, (, true, ), {, alert, (, i, ++, ), ;, }]while/(/true/)/{/alert/(/i/++/)/;/}^");
428
429 s = @"2 < 10;";
430 jsp.tokenizer.string = s;
431 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
432 res = [jsp bestMatchFor:a];
433 TDEqualObjects([res description], @"[2, <, 10, ;]2/</10/;^");
434
435 s = @"while(i<10) {alert(i++);}";
436 jsp.tokenizer.string = s;
437 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
438 res = [jsp bestMatchFor:a];
439 TDEqualObjects([res description], @"[while, (, i, <, 10, ), {, alert, (, i, ++, ), ;, }]while/(/i/</10/)/{/alert/(/i/++/)/;/}^");
440 }
441
442
443 - (void)testForLoop {
444 s = @"for( ; true; true) {}";
445 jsp.tokenizer.string = s;
446 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
447 res = [jsp bestMatchFor:a];
448 TDEqualObjects([res description], @"[for, (, ;, true, ;, true, ), {, }]for/(/;/true/;/true/)/{/}^");
449
450 s = @"i++";
451 jsp.tokenizer.string = s;
452 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
453 res = [jsp.unaryExpr4Parser bestMatchFor:a];
454 TDEqualObjects([res description], @"[i, ++]i/++^");
455
456 s = @"i++";
457 jsp.tokenizer.string = s;
458 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
459 res = [jsp.unaryExprParser bestMatchFor:a];
460 TDEqualObjects([res description], @"[i, ++]i/++^");
461
462 s = @"i++;";
463 jsp.tokenizer.string = s;
464 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
465 res = [jsp bestMatchFor:a];
466 TDEqualObjects([res description], @"[i, ++, ;]i/++/;^");
467
468 s = @"i++";
469 jsp.tokenizer.string = s;
470 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
471 res = [jsp bestMatchFor:a];
472 TDEqualObjects([res description], @"[i, ++]i/++^");
473
474 s = @"for(var i=0; i<10; i++) {alert(i);}";
475 jsp.tokenizer.string = s;
476 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
477 res = [jsp bestMatchFor:a];
478 TDEqualObjects([res description], @"[for, (, var, i, =, 0, ;, i, <, 10, ;, i, ++, ), {, alert, (, i, ), ;, }]for/(/var/i/=/0/;/i/</10/;/i/++/)/{/alert/(/i/)/;/}^");
479 }
480
481
482 - (void)testForInLoop {
483 s = @"for(var p in obj) {alert(p);}";
484 jsp.tokenizer.string = s;
485 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
486 res = [jsp bestMatchFor:a];
487 TDEqualObjects([res description], @"[for, (, var, p, in, obj, ), {, alert, (, p, ), ;, }]for/(/var/p/in/obj/)/{/alert/(/p/)/;/}^");
488
489 s = @"for(var p in obj) alert(p);";
490 jsp.tokenizer.string = s;
491 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
492 res = [jsp bestMatchFor:a];
493 TDEqualObjects([res description], @"[for, (, var, p, in, obj, ), alert, (, p, ), ;]for/(/var/p/in/obj/)/alert/(/p/)/;^");
494
495 s = @"for(var p in obj) {}";
496 jsp.tokenizer.string = s;
497 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
498 res = [jsp bestMatchFor:a];
499 TDEqualObjects([res description], @"[for, (, var, p, in, obj, ), {, }]for/(/var/p/in/obj/)/{/}^");
500
501 s = @"for ( var p in obj );";
502 jsp.tokenizer.string = s;
503 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
504 res = [jsp bestMatchFor:a];
505 TDEqualObjects([res description], @"[for, (, var, p, in, obj, ), ;]for/(/var/p/in/obj/)/;^");
506 }
507
508
509 - (void)testArrayLiteral {
510 s = @"var foo = ['bar'];";
511 jsp.tokenizer.string = s;
512 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
513 res = [jsp bestMatchFor:a];
514 TDEqualObjects([res description], @"[var, foo, =, [, 'bar', ], ;]var/foo/=/[/'bar'/]/;^");
515 }
516
517
518 - (void)testObjectLiteral {
519 s = @"var foo = {foo:'bar'};";
520 jsp.tokenizer.string = s;
521 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
522 res = [jsp bestMatchFor:a];
523 TDEqualObjects([res description], @"[var, foo, =, {, foo, :, 'bar', }, ;]var/foo/=/{/foo/:/'bar'/}/;^");
524 }
525
526
527 - (void)testExecuteAnonFunc {
528 s = @"(function() {})();";
529 jsp.tokenizer.string = s;
530 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
531 res = [jsp bestMatchFor:a];
532 TDEqualObjects([res description], @"[(, function, (, ), {, }, ), (, ), ;](/function/(/)/{/}/)/(/)/;^");
533
534 s = @"(function(a) {alert(a);})();";
535 jsp.tokenizer.string = s;
536 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
537 res = [jsp bestMatchFor:a];
538 TDEqualObjects([res description], @"[(, function, (, a, ), {, alert, (, a, ), ;, }, ), (, ), ;](/function/(/a/)/{/alert/(/a/)/;/}/)/(/)/;^");
539 }
540
541
542 - (void)testSemi {
543 s = @";";
544 jsp.tokenizer.string = s;
545 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
546 res = [jsp bestMatchFor:a];
547 TDEqualObjects([res description], @"[;];^");
548 }
549
550
551 - (void)testString {
552 s = @"'bar';";
553 jsp.tokenizer.string = s;
554 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
555 res = [jsp bestMatchFor:a];
556 TDEqualObjects([res description], @"['bar', ;]'bar'/;^");
557 }
558
559
560 - (void)testMember {
561 s = @"foo.bar;";
562 jsp.tokenizer.string = s;
563 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
564 res = [jsp bestMatchFor:a];
565 TDEqualObjects([res description], @"[foo, ., bar, ;]foo/./bar/;^");
566
567 s = @"foo.bar();";
568 jsp.tokenizer.string = s;
569 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
570 res = [jsp bestMatchFor:a];
571 TDEqualObjects([res description], @"[foo, ., bar, (, ), ;]foo/./bar/(/)/;^");
572
573 s = @"foo[bar];";
574 jsp.tokenizer.string = s;
575 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
576 res = [jsp bestMatchFor:a];
577 TDEqualObjects([res description], @"[foo, [, bar, ], ;]foo/[/bar/]/;^");
578 }
579
580
581 - (void)testConstructor {
582 s = @"new foo();";
583 jsp.tokenizer.string = s;
584 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
585 res = [jsp bestMatchFor:a];
586 TDEqualObjects([res description], @"[new, foo, (, ), ;]new/foo/(/)/;^");
587
588 s = @"var bar = new foo();";
589 jsp.tokenizer.string = s;
590 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
591 res = [jsp bestMatchFor:a];
592 TDEqualObjects([res description], @"[var, bar, =, new, foo, (, ), ;]var/bar/=/new/foo/(/)/;^");
593
594 s = @"baz.bar = new foo();";
595 jsp.tokenizer.string = s;
596 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
597 res = [jsp bestMatchFor:a];
598 TDEqualObjects([res description], @"[baz, ., bar, =, new, foo, (, ), ;]baz/./bar/=/new/foo/(/)/;^");
599
600 s = @"baz[bar] = new foo();";
601 jsp.tokenizer.string = s;
602 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
603 res = [jsp bestMatchFor:a];
604 TDEqualObjects([res description], @"[baz, [, bar, ], =, new, foo, (, ), ;]baz/[/bar/]/=/new/foo/(/)/;^");
605
606 s = @"baz['bar'] = new foo();";
607 jsp.tokenizer.string = s;
608 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
609 res = [jsp bestMatchFor:a];
610 TDEqualObjects([res description], @"[baz, [, 'bar', ], =, new, foo, (, ), ;]baz/[/'bar'/]/=/new/foo/(/)/;^");
611
612 s = @"foo.bar.baz;";
613 jsp.tokenizer.string = s;
614 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
615 res = [jsp bestMatchFor:a];
616 TDEqualObjects([res description], @"[foo, ., bar, ., baz, ;]foo/./bar/./baz/;^");
617
618 s = @"foo[bar].baz;";
619 jsp.tokenizer.string = s;
620 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
621 res = [jsp bestMatchFor:a];
622 TDEqualObjects([res description], @"[foo, [, bar, ], ., baz, ;]foo/[/bar/]/./baz/;^");
623
624 s = @"foo[bar].baz();";
625 jsp.tokenizer.string = s;
626 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
627 res = [jsp bestMatchFor:a];
628 TDEqualObjects([res description], @"[foo, [, bar, ], ., baz, (, ), ;]foo/[/bar/]/./baz/(/)/;^");
629
630 s = @"foo[bar][baz];";
631 jsp.tokenizer.string = s;
632 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
633 res = [jsp bestMatchFor:a];
634 TDEqualObjects([res description], @"[foo, [, bar, ], [, baz, ], ;]foo/[/bar/]/[/baz/]/;^");
635
636 s = @"foo(bar);";
637 jsp.tokenizer.string = s;
638 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
639 res = [jsp bestMatchFor:a];
640 TDEqualObjects([res description], @"[foo, (, bar, ), ;]foo/(/bar/)/;^");
641
642 s = @"foo();";
643 jsp.tokenizer.string = s;
644 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
645 res = [jsp bestMatchFor:a];
646 TDEqualObjects([res description], @"[foo, (, ), ;]foo/(/)/;^");
647
648 s = @"foo()();";
649 jsp.tokenizer.string = s;
650 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
651 res = [jsp bestMatchFor:a];
652 TDEqualObjects([res description], @"[foo, (, ), (, ), ;]foo/(/)/(/)/;^");
653
654 s = @"foo().bat;";
655 jsp.tokenizer.string = s;
656 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
657 res = [jsp bestMatchFor:a];
658 TDEqualObjects([res description], @"[foo, (, ), ., bat, ;]foo/(/)/./bat/;^");
659
660 s = @"foo().bat();";
661 jsp.tokenizer.string = s;
662 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
663 res = [jsp bestMatchFor:a];
664 TDEqualObjects([res description], @"[foo, (, ), ., bat, (, ), ;]foo/(/)/./bat/(/)/;^");
665
666 s = @"foo().bat()[bar];";
667 jsp.tokenizer.string = s;
668 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
669 res = [jsp bestMatchFor:a];
670 TDEqualObjects([res description], @"[foo, (, ), ., bat, (, ), [, bar, ], ;]foo/(/)/./bat/(/)/[/bar/]/;^");
671
672 s = @"new foo();";
673 jsp.tokenizer.string = s;
674 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
675 res = [jsp bestMatchFor:a];
676 TDEqualObjects([res description], @"[new, foo, (, ), ;]new/foo/(/)/;^");
677
678 s = @"new foo;";
679 jsp.tokenizer.string = s;
680 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
681 res = [jsp bestMatchFor:a];
682 TDEqualObjects([res description], @"[new, foo, ;]new/foo/;^");
683
684 s = @"new foo.bar;";
685 jsp.tokenizer.string = s;
686 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
687 res = [jsp bestMatchFor:a];
688 TDEqualObjects([res description], @"[new, foo, ., bar, ;]new/foo/./bar/;^");
689
690 s = @"new foo().bat;";
691 jsp.tokenizer.string = s;
692 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
693 res = [jsp bestMatchFor:a];
694 TDEqualObjects([res description], @"[new, foo, (, ), ., bat, ;]new/foo/(/)/./bat/;^");
695
696 s = @"new String('foo').charAt(0);";
697 jsp.tokenizer.string = s;
698 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
699 res = [jsp bestMatchFor:a];
700 TDEqualObjects([res description], @"[new, String, (, 'foo', ), ., charAt, (, 0, ), ;]new/String/(/'foo'/)/./charAt/(/0/)/;^");
701
702 s = @"new String('foo').charAt(0) instanceof String;";
703 jsp.tokenizer.string = s;
704 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
705 res = [jsp bestMatchFor:a];
706 TDEqualObjects([res description], @"[new, String, (, 'foo', ), ., charAt, (, 0, ), instanceof, String, ;]new/String/(/'foo'/)/./charAt/(/0/)/instanceof/String/;^");
707
708 s = @"new foo()[bar];";
709 jsp.tokenizer.string = s;
710 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
711 res = [jsp bestMatchFor:a];
712 TDEqualObjects([res description], @"[new, foo, (, ), [, bar, ], ;]new/foo/(/)/[/bar/]/;^");
713
714 s = @"new foo.bar();";
715 jsp.tokenizer.string = s;
716 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
717 res = [jsp bestMatchFor:a];
718 TDEqualObjects([res description], @"[new, foo, ., bar, (, ), ;]new/foo/./bar/(/)/;^");
719
720 s = @"new this.bar();";
721 jsp.tokenizer.string = s;
722 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
723 res = [jsp bestMatchFor:a];
724 TDEqualObjects([res description], @"[new, this, ., bar, (, ), ;]new/this/./bar/(/)/;^");
725
726 s = @"new foo().bat[bar];";
727 jsp.tokenizer.string = s;
728 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
729 res = [jsp bestMatchFor:a];
730 TDEqualObjects([res description], @"[new, foo, (, ), ., bat, [, bar, ], ;]new/foo/(/)/./bat/[/bar/]/;^");
731
732 s = @"var _bar = new _foo_();";
733 jsp.tokenizer.string = s;
734 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
735 res = [jsp bestMatchFor:a];
736 TDEqualObjects([res description], @"[var, _bar, =, new, _foo_, (, ), ;]var/_bar/=/new/_foo_/(/)/;^");
737 }
738
739
740 - (void)testDelete {
741 s = @"delete foo[bar];";
742 jsp.tokenizer.string = s;
743 a = [PKTokenAssembly assemblyWithTokenizer:jsp.tokenizer];
744 res = [jsp bestMatchFor:a];
745 TDEqualObjects([res description], @"[delete, foo, [, bar, ], ;]delete/foo/[/bar/]/;^");
746 }
747
748 @end
Something went wrong with that request. Please try again.