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

Side by Side Diff: tests/compiler/dart2js_native/native_call_arity3_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:_js_helper"; 5 import "native_testing.dart";
6 import "package:expect/expect.dart";
7 6
8 // Test similar to NativeCallArity1FrogTest, but with default values to 7 // Test similar to NativeCallArity1FrogTest, but with default values to
9 // parameters set to null. These parameters should be treated as if they 8 // parameters set to null. These parameters should be treated as if they
10 // do not have a default value for the native methods. 9 // do not have a default value for the native methods.
11 10
12 @Native("A") 11 @Native("A")
13 class A { 12 class A {
14 int foo(int x) native ; 13 int foo(int x) native ;
15 } 14 }
16 15
(...skipping 10 matching lines...) Expand all
27 26
28 void setup() native """ 27 void setup() native """
29 function A() {} 28 function A() {}
30 A.prototype.foo = function () { return arguments.length; }; 29 A.prototype.foo = function () { return arguments.length; };
31 30
32 function B() {} 31 function B() {}
33 B.prototype.foo = function () { return arguments.length; }; 32 B.prototype.foo = function () { return arguments.length; };
34 33
35 makeA = function(){return new A;}; 34 makeA = function(){return new A;};
36 makeB = function(){return new B;}; 35 makeB = function(){return new B;};
36
37 self.nativeConstructor(A);
38 self.nativeConstructor(B);
37 """; 39 """;
38 40
39 testDynamicContext() { 41 testDynamicContext() {
40 var things = [makeA(), makeB()]; 42 var a = confuse(makeA());
41 var a = things[0]; 43 var b = confuse(makeB());
42 var b = things[1];
43 44
44 Expect.throws(() => a.foo()); 45 Expect.throws(() => a.foo());
45 Expect.equals(1, a.foo(10)); 46 Expect.equals(1, a.foo(10));
46 Expect.throws(() => a.foo(10, 20)); 47 Expect.throws(() => a.foo(10, 20));
47 Expect.throws(() => a.foo(10, 20, 30)); 48 Expect.throws(() => a.foo(10, 20, 30));
48 49
49 Expect.equals(0, b.foo()); 50 Expect.equals(0, b.foo());
50 Expect.equals(1, b.foo(10)); 51 Expect.equals(1, b.foo(10));
51 Expect.equals(2, b.foo(10, 20)); 52 Expect.equals(2, b.foo(10, 20));
52 Expect.equals(3, b.foo(10, 20, 30)); 53 Expect.equals(3, b.foo(10, 20, 30));
(...skipping 18 matching lines...) Expand all
71 Expect.equals(2, b.foo(10, 20)); 72 Expect.equals(2, b.foo(10, 20));
72 Expect.equals(3, b.foo(10, 20, 30)); 73 Expect.equals(3, b.foo(10, 20, 30));
73 74
74 Expect.equals(1, b.foo(10)); 75 Expect.equals(1, b.foo(10));
75 Expect.equals(2, b.foo(null, 20)); 76 Expect.equals(2, b.foo(null, 20));
76 Expect.equals(3, b.foo(null, null, 30)); 77 Expect.equals(3, b.foo(null, null, 30));
77 Expect.throws(() => b.foo(10, 20, 30, 40)); 78 Expect.throws(() => b.foo(10, 20, 30, 40));
78 } 79 }
79 80
80 main() { 81 main() {
82 nativeTesting();
81 setup(); 83 setup();
82 testDynamicContext(); 84 testDynamicContext();
83 testStaticContext(); 85 testStaticContext();
84 } 86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698