| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 token = token.next; | 131 token = token.next; |
| 132 } | 132 } |
| 133 expect(tokenCount, 26); | 133 expect(tokenCount, 26); |
| 134 expect(spotCheckCount, 3); | 134 expect(spotCheckCount, 3); |
| 135 expect(commentTokenCount, 9); | 135 expect(commentTokenCount, 9); |
| 136 expect(token.precedingComments?.lexeme, '// EOF comment'); | 136 expect(token.precedingComments?.lexeme, '// EOF comment'); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void test_CommentToken_remove() { |
| 140 const code = ''' |
| 141 /// aaa |
| 142 /// bbbb |
| 143 /// ccccc |
| 144 main() {} |
| 145 '''; |
| 146 |
| 147 fasta.Token token; |
| 148 fasta.CommentToken c1; |
| 149 fasta.CommentToken c2; |
| 150 fasta.CommentToken c3; |
| 151 |
| 152 void prepareTokens() { |
| 153 token = new fasta.StringScanner(code, includeComments: true).tokenize(); |
| 154 |
| 155 expect(token.info.kind, fasta.IDENTIFIER_TOKEN); |
| 156 |
| 157 c1 = token.precedingCommentTokens; |
| 158 c2 = c1.next; |
| 159 c3 = c2.next; |
| 160 expect(c3.next, isNull); |
| 161 |
| 162 expect(c1.parent, token); |
| 163 expect(c2.parent, token); |
| 164 expect(c3.parent, token); |
| 165 |
| 166 expect(c1.lexeme, '/// aaa'); |
| 167 expect(c2.lexeme, '/// bbbb'); |
| 168 expect(c3.lexeme, '/// ccccc'); |
| 169 } |
| 170 |
| 171 // Remove the first token. |
| 172 { |
| 173 prepareTokens(); |
| 174 c1.remove(); |
| 175 expect(token.precedingCommentTokens, c2); |
| 176 expect(c2.next, c3); |
| 177 expect(c3.next, isNull); |
| 178 } |
| 179 |
| 180 // Remove the second token. |
| 181 { |
| 182 prepareTokens(); |
| 183 c2.remove(); |
| 184 expect(token.precedingCommentTokens, c1); |
| 185 expect(c1.next, c3); |
| 186 expect(c3.next, isNull); |
| 187 } |
| 188 |
| 189 // Remove the last token. |
| 190 { |
| 191 prepareTokens(); |
| 192 c3.remove(); |
| 193 expect(token.precedingCommentTokens, c1); |
| 194 expect(c1.next, c2); |
| 195 expect(c2.next, isNull); |
| 196 } |
| 197 } |
| 198 |
| 199 @override |
| 200 @failingTest |
| 201 void test_incomplete_string_interpolation() { |
| 202 // TODO(danrubel): fix ToAnalyzerTokenStreamConverter_WithListener |
| 203 // to handle synthetic closers in token stream |
| 204 super.test_incomplete_string_interpolation(); |
| 205 } |
| 206 |
| 139 @override | 207 @override |
| 140 @failingTest | 208 @failingTest |
| 141 void test_mismatched_closer() { | 209 void test_mismatched_closer() { |
| 142 // TODO(paulberry,ahe): Fasta and analyzer recover this error differently. | 210 // TODO(paulberry,ahe): Fasta and analyzer recover this error differently. |
| 143 // Figure out which recovery technique we want the front end to use. | 211 // Figure out which recovery technique we want the front end to use. |
| 144 super.test_mismatched_closer(); | 212 super.test_mismatched_closer(); |
| 145 } | 213 } |
| 146 | 214 |
| 147 @override | 215 @override |
| 148 @failingTest | 216 @failingTest |
| 149 void test_mismatched_opener() { | 217 void test_mismatched_opener() { |
| 150 // TODO(paulberry,ahe): Fasta and analyzer recover this error differently. | 218 // TODO(paulberry,ahe): Fasta and analyzer recover this error differently. |
| 151 // Figure out which recovery technique we want the front end to use. | 219 // Figure out which recovery technique we want the front end to use. |
| 152 super.test_mismatched_opener(); | 220 super.test_mismatched_opener(); |
| 153 } | 221 } |
| 154 | 222 |
| 155 void test_next_previous() { | |
| 156 const source = 'int a; /*1*/ /*2*/ /*3*/ B f(){if (a < 2) {}}'; | |
| 157 fasta.Token token = | |
| 158 new fasta.StringScanner(source, includeComments: true).tokenize(); | |
| 159 while (!token.isEof) { | |
| 160 expect(token.next.previousToken, token); | |
| 161 fasta.CommentToken commentToken = token.precedingComments; | |
| 162 while (commentToken != null) { | |
| 163 if (commentToken.next != null) { | |
| 164 expect(commentToken.next.previousToken, commentToken); | |
| 165 } | |
| 166 commentToken = commentToken.next; | |
| 167 } | |
| 168 token = token.next; | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 @override | |
| 173 @failingTest | |
| 174 void test_incomplete_string_interpolation() { | |
| 175 // TODO(danrubel): fix ToAnalyzerTokenStreamConverter_WithListener | |
| 176 // to handle synthetic closers in token stream | |
| 177 super.test_incomplete_string_interpolation(); | |
| 178 } | |
| 179 | |
| 180 @override | 223 @override |
| 181 void test_mismatched_opener_in_interpolation() { | 224 void test_mismatched_opener_in_interpolation() { |
| 182 // When openers and closers are mismatched, | 225 // When openers and closers are mismatched, |
| 183 // fasta favors considering the opener to be mismatched | 226 // fasta favors considering the opener to be mismatched |
| 184 // and inserts synthetic closers as needed. | 227 // and inserts synthetic closers as needed. |
| 185 // r'"${({(}}"' is parsed as r'"${({()})}"' | 228 // r'"${({(}}"' is parsed as r'"${({()})}"' |
| 186 // where both ')' are synthetic | 229 // where both ')' are synthetic |
| 187 var stringStart = _scan(r'"${({(}}"'); | 230 var stringStart = _scan(r'"${({(}}"'); |
| 188 var interpolationStart = stringStart.next as BeginToken; | 231 var interpolationStart = stringStart.next as BeginToken; |
| 189 var openParen1 = interpolationStart.next as BeginToken; | 232 var openParen1 = interpolationStart.next as BeginToken; |
| 190 var openBrace = openParen1.next as BeginToken; | 233 var openBrace = openParen1.next as BeginToken; |
| 191 var openParen2 = openBrace.next as BeginToken; | 234 var openParen2 = openBrace.next as BeginToken; |
| 192 var closeParen2 = openParen2.next; | 235 var closeParen2 = openParen2.next; |
| 193 var closeBrace = closeParen2.next; | 236 var closeBrace = closeParen2.next; |
| 194 var closeParen1 = closeBrace.next; | 237 var closeParen1 = closeBrace.next; |
| 195 var interpolationEnd = closeParen1.next; | 238 var interpolationEnd = closeParen1.next; |
| 196 var stringEnd = interpolationEnd.next; | 239 var stringEnd = interpolationEnd.next; |
| 197 expect(stringEnd.next.type, TokenType.EOF); | 240 expect(stringEnd.next.type, TokenType.EOF); |
| 198 expect(interpolationStart.endToken, same(interpolationEnd)); | 241 expect(interpolationStart.endToken, same(interpolationEnd)); |
| 199 expect(openParen1.endToken, same(closeParen1)); | 242 expect(openParen1.endToken, same(closeParen1)); |
| 200 expect(openBrace.endToken, same(closeBrace)); | 243 expect(openBrace.endToken, same(closeBrace)); |
| 201 expect(openParen2.endToken, same(closeParen2)); | 244 expect(openParen2.endToken, same(closeParen2)); |
| 202 } | 245 } |
| 203 | 246 |
| 247 void test_next_previous() { |
| 248 const source = 'int a; /*1*/ /*2*/ /*3*/ B f(){if (a < 2) {}}'; |
| 249 fasta.Token token = |
| 250 new fasta.StringScanner(source, includeComments: true).tokenize(); |
| 251 while (!token.isEof) { |
| 252 expect(token.next.previousToken, token); |
| 253 fasta.CommentToken commentToken = token.precedingComments; |
| 254 while (commentToken != null) { |
| 255 if (commentToken.next != null) { |
| 256 expect(commentToken.next.previousToken, commentToken); |
| 257 } |
| 258 commentToken = commentToken.next; |
| 259 } |
| 260 token = token.next; |
| 261 } |
| 262 } |
| 263 |
| 204 @override | 264 @override |
| 205 @failingTest | 265 @failingTest |
| 206 void test_string_multi_unterminated() { | 266 void test_string_multi_unterminated() { |
| 207 // TODO(paulberry,ahe): bad error recovery. | 267 // TODO(paulberry,ahe): bad error recovery. |
| 208 super.test_string_multi_unterminated(); | 268 super.test_string_multi_unterminated(); |
| 209 } | 269 } |
| 210 | 270 |
| 211 @override | 271 @override |
| 212 @failingTest | 272 @failingTest |
| 213 void test_string_multi_unterminated_interpolation_block() { | 273 void test_string_multi_unterminated_interpolation_block() { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 final ErrorListener _listener; | 557 final ErrorListener _listener; |
| 498 | 558 |
| 499 ToAnalyzerTokenStreamConverter_WithListener(this._listener); | 559 ToAnalyzerTokenStreamConverter_WithListener(this._listener); |
| 500 | 560 |
| 501 @override | 561 @override |
| 502 void reportError( | 562 void reportError( |
| 503 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 563 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
| 504 _listener.errors.add(new TestError(offset, errorCode, arguments)); | 564 _listener.errors.add(new TestError(offset, errorCode, arguments)); |
| 505 } | 565 } |
| 506 } | 566 } |
| OLD | NEW |