| 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:analyzer/src/fasta/token_utils.dart'; | 5 import 'package:analyzer/src/fasta/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/string_scanner.dart' as fasta; | 7 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; |
| 8 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 8 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| 9 import 'package:front_end/src/fasta/scanner/token_constants.dart' as fasta; | 9 import 'package:front_end/src/fasta/scanner/token_constants.dart' as fasta; |
| 10 import 'package:front_end/src/scanner/errors.dart'; | 10 import 'package:front_end/src/scanner/errors.dart'; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 return new fasta.StringScanner(source, includeComments: includeComments) | 75 return new fasta.StringScanner(source, includeComments: includeComments) |
| 76 .tokenize(); | 76 .tokenize(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 int tokenCount = 0; | 79 int tokenCount = 0; |
| 80 fasta.Token token = scanSource(includeComments: false); | 80 fasta.Token token = scanSource(includeComments: false); |
| 81 while (!token.isEof) { | 81 while (!token.isEof) { |
| 82 ++tokenCount; | 82 ++tokenCount; |
| 83 // Assert no comments | 83 // Assert no comments |
| 84 expect(token.precedingComments, isNull); | 84 expect(token.precedingComments, isNull); |
| 85 expect(token.info.kind, isNot(fasta.COMMENT_TOKEN)); | 85 expect(token.type.kind, isNot(fasta.COMMENT_TOKEN)); |
| 86 token = token.next; | 86 token = token.next; |
| 87 } | 87 } |
| 88 expect(token.precedingComments, isNull); | 88 expect(token.precedingComments, isNull); |
| 89 expect(tokenCount, 26); | 89 expect(tokenCount, 26); |
| 90 | 90 |
| 91 tokenCount = 0; | 91 tokenCount = 0; |
| 92 int previousEnd = 0; | 92 int previousEnd = 0; |
| 93 int spotCheckCount = 0; | 93 int spotCheckCount = 0; |
| 94 int commentTokenCount = 0; | 94 int commentTokenCount = 0; |
| 95 token = scanSource(includeComments: true); | 95 token = scanSource(includeComments: true); |
| 96 while (!token.isEof) { | 96 while (!token.isEof) { |
| 97 ++tokenCount; | 97 ++tokenCount; |
| 98 // Assert valid comments | 98 // Assert valid comments |
| 99 fasta.CommentToken comment = token.precedingComments; | 99 fasta.CommentToken comment = token.precedingComments; |
| 100 while (comment != null) { | 100 while (comment != null) { |
| 101 ++commentTokenCount; | 101 ++commentTokenCount; |
| 102 expect(comment.info.kind, fasta.COMMENT_TOKEN); | 102 expect(comment.type.kind, fasta.COMMENT_TOKEN); |
| 103 expect(comment.charOffset, greaterThanOrEqualTo(previousEnd)); | 103 expect(comment.charOffset, greaterThanOrEqualTo(previousEnd)); |
| 104 previousEnd = comment.charOffset + comment.charCount; | 104 previousEnd = comment.charOffset + comment.charCount; |
| 105 comment = comment.next; | 105 comment = comment.next; |
| 106 } | 106 } |
| 107 expect(token.info.kind, isNot(fasta.COMMENT_TOKEN)); | 107 expect(token.type.kind, isNot(fasta.COMMENT_TOKEN)); |
| 108 expect(token.charOffset, greaterThanOrEqualTo(previousEnd)); | 108 expect(token.charOffset, greaterThanOrEqualTo(previousEnd)); |
| 109 previousEnd = token.charOffset + token.charCount; | 109 previousEnd = token.charOffset + token.charCount; |
| 110 | 110 |
| 111 // Spot check for specific token/comment combinations | 111 // Spot check for specific token/comment combinations |
| 112 if (token.lexeme == 'class') { | 112 if (token.lexeme == 'class') { |
| 113 ++spotCheckCount; | 113 ++spotCheckCount; |
| 114 expect(token.precedingComments?.lexeme, '/// Doc comment before class'); | 114 expect(token.precedingComments?.lexeme, '/// Doc comment before class'); |
| 115 expect(token.precedingComments?.next?.lexeme, '/// second line'); | 115 expect(token.precedingComments?.next?.lexeme, '/// second line'); |
| 116 expect(token.precedingComments?.next?.next?.lexeme, '/// third'); | 116 expect(token.precedingComments?.next?.next?.lexeme, '/// third'); |
| 117 expect(token.precedingComments?.next?.next?.next, isNull); | 117 expect(token.precedingComments?.next?.next?.next, isNull); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 144 '''; | 144 '''; |
| 145 | 145 |
| 146 fasta.Token token; | 146 fasta.Token token; |
| 147 fasta.CommentToken c1; | 147 fasta.CommentToken c1; |
| 148 fasta.CommentToken c2; | 148 fasta.CommentToken c2; |
| 149 fasta.CommentToken c3; | 149 fasta.CommentToken c3; |
| 150 | 150 |
| 151 void prepareTokens() { | 151 void prepareTokens() { |
| 152 token = new fasta.StringScanner(code, includeComments: true).tokenize(); | 152 token = new fasta.StringScanner(code, includeComments: true).tokenize(); |
| 153 | 153 |
| 154 expect(token.info.kind, fasta.IDENTIFIER_TOKEN); | 154 expect(token.type.kind, fasta.IDENTIFIER_TOKEN); |
| 155 | 155 |
| 156 c1 = token.precedingCommentTokens; | 156 c1 = token.precedingCommentTokens; |
| 157 c2 = c1.next; | 157 c2 = c1.next; |
| 158 c3 = c2.next; | 158 c3 = c2.next; |
| 159 expect(c3.next, isNull); | 159 expect(c3.next, isNull); |
| 160 | 160 |
| 161 expect(c1.parent, token); | 161 expect(c1.parent, token); |
| 162 expect(c2.parent, token); | 162 expect(c2.parent, token); |
| 163 expect(c3.parent, token); | 163 expect(c3.parent, token); |
| 164 | 164 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 final ErrorListener _listener; | 556 final ErrorListener _listener; |
| 557 | 557 |
| 558 ToAnalyzerTokenStreamConverter_WithListener(this._listener); | 558 ToAnalyzerTokenStreamConverter_WithListener(this._listener); |
| 559 | 559 |
| 560 @override | 560 @override |
| 561 void reportError( | 561 void reportError( |
| 562 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 562 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
| 563 _listener.errors.add(new TestError(offset, errorCode, arguments)); | 563 _listener.errors.add(new TestError(offset, errorCode, arguments)); |
| 564 } | 564 } |
| 565 } | 565 } |
| OLD | NEW |