Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: tests/compiler/dart2js_native/native_mixin_test.dart

Issue 2379173002: Add native_testing library to mock @Native classes (Closed)
Patch Set: xxx Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "dart:_js_helper"; 5 import "native_testing.dart";
6 import "package:expect/expect.dart";
7 6
8 // Test that native classes can use ordinary Dart classes as mixins. 7 // Test that native classes can use ordinary Dart classes as mixins.
9 8
10 @Native("A") 9 @Native("A")
11 class A { 10 class A {
12 foo() => "A-foo"; 11 foo() => "A-foo";
13 baz() => "A-baz"; 12 baz() => "A-baz";
14 } 13 }
15 14
16 @Native("B") 15 @Native("B")
17 class B extends A with M { 16 class B extends A with M {
18 bar() => baz(); 17 bar() => baz();
19 } 18 }
20 19
21 class M { 20 class M {
22 foo() => "M-foo"; 21 foo() => "M-foo";
23 bar() => "M-bar"; 22 bar() => "M-bar";
24 } 23 }
25 24
26 A makeA() native ; 25 A makeA() native ;
27 B makeB() native ; 26 B makeB() native ;
28 27
29 void setup() native """ 28 void setup() native """
30 function A() {} 29 function A() {}
31 function B() {} 30 function B() {}
32 makeA = function(){return new A;}; 31 makeA = function(){return new A;};
33 makeB = function(){return new B;}; 32 makeB = function(){return new B;};
33
34 self.nativeConstructor(A);
35 self.nativeConstructor(B);
34 """; 36 """;
35 37
36 main() { 38 main() {
39 nativeTesting();
37 setup(); 40 setup();
38 A a = makeA(); 41 A a = makeA();
39 Expect.equals("A-foo", a.foo()); 42 Expect.equals("A-foo", a.foo());
40 Expect.throws(() => a.bar(), (error) => error is NoSuchMethodError); 43 Expect.throws(() => a.bar(), (error) => error is NoSuchMethodError);
41 Expect.equals("A-baz", a.baz()); 44 Expect.equals("A-baz", a.baz());
42 Expect.isTrue(a is A); 45 Expect.isTrue(a is A);
43 Expect.isFalse(a is B); 46 Expect.isFalse(a is B);
44 Expect.isFalse(a is M); 47 Expect.isFalse(a is M);
45 48
46 B b = makeB(); 49 B b = makeB();
47 Expect.equals("M-foo", b.foo()); 50 Expect.equals("M-foo", b.foo());
48 Expect.equals("A-baz", b.bar()); 51 Expect.equals("A-baz", b.bar());
49 Expect.equals("A-baz", b.baz()); 52 Expect.equals("A-baz", b.baz());
50 Expect.isTrue(b is A); 53 Expect.isTrue(b is A);
51 Expect.isTrue(b is B); 54 Expect.isTrue(b is B);
52 Expect.isTrue(b is M); 55 Expect.isTrue(b is M);
53 56
54 M m = new M(); 57 M m = new M();
55 Expect.equals("M-foo", m.foo()); 58 Expect.equals("M-foo", m.foo());
56 Expect.equals("M-bar", m.bar()); 59 Expect.equals("M-bar", m.bar());
57 Expect.throws(() => m.baz(), (error) => error is NoSuchMethodError); 60 Expect.throws(() => m.baz(), (error) => error is NoSuchMethodError);
58 Expect.isFalse(m is A); 61 Expect.isFalse(m is A);
59 Expect.isFalse(m is B); 62 Expect.isFalse(m is B);
60 Expect.isTrue(m is M); 63 Expect.isTrue(m is M);
61 } 64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698