-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestScanner.java
More file actions
583 lines (519 loc) · 20.1 KB
/
Copy pathTestScanner.java
File metadata and controls
583 lines (519 loc) · 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
package cop5555sp15;
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
import cop5555sp15.TokenStream;
import cop5555sp15.TokenStream.Kind;
import cop5555sp15.TokenStream.Token;
import static cop5555sp15.TokenStream.Kind.*;
public class TestScanner {
private TokenStream scanInput(String input) {
System.out.println(input);
TokenStream stream = new TokenStream(input);
Scanner scanner = new Scanner(stream);
scanner.scan();
System.out.println(stream);
return stream;
}
// Creates an array containing the kinds of the tokens in the token list
private Kind[] makeKindArray(TokenStream stream) {
Kind[] kinds = new Kind[stream.tokens.size()];
for (int i = 0; i < stream.tokens.size(); ++i) {
kinds[i] = stream.tokens.get(i).kind;
}
return kinds;
}
// Creates an array containing the texts of the tokens in the token list
private String[] makeTokenTextArray(TokenStream stream) {
String[] kinds = new String[stream.tokens.size()];
for (int i = 0; i < stream.tokens.size(); ++i) {
kinds[i] = stream.tokens.get(i).getText();
}
return kinds;
}
@Test
public void emptyInput() {
System.out.println("Test: emptyInput");
String input = "";
TokenStream stream = scanInput(input);
assertEquals(1, stream.tokens.size()); // creates EOF token
assertEquals(EOF, stream.nextToken().kind);
}
@Test
public void noWhiteSpace() {
System.out.println("Test: noWhitespace");
String input = "@%";
TokenStream stream = scanInput(input);
assertEquals(3, stream.tokens.size()); // one each for @ and %, plus the
// eof
// token
assertEquals(AT, stream.nextToken().kind);
assertEquals(MOD, stream.nextToken().kind);
assertEquals(EOF, stream.nextToken().kind);
}
@Test
public void errorToken() {
System.out.println("Test: noWhitespace");
String input = "@# *";
TokenStream stream = scanInput(input);
assertEquals(4, stream.tokens.size()); // one each for @,#, and *, plus
// the eof token
assertEquals(AT, stream.nextToken().kind);
assertEquals(ILLEGAL_CHAR, stream.nextToken().kind);
assertEquals(TIMES, stream.nextToken().kind);
assertEquals(EOF, stream.nextToken().kind);
}
@Test
public void onlySpaces() {
System.out.println("Test: onlySpaces");
String input = " "; // five spaces
System.out.println("input is five spaces");
TokenStream stream = new TokenStream(input);
Scanner scanner = new Scanner(stream);
scanner.scan();
assertEquals(1, stream.tokens.size()); // creates EOF token
Token t = stream.nextToken();
System.out.println(stream);
assertEquals(EOF, t.kind);
assertEquals(5, t.beg);
}
@Test
public void skipWhiteSpace() {
System.out.println("skipWhiteSpace");
String input = " ;;; %@%\n \r \r\n ;;;";
TokenStream stream = scanInput(input);
assertEquals(SEMICOLON, stream.nextToken().kind);
assertEquals(SEMICOLON, stream.nextToken().kind);
assertEquals(SEMICOLON, stream.nextToken().kind);
assertEquals(MOD, stream.nextToken().kind);
assertEquals(AT, stream.nextToken().kind);
assertEquals(MOD, stream.nextToken().kind);
assertEquals(SEMICOLON, stream.nextToken().kind);
assertEquals(SEMICOLON, stream.nextToken().kind);
Token t = stream.nextToken();
assertEquals(SEMICOLON, t.kind);
assertEquals(4,t.getLineNumber());
}
@Test
public void dotsAndRanges() {
System.out.println("dotsAndRanges");
String input = ".\n..\n.. . . ..\n...\n";
TokenStream stream = scanInput(input);
assertEquals(DOT, stream.nextToken().kind);
assertEquals(RANGE, stream.nextToken().kind);
assertEquals(RANGE, stream.nextToken().kind);
assertEquals(DOT, stream.nextToken().kind);
assertEquals(DOT, stream.nextToken().kind);
assertEquals(RANGE, stream.nextToken().kind);
assertEquals(RANGE, stream.nextToken().kind);
assertEquals(DOT, stream.nextToken().kind);
assertEquals(EOF, stream.nextToken().kind);
assertEquals(3, stream.tokens.get(5).getLineNumber());// 5th token is on
// line 3
}
@Test
public void firstPartAtEndOfInput() {
System.out.println("firstPartATEndOfInput");
String input = "!";
TokenStream stream = scanInput(input);
assertEquals(NOT, stream.nextToken().kind);
assertEquals(EOF, stream.nextToken().kind);
}
@Test
public void twoStateTokens() {
System.out.println("twoStateTokens");
String input = "= == =\n= ! != - -> -! =!!";
TokenStream stream = scanInput(input);
assertEquals(ASSIGN, stream.nextToken().kind);
assertEquals(EQUAL, stream.nextToken().kind);
assertEquals(ASSIGN, stream.nextToken().kind);
assertEquals(ASSIGN, stream.nextToken().kind);
assertEquals(NOT, stream.nextToken().kind);
assertEquals(NOTEQUAL, stream.nextToken().kind);
assertEquals(MINUS, stream.nextToken().kind);
assertEquals(ARROW, stream.nextToken().kind);
assertEquals(MINUS, stream.nextToken().kind);
assertEquals(NOT, stream.nextToken().kind);
assertEquals(ASSIGN, stream.nextToken().kind);
assertEquals(NOT, stream.nextToken().kind);
assertEquals(NOT, stream.nextToken().kind);
assertEquals(EOF, stream.nextToken().kind);
}
// This test constructs the exptected token list and compares to the one
// created by the Scanner
@Test
public void compareTokenList() {
System.out.println("compareTokenList");
String input = "= ==";
TokenStream stream = scanInput(input);
Token t0 = stream.new Token(ASSIGN, 0, 1, 1);
Token t1 = stream.new Token(EQUAL, 2, 4, 1);
Token t2 = stream.new Token(EOF, 4, 4, 1);
ArrayList<Token> expected_tokens = new ArrayList<Token>();
expected_tokens.add(t0);
expected_tokens.add(t1);
expected_tokens.add(t2);
assertArrayEquals(expected_tokens.toArray(), stream.tokens.toArray());
}
@Test
public void lessAndGreater() {
System.out.println("lessAndGreater");
String input = " < << <= > >> >= -> <>";
TokenStream stream = scanInput(input);
assertEquals(LT, stream.nextToken().kind);
assertEquals(LSHIFT, stream.nextToken().kind);
assertEquals(LE, stream.nextToken().kind);
assertEquals(GT, stream.nextToken().kind);
assertEquals(RSHIFT, stream.nextToken().kind);
assertEquals(GE, stream.nextToken().kind);
assertEquals(ARROW, stream.nextToken().kind);
assertEquals(LT, stream.nextToken().kind);
assertEquals(GT, stream.nextToken().kind);
assertEquals(EOF, stream.nextToken().kind);
}
@Test
public void intLiterals() {
System.out.println("lessAndGreater");
String input = "0 1 23 45+ 67<=9";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { INT_LIT, INT_LIT, INT_LIT, INT_LIT, PLUS,
INT_LIT, LE, INT_LIT, EOF };
String[] expectedTexts = { "0", "1", "23", "45", "+", "67", "<=", "9",
"" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void stringLiterals() {
System.out.println("stringLiterals");
String input = " \"abc\" \"def\" \"ghijk\" \"123\" \"&^%$\" ";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { STRING_LIT, STRING_LIT, STRING_LIT,
STRING_LIT, STRING_LIT, EOF };
String[] expectedTexts = { "abc", "def", "ghijk", "123", "&^%$", "" }; // need
// empty
// string
// for
// eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void identifiers() {
System.out.println("identifiers");
String input = " abc ddef ghijk 123 a234 32a";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { IDENT, IDENT, IDENT, INT_LIT, IDENT, INT_LIT,
IDENT, EOF };
String[] expectedTexts = { "abc", "ddef", "ghijk", "123", "a234", "32",
"a", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void keywords() {
System.out.println("keywords");
String input = " int string boolean import class def while if else return print aaa";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { KW_INT, KW_STRING, KW_BOOLEAN, KW_IMPORT,
KW_CLASS, KW_DEF, KW_WHILE, KW_IF, KW_ELSE, KW_RETURN,
KW_PRINT, IDENT, EOF };
String[] expectedTexts = { "int", "string", "boolean", "import",
"class", "def", "while", "if", "else", "return", "print",
"aaa", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void boolAndNullLiterals() {
System.out.println("boolAndNullLiterals");
String input = " true false\n null";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { BL_TRUE, BL_FALSE, NL_NULL, EOF };
String[] expectedTexts = { "true", "false", "null", "" }; // need empty
// string
// for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void multiLineString() {
System.out.println("multiLineString");
String input = " \"true false\n null\" ";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { STRING_LIT, EOF };
String[] expectedTexts = { "true false\n null", "" }; // need empty
// string for
// eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void comments() {
System.out.println("comments");
String input = "/**/ 0 1 45+ 67<=9";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { INT_LIT, INT_LIT, INT_LIT, PLUS, INT_LIT, LE,
INT_LIT, EOF };
String[] expectedTexts = { "0", "1", "45", "+", "67", "<=", "9", "" }; // need
// empty
// string
// for
// eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void comments2() {
System.out.println("comments2");
String input = "/**/ 0 1 /** ***/ 45+ 67<=9";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { INT_LIT, INT_LIT, INT_LIT, PLUS, INT_LIT, LE,
INT_LIT, EOF };
String[] expectedTexts = { "0", "1", "45", "+", "67", "<=", "9", "" }; // need
// empty
// string
// for
// eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void comments3() {
System.out.println("comments3");
String input = "/**/ 0 1 /** ***/ 45+ 67<=9/*";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { INT_LIT, INT_LIT, INT_LIT, PLUS, INT_LIT, LE,
INT_LIT, UNTERMINATED_COMMENT, EOF };
String[] expectedTexts = { "0", "1", "45", "+", "67", "<=", "9", "/*",
"" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void onlyComment() {
System.out.println("onlyComment");
String input = "/**/";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { EOF };
String[] expectedTexts = { "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void singleSlash(){
System.out.println("singleSlash");
String input = "/";
TokenStream stream = scanInput(input);
assertEquals(DIV, stream.nextToken().kind);
}
// Added By Nakul
@Test
public void separators1(){
String input = ",()[]";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { COMMA, LPAREN, RPAREN, LSQUARE, RSQUARE, EOF };
String[] expectedTexts = { ",", "(", ")", "[", "]", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void separators2(){
String input = "{}:?";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { LCURLY, RCURLY, COLON, QUESTION, EOF };
String[] expectedTexts = { "{", "}", ":", "?", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void operators1(){
String input = "|&<> ";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { BAR, AND, LT, GT, EOF };
String[] expectedTexts = { "|", "&", "<", ">", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void operators2(){
String input = ">= << >>";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { GE, LSHIFT, RSHIFT, EOF };
String[] expectedTexts = { ">=", "<<", ">>", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void twoCharOperators1(){
String input = "<< < <<<";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { LSHIFT, LT, LSHIFT, LT, EOF };
String[] expectedTexts = { "<<", "<", "<<", "<", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void twoCharOperators2(){
String input = ">>> > >>";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { RSHIFT, GT, GT, RSHIFT, EOF };
String[] expectedTexts = { ">>", ">", ">", ">>", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void twoCharOperators3(){
String input = ">>>==== ";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { RSHIFT, GE, EQUAL, ASSIGN, EOF };
String[] expectedTexts = { ">>", ">=", "==", "=", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void twoCharOperators4(){
String input = "<<<<=!=!=";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { LSHIFT, LSHIFT, ASSIGN, NOTEQUAL, NOTEQUAL, EOF };
String[] expectedTexts = { "<<", "<<", "=", "!=", "!=", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void twoCharSeparator1(){
String input = ".......";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { RANGE, RANGE, RANGE, DOT, EOF };
String[] expectedTexts = { "..", "..", "..", ".", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void almostKeywords1(){
String input = "inta stringb booleanc importa classb defc ";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { IDENT, IDENT, IDENT, IDENT, IDENT, IDENT, EOF };
assertArrayEquals(expectedKinds, makeKindArray(stream));
}
@Test
public void almostKeywords2(){
String input = "whiled ifc elseg returnb printm";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { IDENT, IDENT, IDENT, IDENT, IDENT, EOF };
assertArrayEquals(expectedKinds, makeKindArray(stream));
}
@Test
public void almostKeywords3(){
String input = "true$ false_ nulll";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { IDENT, IDENT, IDENT, EOF };
assertArrayEquals(expectedKinds, makeKindArray(stream));
}
@Test
public void illegalChars(){
String input = "# ^ ~ ` '";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { ILLEGAL_CHAR, ILLEGAL_CHAR, ILLEGAL_CHAR, ILLEGAL_CHAR, ILLEGAL_CHAR, EOF };
String[] expectedTexts = { "#", "^", "~", "`", "'", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void identsTest1(){
String input = "$ $8 a$a $$$ aa$9";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { IDENT, IDENT, IDENT, IDENT, IDENT, EOF };
String[] expectedTexts = {"$", "$8", "a$a", "$$$", "aa$9", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void identsTest2(){
String input = "_ _8 a_a ___ aa_9";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { IDENT, IDENT, IDENT, IDENT, IDENT, EOF };
String[] expectedTexts = {"_", "_8", "a_a", "___", "aa_9", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void commentsTest1(){
String input = "X /* \n\r\n\r\n\r */ X";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { IDENT, IDENT, EOF };
String[] expectedTexts = {"X", "X", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void commentsTest2(){
String input = "X /* \n\r\n\r\n\r X";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { IDENT, UNTERMINATED_COMMENT, EOF };
assertArrayEquals(expectedKinds, makeKindArray(stream));
}
@Test
public void commentsTest3(){
String input = "/* /* */ */";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { TIMES, DIV, EOF };
String[] expectedTexts = {"*", "/", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void stringLiteralTest1(){
String input = "\" a\n b \"";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { STRING_LIT, EOF };
String[] expectedTexts = {" a\n b ", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void stringLiteralTest2(){
String input = "\" a\r\n b \"";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { STRING_LIT, EOF };
String[] expectedTexts = {" a\r\n b ", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void stringLiteralTest3(){
String input = "\" a\\\" b \"";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { STRING_LIT, EOF };
String[] expectedTexts = {" a\" b ", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void stringLiteralTest4(){
String input = "\" a\\\n b \"";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { STRING_LIT, EOF };
String[] expectedTexts = {" a\n b ", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void stringLiteralTest5(){
String input = "\" a\\\r b \"";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { STRING_LIT, EOF };
String[] expectedTexts = {" a\r b ", "" }; // need empty string for eof
assertArrayEquals(expectedKinds, makeKindArray(stream));
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
}
@Test
public void intLiteralTest1(){
String input = "5 0 01 100 1251";
TokenStream stream = scanInput(input);
Kind[] expectedKinds = { INT_LIT, INT_LIT, INT_LIT, INT_LIT, INT_LIT, INT_LIT, EOF };
String[] expectedTexts = {"5", "0", "0", "1", "100", "1251", "" }; // need empty string for eof
assertArrayEquals(expectedTexts, makeTokenTextArray(stream));
assertArrayEquals(expectedKinds, makeKindArray(stream));
}
}