| OLD | NEW |
| 1 // This code was auto-generated, is not intended to be edited, and is subject to | 1 // This code was auto-generated, is not intended to be edited, and is subject to |
| 2 // significant change. Please see the README file for more information. | 2 // significant change. Please see the README file for more information. |
| 3 library engine.test_support; | 3 library engine.test_support; |
| 4 import 'dart:collection'; | 4 import 'dart:collection'; |
| 5 import 'package:analyzer_experimental/src/generated/java_core.dart'; | 5 import 'package:analyzer_experimental/src/generated/java_core.dart'; |
| 6 import 'package:analyzer_experimental/src/generated/java_engine.dart'; | 6 import 'package:analyzer_experimental/src/generated/java_engine.dart'; |
| 7 import 'package:analyzer_experimental/src/generated/java_junit.dart'; | 7 import 'package:analyzer_experimental/src/generated/java_junit.dart'; |
| 8 import 'package:analyzer_experimental/src/generated/source.dart'; | 8 import 'package:analyzer_experimental/src/generated/source.dart'; |
| 9 import 'package:analyzer_experimental/src/generated/error.dart'; | 9 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 10 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 10 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 Token left = expectedStream; | 381 Token left = expectedStream; |
| 382 Token right = actualStream; | 382 Token right = actualStream; |
| 383 while (left.type != TokenType.EOF && right.type != TokenType.EOF) { | 383 while (left.type != TokenType.EOF && right.type != TokenType.EOF) { |
| 384 assertMatches(left, right); | 384 assertMatches(left, right); |
| 385 left = left.next; | 385 left = left.next; |
| 386 right = right.next; | 386 right = right.next; |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * Assert that the given array is non-{@code null} and contains the expected e
lements. The |
| 392 * elements can appear in any order. |
| 393 * @param array the array being tested |
| 394 * @param expectedElements the expected elements |
| 395 * @throws AssertionFailedError if the array is {@code null} or does not conta
in the expected |
| 396 * elements |
| 397 */ |
| 398 static void assertContains(List<Object> array, List<Object> expectedElements)
{ |
| 399 int expectedSize = expectedElements.length; |
| 400 if (array == null) { |
| 401 JUnitTestCase.fail("Expected array of length ${expectedSize}; found null")
; |
| 402 } |
| 403 if (array.length != expectedSize) { |
| 404 JUnitTestCase.fail("Expected array of length ${expectedSize}; contained ${
array.length} elements"); |
| 405 } |
| 406 List<bool> found = new List<bool>.filled(expectedSize, false); |
| 407 for (int i = 0; i < expectedSize; i++) { |
| 408 assertContains2(array, found, expectedElements[i]); |
| 409 } |
| 410 } |
| 411 |
| 412 /** |
| 391 * Assert that the array of actual values contain exactly the same values as t
hose in the array of | 413 * Assert that the array of actual values contain exactly the same values as t
hose in the array of |
| 392 * expected value, with the exception that the order of the elements is not re
quired to be the | 414 * expected value, with the exception that the order of the elements is not re
quired to be the |
| 393 * same. | 415 * same. |
| 394 * @param expectedValues the values that are expected to be found | 416 * @param expectedValues the values that are expected to be found |
| 395 * @param actualValues the actual values that are being compared against the e
xpected values | 417 * @param actualValues the actual values that are being compared against the e
xpected values |
| 396 */ | 418 */ |
| 397 static void assertEqualsIgnoreOrder(List<Object> expectedValues, List<Object>
actualValues) { | 419 static void assertEqualsIgnoreOrder(List<Object> expectedValues, List<Object>
actualValues) { |
| 398 JUnitTestCase.assertNotNull(actualValues); | 420 JUnitTestCase.assertNotNull(actualValues); |
| 399 int expectedLength = expectedValues.length; | 421 int expectedLength = expectedValues.length; |
| 400 JUnitTestCase.assertEquals(expectedLength, actualValues.length); | 422 JUnitTestCase.assertEquals(expectedLength, actualValues.length); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected elements | 472 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected elements |
| 451 */ | 473 */ |
| 452 static void assertExactElements(List<Object> list, List<Object> expectedElemen
ts) { | 474 static void assertExactElements(List<Object> list, List<Object> expectedElemen
ts) { |
| 453 int expectedSize = expectedElements.length; | 475 int expectedSize = expectedElements.length; |
| 454 if (list == null) { | 476 if (list == null) { |
| 455 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); | 477 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); |
| 456 } | 478 } |
| 457 if (list.length != expectedSize) { | 479 if (list.length != expectedSize) { |
| 458 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); | 480 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${lis
t.length} elements"); |
| 459 } | 481 } |
| 460 for (int i = 0; i < expectedElements.length; i++) { | 482 for (int i = 0; i < expectedSize; i++) { |
| 461 Object element = list[i]; | 483 Object element = list[i]; |
| 462 Object expectedElement = expectedElements[i]; | 484 Object expectedElement = expectedElements[i]; |
| 463 if (!element == expectedElement) { | 485 if (!element == expectedElement) { |
| 464 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); | 486 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); |
| 465 } | 487 } |
| 466 } | 488 } |
| 467 } | 489 } |
| 468 | 490 |
| 469 /** | 491 /** |
| 470 * Assert that the given array is non-{@code null} and has exactly expected el
ements. | 492 * Assert that the given array is non-{@code null} and has exactly expected el
ements. |
| 471 * @param array the array being tested | 493 * @param array the array being tested |
| 472 * @param expectedElements the expected elements | 494 * @param expectedElements the expected elements |
| 473 * @throws AssertionFailedError if the array is {@code null} or does not have
the expected | 495 * @throws AssertionFailedError if the array is {@code null} or does not have
the expected |
| 474 * elements | 496 * elements |
| 475 */ | 497 */ |
| 476 static void assertExactElements2(List<Object> array, List<Object> expectedElem
ents) { | 498 static void assertExactElements2(List<Object> array, List<Object> expectedElem
ents) { |
| 477 int expectedSize = expectedElements.length; | 499 int expectedSize = expectedElements.length; |
| 478 if (array == null) { | 500 if (array == null) { |
| 479 JUnitTestCase.fail("Expected array of size ${expectedSize}; found null"); | 501 JUnitTestCase.fail("Expected array of size ${expectedSize}; found null"); |
| 480 } | 502 } |
| 481 if (array.length != expectedSize) { | 503 if (array.length != expectedSize) { |
| 482 JUnitTestCase.fail("Expected array of size ${expectedSize}; contained ${ar
ray.length} elements"); | 504 JUnitTestCase.fail("Expected array of size ${expectedSize}; contained ${ar
ray.length} elements"); |
| 483 } | 505 } |
| 484 for (int i = 0; i < expectedElements.length; i++) { | 506 for (int i = 0; i < expectedSize; i++) { |
| 485 Object element = array[i]; | 507 Object element = array[i]; |
| 486 Object expectedElement = expectedElements[i]; | 508 Object expectedElement = expectedElements[i]; |
| 487 if (!element == expectedElement) { | 509 if (!element == expectedElement) { |
| 488 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); | 510 JUnitTestCase.fail("Expected ${expectedElement} at [${i}]; found ${eleme
nt}"); |
| 489 } | 511 } |
| 490 } | 512 } |
| 491 } | 513 } |
| 492 | 514 |
| 493 /** | 515 /** |
| 494 * Assert that the given list is non-{@code null} and has exactly expected ele
ments. | 516 * Assert that the given list is non-{@code null} and has exactly expected ele
ments. |
| 495 * @param set the list being tested | 517 * @param set the list being tested |
| 496 * @param expectedElements the expected elements | 518 * @param expectedElements the expected elements |
| 497 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected elements | 519 * @throws AssertionFailedError if the list is {@code null} or does not have t
he expected elements |
| 498 */ | 520 */ |
| 499 static void assertExactElements3(Set<Object> set, List<Object> expectedElement
s) { | 521 static void assertExactElements3(Set<Object> set, List<Object> expectedElement
s) { |
| 500 int expectedSize = expectedElements.length; | 522 int expectedSize = expectedElements.length; |
| 501 if (set == null) { | 523 if (set == null) { |
| 502 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); | 524 JUnitTestCase.fail("Expected list of size ${expectedSize}; found null"); |
| 503 } | 525 } |
| 504 if (set.length != expectedSize) { | 526 if (set.length != expectedSize) { |
| 505 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${set
.length} elements"); | 527 JUnitTestCase.fail("Expected list of size ${expectedSize}; contained ${set
.length} elements"); |
| 506 } | 528 } |
| 507 for (int i = 0; i < expectedElements.length; i++) { | 529 for (int i = 0; i < expectedSize; i++) { |
| 508 Object expectedElement = expectedElements[i]; | 530 Object expectedElement = expectedElements[i]; |
| 509 if (!set.contains(expectedElement)) { | 531 if (!set.contains(expectedElement)) { |
| 510 JUnitTestCase.fail("Expected ${expectedElement} in set${set}"); | 532 JUnitTestCase.fail("Expected ${expectedElement} in set${set}"); |
| 511 } | 533 } |
| 512 } | 534 } |
| 513 } | 535 } |
| 514 | 536 |
| 515 /** | 537 /** |
| 516 * Assert that the given object is an instance of the expected class. | 538 * Assert that the given object is an instance of the expected class. |
| 517 * @param expectedClass the class that the object is expected to be an instanc
e of | 539 * @param expectedClass the class that the object is expected to be an instanc
e of |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 * @param lines the lines to be merged into a single source string | 631 * @param lines the lines to be merged into a single source string |
| 610 * @return the source string composed of the given lines | 632 * @return the source string composed of the given lines |
| 611 */ | 633 */ |
| 612 static String createSource(List<String> lines) { | 634 static String createSource(List<String> lines) { |
| 613 PrintStringWriter writer = new PrintStringWriter(); | 635 PrintStringWriter writer = new PrintStringWriter(); |
| 614 for (String line in lines) { | 636 for (String line in lines) { |
| 615 writer.println(line); | 637 writer.println(line); |
| 616 } | 638 } |
| 617 return writer.toString(); | 639 return writer.toString(); |
| 618 } | 640 } |
| 641 static void assertContains2(List<Object> array, List<bool> found, Object eleme
nt) { |
| 642 if (element == null) { |
| 643 for (int i = 0; i < array.length; i++) { |
| 644 if (!found[i]) { |
| 645 if (array[i] == null) { |
| 646 found[i] = true; |
| 647 return; |
| 648 } |
| 649 } |
| 650 } |
| 651 JUnitTestCase.fail("Does not contain null"); |
| 652 } else { |
| 653 for (int i = 0; i < array.length; i++) { |
| 654 if (!found[i]) { |
| 655 if (element == array[i]) { |
| 656 found[i] = true; |
| 657 return; |
| 658 } |
| 659 } |
| 660 } |
| 661 JUnitTestCase.fail("Does not contain ${element}"); |
| 662 } |
| 663 } |
| 619 | 664 |
| 620 /** | 665 /** |
| 621 * Calculate the offset where the given strings differ. | 666 * Calculate the offset where the given strings differ. |
| 622 * @param str1 the first String to compare | 667 * @param str1 the first String to compare |
| 623 * @param str2 the second String to compare | 668 * @param str2 the second String to compare |
| 624 * @return the offset at which the strings differ (or <code>-1</code> if they
do not) | 669 * @return the offset at which the strings differ (or <code>-1</code> if they
do not) |
| 625 */ | 670 */ |
| 626 static int getDiffPos(String str1, String str2) { | 671 static int getDiffPos(String str1, String str2) { |
| 627 int len1 = Math.min(str1.length, str2.length); | 672 int len1 = Math.min(str1.length, str2.length); |
| 628 int diffPos = -1; | 673 int diffPos = -1; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 return trampoline(target, arguments[0], arguments[1]); | 785 return trampoline(target, arguments[0], arguments[1]); |
| 741 case 3: | 786 case 3: |
| 742 return trampoline(target, arguments[0], arguments[1], arguments[2]); | 787 return trampoline(target, arguments[0], arguments[1], arguments[2]); |
| 743 case 4: | 788 case 4: |
| 744 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); | 789 return trampoline(target, arguments[0], arguments[1], arguments[2], argu
ments[3]); |
| 745 default: | 790 default: |
| 746 throw new IllegalArgumentException("Not implemented for > 4 arguments"); | 791 throw new IllegalArgumentException("Not implemented for > 4 arguments"); |
| 747 } | 792 } |
| 748 } | 793 } |
| 749 } | 794 } |
| OLD | NEW |