OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "native_testing.dart"; | 5 import "dart:_js_helper"; |
| 6 import "package:expect/expect.dart"; |
6 | 7 |
7 // Test that native classes can use ordinary Dart classes as mixins. | 8 // Test that native classes can use ordinary Dart classes as mixins. |
8 | 9 |
9 @Native("A") | 10 @Native("A") |
10 class A { | 11 class A { |
11 foo() => "A-foo"; | 12 foo() => "A-foo"; |
12 baz() => "A-baz"; | 13 baz() => "A-baz"; |
13 } | 14 } |
14 | 15 |
15 @Native("B") | 16 @Native("B") |
16 class B extends A with M { | 17 class B extends A with M { |
17 bar() => baz(); | 18 bar() => baz(); |
18 } | 19 } |
19 | 20 |
20 class M { | 21 class M { |
21 foo() => "M-foo"; | 22 foo() => "M-foo"; |
22 bar() => "M-bar"; | 23 bar() => "M-bar"; |
23 } | 24 } |
24 | 25 |
25 A makeA() native ; | 26 A makeA() native ; |
26 B makeB() native ; | 27 B makeB() native ; |
27 | 28 |
28 void setup() native """ | 29 void setup() native """ |
29 function A() {} | 30 function A() {} |
30 function B() {} | 31 function B() {} |
31 makeA = function(){return new A;}; | 32 makeA = function(){return new A;}; |
32 makeB = function(){return new B;}; | 33 makeB = function(){return new B;}; |
33 | |
34 self.nativeConstructor(A); | |
35 self.nativeConstructor(B); | |
36 """; | 34 """; |
37 | 35 |
38 main() { | 36 main() { |
39 nativeTesting(); | |
40 setup(); | 37 setup(); |
41 A a = makeA(); | 38 A a = makeA(); |
42 Expect.equals("A-foo", a.foo()); | 39 Expect.equals("A-foo", a.foo()); |
43 Expect.throws(() => a.bar(), (error) => error is NoSuchMethodError); | 40 Expect.throws(() => a.bar(), (error) => error is NoSuchMethodError); |
44 Expect.equals("A-baz", a.baz()); | 41 Expect.equals("A-baz", a.baz()); |
45 Expect.isTrue(a is A); | 42 Expect.isTrue(a is A); |
46 Expect.isFalse(a is B); | 43 Expect.isFalse(a is B); |
47 Expect.isFalse(a is M); | 44 Expect.isFalse(a is M); |
48 | 45 |
49 B b = makeB(); | 46 B b = makeB(); |
50 Expect.equals("M-foo", b.foo()); | 47 Expect.equals("M-foo", b.foo()); |
51 Expect.equals("A-baz", b.bar()); | 48 Expect.equals("A-baz", b.bar()); |
52 Expect.equals("A-baz", b.baz()); | 49 Expect.equals("A-baz", b.baz()); |
53 Expect.isTrue(b is A); | 50 Expect.isTrue(b is A); |
54 Expect.isTrue(b is B); | 51 Expect.isTrue(b is B); |
55 Expect.isTrue(b is M); | 52 Expect.isTrue(b is M); |
56 | 53 |
57 M m = new M(); | 54 M m = new M(); |
58 Expect.equals("M-foo", m.foo()); | 55 Expect.equals("M-foo", m.foo()); |
59 Expect.equals("M-bar", m.bar()); | 56 Expect.equals("M-bar", m.bar()); |
60 Expect.throws(() => m.baz(), (error) => error is NoSuchMethodError); | 57 Expect.throws(() => m.baz(), (error) => error is NoSuchMethodError); |
61 Expect.isFalse(m is A); | 58 Expect.isFalse(m is A); |
62 Expect.isFalse(m is B); | 59 Expect.isFalse(m is B); |
63 Expect.isTrue(m is M); | 60 Expect.isTrue(m is M); |
64 } | 61 } |
OLD | NEW |