OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Test the feature where the native string declares the native method's name. | 5 // Test the feature where the native string declares the native method's name. |
6 // #3. The name does not get | 6 // #3. The name does not get |
7 | 7 |
8 import 'native_testing.dart'; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:_js_helper' show Native, JSName; |
9 | 10 |
10 @Native("A") | 11 @Native("A") |
11 class A { | 12 class A { |
12 @JSName('fooA') | 13 @JSName('fooA') |
13 int foo() native ; | 14 int foo() native ; |
14 } | 15 } |
15 | 16 |
16 @Native("B") | 17 @Native("B") |
17 class B extends A { | 18 class B extends A { |
18 @JSName('fooB') | 19 @JSName('fooB') |
(...skipping 22 matching lines...) Expand all Loading... |
41 } | 42 } |
42 } | 43 } |
43 function A(){} | 44 function A(){} |
44 A.prototype.fooA = function(){return 100;}; | 45 A.prototype.fooA = function(){return 100;}; |
45 function B(){} | 46 function B(){} |
46 inherits(B, A); | 47 inherits(B, A); |
47 B.prototype.fooB = function(){return 200;}; | 48 B.prototype.fooB = function(){return 200;}; |
48 | 49 |
49 makeA = function(){return new A}; | 50 makeA = function(){return new A}; |
50 makeB = function(){return new B}; | 51 makeB = function(){return new B}; |
51 | |
52 self.nativeConstructor(A); | |
53 self.nativeConstructor(B); | |
54 """; | 52 """; |
55 | 53 |
56 testDynamic() { | 54 testDynamic() { |
57 var a = confuse(makeA()); | 55 var things = [makeA(), makeB(), new Decoy()]; |
58 var b = confuse(makeB()); | 56 var a = things[0]; |
59 var d = confuse(new Decoy()); | 57 var b = things[1]; |
| 58 var d = things[2]; |
60 | 59 |
61 Expect.equals(100, a.foo()); | 60 Expect.equals(100, a.foo()); |
62 Expect.equals(200, b.foo()); | 61 Expect.equals(200, b.foo()); |
63 Expect.equals(666, d.fooA()); | 62 Expect.equals(666, d.fooA()); |
64 Expect.equals(999, d.fooB()); | 63 Expect.equals(999, d.fooB()); |
65 | 64 |
66 expectNoSuchMethod(() { | 65 expectNoSuchMethod(() { |
67 a.fooA(); | 66 a.fooA(); |
68 }, 'fooA should be invisible on A'); | 67 }, 'fooA should be invisible on A'); |
69 Expect.equals(333, b.fooA()); | 68 Expect.equals(333, b.fooA()); |
(...skipping 11 matching lines...) Expand all Loading... |
81 B b = makeB(); | 80 B b = makeB(); |
82 Decoy d = new Decoy(); | 81 Decoy d = new Decoy(); |
83 | 82 |
84 Expect.equals(100, a.foo()); | 83 Expect.equals(100, a.foo()); |
85 Expect.equals(200, b.foo()); | 84 Expect.equals(200, b.foo()); |
86 Expect.equals(666, d.fooA()); | 85 Expect.equals(666, d.fooA()); |
87 Expect.equals(999, d.fooB()); | 86 Expect.equals(999, d.fooB()); |
88 } | 87 } |
89 | 88 |
90 main() { | 89 main() { |
91 nativeTesting(); | |
92 setup(); | 90 setup(); |
93 | 91 |
94 testDynamic(); | 92 testDynamic(); |
95 testTyped(); | 93 testTyped(); |
96 } | 94 } |
97 | 95 |
98 expectNoSuchMethod(action, note) { | 96 expectNoSuchMethod(action, note) { |
99 bool caught = false; | 97 bool caught = false; |
100 try { | 98 try { |
101 action(); | 99 action(); |
102 } on NoSuchMethodError catch (ex) { | 100 } on NoSuchMethodError catch (ex) { |
103 caught = true; | 101 caught = true; |
104 Expect.isTrue(ex is NoSuchMethodError, note); | 102 Expect.isTrue(ex is NoSuchMethodError, note); |
105 } | 103 } |
106 Expect.isTrue(caught, note); | 104 Expect.isTrue(caught, note); |
107 } | 105 } |
OLD | NEW |