| 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/analyzer/token_utils.dart'; | 5 import 'package:front_end/src/fasta/analyzer/token_utils.dart'; |
| 6 import 'package:front_end/src/fasta/scanner/error_token.dart' as fasta; | 6 import 'package:front_end/src/fasta/scanner/error_token.dart' as fasta; |
| 7 import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta; | 7 import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta; |
| 8 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; | 8 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; |
| 9 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 9 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| 10 import 'package:front_end/src/fasta/scanner/token_constants.dart' as fasta; | 10 import 'package:front_end/src/fasta/scanner/token_constants.dart' as fasta; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 super.test_ampersand_ampersand_eq(); | 52 super.test_ampersand_ampersand_eq(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 @override | 55 @override |
| 56 @failingTest | 56 @failingTest |
| 57 void test_bar_bar_eq() { | 57 void test_bar_bar_eq() { |
| 58 // TODO(paulberry,ahe): Fasta doesn't support `||=` yet | 58 // TODO(paulberry,ahe): Fasta doesn't support `||=` yet |
| 59 super.test_bar_bar_eq(); | 59 super.test_bar_bar_eq(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void test_comments() { |
| 63 const source = ''' |
| 64 /// Doc comment before class |
| 65 /// second line |
| 66 /// third |
| 67 class Foo { |
| 68 // Random comment |
| 69 Object someField; // trailing comment |
| 70 dynamic secondField; |
| 71 /// Method doc |
| 72 void someMethod(/* comment before closing paren */) { |
| 73 // body comment |
| 74 } |
| 75 /** Doc comment 2 */ |
| 76 Foo2 bar() => new Baz(); |
| 77 } // EOF comment |
| 78 '''; |
| 79 |
| 80 fasta.Token scanSource({bool includeComments}) { |
| 81 return new fasta.StringScanner(source, includeComments: includeComments) |
| 82 .tokenize(); |
| 83 } |
| 84 |
| 85 int tokenCount = 0; |
| 86 fasta.Token token = scanSource(includeComments: false); |
| 87 while (!token.isEof) { |
| 88 ++tokenCount; |
| 89 // Assert no comments |
| 90 expect(token.precedingComments, isNull); |
| 91 expect(token.info.kind, isNot(fasta.COMMENT_TOKEN)); |
| 92 token = token.next; |
| 93 } |
| 94 expect(token.precedingComments, isNull); |
| 95 expect(tokenCount, 26); |
| 96 |
| 97 tokenCount = 0; |
| 98 int previousEnd = 0; |
| 99 int spotCheckCount = 0; |
| 100 int commentTokenCount = 0; |
| 101 token = scanSource(includeComments: true); |
| 102 while (!token.isEof) { |
| 103 ++tokenCount; |
| 104 // Assert valid comments |
| 105 fasta.Token comment = token.precedingComments; |
| 106 while (comment != null) { |
| 107 ++commentTokenCount; |
| 108 expect(comment.info.kind, fasta.COMMENT_TOKEN); |
| 109 expect(comment.charOffset, greaterThanOrEqualTo(previousEnd)); |
| 110 previousEnd = comment.charOffset + comment.charCount; |
| 111 comment = comment.next; |
| 112 } |
| 113 expect(token.info.kind, isNot(fasta.COMMENT_TOKEN)); |
| 114 expect(token.charOffset, greaterThanOrEqualTo(previousEnd)); |
| 115 previousEnd = token.charOffset + token.charCount; |
| 116 |
| 117 // Spot check for specific token/comment combinations |
| 118 if (token.value == 'class') { |
| 119 ++spotCheckCount; |
| 120 expect(token.precedingComments?.value, '/// Doc comment before class'); |
| 121 expect(token.precedingComments?.next?.value, '/// second line'); |
| 122 expect(token.precedingComments?.next?.next?.value, '/// third'); |
| 123 expect(token.precedingComments?.next?.next?.next, isNull); |
| 124 } else if (token.value == 'Foo2') { |
| 125 ++spotCheckCount; |
| 126 expect(token.precedingComments?.value, '/** Doc comment 2 */'); |
| 127 } else if (token.value == ')') { |
| 128 if (token.precedingComments != null) { |
| 129 ++spotCheckCount; |
| 130 expect(token.precedingComments?.value, |
| 131 '/* comment before closing paren */'); |
| 132 expect(token.precedingComments?.next, isNull); |
| 133 } |
| 134 } |
| 135 |
| 136 token = token.next; |
| 137 } |
| 138 expect(tokenCount, 26); |
| 139 expect(spotCheckCount, 3); |
| 140 expect(commentTokenCount, 9); |
| 141 expect(token.precedingComments?.value, '// EOF comment'); |
| 142 } |
| 143 |
| 62 @override | 144 @override |
| 63 @failingTest | 145 @failingTest |
| 64 void test_comment_generic_method_type_assign() { | 146 void test_comment_generic_method_type_assign() { |
| 65 // TODO(paulberry,ahe): Fasta doesn't support generic method comment syntax. | 147 // TODO(paulberry,ahe): Fasta doesn't support generic method comment syntax. |
| 66 super.test_comment_generic_method_type_assign(); | 148 super.test_comment_generic_method_type_assign(); |
| 67 } | 149 } |
| 68 | 150 |
| 69 @override | 151 @override |
| 70 @failingTest | 152 @failingTest |
| 71 void test_comment_generic_method_type_list() { | 153 void test_comment_generic_method_type_list() { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 final ErrorListener _listener; | 479 final ErrorListener _listener; |
| 398 | 480 |
| 399 ToAnalyzerTokenStreamConverter_WithListener(this._listener); | 481 ToAnalyzerTokenStreamConverter_WithListener(this._listener); |
| 400 | 482 |
| 401 @override | 483 @override |
| 402 void reportError( | 484 void reportError( |
| 403 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 485 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
| 404 _listener.errors.add(new TestError(offset, errorCode, arguments)); | 486 _listener.errors.add(new TestError(offset, errorCode, arguments)); |
| 405 } | 487 } |
| 406 } | 488 } |
| OLD | NEW |