OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import 'package:compiler/src/scanner/string_scanner.dart'; | 6 import 'package:compiler/src/scanner/string_scanner.dart'; |
7 import 'package:compiler/src/tokens/token.dart'; | 7 import 'package:compiler/src/tokens/token.dart'; |
8 import 'package:compiler/src/tokens/token_constants.dart'; | 8 import 'package:compiler/src/tokens/token_constants.dart'; |
9 | 9 |
10 Token scan(String text) => | 10 Token scan(String text) => |
11 new StringScanner.fromString(text, includeComments: true).tokenize(); | 11 new StringScanner.fromString(text, includeComments: true).tokenize(); |
12 | 12 |
13 check(String text) { | 13 check(String text) { |
14 Token token = scan(text); | 14 Token token = scan(text); |
15 while (token.kind != EOF_TOKEN) { | 15 while (token.kind != EOF_TOKEN) { |
16 Expect.equals(token.value.length, token.charCount); | 16 Expect.equals(token.value.length, token.charCount); |
17 | 17 |
18 var start = token.charOffset; | 18 var start = token.charOffset; |
19 var end = token.charOffset + token.charCount; | 19 var end = token.charOffset + token.charCount; |
20 | 20 |
21 Expect.isTrue(start < text.length, | 21 Expect.isTrue(start < text.length, |
22 'start=$start < text.length=${text.length}: $text'); | 22 'start=$start < text.length=${text.length}: $text'); |
23 | 23 |
24 Expect.isTrue(end <= text.length, | 24 Expect.isTrue( |
25 'end=$end <= text.length=${text.length}: $text'); | 25 end <= text.length, 'end=$end <= text.length=${text.length}: $text'); |
26 | 26 |
27 Expect.isTrue(start <= end, 'start=$end <= end=$end: $text'); | 27 Expect.isTrue(start <= end, 'start=$end <= end=$end: $text'); |
28 | 28 |
29 var substring = text.substring(start, end); | 29 var substring = text.substring(start, end); |
30 | 30 |
31 Expect.stringEquals(token.value, substring, | 31 Expect.stringEquals( |
| 32 token.value, |
| 33 substring, |
32 'token.value=${token.value} == ' | 34 'token.value=${token.value} == ' |
33 'text.substring(start,end)=${substring}: $text'); | 35 'text.substring(start,end)=${substring}: $text'); |
34 | 36 |
35 print('$text: [$start,$end]:$token'); | 37 print('$text: [$start,$end]:$token'); |
36 | 38 |
37 token = token.next; | 39 token = token.next; |
38 } | 40 } |
39 } | 41 } |
40 | 42 |
41 main() { | 43 main() { |
42 check('foo'); // identifier | 44 check('foo'); // identifier |
43 check('\'\''); // empty string | 45 check('\'\''); // empty string |
44 check('\'foo\''); // simple string | 46 check('\'foo\''); // simple string |
45 check('\'\$foo\''); // interpolation, identifier | 47 check('\'\$foo\''); // interpolation, identifier |
46 check('\'\${foo}\''); // interpolation, expression | 48 check('\'\${foo}\''); // interpolation, expression |
47 | 49 |
48 check('//'); // single line comment | 50 check('//'); // single line comment |
49 check('/**/'); // multi line comment | 51 check('/**/'); // multi line comment |
50 } | 52 } |
OLD | NEW |