Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 check(value, expectComparable, expectHashable, expectPattern) { | 5 check(value, expectComparable, expectPattern) { |
| 6 Expect.equals(expectComparable, value is Comparable); | 6 Expect.equals(expectComparable, value is Comparable); |
| 7 Expect.equals(expectHashable, value is Hashable); | |
| 8 Expect.equals(expectPattern, value is Pattern); | 7 Expect.equals(expectPattern, value is Pattern); |
| 9 } | 8 } |
| 10 | 9 |
| 11 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); | 10 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); |
| 12 | 11 |
| 13 class A implements Comparable { | 12 class A implements Comparable { |
| 14 } | 13 } |
| 15 | 14 |
| 16 class B implements Hashable { | 15 class B { |
|
Mads Ager (google)
2012/09/27 12:48:27
hep
| |
| 17 } | 16 } |
| 18 | 17 |
| 19 class C implements Comparable, Hashable { | 18 class C implements Pattern { |
| 20 } | 19 } |
| 21 | 20 |
| 22 class D implements Pattern { | 21 class D implements Pattern, Comparable { |
| 23 } | |
| 24 | |
| 25 class E implements Pattern, Comparable { | |
| 26 } | |
| 27 | |
| 28 class F implements Pattern, Hashable { | |
| 29 } | |
| 30 | |
| 31 class G implements Pattern, Hashable, Comparable { | |
| 32 } | 22 } |
| 33 | 23 |
| 34 main() { | 24 main() { |
| 35 var things = [[], 4, 4.2, 'foo', new Object(), new A(), new B(), | 25 var things = [[], 4, 4.2, 'foo', new Object(), new A(), new B(), |
| 36 new C(), new D(), new E(), new F(), new G()]; | 26 new C(), new D()]; |
| 37 | 27 |
| 38 check(things[inscrutable(0)], false, false, false); // List | 28 check(things[inscrutable(0)], false, false); // List |
| 39 check(things[inscrutable(1)], true, true, false); // int | 29 check(things[inscrutable(1)], true, false); // int |
| 40 check(things[inscrutable(2)], true, true, false); // num | 30 check(things[inscrutable(2)], true, false); // num |
| 41 check(things[inscrutable(3)], true, true, true); // string | 31 check(things[inscrutable(3)], true, true); // string |
| 42 check(things[inscrutable(4)], false, false, false); // Object | 32 check(things[inscrutable(4)], false, false); // Object |
| 43 check(things[inscrutable(5)], true, false, false); // A | 33 check(things[inscrutable(5)], true, false); // A |
| 44 check(things[inscrutable(6)], false, true, false); // B | 34 check(things[inscrutable(6)], false, false); // B |
| 45 check(things[inscrutable(7)], true, true, false); // C | 35 check(things[inscrutable(7)], false, true); // C |
| 46 check(things[inscrutable(8)], false, false, true); // D | 36 check(things[inscrutable(8)], true, true); // D |
| 47 check(things[inscrutable(9)], true, false, true); // E | |
| 48 check(things[inscrutable(10)], false, true, true); // F | |
| 49 check(things[inscrutable(11)], true, true, true); // G | |
| 50 } | 37 } |
| OLD | NEW |