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/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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 expect(commentToken.next.previousToken, commentToken); | 183 expect(commentToken.next.previousToken, commentToken); |
184 } | 184 } |
185 commentToken = commentToken.next; | 185 commentToken = commentToken.next; |
186 } | 186 } |
187 token = token.next; | 187 token = token.next; |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 @override | 191 @override |
192 @failingTest | 192 @failingTest |
| 193 void test_incomplete_string_interpolation() { |
| 194 // TODO(danrubel): fix ToAnalyzerTokenStreamConverter_WithListener |
| 195 // to handle synthetic closers in token stream |
| 196 super.test_incomplete_string_interpolation(); |
| 197 } |
| 198 |
| 199 @override |
| 200 void test_mismatched_opener_in_interpolation() { |
| 201 // When openers and closers are mismatched, |
| 202 // fasta favors considering the opener to be mismatched |
| 203 // and inserts synthetic closers as needed. |
| 204 // r'"${({(}}"' is parsed as r'"${({()})}"' |
| 205 // where both ')' are synthetic |
| 206 var stringStart = _scan(r'"${({(}}"'); |
| 207 var interpolationStart = stringStart.next as BeginToken; |
| 208 var openParen1 = interpolationStart.next as BeginToken; |
| 209 var openBrace = openParen1.next as BeginToken; |
| 210 var openParen2 = openBrace.next as BeginToken; |
| 211 var closeParen2 = openParen2.next; |
| 212 var closeBrace = closeParen2.next; |
| 213 var closeParen1 = closeBrace.next; |
| 214 var interpolationEnd = closeParen1.next; |
| 215 var stringEnd = interpolationEnd.next; |
| 216 expect(stringEnd.next.type, TokenType.EOF); |
| 217 expect(interpolationStart.endToken, same(interpolationEnd)); |
| 218 expect(openParen1.endToken, same(closeParen1)); |
| 219 expect(openBrace.endToken, same(closeBrace)); |
| 220 expect(openParen2.endToken, same(closeParen2)); |
| 221 } |
| 222 |
| 223 @override |
| 224 @failingTest |
193 void test_string_multi_unterminated() { | 225 void test_string_multi_unterminated() { |
194 // TODO(paulberry,ahe): bad error recovery. | 226 // TODO(paulberry,ahe): bad error recovery. |
195 super.test_string_multi_unterminated(); | 227 super.test_string_multi_unterminated(); |
196 } | 228 } |
197 | 229 |
198 @override | 230 @override |
199 @failingTest | 231 @failingTest |
200 void test_string_multi_unterminated_interpolation_block() { | 232 void test_string_multi_unterminated_interpolation_block() { |
201 // TODO(paulberry,ahe): bad error recovery. | 233 // TODO(paulberry,ahe): bad error recovery. |
202 super.test_string_multi_unterminated_interpolation_block(); | 234 super.test_string_multi_unterminated_interpolation_block(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // TODO(paulberry,ahe): bad error recovery. | 282 // TODO(paulberry,ahe): bad error recovery. |
251 super.test_string_simple_unterminated_interpolation_block(); | 283 super.test_string_simple_unterminated_interpolation_block(); |
252 } | 284 } |
253 | 285 |
254 @override | 286 @override |
255 @failingTest | 287 @failingTest |
256 void test_string_simple_unterminated_interpolation_identifier() { | 288 void test_string_simple_unterminated_interpolation_identifier() { |
257 // TODO(paulberry,ahe): bad error recovery. | 289 // TODO(paulberry,ahe): bad error recovery. |
258 super.test_string_simple_unterminated_interpolation_identifier(); | 290 super.test_string_simple_unterminated_interpolation_identifier(); |
259 } | 291 } |
| 292 |
| 293 @override |
| 294 void test_unmatched_openers() { |
| 295 var openBrace = _scan('{[(') as BeginToken; |
| 296 var openBracket = openBrace.next as BeginToken; |
| 297 var openParen = openBracket.next as BeginToken; |
| 298 var closeParen = openParen.next; |
| 299 var closeBracket = closeParen.next; |
| 300 var closeBrace = closeBracket.next; |
| 301 expect(closeBrace.next.type, TokenType.EOF); |
| 302 expect(openBrace.endToken, same(closeBrace)); |
| 303 expect(openBracket.endToken, same(closeBracket)); |
| 304 expect(openParen.endToken, same(closeParen)); |
| 305 } |
| 306 |
| 307 Token _scan(String source, |
| 308 {bool genericMethodComments: false, |
| 309 bool lazyAssignmentOperators: false}) { |
| 310 ErrorListener listener = new ErrorListener(); |
| 311 Token token = scanWithListener(source, listener, |
| 312 genericMethodComments: genericMethodComments, |
| 313 lazyAssignmentOperators: lazyAssignmentOperators); |
| 314 listener.assertNoErrors(); |
| 315 return token; |
| 316 } |
260 } | 317 } |
261 | 318 |
262 /// Base class for scanner tests that examine the token stream in Fasta format. | 319 /// Base class for scanner tests that examine the token stream in Fasta format. |
263 abstract class ScannerTest_Fasta_Base { | 320 abstract class ScannerTest_Fasta_Base { |
264 fasta.Token scan(String source); | 321 fasta.Token scan(String source); |
265 | 322 |
266 void test_match_angle_brackets() { | 323 void test_match_angle_brackets() { |
267 var x = scan('x<y>'); | 324 var x = scan('x<y>'); |
268 var lessThan = x.next as fasta.BeginGroupToken; | 325 var lessThan = x.next as fasta.BeginGroupToken; |
269 var y = lessThan.next; | 326 var y = lessThan.next; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 final ErrorListener _listener; | 516 final ErrorListener _listener; |
460 | 517 |
461 ToAnalyzerTokenStreamConverter_WithListener(this._listener); | 518 ToAnalyzerTokenStreamConverter_WithListener(this._listener); |
462 | 519 |
463 @override | 520 @override |
464 void reportError( | 521 void reportError( |
465 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 522 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
466 _listener.errors.add(new TestError(offset, errorCode, arguments)); | 523 _listener.errors.add(new TestError(offset, errorCode, arguments)); |
467 } | 524 } |
468 } | 525 } |
OLD | NEW |