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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 checkClass(B, indirectlyInstantiated: true); | 84 checkClass(B, indirectlyInstantiated: true); |
85 checkClass(C, directlyInstantiated: true, indirectlyInstantiated: true); | 85 checkClass(C, directlyInstantiated: true, indirectlyInstantiated: true); |
86 checkClass(D, directlyInstantiated: true); | 86 checkClass(D, directlyInstantiated: true); |
87 checkClass(E, directlyInstantiated: true); | 87 checkClass(E, directlyInstantiated: true); |
88 checkClass(F, directlyInstantiated: true); | 88 checkClass(F, directlyInstantiated: true); |
89 checkClass(G, directlyInstantiated: true); | 89 checkClass(G, directlyInstantiated: true); |
90 | 90 |
91 ClassHierarchyNodeIterator iterator; | 91 ClassHierarchyNodeIterator iterator; |
92 | 92 |
93 void checkState(ClassElement root, | 93 void checkState(ClassElement root, |
94 {ClassElement currentNode, List<List<ClassElement>> stack}) { | 94 {ClassElement currentNode, List<ClassElement> stack}) { |
95 ClassElement classOf(ClassHierarchyNode node) { | 95 ClassElement classOf(ClassHierarchyNode node) { |
96 return node != null ? node.cls : null; | 96 return node != null ? node.cls : null; |
97 } | 97 } |
98 | 98 |
99 List<ClassElement> classesOf(Link<ClassHierarchyNode> link) { | 99 List<ClassElement> classesOf(Link<ClassHierarchyNode> link) { |
100 if (link == null) return null; | 100 if (link == null) return null; |
101 return link.map(classOf).toList(); | 101 return link.map(classOf).toList(); |
102 } | 102 } |
103 | 103 |
104 ClassElement foundRoot = iterator.root.cls; | 104 ClassElement foundRoot = iterator.root.cls; |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 ClassElement E = env.getElement("E"); | 392 ClassElement E = env.getElement("E"); |
393 ClassElement F = env.getElement("F"); | 393 ClassElement F = env.getElement("F"); |
394 ClassElement G = env.getElement("G"); | 394 ClassElement G = env.getElement("G"); |
395 ClassElement H = env.getElement("H"); | 395 ClassElement H = env.getElement("H"); |
396 ClassElement I = env.getElement("I"); | 396 ClassElement I = env.getElement("I"); |
397 ClassElement X = env.getElement("X"); | 397 ClassElement X = env.getElement("X"); |
398 | 398 |
399 void checkForEachSubclass(ClassElement cls, List<ClassElement> expected) { | 399 void checkForEachSubclass(ClassElement cls, List<ClassElement> expected) { |
400 ClassSet classSet = world.getClassSet(cls); | 400 ClassSet classSet = world.getClassSet(cls); |
401 List<ClassElement> visited = <ClassElement>[]; | 401 List<ClassElement> visited = <ClassElement>[]; |
402 classSet.forEachSubclass((ClassElement cls) { | 402 classSet.forEachSubclass((cls) { |
403 visited.add(cls); | 403 visited.add(cls); |
404 }, ClassHierarchyNode.ALL); | 404 }, ClassHierarchyNode.ALL); |
405 | 405 |
406 Expect.listEquals( | 406 Expect.listEquals( |
407 expected, | 407 expected, |
408 visited, | 408 visited, |
409 "Unexpected classes on $cls.forEachSubclass:\n" | 409 "Unexpected classes on $cls.forEachSubclass:\n" |
410 "Actual: $visited, expected: $expected\n$classSet"); | 410 "Actual: $visited, expected: $expected\n$classSet"); |
411 | 411 |
412 visited = <ClassElement>[]; | 412 visited = <ClassElement>[]; |
413 classSet.forEachSubclass((ClassElement cls) { | 413 classSet.forEachSubclass((cls) { |
414 visited.add(cls); | 414 visited.add(cls); |
415 return IterationStep.CONTINUE; | 415 return IterationStep.CONTINUE; |
416 }, ClassHierarchyNode.ALL); | 416 }, ClassHierarchyNode.ALL); |
417 | 417 |
418 Expect.listEquals( | 418 Expect.listEquals( |
419 expected, | 419 expected, |
420 visited, | 420 visited, |
421 "Unexpected classes on $cls.forEachSubclass:\n" | 421 "Unexpected classes on $cls.forEachSubclass:\n" |
422 "Actual: $visited, expected: $expected\n$classSet"); | 422 "Actual: $visited, expected: $expected\n$classSet"); |
423 } | 423 } |
424 | 424 |
425 checkForEachSubclass(A, [A, B, D, C, G, F, I, H, E]); | 425 checkForEachSubclass(A, [A, B, D, C, G, F, I, H, E]); |
426 checkForEachSubclass(B, [B, D]); | 426 checkForEachSubclass(B, [B, D]); |
427 checkForEachSubclass(C, [C, G, F, I, H, E]); | 427 checkForEachSubclass(C, [C, G, F, I, H, E]); |
428 checkForEachSubclass(D, [D]); | 428 checkForEachSubclass(D, [D]); |
429 checkForEachSubclass(E, [E]); | 429 checkForEachSubclass(E, [E]); |
430 checkForEachSubclass(F, [F, I, H]); | 430 checkForEachSubclass(F, [F, I, H]); |
431 checkForEachSubclass(G, [G]); | 431 checkForEachSubclass(G, [G]); |
432 checkForEachSubclass(H, [H]); | 432 checkForEachSubclass(H, [H]); |
433 checkForEachSubclass(I, [I]); | 433 checkForEachSubclass(I, [I]); |
434 checkForEachSubclass(X, [X]); | 434 checkForEachSubclass(X, [X]); |
435 | 435 |
436 void checkForEachSubtype(ClassElement cls, List<ClassElement> expected) { | 436 void checkForEachSubtype(ClassElement cls, List<ClassElement> expected) { |
437 ClassSet classSet = world.getClassSet(cls); | 437 ClassSet classSet = world.getClassSet(cls); |
438 List<ClassElement> visited = <ClassElement>[]; | 438 List<ClassElement> visited = <ClassElement>[]; |
439 classSet.forEachSubtype((ClassElement cls) { | 439 classSet.forEachSubtype((cls) { |
440 visited.add(cls); | 440 visited.add(cls); |
441 }, ClassHierarchyNode.ALL); | 441 }, ClassHierarchyNode.ALL); |
442 | 442 |
443 Expect.listEquals( | 443 Expect.listEquals( |
444 expected, | 444 expected, |
445 visited, | 445 visited, |
446 "Unexpected classes on $cls.forEachSubtype:\n" | 446 "Unexpected classes on $cls.forEachSubtype:\n" |
447 "Actual: $visited, expected: $expected\n$classSet"); | 447 "Actual: $visited, expected: $expected\n$classSet"); |
448 | 448 |
449 visited = <ClassElement>[]; | 449 visited = <ClassElement>[]; |
450 classSet.forEachSubtype((ClassElement cls) { | 450 classSet.forEachSubtype((cls) { |
451 visited.add(cls); | 451 visited.add(cls); |
452 return IterationStep.CONTINUE; | 452 return IterationStep.CONTINUE; |
453 }, ClassHierarchyNode.ALL); | 453 }, ClassHierarchyNode.ALL); |
454 | 454 |
455 Expect.listEquals( | 455 Expect.listEquals( |
456 expected, | 456 expected, |
457 visited, | 457 visited, |
458 "Unexpected classes on $cls.forEachSubtype:\n" | 458 "Unexpected classes on $cls.forEachSubtype:\n" |
459 "Actual: $visited, expected: $expected\n$classSet"); | 459 "Actual: $visited, expected: $expected\n$classSet"); |
460 } | 460 } |
(...skipping 14 matching lines...) Expand all Loading... |
475 List<ClassElement> skipSubclasses: const <ClassElement>[], | 475 List<ClassElement> skipSubclasses: const <ClassElement>[], |
476 bool forEachSubtype: false, | 476 bool forEachSubtype: false, |
477 EnumSet<Instantiation> mask}) { | 477 EnumSet<Instantiation> mask}) { |
478 if (mask == null) { | 478 if (mask == null) { |
479 mask = ClassHierarchyNode.ALL; | 479 mask = ClassHierarchyNode.ALL; |
480 } | 480 } |
481 | 481 |
482 ClassSet classSet = world.getClassSet(cls); | 482 ClassSet classSet = world.getClassSet(cls); |
483 List<ClassElement> visited = <ClassElement>[]; | 483 List<ClassElement> visited = <ClassElement>[]; |
484 | 484 |
485 IterationStep visit(ClassElement cls) { | 485 IterationStep visit(_cls) { |
| 486 ClassElement cls = _cls; |
486 visited.add(cls); | 487 visited.add(cls); |
487 if (cls == stop) { | 488 if (cls == stop) { |
488 return IterationStep.STOP; | 489 return IterationStep.STOP; |
489 } else if (skipSubclasses.contains(cls)) { | 490 } else if (skipSubclasses.contains(cls)) { |
490 return IterationStep.SKIP_SUBCLASSES; | 491 return IterationStep.SKIP_SUBCLASSES; |
491 } | 492 } |
492 return IterationStep.CONTINUE; | 493 return IterationStep.CONTINUE; |
493 } | 494 } |
494 | 495 |
495 if (forEachSubtype) { | 496 if (forEachSubtype) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 checkForEach(X, [A, D, C, G, F, I, H, E], | 532 checkForEach(X, [A, D, C, G, F, I, H, E], |
532 forEachSubtype: true, mask: ClassHierarchyNode.EXPLICITLY_INSTANTIATED); | 533 forEachSubtype: true, mask: ClassHierarchyNode.EXPLICITLY_INSTANTIATED); |
533 checkForEach(X, [A, B, D, C, G, F, I, H, E], | 534 checkForEach(X, [A, B, D, C, G, F, I, H, E], |
534 forEachSubtype: true, mask: ClassHierarchyNode.INSTANTIATED); | 535 forEachSubtype: true, mask: ClassHierarchyNode.INSTANTIATED); |
535 | 536 |
536 void checkAny(ClassElement cls, List<ClassElement> expected, | 537 void checkAny(ClassElement cls, List<ClassElement> expected, |
537 {ClassElement find, bool expectedResult, bool anySubtype: false}) { | 538 {ClassElement find, bool expectedResult, bool anySubtype: false}) { |
538 ClassSet classSet = world.getClassSet(cls); | 539 ClassSet classSet = world.getClassSet(cls); |
539 List<ClassElement> visited = <ClassElement>[]; | 540 List<ClassElement> visited = <ClassElement>[]; |
540 | 541 |
541 bool visit(ClassElement cls) { | 542 bool visit(cls) { |
542 visited.add(cls); | 543 visited.add(cls); |
543 return cls == find; | 544 return cls == find; |
544 } | 545 } |
545 | 546 |
546 bool result; | 547 bool result; |
547 if (anySubtype) { | 548 if (anySubtype) { |
548 result = classSet.anySubtype(visit, ClassHierarchyNode.ALL); | 549 result = classSet.anySubtype(visit, ClassHierarchyNode.ALL); |
549 } else { | 550 } else { |
550 result = classSet.anySubclass(visit, ClassHierarchyNode.ALL); | 551 result = classSet.anySubclass(visit, ClassHierarchyNode.ALL); |
551 } | 552 } |
(...skipping 24 matching lines...) Expand all Loading... |
576 checkAny(B, [B, D], find: D, anySubtype: true, expectedResult: true); | 577 checkAny(B, [B, D], find: D, anySubtype: true, expectedResult: true); |
577 checkAny(B, [B, D, F, I], find: I, anySubtype: true, expectedResult: true); | 578 checkAny(B, [B, D, F, I], find: I, anySubtype: true, expectedResult: true); |
578 | 579 |
579 checkAny(X, [X, A, B, D, C, G, F, I, H, E], | 580 checkAny(X, [X, A, B, D, C, G, F, I, H, E], |
580 anySubtype: true, expectedResult: false); | 581 anySubtype: true, expectedResult: false); |
581 checkAny(X, [X, A], find: A, anySubtype: true, expectedResult: true); | 582 checkAny(X, [X, A], find: A, anySubtype: true, expectedResult: true); |
582 checkAny(X, [X, A, B, D], find: D, anySubtype: true, expectedResult: true); | 583 checkAny(X, [X, A, B, D], find: D, anySubtype: true, expectedResult: true); |
583 checkAny(X, [X, A, B, D, C, G, F, I], | 584 checkAny(X, [X, A, B, D, C, G, F, I], |
584 find: I, anySubtype: true, expectedResult: true); | 585 find: I, anySubtype: true, expectedResult: true); |
585 } | 586 } |
OLD | NEW |