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

Side by Side Diff: compiler/javatests/com/google/dart/compiler/resolver/CompileTimeConstantTest.java

Issue 8513011: Sorted some files before refactoring (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 package com.google.dart.compiler.resolver; 5 package com.google.dart.compiler.resolver;
6 6
7 import com.google.common.base.Joiner; 7 import com.google.common.base.Joiner;
8 8
9 /** 9 /**
10 * Tests the code in {@link CompileTimeConstantVisitor} 10 * Tests the code in {@link CompileTimeConstantVisitor}
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 238 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER,
239 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 239 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER,
240 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 240 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER,
241 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 241 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER,
242 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 242 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER,
243 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 243 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER,
244 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER, 244 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER,
245 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER); 245 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_NUMBER);
246 } 246 }
247 247
248 public void testConstantUnaryExpression() {
249 resolveAndTest(Joiner.on("\n").join(
250 "class Object {}",
251 "class A {",
252 " // Unary expression",
253 " static final BOOL_LIT = true;",
254 " static final INT_LIT = 123;",
255 " static final DOUBLE_LIT = 12.3;",
256 " static final UOP1_0 = !BOOL_LIT;",
257 " static final UOP1_1 = BOOL_LIT || !true;",
258 " static final UOP1_2 = !BOOL_LIT || true;",
259 " static final UOP1_3 = !(BOOL_LIT && true);",
260 " static final UOP2_0 = ~0xf0;",
261 " static final UOP2_1 = ~INT_LIT;",
262 " static final UOP2_2 = ~INT_LIT & 123;",
263 " static final UOP2_3 = ~(INT_LIT | 0xff);",
264 " static final UOP3_0 = -0xf0;",
265 " static final UOP3_1 = -INT_LIT;",
266 " static final UOP3_2 = -INT_LIT + 123;",
267 " static final UOP3_3 = -(INT_LIT * 0xff);",
268 " static final UOP3_4 = -0xf0;",
269 " static final UOP3_5 = -DOUBLE_LIT;",
270 " static final UOP3_6 = -DOUBLE_LIT + 123;",
271 " static final UOP3_7 = -(DOUBLE_LIT * 0xff);",
272 "}"));
273
274 resolveAndTest(Joiner.on("\n").join(
275 "class Object {}",
276 "class int {}",
277 "class A {",
278 " // Unary expression",
279 " static final BOOL_LIT = true;",
280 " static int foo() { return 3; }",
281 " static final UOP1 = !5;",
282 " static final UOP2 = !foo();",
283 " static final UOP3 = !(5);",
284 " static final UOP4 = !(foo());",
285 "}"),
286 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN,
287 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION,
288 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN,
289 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN,
290 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION,
291 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN);
292 }
293
294 public void testConstantConstructorAssign() { 248 public void testConstantConstructorAssign() {
295 249
296 resolveAndTest(Joiner.on("\n").join( 250 resolveAndTest(Joiner.on("\n").join(
297 "class Object {}", 251 "class Object {}",
298 "class A {", 252 "class A {",
299 " const A();", 253 " const A();",
300 "}", 254 "}",
301 "class B {", 255 "class B {",
302 " static final a = const A();", // Constant constructor 256 " static final a = const A();", // Constant constructor
303 "}")); 257 "}"));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 " static String foo() { return \"one\"; }", 338 " static String foo() { return \"one\"; }",
385 " static final String s = \"apple\";", 339 " static final String s = \"apple\";",
386 " // map literal contains non-const member", 340 " // map literal contains non-const member",
387 " static final map = const { \"1\":foo(), \"2\": \"banana\" };", 341 " static final map = const { \"1\":foo(), \"2\": \"banana\" };",
388 " static final stringInterp = \"It was that woman who gave me the ${s}\ ";", 342 " static final stringInterp = \"It was that woman who gave me the ${s}\ ";",
389 "}"), 343 "}"),
390 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION, 344 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION,
391 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); 345 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION);
392 } 346 }
393 347
348 public void testConstantUnaryExpression() {
349 resolveAndTest(Joiner.on("\n").join(
350 "class Object {}",
351 "class A {",
352 " // Unary expression",
353 " static final BOOL_LIT = true;",
354 " static final INT_LIT = 123;",
355 " static final DOUBLE_LIT = 12.3;",
356 " static final UOP1_0 = !BOOL_LIT;",
357 " static final UOP1_1 = BOOL_LIT || !true;",
358 " static final UOP1_2 = !BOOL_LIT || true;",
359 " static final UOP1_3 = !(BOOL_LIT && true);",
360 " static final UOP2_0 = ~0xf0;",
361 " static final UOP2_1 = ~INT_LIT;",
362 " static final UOP2_2 = ~INT_LIT & 123;",
363 " static final UOP2_3 = ~(INT_LIT | 0xff);",
364 " static final UOP3_0 = -0xf0;",
365 " static final UOP3_1 = -INT_LIT;",
366 " static final UOP3_2 = -INT_LIT + 123;",
367 " static final UOP3_3 = -(INT_LIT * 0xff);",
368 " static final UOP3_4 = -0xf0;",
369 " static final UOP3_5 = -DOUBLE_LIT;",
370 " static final UOP3_6 = -DOUBLE_LIT + 123;",
371 " static final UOP3_7 = -(DOUBLE_LIT * 0xff);",
372 "}"));
373
374 resolveAndTest(Joiner.on("\n").join(
375 "class Object {}",
376 "class int {}",
377 "class A {",
378 " // Unary expression",
379 " static final BOOL_LIT = true;",
380 " static int foo() { return 3; }",
381 " static final UOP1 = !5;",
382 " static final UOP2 = !foo();",
383 " static final UOP3 = !(5);",
384 " static final UOP4 = !(foo());",
385 "}"),
386 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN,
387 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION,
388 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN,
389 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN,
390 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION,
391 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION_BOOLEAN);
392 }
393
394 public void testConstantVariableAssign() { 394 public void testConstantVariableAssign() {
395 resolveAndTest(Joiner.on("\n").join( 395 resolveAndTest(Joiner.on("\n").join(
396 "class Object {}", 396 "class Object {}",
397 "class A {", 397 "class A {",
398 " static final a = 1;", 398 " static final a = 1;",
399 "}", 399 "}",
400 "class B {", 400 "class B {",
401 " static final i = 1;", 401 " static final i = 1;",
402 " static final j = i;", // variable that is a compile-time constant 402 " static final j = i;", // variable that is a compile-time constant
403 " static final k = A.a;", // variable that is a compile-time constant 403 " static final k = A.a;", // variable that is a compile-time constant
404 "}")); 404 "}"));
405 405
406 // Negative tests 406 // Negative tests
407 resolveAndTest(Joiner.on("\n").join( 407 resolveAndTest(Joiner.on("\n").join(
408 "class Object {}", 408 "class Object {}",
409 "class A {", 409 "class A {",
410 " static foo() {return 1;}", 410 " static foo() {return 1;}",
411 " static final i = foo();", // Error: not a constant integer 411 " static final i = foo();", // Error: not a constant integer
412 "}"), 412 "}"),
413 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION); 413 ResolverErrorCode.EXPECTED_CONSTANT_EXPRESSION);
414 414
415 resolveAndTest(Joiner.on("\n").join( 415 resolveAndTest(Joiner.on("\n").join(
416 "class Object {}", 416 "class Object {}",
417 "class A {", 417 "class A {",
418 " static final foo;", 418 " static final foo;",
419 "}"), 419 "}"),
420 ResolverErrorCode.STATIC_FINAL_REQUIRES_VALUE); 420 ResolverErrorCode.STATIC_FINAL_REQUIRES_VALUE);
421 } 421 }
422 } 422 }
OLDNEW
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698