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 import "dart:_js_helper"; | 5 import "native_testing.dart"; |
6 import "package:expect/expect.dart"; | |
7 | 6 |
8 // Test for values of some basic types. | 7 // Test for values of some basic types. |
9 | 8 |
10 @Native("A") | 9 @Native("A") |
11 class A { | 10 class A { |
12 returnNull() native ; | 11 returnNull() native ; |
13 returnUndefined() native ; | 12 returnUndefined() native ; |
14 returnEmptyString() native ; | 13 returnEmptyString() native ; |
15 returnZero() native ; | 14 returnZero() native ; |
16 } | 15 } |
17 | 16 |
18 A makeA() native ; | 17 A makeA() native ; |
19 | 18 |
20 void setup() native """ | 19 void setup() native """ |
21 function A() {} | 20 function A() {} |
22 A.prototype.returnNull = function() { return null; }; | 21 A.prototype.returnNull = function() { return null; }; |
23 A.prototype.returnUndefined = function() { return void 0; }; | 22 A.prototype.returnUndefined = function() { return void 0; }; |
24 A.prototype.returnEmptyString = function() { return ""; }; | 23 A.prototype.returnEmptyString = function() { return ""; }; |
25 A.prototype.returnZero = function() { return 0; }; | 24 A.prototype.returnZero = function() { return 0; }; |
26 makeA = function(){return new A;}; | 25 makeA = function(){return new A;}; |
| 26 self.nativeConstructor(A); |
27 """; | 27 """; |
28 | 28 |
29 main() { | 29 @NoInline() |
30 setup(); | 30 staticTests() { |
31 A a = makeA(); | 31 A a = makeA(); |
32 Expect.equals(null, a.returnNull()); | 32 Expect.equals(null, a.returnNull()); |
33 Expect.equals(null, a.returnUndefined()); | 33 Expect.equals(null, a.returnUndefined()); |
34 | 34 |
35 Expect.equals('', a.returnEmptyString()); | 35 Expect.equals('', a.returnEmptyString()); |
36 Expect.isTrue(a.returnEmptyString().isEmpty); | 36 Expect.isTrue(a.returnEmptyString().isEmpty); |
37 Expect.isTrue(a.returnEmptyString() is String); | 37 Expect.isTrue(a.returnEmptyString() is String); |
38 | 38 |
39 Expect.isTrue(a.returnZero() is int); | 39 Expect.isTrue(a.returnZero() is int); |
40 Expect.equals(0, a.returnZero()); | 40 Expect.equals(0, a.returnZero()); |
41 } | 41 } |
| 42 |
| 43 @NoInline() |
| 44 dynamicTests() { |
| 45 A a = makeA(); |
| 46 Expect.equals(null, confuse(a).returnNull()); |
| 47 Expect.equals(null, confuse(a).returnUndefined()); |
| 48 |
| 49 Expect.equals('', confuse(a).returnEmptyString()); |
| 50 Expect.isTrue(confuse(a).returnEmptyString().isEmpty); |
| 51 Expect.isTrue(confuse(a).returnEmptyString() is String); |
| 52 |
| 53 Expect.isTrue(confuse(a).returnZero() is int); |
| 54 Expect.equals(0, confuse(a).returnZero()); |
| 55 } |
| 56 |
| 57 main() { |
| 58 nativeTesting(); |
| 59 setup(); |
| 60 staticTests(); |
| 61 dynamicTests(); |
| 62 } |
OLD | NEW |