| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.dart.ast.ast_test; | 5 library analyzer.test.dart.ast.ast_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_ast_factory.dart'; | 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/src/dart/ast/token.dart'; | 10 import 'package:analyzer/src/dart/ast/token.dart'; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 declaration.operatorKeyword); | 359 declaration.operatorKeyword); |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 | 362 |
| 363 @reflectiveTest | 363 @reflectiveTest |
| 364 class NodeListTest extends EngineTestCase { | 364 class NodeListTest extends EngineTestCase { |
| 365 void test_add() { | 365 void test_add() { |
| 366 AstNode parent = AstTestFactory.argumentList(); | 366 AstNode parent = AstTestFactory.argumentList(); |
| 367 AstNode firstNode = AstTestFactory.booleanLiteral(true); | 367 AstNode firstNode = AstTestFactory.booleanLiteral(true); |
| 368 AstNode secondNode = AstTestFactory.booleanLiteral(false); | 368 AstNode secondNode = AstTestFactory.booleanLiteral(false); |
| 369 NodeList<AstNode> list = astFactory.nodeList/*<AstNode>*/(parent); | 369 NodeList<AstNode> list = astFactory.nodeList<AstNode>(parent); |
| 370 list.insert(0, secondNode); | 370 list.insert(0, secondNode); |
| 371 list.insert(0, firstNode); | 371 list.insert(0, firstNode); |
| 372 expect(list, hasLength(2)); | 372 expect(list, hasLength(2)); |
| 373 expect(list[0], same(firstNode)); | 373 expect(list[0], same(firstNode)); |
| 374 expect(list[1], same(secondNode)); | 374 expect(list[1], same(secondNode)); |
| 375 expect(firstNode.parent, same(parent)); | 375 expect(firstNode.parent, same(parent)); |
| 376 expect(secondNode.parent, same(parent)); | 376 expect(secondNode.parent, same(parent)); |
| 377 AstNode thirdNode = AstTestFactory.booleanLiteral(false); | 377 AstNode thirdNode = AstTestFactory.booleanLiteral(false); |
| 378 list.insert(1, thirdNode); | 378 list.insert(1, thirdNode); |
| 379 expect(list, hasLength(3)); | 379 expect(list, hasLength(3)); |
| 380 expect(list[0], same(firstNode)); | 380 expect(list[0], same(firstNode)); |
| 381 expect(list[1], same(thirdNode)); | 381 expect(list[1], same(thirdNode)); |
| 382 expect(list[2], same(secondNode)); | 382 expect(list[2], same(secondNode)); |
| 383 expect(firstNode.parent, same(parent)); | 383 expect(firstNode.parent, same(parent)); |
| 384 expect(secondNode.parent, same(parent)); | 384 expect(secondNode.parent, same(parent)); |
| 385 expect(thirdNode.parent, same(parent)); | 385 expect(thirdNode.parent, same(parent)); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void test_add_negative() { | 388 void test_add_negative() { |
| 389 NodeList<AstNode> list = | 389 NodeList<AstNode> list = |
| 390 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 390 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 391 try { | 391 try { |
| 392 list.insert(-1, AstTestFactory.booleanLiteral(true)); | 392 list.insert(-1, AstTestFactory.booleanLiteral(true)); |
| 393 fail("Expected IndexOutOfBoundsException"); | 393 fail("Expected IndexOutOfBoundsException"); |
| 394 } on RangeError { | 394 } on RangeError { |
| 395 // Expected | 395 // Expected |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 void test_add_tooBig() { | 399 void test_add_tooBig() { |
| 400 NodeList<AstNode> list = | 400 NodeList<AstNode> list = |
| 401 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 401 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 402 try { | 402 try { |
| 403 list.insert(1, AstTestFactory.booleanLiteral(true)); | 403 list.insert(1, AstTestFactory.booleanLiteral(true)); |
| 404 fail("Expected IndexOutOfBoundsException"); | 404 fail("Expected IndexOutOfBoundsException"); |
| 405 } on RangeError { | 405 } on RangeError { |
| 406 // Expected | 406 // Expected |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 | 409 |
| 410 void test_addAll() { | 410 void test_addAll() { |
| 411 AstNode parent = AstTestFactory.argumentList(); | 411 AstNode parent = AstTestFactory.argumentList(); |
| 412 List<AstNode> firstNodes = new List<AstNode>(); | 412 List<AstNode> firstNodes = new List<AstNode>(); |
| 413 AstNode firstNode = AstTestFactory.booleanLiteral(true); | 413 AstNode firstNode = AstTestFactory.booleanLiteral(true); |
| 414 AstNode secondNode = AstTestFactory.booleanLiteral(false); | 414 AstNode secondNode = AstTestFactory.booleanLiteral(false); |
| 415 firstNodes.add(firstNode); | 415 firstNodes.add(firstNode); |
| 416 firstNodes.add(secondNode); | 416 firstNodes.add(secondNode); |
| 417 NodeList<AstNode> list = astFactory.nodeList/*<AstNode>*/(parent); | 417 NodeList<AstNode> list = astFactory.nodeList<AstNode>(parent); |
| 418 list.addAll(firstNodes); | 418 list.addAll(firstNodes); |
| 419 expect(list, hasLength(2)); | 419 expect(list, hasLength(2)); |
| 420 expect(list[0], same(firstNode)); | 420 expect(list[0], same(firstNode)); |
| 421 expect(list[1], same(secondNode)); | 421 expect(list[1], same(secondNode)); |
| 422 expect(firstNode.parent, same(parent)); | 422 expect(firstNode.parent, same(parent)); |
| 423 expect(secondNode.parent, same(parent)); | 423 expect(secondNode.parent, same(parent)); |
| 424 List<AstNode> secondNodes = new List<AstNode>(); | 424 List<AstNode> secondNodes = new List<AstNode>(); |
| 425 AstNode thirdNode = AstTestFactory.booleanLiteral(true); | 425 AstNode thirdNode = AstTestFactory.booleanLiteral(true); |
| 426 AstNode fourthNode = AstTestFactory.booleanLiteral(false); | 426 AstNode fourthNode = AstTestFactory.booleanLiteral(false); |
| 427 secondNodes.add(thirdNode); | 427 secondNodes.add(thirdNode); |
| 428 secondNodes.add(fourthNode); | 428 secondNodes.add(fourthNode); |
| 429 list.addAll(secondNodes); | 429 list.addAll(secondNodes); |
| 430 expect(list, hasLength(4)); | 430 expect(list, hasLength(4)); |
| 431 expect(list[0], same(firstNode)); | 431 expect(list[0], same(firstNode)); |
| 432 expect(list[1], same(secondNode)); | 432 expect(list[1], same(secondNode)); |
| 433 expect(list[2], same(thirdNode)); | 433 expect(list[2], same(thirdNode)); |
| 434 expect(list[3], same(fourthNode)); | 434 expect(list[3], same(fourthNode)); |
| 435 expect(firstNode.parent, same(parent)); | 435 expect(firstNode.parent, same(parent)); |
| 436 expect(secondNode.parent, same(parent)); | 436 expect(secondNode.parent, same(parent)); |
| 437 expect(thirdNode.parent, same(parent)); | 437 expect(thirdNode.parent, same(parent)); |
| 438 expect(fourthNode.parent, same(parent)); | 438 expect(fourthNode.parent, same(parent)); |
| 439 } | 439 } |
| 440 | 440 |
| 441 void test_creation() { | 441 void test_creation() { |
| 442 AstNode owner = AstTestFactory.argumentList(); | 442 AstNode owner = AstTestFactory.argumentList(); |
| 443 NodeList<AstNode> list = astFactory.nodeList/*<AstNode>*/(owner); | 443 NodeList<AstNode> list = astFactory.nodeList<AstNode>(owner); |
| 444 expect(list, isNotNull); | 444 expect(list, isNotNull); |
| 445 expect(list, hasLength(0)); | 445 expect(list, hasLength(0)); |
| 446 expect(list.owner, same(owner)); | 446 expect(list.owner, same(owner)); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void test_get_negative() { | 449 void test_get_negative() { |
| 450 NodeList<AstNode> list = | 450 NodeList<AstNode> list = |
| 451 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 451 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 452 try { | 452 try { |
| 453 list[-1]; | 453 list[-1]; |
| 454 fail("Expected IndexOutOfBoundsException"); | 454 fail("Expected IndexOutOfBoundsException"); |
| 455 } on RangeError { | 455 } on RangeError { |
| 456 // Expected | 456 // Expected |
| 457 } | 457 } |
| 458 } | 458 } |
| 459 | 459 |
| 460 void test_get_tooBig() { | 460 void test_get_tooBig() { |
| 461 NodeList<AstNode> list = | 461 NodeList<AstNode> list = |
| 462 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 462 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 463 try { | 463 try { |
| 464 list[1]; | 464 list[1]; |
| 465 fail("Expected IndexOutOfBoundsException"); | 465 fail("Expected IndexOutOfBoundsException"); |
| 466 } on RangeError { | 466 } on RangeError { |
| 467 // Expected | 467 // Expected |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 | 470 |
| 471 void test_getBeginToken_empty() { | 471 void test_getBeginToken_empty() { |
| 472 NodeList<AstNode> list = | 472 NodeList<AstNode> list = |
| 473 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 473 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 474 expect(list.beginToken, isNull); | 474 expect(list.beginToken, isNull); |
| 475 } | 475 } |
| 476 | 476 |
| 477 void test_getBeginToken_nonEmpty() { | 477 void test_getBeginToken_nonEmpty() { |
| 478 NodeList<AstNode> list = | 478 NodeList<AstNode> list = |
| 479 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 479 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 480 AstNode node = AstTestFactory | 480 AstNode node = AstTestFactory |
| 481 .parenthesizedExpression(AstTestFactory.booleanLiteral(true)); | 481 .parenthesizedExpression(AstTestFactory.booleanLiteral(true)); |
| 482 list.add(node); | 482 list.add(node); |
| 483 expect(list.beginToken, same(node.beginToken)); | 483 expect(list.beginToken, same(node.beginToken)); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void test_getEndToken_empty() { | 486 void test_getEndToken_empty() { |
| 487 NodeList<AstNode> list = | 487 NodeList<AstNode> list = |
| 488 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 488 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 489 expect(list.endToken, isNull); | 489 expect(list.endToken, isNull); |
| 490 } | 490 } |
| 491 | 491 |
| 492 void test_getEndToken_nonEmpty() { | 492 void test_getEndToken_nonEmpty() { |
| 493 NodeList<AstNode> list = | 493 NodeList<AstNode> list = |
| 494 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 494 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 495 AstNode node = AstTestFactory | 495 AstNode node = AstTestFactory |
| 496 .parenthesizedExpression(AstTestFactory.booleanLiteral(true)); | 496 .parenthesizedExpression(AstTestFactory.booleanLiteral(true)); |
| 497 list.add(node); | 497 list.add(node); |
| 498 expect(list.endToken, same(node.endToken)); | 498 expect(list.endToken, same(node.endToken)); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void test_indexOf() { | 501 void test_indexOf() { |
| 502 List<AstNode> nodes = new List<AstNode>(); | 502 List<AstNode> nodes = new List<AstNode>(); |
| 503 AstNode firstNode = AstTestFactory.booleanLiteral(true); | 503 AstNode firstNode = AstTestFactory.booleanLiteral(true); |
| 504 AstNode secondNode = AstTestFactory.booleanLiteral(false); | 504 AstNode secondNode = AstTestFactory.booleanLiteral(false); |
| 505 AstNode thirdNode = AstTestFactory.booleanLiteral(true); | 505 AstNode thirdNode = AstTestFactory.booleanLiteral(true); |
| 506 AstNode fourthNode = AstTestFactory.booleanLiteral(false); | 506 AstNode fourthNode = AstTestFactory.booleanLiteral(false); |
| 507 nodes.add(firstNode); | 507 nodes.add(firstNode); |
| 508 nodes.add(secondNode); | 508 nodes.add(secondNode); |
| 509 nodes.add(thirdNode); | 509 nodes.add(thirdNode); |
| 510 NodeList<AstNode> list = | 510 NodeList<AstNode> list = |
| 511 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 511 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 512 list.addAll(nodes); | 512 list.addAll(nodes); |
| 513 expect(list, hasLength(3)); | 513 expect(list, hasLength(3)); |
| 514 expect(list.indexOf(firstNode), 0); | 514 expect(list.indexOf(firstNode), 0); |
| 515 expect(list.indexOf(secondNode), 1); | 515 expect(list.indexOf(secondNode), 1); |
| 516 expect(list.indexOf(thirdNode), 2); | 516 expect(list.indexOf(thirdNode), 2); |
| 517 expect(list.indexOf(fourthNode), -1); | 517 expect(list.indexOf(fourthNode), -1); |
| 518 expect(list.indexOf(null), -1); | 518 expect(list.indexOf(null), -1); |
| 519 } | 519 } |
| 520 | 520 |
| 521 void test_remove() { | 521 void test_remove() { |
| 522 List<AstNode> nodes = new List<AstNode>(); | 522 List<AstNode> nodes = new List<AstNode>(); |
| 523 AstNode firstNode = AstTestFactory.booleanLiteral(true); | 523 AstNode firstNode = AstTestFactory.booleanLiteral(true); |
| 524 AstNode secondNode = AstTestFactory.booleanLiteral(false); | 524 AstNode secondNode = AstTestFactory.booleanLiteral(false); |
| 525 AstNode thirdNode = AstTestFactory.booleanLiteral(true); | 525 AstNode thirdNode = AstTestFactory.booleanLiteral(true); |
| 526 nodes.add(firstNode); | 526 nodes.add(firstNode); |
| 527 nodes.add(secondNode); | 527 nodes.add(secondNode); |
| 528 nodes.add(thirdNode); | 528 nodes.add(thirdNode); |
| 529 NodeList<AstNode> list = | 529 NodeList<AstNode> list = |
| 530 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 530 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 531 list.addAll(nodes); | 531 list.addAll(nodes); |
| 532 expect(list, hasLength(3)); | 532 expect(list, hasLength(3)); |
| 533 expect(list.removeAt(1), same(secondNode)); | 533 expect(list.removeAt(1), same(secondNode)); |
| 534 expect(list, hasLength(2)); | 534 expect(list, hasLength(2)); |
| 535 expect(list[0], same(firstNode)); | 535 expect(list[0], same(firstNode)); |
| 536 expect(list[1], same(thirdNode)); | 536 expect(list[1], same(thirdNode)); |
| 537 } | 537 } |
| 538 | 538 |
| 539 void test_remove_negative() { | 539 void test_remove_negative() { |
| 540 NodeList<AstNode> list = | 540 NodeList<AstNode> list = |
| 541 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 541 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 542 try { | 542 try { |
| 543 list.removeAt(-1); | 543 list.removeAt(-1); |
| 544 fail("Expected IndexOutOfBoundsException"); | 544 fail("Expected IndexOutOfBoundsException"); |
| 545 } on RangeError { | 545 } on RangeError { |
| 546 // Expected | 546 // Expected |
| 547 } | 547 } |
| 548 } | 548 } |
| 549 | 549 |
| 550 void test_remove_tooBig() { | 550 void test_remove_tooBig() { |
| 551 NodeList<AstNode> list = | 551 NodeList<AstNode> list = |
| 552 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 552 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 553 try { | 553 try { |
| 554 list.removeAt(1); | 554 list.removeAt(1); |
| 555 fail("Expected IndexOutOfBoundsException"); | 555 fail("Expected IndexOutOfBoundsException"); |
| 556 } on RangeError { | 556 } on RangeError { |
| 557 // Expected | 557 // Expected |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 void test_set() { | 561 void test_set() { |
| 562 List<AstNode> nodes = new List<AstNode>(); | 562 List<AstNode> nodes = new List<AstNode>(); |
| 563 AstNode firstNode = AstTestFactory.booleanLiteral(true); | 563 AstNode firstNode = AstTestFactory.booleanLiteral(true); |
| 564 AstNode secondNode = AstTestFactory.booleanLiteral(false); | 564 AstNode secondNode = AstTestFactory.booleanLiteral(false); |
| 565 AstNode thirdNode = AstTestFactory.booleanLiteral(true); | 565 AstNode thirdNode = AstTestFactory.booleanLiteral(true); |
| 566 nodes.add(firstNode); | 566 nodes.add(firstNode); |
| 567 nodes.add(secondNode); | 567 nodes.add(secondNode); |
| 568 nodes.add(thirdNode); | 568 nodes.add(thirdNode); |
| 569 NodeList<AstNode> list = | 569 NodeList<AstNode> list = |
| 570 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 570 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 571 list.addAll(nodes); | 571 list.addAll(nodes); |
| 572 expect(list, hasLength(3)); | 572 expect(list, hasLength(3)); |
| 573 AstNode fourthNode = AstTestFactory.integer(0); | 573 AstNode fourthNode = AstTestFactory.integer(0); |
| 574 list[1] = fourthNode; | 574 list[1] = fourthNode; |
| 575 expect(list, hasLength(3)); | 575 expect(list, hasLength(3)); |
| 576 expect(list[0], same(firstNode)); | 576 expect(list[0], same(firstNode)); |
| 577 expect(list[1], same(fourthNode)); | 577 expect(list[1], same(fourthNode)); |
| 578 expect(list[2], same(thirdNode)); | 578 expect(list[2], same(thirdNode)); |
| 579 } | 579 } |
| 580 | 580 |
| 581 void test_set_negative() { | 581 void test_set_negative() { |
| 582 AstNode node = AstTestFactory.booleanLiteral(true); | 582 AstNode node = AstTestFactory.booleanLiteral(true); |
| 583 NodeList<AstNode> list = | 583 NodeList<AstNode> list = |
| 584 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 584 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 585 try { | 585 try { |
| 586 list[-1] = node; | 586 list[-1] = node; |
| 587 fail("Expected IndexOutOfBoundsException"); | 587 fail("Expected IndexOutOfBoundsException"); |
| 588 } on RangeError { | 588 } on RangeError { |
| 589 // Expected | 589 // Expected |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 void test_set_tooBig() { | 593 void test_set_tooBig() { |
| 594 AstNode node = AstTestFactory.booleanLiteral(true); | 594 AstNode node = AstTestFactory.booleanLiteral(true); |
| 595 NodeList<AstNode> list = | 595 NodeList<AstNode> list = |
| 596 astFactory.nodeList/*<AstNode>*/(AstTestFactory.argumentList()); | 596 astFactory.nodeList<AstNode>(AstTestFactory.argumentList()); |
| 597 try { | 597 try { |
| 598 list[1] = node; | 598 list[1] = node; |
| 599 fail("Expected IndexOutOfBoundsException"); | 599 fail("Expected IndexOutOfBoundsException"); |
| 600 } on RangeError { | 600 } on RangeError { |
| 601 // Expected | 601 // Expected |
| 602 } | 602 } |
| 603 } | 603 } |
| 604 } | 604 } |
| 605 | 605 |
| 606 @reflectiveTest | 606 @reflectiveTest |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 final int ordinal; | 1314 final int ordinal; |
| 1315 | 1315 |
| 1316 const _WrapperKind(this.name, this.ordinal); | 1316 const _WrapperKind(this.name, this.ordinal); |
| 1317 | 1317 |
| 1318 int get hashCode => ordinal; | 1318 int get hashCode => ordinal; |
| 1319 | 1319 |
| 1320 int compareTo(_WrapperKind other) => ordinal - other.ordinal; | 1320 int compareTo(_WrapperKind other) => ordinal - other.ordinal; |
| 1321 | 1321 |
| 1322 String toString() => name; | 1322 String toString() => name; |
| 1323 } | 1323 } |
| OLD | NEW |