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 import "dart:_js_helper"; | 5 import "native_testing.dart"; |
6 import "package:expect/expect.dart"; | |
7 | |
8 var inscrutable = (int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); | |
9 | 6 |
10 @Native("A") | 7 @Native("A") |
11 class A {} | 8 class A {} |
12 | 9 |
13 @Native("B") | 10 @Native("B") |
14 class B implements Comparable {} | 11 class B implements Comparable {} |
15 | 12 |
16 @Native("C") | 13 @Native("C") |
17 class C implements Pattern {} | 14 class C implements Pattern {} |
18 | 15 |
19 @Native("D") | 16 @Native("D") |
20 class D implements Pattern, Comparable {} | 17 class D implements Pattern, Comparable {} |
21 | 18 |
22 makeA() native ; | 19 makeA() native ; |
23 makeB() native ; | 20 makeB() native ; |
24 makeC() native ; | 21 makeC() native ; |
25 makeD() native ; | 22 makeD() native ; |
26 | 23 |
27 void setup() native """ | 24 void setup() native """ |
28 function A() {}; | 25 function A() {}; |
29 makeA = function() { return new A; } | 26 makeA = function() { return new A; } |
30 function B() {}; | 27 function B() {}; |
31 makeB = function() { return new B; } | 28 makeB = function() { return new B; } |
32 function C() {}; | 29 function C() {}; |
33 makeC = function() { return new C; } | 30 makeC = function() { return new C; } |
34 function D() {}; | 31 function D() {}; |
35 makeD = function() { return new D; } | 32 makeD = function() { return new D; } |
| 33 |
| 34 self.nativeConstructor(A); |
| 35 self.nativeConstructor(B); |
| 36 self.nativeConstructor(C); |
| 37 self.nativeConstructor(D); |
36 """; | 38 """; |
37 | 39 |
38 checkTest(value, expectComparable, expectPattern) { | 40 checkTest(value, expectComparable, expectPattern) { |
39 Expect.equals(expectComparable, value is Comparable); | 41 Expect.equals(expectComparable, value is Comparable); |
40 Expect.equals(expectPattern, value is Pattern); | 42 Expect.equals(expectPattern, value is Pattern); |
41 } | 43 } |
42 | 44 |
43 checkCast(value, expectComparable, expectPattern) { | 45 checkCast(value, expectComparable, expectPattern) { |
44 if (expectComparable) { | 46 if (expectComparable) { |
45 Expect.identical(value, value as Comparable); | 47 Expect.identical(value, value as Comparable); |
(...skipping 12 matching lines...) Expand all Loading... |
58 [], | 60 [], |
59 4, | 61 4, |
60 4.2, | 62 4.2, |
61 'foo', | 63 'foo', |
62 new Object(), | 64 new Object(), |
63 makeA(), | 65 makeA(), |
64 makeB(), | 66 makeB(), |
65 makeC(), | 67 makeC(), |
66 makeD() | 68 makeD() |
67 ]; | 69 ]; |
68 value(i) => things[inscrutable(i)]; | 70 value(i) => confuse(things[i]); |
69 | 71 |
70 check(value(0), false, false); // List | 72 check(value(0), false, false); // List |
71 check(value(1), true, false); // int | 73 check(value(1), true, false); // int |
72 check(value(2), true, false); // num | 74 check(value(2), true, false); // num |
73 check(value(3), true, true); // String | 75 check(value(3), true, true); // String |
74 check(value(4), false, false); // Object | 76 check(value(4), false, false); // Object |
75 check(value(5), false, false); // A | 77 check(value(5), false, false); // A |
76 check(value(6), true, false); // B | 78 check(value(6), true, false); // B |
77 check(value(7), false, true); // C | 79 check(value(7), false, true); // C |
78 check(value(8), true, true); // D | 80 check(value(8), true, true); // D |
79 } | 81 } |
80 | 82 |
81 main() { | 83 main() { |
| 84 nativeTesting(); |
82 setup(); | 85 setup(); |
83 | 86 |
84 checkAll(checkTest); | 87 checkAll(checkTest); |
85 checkAll(checkCast); | 88 checkAll(checkCast); |
86 } | 89 } |
OLD | NEW |