| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library analyzer.test.generated.simple_resolver_test; | 5 library analyzer.test.generated.simple_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 String text = r''' | 268 String text = r''' |
| 269 void f() { | 269 void f() { |
| 270 loop1: while (true) { | 270 loop1: while (true) { |
| 271 loop2: for (int i = 0; i < 10; i++) { | 271 loop2: for (int i = 0; i < 10; i++) { |
| 272 break loop1; | 272 break loop1; |
| 273 break loop2; | 273 break loop2; |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 '''; | 277 '''; |
| 278 CompilationUnit unit = resolveSource(text); | 278 CompilationUnit unit = await resolveSource(text); |
| 279 WhileStatement whileStatement = EngineTestCase.findNode( | 279 WhileStatement whileStatement = EngineTestCase.findNode( |
| 280 unit, text, 'while (true)', (n) => n is WhileStatement); | 280 unit, text, 'while (true)', (n) => n is WhileStatement); |
| 281 ForStatement forStatement = | 281 ForStatement forStatement = |
| 282 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); | 282 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); |
| 283 BreakStatement break1 = EngineTestCase.findNode( | 283 BreakStatement break1 = EngineTestCase.findNode( |
| 284 unit, text, 'break loop1', (n) => n is BreakStatement); | 284 unit, text, 'break loop1', (n) => n is BreakStatement); |
| 285 BreakStatement break2 = EngineTestCase.findNode( | 285 BreakStatement break2 = EngineTestCase.findNode( |
| 286 unit, text, 'break loop2', (n) => n is BreakStatement); | 286 unit, text, 'break loop2', (n) => n is BreakStatement); |
| 287 expect(break1.target, same(whileStatement)); | 287 expect(break1.target, same(whileStatement)); |
| 288 expect(break2.target, same(forStatement)); | 288 expect(break2.target, same(forStatement)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 test_breakTarget_unlabeledBreakFromDo() async { | 291 test_breakTarget_unlabeledBreakFromDo() async { |
| 292 String text = r''' | 292 String text = r''' |
| 293 void f() { | 293 void f() { |
| 294 do { | 294 do { |
| 295 break; | 295 break; |
| 296 } while (true); | 296 } while (true); |
| 297 } | 297 } |
| 298 '''; | 298 '''; |
| 299 CompilationUnit unit = resolveSource(text); | 299 CompilationUnit unit = await resolveSource(text); |
| 300 DoStatement doStatement = | 300 DoStatement doStatement = |
| 301 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement); | 301 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement); |
| 302 BreakStatement breakStatement = EngineTestCase.findNode( | 302 BreakStatement breakStatement = EngineTestCase.findNode( |
| 303 unit, text, 'break', (n) => n is BreakStatement); | 303 unit, text, 'break', (n) => n is BreakStatement); |
| 304 expect(breakStatement.target, same(doStatement)); | 304 expect(breakStatement.target, same(doStatement)); |
| 305 } | 305 } |
| 306 | 306 |
| 307 test_breakTarget_unlabeledBreakFromFor() async { | 307 test_breakTarget_unlabeledBreakFromFor() async { |
| 308 String text = r''' | 308 String text = r''' |
| 309 void f() { | 309 void f() { |
| 310 for (int i = 0; i < 10; i++) { | 310 for (int i = 0; i < 10; i++) { |
| 311 break; | 311 break; |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 '''; | 314 '''; |
| 315 CompilationUnit unit = resolveSource(text); | 315 CompilationUnit unit = await resolveSource(text); |
| 316 ForStatement forStatement = | 316 ForStatement forStatement = |
| 317 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); | 317 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); |
| 318 BreakStatement breakStatement = EngineTestCase.findNode( | 318 BreakStatement breakStatement = EngineTestCase.findNode( |
| 319 unit, text, 'break', (n) => n is BreakStatement); | 319 unit, text, 'break', (n) => n is BreakStatement); |
| 320 expect(breakStatement.target, same(forStatement)); | 320 expect(breakStatement.target, same(forStatement)); |
| 321 } | 321 } |
| 322 | 322 |
| 323 test_breakTarget_unlabeledBreakFromForEach() async { | 323 test_breakTarget_unlabeledBreakFromForEach() async { |
| 324 String text = r''' | 324 String text = r''' |
| 325 void f() { | 325 void f() { |
| 326 for (x in []) { | 326 for (x in []) { |
| 327 break; | 327 break; |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 '''; | 330 '''; |
| 331 CompilationUnit unit = resolveSource(text); | 331 CompilationUnit unit = await resolveSource(text); |
| 332 ForEachStatement forStatement = EngineTestCase.findNode( | 332 ForEachStatement forStatement = EngineTestCase.findNode( |
| 333 unit, text, 'for', (n) => n is ForEachStatement); | 333 unit, text, 'for', (n) => n is ForEachStatement); |
| 334 BreakStatement breakStatement = EngineTestCase.findNode( | 334 BreakStatement breakStatement = EngineTestCase.findNode( |
| 335 unit, text, 'break', (n) => n is BreakStatement); | 335 unit, text, 'break', (n) => n is BreakStatement); |
| 336 expect(breakStatement.target, same(forStatement)); | 336 expect(breakStatement.target, same(forStatement)); |
| 337 } | 337 } |
| 338 | 338 |
| 339 test_breakTarget_unlabeledBreakFromSwitch() async { | 339 test_breakTarget_unlabeledBreakFromSwitch() async { |
| 340 String text = r''' | 340 String text = r''' |
| 341 void f() { | 341 void f() { |
| 342 while (true) { | 342 while (true) { |
| 343 switch (0) { | 343 switch (0) { |
| 344 case 0: | 344 case 0: |
| 345 break; | 345 break; |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 '''; | 349 '''; |
| 350 CompilationUnit unit = resolveSource(text); | 350 CompilationUnit unit = await resolveSource(text); |
| 351 SwitchStatement switchStatement = EngineTestCase.findNode( | 351 SwitchStatement switchStatement = EngineTestCase.findNode( |
| 352 unit, text, 'switch', (n) => n is SwitchStatement); | 352 unit, text, 'switch', (n) => n is SwitchStatement); |
| 353 BreakStatement breakStatement = EngineTestCase.findNode( | 353 BreakStatement breakStatement = EngineTestCase.findNode( |
| 354 unit, text, 'break', (n) => n is BreakStatement); | 354 unit, text, 'break', (n) => n is BreakStatement); |
| 355 expect(breakStatement.target, same(switchStatement)); | 355 expect(breakStatement.target, same(switchStatement)); |
| 356 } | 356 } |
| 357 | 357 |
| 358 test_breakTarget_unlabeledBreakFromWhile() async { | 358 test_breakTarget_unlabeledBreakFromWhile() async { |
| 359 String text = r''' | 359 String text = r''' |
| 360 void f() { | 360 void f() { |
| 361 while (true) { | 361 while (true) { |
| 362 break; | 362 break; |
| 363 } | 363 } |
| 364 } | 364 } |
| 365 '''; | 365 '''; |
| 366 CompilationUnit unit = resolveSource(text); | 366 CompilationUnit unit = await resolveSource(text); |
| 367 WhileStatement whileStatement = EngineTestCase.findNode( | 367 WhileStatement whileStatement = EngineTestCase.findNode( |
| 368 unit, text, 'while', (n) => n is WhileStatement); | 368 unit, text, 'while', (n) => n is WhileStatement); |
| 369 BreakStatement breakStatement = EngineTestCase.findNode( | 369 BreakStatement breakStatement = EngineTestCase.findNode( |
| 370 unit, text, 'break', (n) => n is BreakStatement); | 370 unit, text, 'break', (n) => n is BreakStatement); |
| 371 expect(breakStatement.target, same(whileStatement)); | 371 expect(breakStatement.target, same(whileStatement)); |
| 372 } | 372 } |
| 373 | 373 |
| 374 test_breakTarget_unlabeledBreakToOuterFunction() async { | 374 test_breakTarget_unlabeledBreakToOuterFunction() async { |
| 375 // Verify that unlabeled break statements can't resolve to loops in an | 375 // Verify that unlabeled break statements can't resolve to loops in an |
| 376 // outer function. | 376 // outer function. |
| 377 String text = r''' | 377 String text = r''' |
| 378 void f() { | 378 void f() { |
| 379 while (true) { | 379 while (true) { |
| 380 void g() { | 380 void g() { |
| 381 break; | 381 break; |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 '''; | 385 '''; |
| 386 CompilationUnit unit = resolveSource(text); | 386 CompilationUnit unit = await resolveSource(text); |
| 387 BreakStatement breakStatement = EngineTestCase.findNode( | 387 BreakStatement breakStatement = EngineTestCase.findNode( |
| 388 unit, text, 'break', (n) => n is BreakStatement); | 388 unit, text, 'break', (n) => n is BreakStatement); |
| 389 expect(breakStatement.target, isNull); | 389 expect(breakStatement.target, isNull); |
| 390 } | 390 } |
| 391 | 391 |
| 392 test_class_definesCall() async { | 392 test_class_definesCall() async { |
| 393 Source source = addSource(r''' | 393 Source source = addSource(r''' |
| 394 class A { | 394 class A { |
| 395 int call(int x) { return x; } | 395 int call(int x) { return x; } |
| 396 } | 396 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 String text = r''' | 454 String text = r''' |
| 455 void f() { | 455 void f() { |
| 456 loop1: while (true) { | 456 loop1: while (true) { |
| 457 loop2: for (int i = 0; i < 10; i++) { | 457 loop2: for (int i = 0; i < 10; i++) { |
| 458 continue loop1; | 458 continue loop1; |
| 459 continue loop2; | 459 continue loop2; |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 '''; | 463 '''; |
| 464 CompilationUnit unit = resolveSource(text); | 464 CompilationUnit unit = await resolveSource(text); |
| 465 WhileStatement whileStatement = EngineTestCase.findNode( | 465 WhileStatement whileStatement = EngineTestCase.findNode( |
| 466 unit, text, 'while (true)', (n) => n is WhileStatement); | 466 unit, text, 'while (true)', (n) => n is WhileStatement); |
| 467 ForStatement forStatement = | 467 ForStatement forStatement = |
| 468 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); | 468 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); |
| 469 ContinueStatement continue1 = EngineTestCase.findNode( | 469 ContinueStatement continue1 = EngineTestCase.findNode( |
| 470 unit, text, 'continue loop1', (n) => n is ContinueStatement); | 470 unit, text, 'continue loop1', (n) => n is ContinueStatement); |
| 471 ContinueStatement continue2 = EngineTestCase.findNode( | 471 ContinueStatement continue2 = EngineTestCase.findNode( |
| 472 unit, text, 'continue loop2', (n) => n is ContinueStatement); | 472 unit, text, 'continue loop2', (n) => n is ContinueStatement); |
| 473 expect(continue1.target, same(whileStatement)); | 473 expect(continue1.target, same(whileStatement)); |
| 474 expect(continue2.target, same(forStatement)); | 474 expect(continue2.target, same(forStatement)); |
| 475 } | 475 } |
| 476 | 476 |
| 477 test_continueTarget_unlabeledContinueFromDo() async { | 477 test_continueTarget_unlabeledContinueFromDo() async { |
| 478 String text = r''' | 478 String text = r''' |
| 479 void f() { | 479 void f() { |
| 480 do { | 480 do { |
| 481 continue; | 481 continue; |
| 482 } while (true); | 482 } while (true); |
| 483 } | 483 } |
| 484 '''; | 484 '''; |
| 485 CompilationUnit unit = resolveSource(text); | 485 CompilationUnit unit = await resolveSource(text); |
| 486 DoStatement doStatement = | 486 DoStatement doStatement = |
| 487 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement); | 487 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement); |
| 488 ContinueStatement continueStatement = EngineTestCase.findNode( | 488 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 489 unit, text, 'continue', (n) => n is ContinueStatement); | 489 unit, text, 'continue', (n) => n is ContinueStatement); |
| 490 expect(continueStatement.target, same(doStatement)); | 490 expect(continueStatement.target, same(doStatement)); |
| 491 } | 491 } |
| 492 | 492 |
| 493 test_continueTarget_unlabeledContinueFromFor() async { | 493 test_continueTarget_unlabeledContinueFromFor() async { |
| 494 String text = r''' | 494 String text = r''' |
| 495 void f() { | 495 void f() { |
| 496 for (int i = 0; i < 10; i++) { | 496 for (int i = 0; i < 10; i++) { |
| 497 continue; | 497 continue; |
| 498 } | 498 } |
| 499 } | 499 } |
| 500 '''; | 500 '''; |
| 501 CompilationUnit unit = resolveSource(text); | 501 CompilationUnit unit = await resolveSource(text); |
| 502 ForStatement forStatement = | 502 ForStatement forStatement = |
| 503 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); | 503 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); |
| 504 ContinueStatement continueStatement = EngineTestCase.findNode( | 504 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 505 unit, text, 'continue', (n) => n is ContinueStatement); | 505 unit, text, 'continue', (n) => n is ContinueStatement); |
| 506 expect(continueStatement.target, same(forStatement)); | 506 expect(continueStatement.target, same(forStatement)); |
| 507 } | 507 } |
| 508 | 508 |
| 509 test_continueTarget_unlabeledContinueFromForEach() async { | 509 test_continueTarget_unlabeledContinueFromForEach() async { |
| 510 String text = r''' | 510 String text = r''' |
| 511 void f() { | 511 void f() { |
| 512 for (x in []) { | 512 for (x in []) { |
| 513 continue; | 513 continue; |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 '''; | 516 '''; |
| 517 CompilationUnit unit = resolveSource(text); | 517 CompilationUnit unit = await resolveSource(text); |
| 518 ForEachStatement forStatement = EngineTestCase.findNode( | 518 ForEachStatement forStatement = EngineTestCase.findNode( |
| 519 unit, text, 'for', (n) => n is ForEachStatement); | 519 unit, text, 'for', (n) => n is ForEachStatement); |
| 520 ContinueStatement continueStatement = EngineTestCase.findNode( | 520 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 521 unit, text, 'continue', (n) => n is ContinueStatement); | 521 unit, text, 'continue', (n) => n is ContinueStatement); |
| 522 expect(continueStatement.target, same(forStatement)); | 522 expect(continueStatement.target, same(forStatement)); |
| 523 } | 523 } |
| 524 | 524 |
| 525 test_continueTarget_unlabeledContinueFromWhile() async { | 525 test_continueTarget_unlabeledContinueFromWhile() async { |
| 526 String text = r''' | 526 String text = r''' |
| 527 void f() { | 527 void f() { |
| 528 while (true) { | 528 while (true) { |
| 529 continue; | 529 continue; |
| 530 } | 530 } |
| 531 } | 531 } |
| 532 '''; | 532 '''; |
| 533 CompilationUnit unit = resolveSource(text); | 533 CompilationUnit unit = await resolveSource(text); |
| 534 WhileStatement whileStatement = EngineTestCase.findNode( | 534 WhileStatement whileStatement = EngineTestCase.findNode( |
| 535 unit, text, 'while', (n) => n is WhileStatement); | 535 unit, text, 'while', (n) => n is WhileStatement); |
| 536 ContinueStatement continueStatement = EngineTestCase.findNode( | 536 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 537 unit, text, 'continue', (n) => n is ContinueStatement); | 537 unit, text, 'continue', (n) => n is ContinueStatement); |
| 538 expect(continueStatement.target, same(whileStatement)); | 538 expect(continueStatement.target, same(whileStatement)); |
| 539 } | 539 } |
| 540 | 540 |
| 541 test_continueTarget_unlabeledContinueSkipsSwitch() async { | 541 test_continueTarget_unlabeledContinueSkipsSwitch() async { |
| 542 String text = r''' | 542 String text = r''' |
| 543 void f() { | 543 void f() { |
| 544 while (true) { | 544 while (true) { |
| 545 switch (0) { | 545 switch (0) { |
| 546 case 0: | 546 case 0: |
| 547 continue; | 547 continue; |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 } | 550 } |
| 551 '''; | 551 '''; |
| 552 CompilationUnit unit = resolveSource(text); | 552 CompilationUnit unit = await resolveSource(text); |
| 553 WhileStatement whileStatement = EngineTestCase.findNode( | 553 WhileStatement whileStatement = EngineTestCase.findNode( |
| 554 unit, text, 'while', (n) => n is WhileStatement); | 554 unit, text, 'while', (n) => n is WhileStatement); |
| 555 ContinueStatement continueStatement = EngineTestCase.findNode( | 555 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 556 unit, text, 'continue', (n) => n is ContinueStatement); | 556 unit, text, 'continue', (n) => n is ContinueStatement); |
| 557 expect(continueStatement.target, same(whileStatement)); | 557 expect(continueStatement.target, same(whileStatement)); |
| 558 } | 558 } |
| 559 | 559 |
| 560 test_continueTarget_unlabeledContinueToOuterFunction() async { | 560 test_continueTarget_unlabeledContinueToOuterFunction() async { |
| 561 // Verify that unlabeled continue statements can't resolve to loops in an | 561 // Verify that unlabeled continue statements can't resolve to loops in an |
| 562 // outer function. | 562 // outer function. |
| 563 String text = r''' | 563 String text = r''' |
| 564 void f() { | 564 void f() { |
| 565 while (true) { | 565 while (true) { |
| 566 void g() { | 566 void g() { |
| 567 continue; | 567 continue; |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 '''; | 571 '''; |
| 572 CompilationUnit unit = resolveSource(text); | 572 CompilationUnit unit = await resolveSource(text); |
| 573 ContinueStatement continueStatement = EngineTestCase.findNode( | 573 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 574 unit, text, 'continue', (n) => n is ContinueStatement); | 574 unit, text, 'continue', (n) => n is ContinueStatement); |
| 575 expect(continueStatement.target, isNull); | 575 expect(continueStatement.target, isNull); |
| 576 } | 576 } |
| 577 | 577 |
| 578 test_empty() async { | 578 test_empty() async { |
| 579 Source source = addSource(""); | 579 Source source = addSource(""); |
| 580 await computeAnalysisResult(source); | 580 await computeAnalysisResult(source); |
| 581 assertNoErrors(source); | 581 assertNoErrors(source); |
| 582 verify([source]); | 582 verify([source]); |
| (...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1904 // check propagated type | 1904 // check propagated type |
| 1905 FunctionType propagatedType = node.propagatedType as FunctionType; | 1905 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 1906 expect(propagatedType.returnType, test.typeProvider.stringType); | 1906 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 1907 } on AnalysisException catch (e, stackTrace) { | 1907 } on AnalysisException catch (e, stackTrace) { |
| 1908 thrownException[0] = new CaughtException(e, stackTrace); | 1908 thrownException[0] = new CaughtException(e, stackTrace); |
| 1909 } | 1909 } |
| 1910 } | 1910 } |
| 1911 return null; | 1911 return null; |
| 1912 } | 1912 } |
| 1913 } | 1913 } |
| OLD | NEW |