Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: pkg/front_end/test/scanner_fasta_test.dart

Issue 2694433002: Stop testing scanner error lengths. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/front_end/test/scanner_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void test_string_simple_unterminated_interpolation_identifier() { 217 void test_string_simple_unterminated_interpolation_identifier() {
218 // TODO(paulberry,ahe): bad error recovery. 218 // TODO(paulberry,ahe): bad error recovery.
219 super.test_string_simple_unterminated_interpolation_identifier(); 219 super.test_string_simple_unterminated_interpolation_identifier();
220 } 220 }
221 221
222 TestError _translateErrorToken(fasta.ErrorToken token, int inputLength) { 222 TestError _translateErrorToken(fasta.ErrorToken token, int inputLength) {
223 int charOffset = token.charOffset; 223 int charOffset = token.charOffset;
224 // TODO(paulberry,ahe): why is endOffset sometimes null? 224 // TODO(paulberry,ahe): why is endOffset sometimes null?
225 int endOffset = token.endOffset ?? charOffset; 225 int endOffset = token.endOffset ?? charOffset;
226 TestError _makeError(ScannerErrorCode errorCode, List<Object> arguments) { 226 TestError _makeError(ScannerErrorCode errorCode, List<Object> arguments) {
227 int errorLength = endOffset - charOffset;
228 if (charOffset == inputLength) { 227 if (charOffset == inputLength) {
229 // Analyzer never generates an error message past the end of the input, 228 // Analyzer never generates an error message past the end of the input,
230 // since such an error would not be visible in an editor. 229 // since such an error would not be visible in an editor.
231 // TODO(paulberry,ahe): would it make sense to replicate this behavior 230 // TODO(paulberry,ahe): would it make sense to replicate this behavior
232 // in fasta, or move it elsewhere in analyzer? 231 // in fasta, or move it elsewhere in analyzer?
233 charOffset--; 232 charOffset--;
234 } 233 }
235 if (errorLength == 0) { 234 return new TestError(charOffset, errorCode, arguments);
236 // Analyzer never generates an error message of length zero,
237 // since such an error would not be visible in an editor.
238 // TODO(paulberry,ahe): would it make sense to replicate this behavior
239 // in fasta, or move it elsewhere in analyzer?
240 errorLength = 1;
241 }
242 return new TestError(charOffset, errorLength, errorCode, arguments);
243 } 235 }
244 236
245 var errorCode = token.errorCode; 237 var errorCode = token.errorCode;
246 switch (errorCode) { 238 switch (errorCode) {
247 case fasta.ErrorKind.UnterminatedString: 239 case fasta.ErrorKind.UnterminatedString:
248 // TODO(paulberry,ahe): Fasta reports the error location as the entire 240 // TODO(paulberry,ahe): Fasta reports the error location as the entire
249 // string; analyzer expects the end of the string. 241 // string; analyzer expects the end of the string.
250 charOffset = endOffset; 242 charOffset = endOffset;
251 return _makeError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, null); 243 return _makeError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, null);
252 case fasta.ErrorKind.UnmatchedToken: 244 case fasta.ErrorKind.UnmatchedToken:
(...skipping 18 matching lines...) Expand all
271 case fasta.ErrorKind.NonAsciiWhitespace: 263 case fasta.ErrorKind.NonAsciiWhitespace:
272 return _makeError( 264 return _makeError(
273 ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]); 265 ScannerErrorCode.ILLEGAL_CHARACTER, [token.character]);
274 case fasta.ErrorKind.UnexpectedDollarInString: 266 case fasta.ErrorKind.UnexpectedDollarInString:
275 return null; 267 return null;
276 default: 268 default:
277 throw new UnimplementedError('$errorCode'); 269 throw new UnimplementedError('$errorCode');
278 } 270 }
279 } 271 }
280 } 272 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/test/scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698