OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // Test for iterators on for [SubclassNode]. | 5 // Test for iterators on for [SubclassNode]. |
6 | 6 |
7 library class_set_test; | 7 library class_set_test; |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import 'package:async_helper/async_helper.dart'; | 10 import 'package:async_helper/async_helper.dart'; |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 visited.add(cls); | 404 visited.add(cls); |
405 }, ClassHierarchyNode.ALL); | 405 }, ClassHierarchyNode.ALL); |
406 | 406 |
407 Expect.listEquals(expected, visited, | 407 Expect.listEquals(expected, visited, |
408 "Unexpected classes on $cls.forEachSubclass:\n" | 408 "Unexpected classes on $cls.forEachSubclass:\n" |
409 "Actual: $visited, expected: $expected\n$classSet"); | 409 "Actual: $visited, expected: $expected\n$classSet"); |
410 | 410 |
411 visited = <ClassElement>[]; | 411 visited = <ClassElement>[]; |
412 classSet.forEachSubclass((ClassElement cls) { | 412 classSet.forEachSubclass((ClassElement cls) { |
413 visited.add(cls); | 413 visited.add(cls); |
414 return ForEach.CONTINUE; | 414 return IterationStep.CONTINUE; |
415 }, ClassHierarchyNode.ALL); | 415 }, ClassHierarchyNode.ALL); |
416 | 416 |
417 Expect.listEquals(expected, visited, | 417 Expect.listEquals(expected, visited, |
418 "Unexpected classes on $cls.forEachSubclass:\n" | 418 "Unexpected classes on $cls.forEachSubclass:\n" |
419 "Actual: $visited, expected: $expected\n$classSet"); | 419 "Actual: $visited, expected: $expected\n$classSet"); |
420 } | 420 } |
421 | 421 |
422 checkForEachSubclass(A, [A, B, D, C, G, F, I, H, E]); | 422 checkForEachSubclass(A, [A, B, D, C, G, F, I, H, E]); |
423 checkForEachSubclass(B, [B, D]); | 423 checkForEachSubclass(B, [B, D]); |
424 checkForEachSubclass(C, [C, G, F, I, H, E]); | 424 checkForEachSubclass(C, [C, G, F, I, H, E]); |
(...skipping 12 matching lines...) Expand all Loading... |
437 visited.add(cls); | 437 visited.add(cls); |
438 }, ClassHierarchyNode.ALL); | 438 }, ClassHierarchyNode.ALL); |
439 | 439 |
440 Expect.listEquals(expected, visited, | 440 Expect.listEquals(expected, visited, |
441 "Unexpected classes on $cls.forEachSubtype:\n" | 441 "Unexpected classes on $cls.forEachSubtype:\n" |
442 "Actual: $visited, expected: $expected\n$classSet"); | 442 "Actual: $visited, expected: $expected\n$classSet"); |
443 | 443 |
444 visited = <ClassElement>[]; | 444 visited = <ClassElement>[]; |
445 classSet.forEachSubtype((ClassElement cls) { | 445 classSet.forEachSubtype((ClassElement cls) { |
446 visited.add(cls); | 446 visited.add(cls); |
447 return ForEach.CONTINUE; | 447 return IterationStep.CONTINUE; |
448 }, ClassHierarchyNode.ALL); | 448 }, ClassHierarchyNode.ALL); |
449 | 449 |
450 Expect.listEquals(expected, visited, | 450 Expect.listEquals(expected, visited, |
451 "Unexpected classes on $cls.forEachSubtype:\n" | 451 "Unexpected classes on $cls.forEachSubtype:\n" |
452 "Actual: $visited, expected: $expected\n$classSet"); | 452 "Actual: $visited, expected: $expected\n$classSet"); |
453 } | 453 } |
454 | 454 |
455 checkForEachSubtype(A, [A, B, D, C, G, F, I, H, E]); | 455 checkForEachSubtype(A, [A, B, D, C, G, F, I, H, E]); |
456 checkForEachSubtype(B, [B, D, F, I, H, G]); | 456 checkForEachSubtype(B, [B, D, F, I, H, G]); |
457 checkForEachSubtype(C, [C, G, F, I, H, E]); | 457 checkForEachSubtype(C, [C, G, F, I, H, E]); |
(...skipping 13 matching lines...) Expand all Loading... |
471 bool forEachSubtype: false, | 471 bool forEachSubtype: false, |
472 EnumSet<Instantiation> mask}) { | 472 EnumSet<Instantiation> mask}) { |
473 | 473 |
474 if (mask == null) { | 474 if (mask == null) { |
475 mask = ClassHierarchyNode.ALL; | 475 mask = ClassHierarchyNode.ALL; |
476 } | 476 } |
477 | 477 |
478 ClassSet classSet = world.getClassSet(cls); | 478 ClassSet classSet = world.getClassSet(cls); |
479 List<ClassElement> visited = <ClassElement>[]; | 479 List<ClassElement> visited = <ClassElement>[]; |
480 | 480 |
481 ForEach visit(ClassElement cls) { | 481 IterationStep visit(ClassElement cls) { |
482 visited.add(cls); | 482 visited.add(cls); |
483 if (cls == stop) { | 483 if (cls == stop) { |
484 return ForEach.STOP; | 484 return IterationStep.STOP; |
485 } else if (skipSubclasses.contains(cls)) { | 485 } else if (skipSubclasses.contains(cls)) { |
486 return ForEach.SKIP_SUBCLASSES; | 486 return IterationStep.SKIP_SUBCLASSES; |
487 } | 487 } |
488 return ForEach.CONTINUE; | 488 return IterationStep.CONTINUE; |
489 } | 489 } |
490 | 490 |
491 if (forEachSubtype) { | 491 if (forEachSubtype) { |
492 classSet.forEachSubtype(visit, mask); | 492 classSet.forEachSubtype(visit, mask); |
493 } else { | 493 } else { |
494 classSet.forEachSubclass(visit, mask); | 494 classSet.forEachSubclass(visit, mask); |
495 } | 495 } |
496 | 496 |
497 Expect.listEquals(expected, visited, | 497 Expect.listEquals(expected, visited, |
498 "Unexpected classes on $cls." | 498 "Unexpected classes on $cls." |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 575 |
576 checkAny(X, [X, A, B, D, C, G, F, I, H, E], | 576 checkAny(X, [X, A, B, D, C, G, F, I, H, E], |
577 anySubtype: true, expectedResult: false); | 577 anySubtype: true, expectedResult: false); |
578 checkAny(X, [X, A], | 578 checkAny(X, [X, A], |
579 find: A, anySubtype: true, expectedResult: true); | 579 find: A, anySubtype: true, expectedResult: true); |
580 checkAny(X, [X, A, B, D], | 580 checkAny(X, [X, A, B, D], |
581 find: D, anySubtype: true, expectedResult: true); | 581 find: D, anySubtype: true, expectedResult: true); |
582 checkAny(X, [X, A, B, D, C, G, F, I], | 582 checkAny(X, [X, A, B, D, C, G, F, I], |
583 find: I, anySubtype: true, expectedResult: true); | 583 find: I, anySubtype: true, expectedResult: true); |
584 } | 584 } |
OLD | NEW |