OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, 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 library dart2js.serialization_test_data; | |
6 | |
7 const List<Test> TESTS = const <Test>[ | |
8 const Test(const { | |
9 'main.dart': 'main() {}' | |
10 }), | |
11 | |
12 const Test(const { | |
13 'main.dart': 'main() => print("Hello World");' | |
14 }), | |
15 | |
16 const Test(const { | |
17 'main.dart': 'main() => print("Hello World", 0);' | |
18 }, | |
19 expectedWarningCount: 1, | |
20 expectedInfoCount: 1), | |
21 | |
22 const Test(const { | |
23 'main.dart': r''' | |
24 main() { | |
25 String text = "Hello World"; | |
26 print('$text'); | |
27 }''' | |
28 }), | |
29 | |
30 const Test(const { | |
31 'main.dart': r''' | |
32 main() { | |
33 String text = "Hello World"; | |
34 print('$text', text); | |
35 }''' | |
36 }, | |
37 expectedWarningCount: 1, | |
38 expectedInfoCount: 1), | |
39 | |
40 const Test(const { | |
41 'main.dart': r''' | |
42 main(List<String> arguments) { | |
43 print(arguments); | |
44 }''' | |
45 }), | |
46 | |
47 const Test(const { | |
48 'main.dart': r''' | |
49 main(List<String> arguments) { | |
50 for (int i = 0; i < arguments.length; i++) { | |
51 print(arguments[i]); | |
52 } | |
53 }''' | |
54 }), | |
55 | |
56 const Test(const { | |
57 'main.dart': r''' | |
58 main(List<String> arguments) { | |
59 for (String argument in arguments) { | |
60 print(argument); | |
61 } | |
62 }''' | |
63 }), | |
64 | |
65 const Test(const { | |
66 'main.dart': r''' | |
67 class Class {} | |
68 main() { | |
69 print(new Class()); | |
70 }''' | |
71 }), | |
72 | |
73 const Test(const { | |
74 'main.dart': r''' | |
75 class Class implements Function {} | |
76 main() { | |
77 print(new Class()); | |
78 }''' | |
79 }, | |
80 expectedWarningCount: 1), | |
81 | |
82 const Test(const { | |
83 'main.dart': r''' | |
84 class Class implements Function { | |
85 call() {} | |
86 } | |
87 main() { | |
88 print(new Class()()); | |
89 }''' | |
90 }), | |
91 | |
92 const Test(const { | |
93 'main.dart': r''' | |
94 class Class implements Comparable<Class> { | |
95 int compareTo(Class other) => 0; | |
96 } | |
97 main() { | |
98 print(new Class()); | |
99 }''' | |
100 }), | |
101 | |
102 const Test(const { | |
103 'main.dart': r''' | |
104 class Class implements Comparable<Class, Class> { | |
105 int compareTo(other) => 0; | |
106 } | |
107 main() { | |
108 print(new Class()); | |
109 }''' | |
110 }, | |
111 expectedWarningCount: 1), | |
112 | |
113 const Test(const { | |
114 'main.dart': r''' | |
115 class Class implements Comparable<Class> { | |
116 int compareTo(String other) => 0; | |
117 } | |
118 main() { | |
119 print(new Class().compareTo(null)); | |
120 }''' | |
121 }, | |
122 expectedWarningCount: 1, | |
123 expectedInfoCount: 1), | |
124 | |
125 const Test(const { | |
126 'main.dart': r''' | |
127 class Class implements Comparable { | |
128 bool compareTo(a, b) => true; | |
129 } | |
130 main() { | |
131 print(new Class().compareTo(null, null)); | |
132 }''' | |
133 }, | |
134 expectedWarningCount: 1, | |
135 expectedInfoCount: 1), | |
136 | |
137 const Test(const { | |
138 'main.dart': r''' | |
139 import 'dart:math'; | |
140 | |
141 class MyRandom implements Random { | |
142 int nextInt(int max) { | |
143 return max.length; | |
144 } | |
145 bool nextBool() => true; | |
146 double nextDouble() => 0.0; | |
147 } | |
148 main() { | |
149 new MyRandom().nextInt(0); | |
150 }''' | |
151 }, | |
152 expectedWarningCount: 1, | |
153 expectedInfoCount: 0), | |
154 | |
155 const Test(const { | |
156 'main.dart': r''' | |
157 import 'dart:math'; | |
158 | |
159 class MyRandom implements Random { | |
160 int nextInt(int max) { | |
161 return max.length; | |
162 } | |
163 bool nextBool() => true; | |
164 double nextDouble() => 0.0; | |
165 } | |
166 main() { | |
167 new MyRandom(); | |
168 }''' | |
169 }), | |
170 | |
171 const Test(const { | |
172 'main.dart': r''' | |
173 import 'dart:math'; | |
174 | |
175 class MyRandom implements Random { | |
176 int nextInt(int max) { | |
177 return max.length; | |
178 } | |
179 bool nextBool() => true; | |
180 double nextDouble() => 0.0; | |
181 } | |
182 main() { | |
183 // Invocation of `MyRandom.nextInt` is only detected knowing the actual | |
184 // implementation class for `List` and the world impact of its `shuffle` | |
185 // method. | |
186 [].shuffle(new MyRandom()); | |
187 }''' | |
188 }, | |
189 expectedWarningCount: 1, | |
190 expectedInfoCount: 0), | |
191 | |
192 const Test(const { | |
193 'main.dart': ''' | |
194 main() { | |
195 loop: for (var a in []) { | |
196 for (var b in []) { | |
197 continue loop; | |
198 } | |
199 break; | |
200 } | |
201 }''' | |
202 }), | |
203 | |
204 ]; | |
205 | |
206 class Test { | |
207 final Map sourceFiles; | |
208 final int expectedErrorCount; | |
209 final int expectedWarningCount; | |
210 final int expectedHintCount; | |
211 final int expectedInfoCount; | |
212 | |
213 const Test(this.sourceFiles, { | |
214 this.expectedErrorCount: 0, | |
215 this.expectedWarningCount: 0, | |
216 this.expectedHintCount: 0, | |
217 this.expectedInfoCount: 0}); | |
218 } | |
OLD | NEW |