| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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:front_end/src/fasta/scanner/string_scanner.dart'; | 5 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; |
| 6 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 6 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| 7 import 'package:front_end/src/scanner/token.dart'; | 7 import 'package:front_end/src/scanner/token.dart'; |
| 8 import 'package:front_end/src/scanner/reader.dart' as analyzer; | 8 import 'package:front_end/src/scanner/reader.dart' as analyzer; |
| 9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 void test_applyDelta() { | 22 void test_applyDelta() { |
| 23 var scanner = new StringScanner('/* 1 */ foo', includeComments: true); | 23 var scanner = new StringScanner('/* 1 */ foo', includeComments: true); |
| 24 var token = scanner.tokenize(); | 24 var token = scanner.tokenize(); |
| 25 expect(token.offset, 8); | 25 expect(token.offset, 8); |
| 26 expect(token.precedingComments.offset, 0); | 26 expect(token.precedingComments.offset, 0); |
| 27 token.applyDelta(12); | 27 token.applyDelta(12); |
| 28 expect(token.offset, 20); | 28 expect(token.offset, 20); |
| 29 expect(token.precedingComments.offset, 12); | 29 expect(token.precedingComments.offset, 12); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void test_comments() { |
| 33 var source = ''' |
| 34 /// Single line dartdoc comment |
| 35 class Foo { |
| 36 /** |
| 37 * Multi-line dartdoc comment |
| 38 */ |
| 39 void bar() { |
| 40 // Single line comment |
| 41 int x = 0; |
| 42 /* Multi-line comment */ |
| 43 x = x + 1; |
| 44 } |
| 45 } |
| 46 '''; |
| 47 var scanner = new StringScanner(source, includeComments: true); |
| 48 fasta.Token token = scanner.tokenize(); |
| 49 |
| 50 Token nextComment() { |
| 51 while (!token.isEof) { |
| 52 Token comment = token.precedingComments; |
| 53 token = token.next; |
| 54 if (comment != null) return comment; |
| 55 } |
| 56 return null; |
| 57 } |
| 58 |
| 59 fasta.Token comment = nextComment(); |
| 60 expect(comment.lexeme, contains('Single line dartdoc comment')); |
| 61 expect(comment.type, TokenType.SINGLE_LINE_COMMENT); |
| 62 |
| 63 comment = nextComment(); |
| 64 expect(comment.lexeme, contains('Multi-line dartdoc comment')); |
| 65 expect(comment.type, TokenType.MULTI_LINE_COMMENT); |
| 66 |
| 67 comment = nextComment(); |
| 68 expect(comment.lexeme, contains('Single line comment')); |
| 69 expect(comment.type, TokenType.SINGLE_LINE_COMMENT); |
| 70 |
| 71 comment = nextComment(); |
| 72 expect(comment.lexeme, contains('Multi-line comment')); |
| 73 expect(comment.type, TokenType.MULTI_LINE_COMMENT); |
| 74 } |
| 75 |
| 32 void test_copy() { | 76 void test_copy() { |
| 33 String source = '/* 1 */ /* 2 */ main() {print("hello"); return;}'; | 77 String source = '/* 1 */ /* 2 */ main() {print("hello"); return;}'; |
| 34 int commentCount = 0; | 78 int commentCount = 0; |
| 35 | 79 |
| 36 void assertCopiedToken(Token token1, Token token2) { | 80 void assertCopiedToken(Token token1, Token token2) { |
| 37 if (token1 == null) { | 81 if (token1 == null) { |
| 38 expect(token2, isNull); | 82 expect(token2, isNull); |
| 39 return; | 83 return; |
| 40 } | 84 } |
| 41 expect(token1.lexeme, token2.lexeme); | 85 expect(token1.lexeme, token2.lexeme); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 token = token.next; | 160 token = token.next; |
| 117 expect(token.lexeme, '&'); | 161 expect(token.lexeme, '&'); |
| 118 expect(token.value(), '&'); | 162 expect(token.value(), '&'); |
| 119 // String tokens | 163 // String tokens |
| 120 token = token.next; | 164 token = token.next; |
| 121 print('String token :: ${token.runtimeType}'); | 165 print('String token :: ${token.runtimeType}'); |
| 122 expect(token.lexeme, '"home"'); | 166 expect(token.lexeme, '"home"'); |
| 123 expect(token.value(), '"home"'); | 167 expect(token.value(), '"home"'); |
| 124 } | 168 } |
| 125 } | 169 } |
| OLD | NEW |