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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // Test that native classes can use ordinary Dart classes with fields | 7 // Test that native classes can use ordinary Dart classes with fields |
8 // as mixins. | 8 // as mixins. |
9 | 9 |
10 class A native "A" { | 10 class A native "A" { |
11 var foo; | 11 var foo; |
12 } | 12 } |
13 | 13 |
14 class B extends A with M1, M2 native "B" { | 14 class B extends A with M1, M2 native "B" { |
15 var bar; | 15 var bar; |
16 } | 16 } |
17 | 17 |
18 class M1 { | 18 class M1 { |
19 var baz; | 19 var baz; // This field is not a native field, even when mixed in. |
20 } | 20 } |
21 | 21 |
22 class M2 { | 22 class M2 { |
23 var bar; | 23 var bar; |
24 var buz; | 24 var buz; |
25 } | 25 } |
26 | 26 |
27 A makeA() native; | 27 A makeA() native; |
28 B makeB() native; | 28 B makeB() native; |
29 | 29 |
30 void setup() native """ | 30 void setup() native """ |
31 function A() {this.foo='A-foo';} | 31 function A() {this.foo='A-foo';} |
32 function B() {A.call(this);this.bar='B-bar';this.baz='M1-baz';} | 32 function B() {A.call(this);this.bar='B-bar';this.baz='M1-baz';} |
33 makeA = function(){return new A;}; | 33 makeA = function(){return new A;}; |
34 makeB = function(){return new B;}; | 34 makeB = function(){return new B;}; |
35 """; | 35 """; |
36 | 36 |
37 main() { | 37 main() { |
38 setup(); | 38 setup(); |
39 A a = makeA(); | 39 A a = makeA(); |
40 Expect.equals("A-foo", a.foo); | 40 Expect.equals("A-foo", a.foo); |
41 Expect.throws(() => a.bar, (e) => e is NoSuchMethodError); | 41 Expect.throws(() => a.bar, (e) => e is NoSuchMethodError); |
42 Expect.throws(() => a.baz, (e) => e is NoSuchMethodError); | 42 Expect.throws(() => a.baz, (e) => e is NoSuchMethodError); |
43 Expect.throws(() => a.buz, (e) => e is NoSuchMethodError); | 43 Expect.throws(() => a.buz, (e) => e is NoSuchMethodError); |
44 | 44 |
45 B b = makeB(); | 45 B b = makeB(); |
46 Expect.equals("A-foo", b.foo); | 46 Expect.equals("A-foo", b.foo); |
47 Expect.equals("B-bar", b.bar); | 47 Expect.equals("B-bar", b.bar); |
48 Expect.equals("M1-baz", b.baz); | 48 // Expect.equals("M1-baz", b.baz); // not true, see M1. |
| 49 Expect.isNull(b.baz); // native b.baz is not the same as dart b.baz. |
49 Expect.isNull(b.buz); | 50 Expect.isNull(b.buz); |
50 | 51 |
51 M1 m1 = new M1(); | 52 M1 m1 = new M1(); |
52 Expect.throws(() => m1.foo, (e) => e is NoSuchMethodError); | 53 Expect.throws(() => m1.foo, (e) => e is NoSuchMethodError); |
53 Expect.throws(() => m1.bar, (e) => e is NoSuchMethodError); | 54 Expect.throws(() => m1.bar, (e) => e is NoSuchMethodError); |
54 Expect.isNull(m1.baz); | 55 Expect.isNull(m1.baz); |
55 Expect.throws(() => m1.buz, (e) => e is NoSuchMethodError); | 56 Expect.throws(() => m1.buz, (e) => e is NoSuchMethodError); |
56 | 57 |
57 M2 m2 = new M2(); | 58 M2 m2 = new M2(); |
58 Expect.throws(() => m2.foo, (e) => e is NoSuchMethodError); | 59 Expect.throws(() => m2.foo, (e) => e is NoSuchMethodError); |
59 Expect.isNull(m2.bar); | 60 Expect.isNull(m2.bar); |
60 Expect.throws(() => m2.baz, (e) => e is NoSuchMethodError); | 61 Expect.throws(() => m2.baz, (e) => e is NoSuchMethodError); |
61 Expect.isNull(m2.buz); | 62 Expect.isNull(m2.buz); |
62 } | 63 } |
OLD | NEW |