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

Side by Side Diff: tests/compiler/dart2js_native/native_no_such_method_exception3_frog_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) 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:mirrors" show reflect; 5 import "dart:mirrors" show reflect;
6 import "dart:_js_helper"; 6 import "native_testing.dart";
7 import "package:expect/expect.dart";
8 7
9 class GetName { 8 class GetName {
10 foo(x, y, [z]) => "foo"; 9 foo(x, y, [z]) => "foo";
11 } 10 }
12 11
13 String getName(im) => reflect(new GetName()).delegate(im); 12 String getName(im) => reflect(new GetName()).delegate(im);
14 13
15 @Native("A") 14 @Native("A")
16 class A { 15 class A {
17 bar() => 42; 16 bar() => 42;
18 } 17 }
19 18
20 @Native("B") 19 @Native("B")
21 class B { 20 class B {
22 foo() => 42; 21 foo() => 42;
23 } 22 }
24 23
25 class C { 24 class C {
26 static create() => new C(); 25 static create() => new C();
27 noSuchMethod(x) => "${getName(x)}:${x.positionalArguments}"; 26 noSuchMethod(x) => "${getName(x)}:${x.positionalArguments}";
28 } 27 }
29 28
30 makeA() native ; 29 makeA() native ;
31 30
32 setup() native """ 31 setup() native """
33 function A() {} 32 function A() {}
34 makeA = function() { return new A; } 33 makeA = function() { return new A; }
34
35 self.nativeConstructor(A);
35 """; 36 """;
36 37
37 main() { 38 main() {
39 nativeTesting();
38 setup(); 40 setup();
39 var a = makeA(); 41 var a = makeA();
40 a.bar(); 42 a.bar();
41 var exception; 43 var exception;
42 try { 44 try {
43 a.foo(); 45 a.foo();
44 } on NoSuchMethodError catch (e) { 46 } on NoSuchMethodError catch (e) {
45 exception = e; 47 exception = e;
46 } 48 }
47 Expect.isNotNull(exception); 49 Expect.isNotNull(exception);
48 var c = C.create(); 50 var c = C.create();
49 Expect.equals("foo:[1, 2]", c.foo(1, 2)); 51 Expect.equals("foo:[1, 2]", c.foo(1, 2));
50 Expect.equals("foo:[3, 4, 5]", c.foo(3, 4, 5)); 52 Expect.equals("foo:[3, 4, 5]", c.foo(3, 4, 5));
51 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698