| 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 enumset.test; | 5 library enumset.test; | 
| 6 | 6 | 
| 7 import 'package:compiler/src/util/enumset.dart'; | 7 import 'package:compiler/src/util/enumset.dart'; | 
| 8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; | 
| 9 | 9 | 
| 10 enum Enum { A, B, C, D, E, F, } | 10 enum Enum { | 
|  | 11   A, | 
|  | 12   B, | 
|  | 13   C, | 
|  | 14   D, | 
|  | 15   E, | 
|  | 16   F, | 
|  | 17 } | 
| 11 | 18 | 
| 12 main() { | 19 main() { | 
| 13   testAddRemoveContains(); | 20   testAddRemoveContains(); | 
| 14   testConstructorsIntersects(); | 21   testConstructorsIntersects(); | 
| 15 } | 22 } | 
| 16 | 23 | 
| 17 | 24 void checkEnumSet(EnumSet<Enum> enumSet, int expectedValue, | 
| 18 void checkEnumSet(EnumSet<Enum> enumSet, | 25     List<Enum> expectedValues, String expectedToString) { | 
| 19                  int expectedValue, |  | 
| 20                  List<Enum> expectedValues, |  | 
| 21                  String expectedToString) { |  | 
| 22   Expect.equals(expectedValue, enumSet.value, | 26   Expect.equals(expectedValue, enumSet.value, | 
| 23       "Unexpected EnumSet.value for ${enumSet.iterable(Enum.values)}"); | 27       "Unexpected EnumSet.value for ${enumSet.iterable(Enum.values)}"); | 
| 24   Expect.listEquals(expectedValues, enumSet.iterable(Enum.values).toList(), | 28   Expect.listEquals(expectedValues, enumSet.iterable(Enum.values).toList(), | 
| 25       "Unexpected values: ${enumSet.iterable(Enum.values)}"); | 29       "Unexpected values: ${enumSet.iterable(Enum.values)}"); | 
| 26   Expect.equals(expectedValues.isEmpty, enumSet.isEmpty, | 30   Expect.equals(expectedValues.isEmpty, enumSet.isEmpty, | 
| 27       "Unexpected EnumSet.isEmpty for ${enumSet.iterable(Enum.values)}"); | 31       "Unexpected EnumSet.isEmpty for ${enumSet.iterable(Enum.values)}"); | 
| 28   Expect.equals(expectedToString, enumSet.toString(), | 32   Expect.equals(expectedToString, enumSet.toString(), | 
| 29       "Unexpected EnumSet.toString for ${enumSet.iterable(Enum.values)}"); | 33       "Unexpected EnumSet.toString for ${enumSet.iterable(Enum.values)}"); | 
| 30   for (Enum value in Enum.values) { | 34   for (Enum value in Enum.values) { | 
| 31     Expect.equals(expectedValues.contains(value), enumSet.contains(value), | 35     Expect.equals( | 
|  | 36         expectedValues.contains(value), | 
|  | 37         enumSet.contains(value), | 
| 32         "Unexpected EnumSet.contains for $value in " | 38         "Unexpected EnumSet.contains for $value in " | 
| 33         "${enumSet.iterable(Enum.values)}"); | 39         "${enumSet.iterable(Enum.values)}"); | 
| 34   } | 40   } | 
| 35 } | 41 } | 
| 36 | 42 | 
| 37 void testAddRemoveContains() { | 43 void testAddRemoveContains() { | 
| 38   EnumSet<Enum> enumSet = new EnumSet<Enum>(); | 44   EnumSet<Enum> enumSet = new EnumSet<Enum>(); | 
| 39 | 45 | 
| 40   void check(int expectedValue, | 46   void check( | 
| 41              List<Enum> expectedValues, | 47       int expectedValue, List<Enum> expectedValues, String expectedToString) { | 
| 42              String expectedToString) { |  | 
| 43     checkEnumSet(enumSet, expectedValue, expectedValues, expectedToString); | 48     checkEnumSet(enumSet, expectedValue, expectedValues, expectedToString); | 
| 44   } | 49   } | 
| 45 | 50 | 
| 46   check(0, [], '0'); | 51   check(0, [], '0'); | 
| 47 | 52 | 
| 48   enumSet.add(Enum.B); | 53   enumSet.add(Enum.B); | 
| 49   check(2, [Enum.B], '10'); | 54   check(2, [Enum.B], '10'); | 
| 50 | 55 | 
| 51   enumSet.add(Enum.F); | 56   enumSet.add(Enum.F); | 
| 52   check(34, [Enum.F, Enum.B], '100010'); | 57   check(34, [Enum.F, Enum.B], '100010'); | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 77   enumSet.add(Enum.F); | 82   enumSet.add(Enum.F); | 
| 78   check(63, [Enum.F, Enum.E, Enum.D, Enum.C, Enum.B, Enum.A], '111111'); | 83   check(63, [Enum.F, Enum.E, Enum.D, Enum.C, Enum.B, Enum.A], '111111'); | 
| 79 } | 84 } | 
| 80 | 85 | 
| 81 void testConstructorsIntersects() { | 86 void testConstructorsIntersects() { | 
| 82   EnumSet<Enum> emptyA = new EnumSet<Enum>(); | 87   EnumSet<Enum> emptyA = new EnumSet<Enum>(); | 
| 83   EnumSet<Enum> emptyB = new EnumSet<Enum>.fromValue(0); | 88   EnumSet<Enum> emptyB = new EnumSet<Enum>.fromValue(0); | 
| 84   EnumSet<Enum> emptyC = const EnumSet<Enum>.fixed(0); | 89   EnumSet<Enum> emptyC = const EnumSet<Enum>.fixed(0); | 
| 85   EnumSet<Enum> emptyD = new EnumSet<Enum>.fixed(0); | 90   EnumSet<Enum> emptyD = new EnumSet<Enum>.fixed(0); | 
| 86 | 91 | 
| 87 |  | 
| 88   void checkIntersects(EnumSet<Enum> a, EnumSet<Enum> b, bool expectedValue) { | 92   void checkIntersects(EnumSet<Enum> a, EnumSet<Enum> b, bool expectedValue) { | 
| 89     Expect.equals(expectedValue, a.intersects(b), | 93     Expect.equals( | 
| 90         "Unexpected intersects of $a and $b"); | 94         expectedValue, a.intersects(b), "Unexpected intersects of $a and $b"); | 
| 91     Expect.equals(a.intersects(b), b.intersects(a), | 95     Expect.equals(a.intersects(b), b.intersects(a), | 
| 92         "Unsymmetric intersects of $a and $b"); | 96         "Unsymmetric intersects of $a and $b"); | 
| 93   } | 97   } | 
| 94 | 98 | 
| 95   void check(EnumSet<Enum> a, EnumSet<Enum> b) { | 99   void check(EnumSet<Enum> a, EnumSet<Enum> b) { | 
| 96     Expect.equals(a.value, b.value, | 100     Expect.equals(a.value, b.value, "Unexpected values of $a and $b"); | 
| 97         "Unexpected values of $a and $b"); | 101     Expect.equals(a.hashCode, b.hashCode, "Unexpected hash codes of $a and $b"); | 
| 98     Expect.equals(a.hashCode, b.hashCode, | 102     Expect.equals(a, b, "Unexpected equality of $a and $b"); | 
| 99         "Unexpected hash codes of $a and $b"); |  | 
| 100     Expect.equals(a, b, |  | 
| 101         "Unexpected equality of $a and $b"); |  | 
| 102     checkIntersects(a, b, !a.isEmpty); | 103     checkIntersects(a, b, !a.isEmpty); | 
| 103   } | 104   } | 
| 104 | 105 | 
| 105   check(emptyA, emptyA); | 106   check(emptyA, emptyA); | 
| 106   check(emptyA, emptyB); | 107   check(emptyA, emptyB); | 
| 107   check(emptyA, emptyC); | 108   check(emptyA, emptyC); | 
| 108   check(emptyA, emptyD); | 109   check(emptyA, emptyD); | 
| 109 | 110 | 
| 110   EnumSet<Enum> singleA = new EnumSet<Enum>()..add(Enum.C); | 111   EnumSet<Enum> singleA = new EnumSet<Enum>()..add(Enum.C); | 
| 111   EnumSet<Enum> singleB = new EnumSet<Enum>.fromValue(4); | 112   EnumSet<Enum> singleB = new EnumSet<Enum>.fromValue(4); | 
| 112   EnumSet<Enum> singleC = const EnumSet<Enum>.fixed(4); | 113   EnumSet<Enum> singleC = const EnumSet<Enum>.fixed(4); | 
| 113   EnumSet<Enum> singleD = new EnumSet<Enum>.fixed(4); | 114   EnumSet<Enum> singleD = new EnumSet<Enum>.fixed(4); | 
| 114   EnumSet<Enum> singleE = new EnumSet<Enum>.fromValues([Enum.C]); | 115   EnumSet<Enum> singleE = new EnumSet<Enum>.fromValues([Enum.C]); | 
| 115   EnumSet<Enum> singleF = new EnumSet<Enum>.fromValues([Enum.C], fixed: true); | 116   EnumSet<Enum> singleF = new EnumSet<Enum>.fromValues([Enum.C], fixed: true); | 
| 116 | 117 | 
| 117   check(singleA, singleA); | 118   check(singleA, singleA); | 
| 118   check(singleA, singleB); | 119   check(singleA, singleB); | 
| 119   check(singleA, singleC); | 120   check(singleA, singleC); | 
| 120   check(singleA, singleD); | 121   check(singleA, singleD); | 
| 121   check(singleA, singleE); | 122   check(singleA, singleE); | 
| 122   check(singleA, singleF); | 123   check(singleA, singleF); | 
| 123 | 124 | 
| 124   EnumSet<Enum> multiA = new EnumSet<Enum>() | 125   EnumSet<Enum> multiA = new EnumSet<Enum>() | 
| 125       ..add(Enum.A)..add(Enum.D)..add(Enum.F); | 126     ..add(Enum.A) | 
|  | 127     ..add(Enum.D) | 
|  | 128     ..add(Enum.F); | 
| 126   EnumSet<Enum> multiB = new EnumSet<Enum>.fromValue(41); | 129   EnumSet<Enum> multiB = new EnumSet<Enum>.fromValue(41); | 
| 127   EnumSet<Enum> multiC = const EnumSet<Enum>.fixed(41); | 130   EnumSet<Enum> multiC = const EnumSet<Enum>.fixed(41); | 
| 128   EnumSet<Enum> multiD = new EnumSet<Enum>.fixed(41); | 131   EnumSet<Enum> multiD = new EnumSet<Enum>.fixed(41); | 
| 129   EnumSet<Enum> multiE = new EnumSet<Enum>.fromValues([Enum.F, Enum.A, Enum.D]); | 132   EnumSet<Enum> multiE = new EnumSet<Enum>.fromValues([Enum.F, Enum.A, Enum.D]); | 
| 130   EnumSet<Enum> multiF = | 133   EnumSet<Enum> multiF = | 
| 131       new EnumSet<Enum>.fromValues([Enum.F, Enum.A, Enum.D], fixed: true); | 134       new EnumSet<Enum>.fromValues([Enum.F, Enum.A, Enum.D], fixed: true); | 
| 132 | 135 | 
| 133   check(multiA, multiA); | 136   check(multiA, multiA); | 
| 134   check(multiA, multiB); | 137   check(multiA, multiB); | 
| 135   check(multiA, multiC); | 138   check(multiA, multiC); | 
| 136   check(multiA, multiD); | 139   check(multiA, multiD); | 
| 137   check(multiA, multiE); | 140   check(multiA, multiE); | 
| 138   check(multiA, multiF); | 141   check(multiA, multiF); | 
| 139 | 142 | 
| 140   EnumSet<Enum> multi2 = new EnumSet<Enum>.fromValues([Enum.F, Enum.A, Enum.C]); | 143   EnumSet<Enum> multi2 = new EnumSet<Enum>.fromValues([Enum.F, Enum.A, Enum.C]); | 
| 141 | 144 | 
| 142   checkIntersects(emptyA, singleA, false); | 145   checkIntersects(emptyA, singleA, false); | 
| 143   checkIntersects(emptyA, multiA, false); | 146   checkIntersects(emptyA, multiA, false); | 
| 144   checkIntersects(emptyA, multi2, false); | 147   checkIntersects(emptyA, multi2, false); | 
| 145 | 148 | 
| 146   checkIntersects(singleA, multiA, false); | 149   checkIntersects(singleA, multiA, false); | 
| 147   checkIntersects(singleA, multi2, true); | 150   checkIntersects(singleA, multi2, true); | 
| 148 | 151 | 
| 149   checkIntersects(multiA, multi2, true); | 152   checkIntersects(multiA, multi2, true); | 
| 150 } | 153 } | 
| OLD | NEW | 
|---|