| 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 'dart:convert' show UTF8; | 5 import 'dart:convert' show UTF8; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/scanner/recover.dart' | 7 import 'package:front_end/src/fasta/scanner/recover.dart' |
| 8 show defaultRecoveryStrategy; | 8 show defaultRecoveryStrategy; |
| 9 import 'package:front_end/src/fasta/scanner.dart' as fasta; | 9 import 'package:front_end/src/fasta/scanner.dart' as fasta; |
| 10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 }); | 23 }); |
| 24 } | 24 } |
| 25 | 25 |
| 26 /// Scanner tests that use the analyzer scanner, then convert the resulting | 26 /// Scanner tests that use the analyzer scanner, then convert the resulting |
| 27 /// token stream into a Fasta token stream, then convert back to an analyzer | 27 /// token stream into a Fasta token stream, then convert back to an analyzer |
| 28 /// token stream before verifying assertions. | 28 /// token stream before verifying assertions. |
| 29 /// | 29 /// |
| 30 /// These tests help to validate the correctness of the analyzer->Fasta token | 30 /// These tests help to validate the correctness of the analyzer->Fasta token |
| 31 /// stream conversion. | 31 /// stream conversion. |
| 32 @reflectiveTest | 32 @reflectiveTest |
| 33 class ScannerTest_Replacement extends ScannerTest { | 33 class ScannerTest_Replacement extends ScannerTestBase { |
| 34 ScannerTest_Replacement() { |
| 35 usingFasta = true; |
| 36 } |
| 37 |
| 34 @override | 38 @override |
| 35 analyzer.Token scanWithListener(String source, ErrorListener listener, | 39 analyzer.Token scanWithListener(String source, ErrorListener listener, |
| 36 {bool genericMethodComments: false, | 40 {bool genericMethodComments: false, |
| 37 bool lazyAssignmentOperators: false}) { | 41 bool lazyAssignmentOperators: false}) { |
| 42 // Process the source similar to |
| 43 // pkg/analyzer/lib/src/dart/scanner/scanner.dart |
| 44 // to simulate replacing the analyzer scanner |
| 45 |
| 38 fasta.ScannerResult result = fasta.scanString(source, | 46 fasta.ScannerResult result = fasta.scanString(source, |
| 39 includeComments: true, | 47 includeComments: true, |
| 40 scanGenericMethodComments: genericMethodComments, | 48 scanGenericMethodComments: genericMethodComments, |
| 41 scanLazyAssignmentOperators: lazyAssignmentOperators, | 49 scanLazyAssignmentOperators: lazyAssignmentOperators, |
| 42 recover: ((List<int> bytes, fasta.Token tokens, List<int> lineStarts) { | 50 recover: ((List<int> bytes, fasta.Token tokens, List<int> lineStarts) { |
| 43 // perform recovery as a separate step | 51 // perform recovery as a separate step |
| 44 // so that the token stream can be validated before and after recovery | 52 // so that the token stream can be validated before and after recovery |
| 45 return tokens; | 53 return tokens; |
| 46 })); | 54 })); |
| 55 |
| 47 fasta.Token tokens = result.tokens; | 56 fasta.Token tokens = result.tokens; |
| 48 assertValidTokenStream(tokens); | 57 assertValidTokenStream(tokens); |
| 49 assertValidBeginTokens(tokens); | 58 assertValidBeginTokens(tokens); |
| 50 if (result.hasErrors) { | 59 if (result.hasErrors) { |
| 51 List<int> bytes = UTF8.encode(source); | 60 List<int> bytes = UTF8.encode(source); |
| 52 tokens = defaultRecoveryStrategy(bytes, tokens, result.lineStarts); | 61 tokens = defaultRecoveryStrategy(bytes, tokens, result.lineStarts); |
| 53 assertValidTokenStream(tokens, errorsFirst: true); | 62 assertValidTokenStream(tokens, errorsFirst: true); |
| 54 } | 63 } |
| 64 |
| 65 // fasta pretends there is an additional line at EOF |
| 66 result.lineStarts.removeLast(); |
| 67 |
| 55 return extractErrors(tokens, listener); | 68 return extractErrors(tokens, listener); |
| 56 } | 69 } |
| 57 | 70 |
| 58 void _assertOpenClosePair(String source) { | 71 void _assertOpenClosePair(String source) { |
| 59 analyzer.BeginToken open = _scan(source); | 72 analyzer.BeginToken open = _scan(source); |
| 60 fasta.Token close = open.next; | 73 fasta.Token close = open.next; |
| 61 expect(close.next.isEof, isTrue); | 74 expect(close.next.isEof, isTrue); |
| 62 expect(open.endGroup, close); | 75 expect(open.endGroup, close); |
| 63 expect(open.isSynthetic, isFalse); | 76 expect(open.isSynthetic, isFalse); |
| 64 expect(close.isSynthetic, isFalse); | 77 expect(close.isSynthetic, isFalse); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } else if (token is fasta.UnmatchedToken) { | 365 } else if (token is fasta.UnmatchedToken) { |
| 353 expect(lastClosedGroup?.endGroup?.next, same(token), | 366 expect(lastClosedGroup?.endGroup?.next, same(token), |
| 354 reason: 'Unexpected error token for group: $lastClosedGroup'); | 367 reason: 'Unexpected error token for group: $lastClosedGroup'); |
| 355 expect(token.begin, lastClosedGroup); | 368 expect(token.begin, lastClosedGroup); |
| 356 } | 369 } |
| 357 token = token.next; | 370 token = token.next; |
| 358 } | 371 } |
| 359 expect(openerStack, isEmpty, reason: 'Missing closers'); | 372 expect(openerStack, isEmpty, reason: 'Missing closers'); |
| 360 } | 373 } |
| 361 } | 374 } |
| OLD | NEW |