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

Side by Side Diff: tests/compiler/dart2js/js_safety_test.dart

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test Created 4 years, 3 months 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) 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 'package:expect/expect.dart'; 5 import 'package:expect/expect.dart';
6 import 'package:compiler/src/js/js.dart' as js; 6 import 'package:compiler/src/js/js.dart' as js;
7 import 'package:compiler/src/js/placeholder_safety.dart'; 7 import 'package:compiler/src/js/placeholder_safety.dart';
8 8
9 void test(String source, int expected, {List notNull: const[]}) { 9 void test(String source, int expected, {List notNull: const []}) {
10 var predicate = (int pos) => ! notNull.contains(pos); 10 var predicate = (int pos) => !notNull.contains(pos);
11 js.Template template = js.js.parseForeignJS(source); 11 js.Template template = js.js.parseForeignJS(source);
12 int actual = PlaceholderSafetyAnalysis.analyze(template.ast, predicate); 12 int actual = PlaceholderSafetyAnalysis.analyze(template.ast, predicate);
13 Expect.equals(expected, actual, 'source: "$source", notNull: $notNull'); 13 Expect.equals(expected, actual, 'source: "$source", notNull: $notNull');
14 } 14 }
15 15
16
17 void main() { 16 void main() {
18 test('0', 0); 17 test('0', 0);
19 18
20 test('#.x', 1); 19 test('#.x', 1);
21 test('!!#.x', 1); 20 test('!!#.x', 1);
22 test('#.x + 1', 1); 21 test('#.x + 1', 1);
23 test('1 + #.x', 1); 22 test('1 + #.x', 1);
24 test('#[#] + 2', 2); 23 test('#[#] + 2', 2);
25 test('2 + #[#]', 2); 24 test('2 + #[#]', 2);
26 test('(# & #) >>> 0', 2); 25 test('(# & #) >>> 0', 2);
27 26
28 test('#.a + #.b + #.c', 1); 27 test('#.a + #.b + #.c', 1);
29 test('#.b + #.b + #.c', 2, notNull: [0]); 28 test('#.b + #.b + #.c', 2, notNull: [0]);
30 test('#.c + #.b + #.c', 3, notNull: [0, 1]); 29 test('#.c + #.b + #.c', 3, notNull: [0, 1]);
31 test('#.d + #.b + #.c', 1, notNull: [1]); 30 test('#.d + #.b + #.c', 1, notNull: [1]);
32 31
33 test('typeof(#) == "string"', 1); 32 test('typeof(#) == "string"', 1);
34 test('"object" === typeof #', 1); 33 test('"object" === typeof #', 1);
35 34
36 test('# == 1 || # == 2 || # == 3', 1); 35 test('# == 1 || # == 2 || # == 3', 1);
37 test('# != 1 && # != 2 && # != 3', 1); 36 test('# != 1 && # != 2 && # != 3', 1);
38 37
39 test('#.x == 1 || # == 1', 1); 38 test('#.x == 1 || # == 1', 1);
40 test('# == 1 || #.x == 1', 1); 39 test('# == 1 || #.x == 1', 1);
41 40
42 test('(# || 1, #)', 1); // Could also be 2. 41 test('(# || 1, #)', 1); // Could also be 2.
43 42
44 test('(#, null.a, #)', 1); 43 test('(#, null.a, #)', 1);
45 test('(#, undefined.a, #)', 1); 44 test('(#, undefined.a, #)', 1);
46 test('(#, (void 0).a, #)', 1); 45 test('(#, (void 0).a, #)', 1);
47 test('(#, "a".a, #)', 2); 46 test('(#, "a".a, #)', 2);
48 test('((#, "a").a, #)', 2); 47 test('((#, "a").a, #)', 2);
49 48
50 test('#[#][#][#][#]', 2); 49 test('#[#][#][#][#]', 2);
51 test('#[#][#][#][#]', 3, notNull: [0]); 50 test('#[#][#][#][#]', 3, notNull: [0]);
52 test('#[#][#][#][#]', 3, notNull: [0, 1, 2, 3]); 51 test('#[#][#][#][#]', 3, notNull: [0, 1, 2, 3]);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 test('throw #.x', 1); 88 test('throw #.x', 1);
90 89
91 test('(function(){})()', 0); 90 test('(function(){})()', 0);
92 test('(function(a,b){#})(#, #)', 0); 91 test('(function(a,b){#})(#, #)', 0);
93 // Placeholders in an immediate call are ok. 92 // Placeholders in an immediate call are ok.
94 test('(function(a,b){a++;b++;return a+b})(#, #)', 2); 93 test('(function(a,b){a++;b++;return a+b})(#, #)', 2);
95 94
96 test('# ? # : #', 1); 95 test('# ? # : #', 1);
97 test('(# ? 1 : #, #)', 1); 96 test('(# ? 1 : #, #)', 1);
98 test('(# ? # : 2, #)', 1); 97 test('(# ? # : 2, #)', 1);
99 test('(# ? 1 : 2, #)', 1); // Could also be 4. 98 test('(# ? 1 : 2, #)', 1); // Could also be 4.
100 99
101 test('{A:#, B:#, C:#}', 3); 100 test('{A:#, B:#, C:#}', 3);
102 test('[#,#,#,#]', 4); 101 test('[#,#,#,#]', 4);
103 test('[,,,,#,#,,,]', 2); 102 test('[,,,,#,#,,,]', 2);
104 } 103 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/js_parser_test.dart ('k') | tests/compiler/dart2js/js_spec_optimization_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698