OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:async'; | 5 import 'dart:async'; |
6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 import 'compiler_helper.dart'; | 8 import 'compiler_helper.dart'; |
9 | 9 |
10 const String TEST_1 = r""" | 10 const String TEST_1 = r""" |
11 import 'dart:_foreign_helper'; | 11 import 'dart:_foreign_helper'; |
12 main() { | 12 main() { |
13 // present: 'Moose' | 13 JS('', '#.toString()', -5); |
14 JS('', 'Moose'); | 14 // absent: "5.toString" |
15 | 15 // present: "(-5).toString" |
16 // absent: 'Phantom' - pure. | |
17 JS('returns: bool;effects:none;depends:none;throws:never', 'Phantom'); | |
18 | |
19 // present: 'Spider' - unused after constant folding 'is', but unpure. | |
20 print(JS('returns:bool;effects:none;depends:all', 'Spider') is bool); | |
21 | |
22 // absent: 'Wasp' - unused after constant folding 'is', and unpure. | |
23 print(JS('returns:bool;effects:none;depends:all;throws:never', 'Wasp') | |
24 is bool); | |
25 | |
26 JS('', 'Array'); // absent: "Array" | |
27 } | 16 } |
28 """; | 17 """; |
29 | 18 |
30 const String TEST_2 = r""" | |
31 import 'dart:_foreign_helper'; | |
32 main() { | |
33 var w1 = JS('returns:int;depends:none;effects:none;throws:never', | |
34 'foo(#)', 1); | |
35 var w2 = JS('returns:int;depends:none;effects:none;throws:never', | |
36 'foo(#)', 2); | |
37 | |
38 print([w2, w1]); | |
39 | |
40 // present: '[foo(2), foo(1)]' - since 'foo' is pure, we expect to generate | |
41 // code out-of-order. | |
42 } | |
43 """; | |
44 | |
45 const String TEST_3 = r""" | |
46 import 'dart:_foreign_helper'; | |
47 main() { | |
48 var s = JS('String|Null', '"Hello"'); | |
49 var s1 = JS('returns:String;depends:none;effects:none;throws:null(1)', | |
50 '#.toLowerCase()', s); | |
51 var s2 = JS('returns:String;depends:none;effects:none;throws:null(1)', | |
52 '#.toUpperCase()', s); | |
53 print(s2); | |
54 | |
55 // absent: 'toLowerCase' - removed since s.toUpperCase() generates the same | |
56 // noSuchMethod. | |
57 } | |
58 """; | |
59 | |
60 | 19 |
61 main() { | 20 main() { |
62 RegExp directivePattern = new RegExp( | 21 RegExp directivePattern = new RegExp( |
63 // \1 \2 \3 | 22 // \1 \2 \3 |
64 r'''// *(present|absent): (?:"([^"]*)"|'([^'']*)')''', | 23 r'''// *(present|absent): (?:"([^"]*)"|'([^'']*)')''', |
65 multiLine: true); | 24 multiLine: true); |
66 | 25 |
67 Future check(String test) { | 26 Future check(String test) { |
68 Uri uri = new Uri(scheme: 'dart', path: 'test'); | 27 Uri uri = new Uri(scheme: 'dart', path: 'test'); |
69 var compiler = compilerFor(test, uri, expectedErrors: 0); | 28 var compiler = compilerFor(test, uri, expectedErrors: 0); |
(...skipping 12 matching lines...) Expand all Loading... |
82 assert(directive == 'absent'); | 41 assert(directive == 'absent'); |
83 Expect.isFalse(generated.contains(pattern), | 42 Expect.isFalse(generated.contains(pattern), |
84 "Must not find '$pattern' in:\n$generated"); | 43 "Must not find '$pattern' in:\n$generated"); |
85 } | 44 } |
86 } | 45 } |
87 }); | 46 }); |
88 } | 47 } |
89 | 48 |
90 asyncTest(() => Future.wait([ | 49 asyncTest(() => Future.wait([ |
91 check(TEST_1), | 50 check(TEST_1), |
92 check(TEST_2), | |
93 check(TEST_3), | |
94 ])); | 51 ])); |
95 } | 52 } |
OLD | NEW |