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

Side by Side Diff: tests/compiler/dart2js_extra/consistent_codeUnitAt_error_test.dart

Issue 1463933004: Test dart2js for consistent codeUnitAt errors under optimization (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6
7 // Test that optimized codeUnitAt and slow path codeUnitAt produce the same
8 // error.
9
10 @NoInline()
11 @AssumeDynamic()
12 confuse(x) => x;
13
14 void check2(String name, name1, f1, name2, f2) {
15 Error trap(part, f) {
16 try {
17 f();
18 } catch (e) {
19 return e;
20 }
21 Expect.fail('should throw: $name.$part');
22 }
23 var e1 = trap(name1, f1);
24 var e2 = trap(name2, f2);
25 var s1 = '$e1';
26 var s2 = '$e2';
27 Expect.equals(s1, s2, '\n $name.$name1: "$s1"\n $name.$name2: "$s2"\n');
28 }
29
30 void check(String name, f1, f2, [f3, f4]) {
31 check2(name, 'f1', f1, 'f2', f2);
32 if (f3 != null) check2(name, 'f1', f1, 'f3', f3);
33 if (f4 != null) check2(name, 'f1', f1, 'f4', f4);
34 }
35
36
37 class TooHigh {
38 static f1() {
39 return confuse('AB').codeUnitAt(3); // dynamic receiver.
40 }
41
42 static f2() {
43 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
44 var i = confuse(3);
45 return a.codeUnitAt(i);
46 }
47
48 static f3() {
49 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
50 return a.codeUnitAt(3);
51 }
52
53 static test() {
54 check('TooHigh', f1, f2, f3);
55 }
56 }
57
58 class Negative {
59 static f1() {
60 return confuse('AB').codeUnitAt(-3); // dynamic receiver.
61 }
62
63 static f2() {
64 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
65 var i = confuse(-3);
66 return a.codeUnitAt(i);
67 }
68
69 static f3() {
70 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
71 var i = confuse(true) ? -3 : 0;
72 return a.codeUnitAt(i);
73 }
74
75 static f4() {
76 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
77 return a.codeUnitAt(-3);
78 }
79
80 static test() {
81 check('Negative', f1, f2, f3, f4);
82 }
83 }
84
85 class Empty {
86 static f1() {
87 return confuse('').codeUnitAt(0); // dynamic receiver.
88 }
89
90 static f2() {
91 var a = confuse(true) ? '' : 'ABCDE'; // Empty String with unknown length.
92 var i = confuse(true) ? 0 : 1;
93 return a.codeUnitAt(i);
94 }
95
96 static f3() {
97 var a = confuse(true) ? '' : 'ABCDE'; // Empty String with unknown length.
98 return a.codeUnitAt(0);
99 }
100
101 static test() {
102 check('Empty', f1, f2, f3);
103 }
104 }
105
106 class BadType {
107 static f1() {
108 return confuse('AB').codeUnitAt('a'); // dynamic receiver.
109 }
110
111 static f2() {
112 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
113 var i = confuse('a');
114 return a.codeUnitAt(i);
115 }
116
117 static f3() {
118 var a = confuse(true) ? 'AB' : 'ABCDE'; // String with unknown length.
119 return a.codeUnitAt('a');
120 }
121
122 static test() {
123 check('BadType', f1, f2, f3);
124 }
125 }
126
127 main() {
128 TooHigh.test();
129 Negative.test();
130 Empty.test();
131 BadType.test();
132 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698