| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.all_the_rest_test; | 8 library engine.all_the_rest_test; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 2093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2104 _assertType(c_int, "C<int>"); | 2104 _assertType(c_int, "C<int>"); |
| 2105 DartObjectImpl c_int_value = c_int.value; | 2105 DartObjectImpl c_int_value = c_int.value; |
| 2106 EvaluationResultImpl c_num = | 2106 EvaluationResultImpl c_num = |
| 2107 _evaluateInstanceCreationExpression(compilationUnit, "c_num"); | 2107 _evaluateInstanceCreationExpression(compilationUnit, "c_num"); |
| 2108 _assertType(c_num, "C<num>"); | 2108 _assertType(c_num, "C<num>"); |
| 2109 DartObjectImpl c_num_value = c_num.value; | 2109 DartObjectImpl c_num_value = c_num.value; |
| 2110 expect(c_int_value == c_num_value, isFalse); | 2110 expect(c_int_value == c_num_value, isFalse); |
| 2111 } | 2111 } |
| 2112 | 2112 |
| 2113 void test_isValidSymbol() { | 2113 void test_isValidSymbol() { |
| 2114 expect(ConstantValueComputer.isValidPublicSymbol(""), isTrue); | 2114 expect(ConstantEvaluationEngine.isValidPublicSymbol(""), isTrue); |
| 2115 expect(ConstantValueComputer.isValidPublicSymbol("foo"), isTrue); | 2115 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo"), isTrue); |
| 2116 expect(ConstantValueComputer.isValidPublicSymbol("foo.bar"), isTrue); | 2116 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.bar"), isTrue); |
| 2117 expect(ConstantValueComputer.isValidPublicSymbol("foo\$"), isTrue); | 2117 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo\$"), isTrue); |
| 2118 expect(ConstantValueComputer.isValidPublicSymbol("foo\$bar"), isTrue); | 2118 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo\$bar"), isTrue); |
| 2119 expect(ConstantValueComputer.isValidPublicSymbol("iff"), isTrue); | 2119 expect(ConstantEvaluationEngine.isValidPublicSymbol("iff"), isTrue); |
| 2120 expect(ConstantValueComputer.isValidPublicSymbol("gif"), isTrue); | 2120 expect(ConstantEvaluationEngine.isValidPublicSymbol("gif"), isTrue); |
| 2121 expect(ConstantValueComputer.isValidPublicSymbol("if\$"), isTrue); | 2121 expect(ConstantEvaluationEngine.isValidPublicSymbol("if\$"), isTrue); |
| 2122 expect(ConstantValueComputer.isValidPublicSymbol("\$if"), isTrue); | 2122 expect(ConstantEvaluationEngine.isValidPublicSymbol("\$if"), isTrue); |
| 2123 expect(ConstantValueComputer.isValidPublicSymbol("foo="), isTrue); | 2123 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo="), isTrue); |
| 2124 expect(ConstantValueComputer.isValidPublicSymbol("foo.bar="), isTrue); | 2124 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.bar="), isTrue); |
| 2125 expect(ConstantValueComputer.isValidPublicSymbol("foo.+"), isTrue); | 2125 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.+"), isTrue); |
| 2126 expect(ConstantValueComputer.isValidPublicSymbol("void"), isTrue); | 2126 expect(ConstantEvaluationEngine.isValidPublicSymbol("void"), isTrue); |
| 2127 expect(ConstantValueComputer.isValidPublicSymbol("_foo"), isFalse); | 2127 expect(ConstantEvaluationEngine.isValidPublicSymbol("_foo"), isFalse); |
| 2128 expect(ConstantValueComputer.isValidPublicSymbol("_foo.bar"), isFalse); | 2128 expect(ConstantEvaluationEngine.isValidPublicSymbol("_foo.bar"), isFalse); |
| 2129 expect(ConstantValueComputer.isValidPublicSymbol("foo._bar"), isFalse); | 2129 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo._bar"), isFalse); |
| 2130 expect(ConstantValueComputer.isValidPublicSymbol("if"), isFalse); | 2130 expect(ConstantEvaluationEngine.isValidPublicSymbol("if"), isFalse); |
| 2131 expect(ConstantValueComputer.isValidPublicSymbol("if.foo"), isFalse); | 2131 expect(ConstantEvaluationEngine.isValidPublicSymbol("if.foo"), isFalse); |
| 2132 expect(ConstantValueComputer.isValidPublicSymbol("foo.if"), isFalse); | 2132 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.if"), isFalse); |
| 2133 expect(ConstantValueComputer.isValidPublicSymbol("foo=.bar"), isFalse); | 2133 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo=.bar"), isFalse); |
| 2134 expect(ConstantValueComputer.isValidPublicSymbol("foo."), isFalse); | 2134 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo."), isFalse); |
| 2135 expect(ConstantValueComputer.isValidPublicSymbol("+.foo"), isFalse); | 2135 expect(ConstantEvaluationEngine.isValidPublicSymbol("+.foo"), isFalse); |
| 2136 expect(ConstantValueComputer.isValidPublicSymbol("void.foo"), isFalse); | 2136 expect(ConstantEvaluationEngine.isValidPublicSymbol("void.foo"), isFalse); |
| 2137 expect(ConstantValueComputer.isValidPublicSymbol("foo.void"), isFalse); | 2137 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.void"), isFalse); |
| 2138 } | 2138 } |
| 2139 | 2139 |
| 2140 void test_length_of_improperly_typed_string_expression() { | 2140 void test_length_of_improperly_typed_string_expression() { |
| 2141 // Since type annotations are ignored in unchecked mode, the improper | 2141 // Since type annotations are ignored in unchecked mode, the improper |
| 2142 // types on s1 and s2 shouldn't prevent us from evaluating i to | 2142 // types on s1 and s2 shouldn't prevent us from evaluating i to |
| 2143 // 'alpha'.length. | 2143 // 'alpha'.length. |
| 2144 CompilationUnit compilationUnit = resolveSource(''' | 2144 CompilationUnit compilationUnit = resolveSource(''' |
| 2145 const int s1 = 'alpha'; | 2145 const int s1 = 'alpha'; |
| 2146 const int s2 = 'beta'; | 2146 const int s2 = 'beta'; |
| 2147 const int i = (true ? s1 : s2).length; | 2147 const int i = (true ? s1 : s2).length; |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2425 @reflectiveTest | 2425 @reflectiveTest |
| 2426 class ConstantVisitorTest extends ResolverTestCase { | 2426 class ConstantVisitorTest extends ResolverTestCase { |
| 2427 void test_visitConditionalExpression_false() { | 2427 void test_visitConditionalExpression_false() { |
| 2428 Expression thenExpression = AstFactory.integer(1); | 2428 Expression thenExpression = AstFactory.integer(1); |
| 2429 Expression elseExpression = AstFactory.integer(0); | 2429 Expression elseExpression = AstFactory.integer(0); |
| 2430 ConditionalExpression expression = AstFactory.conditionalExpression( | 2430 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2431 AstFactory.booleanLiteral(false), thenExpression, elseExpression); | 2431 AstFactory.booleanLiteral(false), thenExpression, elseExpression); |
| 2432 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2432 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2433 ErrorReporter errorReporter = | 2433 ErrorReporter errorReporter = |
| 2434 new ErrorReporter(errorListener, _dummySource()); | 2434 new ErrorReporter(errorListener, _dummySource()); |
| 2435 _assertValue(0, expression | 2435 _assertValue(0, expression.accept(new ConstantVisitor( |
| 2436 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter))); | 2436 new ConstantEvaluationEngine( |
| 2437 new TestTypeProvider(), new DeclaredVariables()), errorReporter))); |
| 2437 errorListener.assertNoErrors(); | 2438 errorListener.assertNoErrors(); |
| 2438 } | 2439 } |
| 2439 | 2440 |
| 2440 void test_visitConditionalExpression_instanceCreation_invalidFieldInitializer(
) { | 2441 void test_visitConditionalExpression_instanceCreation_invalidFieldInitializer(
) { |
| 2441 TestTypeProvider typeProvider = new TestTypeProvider(); | 2442 TestTypeProvider typeProvider = new TestTypeProvider(); |
| 2442 LibraryElementImpl libraryElement = ElementFactory.library(null, "lib"); | 2443 LibraryElementImpl libraryElement = ElementFactory.library(null, "lib"); |
| 2443 String className = "C"; | 2444 String className = "C"; |
| 2444 ClassElementImpl classElement = ElementFactory.classElement2(className); | 2445 ClassElementImpl classElement = ElementFactory.classElement2(className); |
| 2445 (libraryElement.definingCompilationUnit as CompilationUnitElementImpl).types
= | 2446 (libraryElement.definingCompilationUnit as CompilationUnitElementImpl).types
= |
| 2446 <ClassElement>[classElement]; | 2447 <ClassElement>[classElement]; |
| 2447 ConstructorElementImpl constructorElement = ElementFactory | 2448 ConstructorElementImpl constructorElement = ElementFactory |
| 2448 .constructorElement(classElement, null, true, [typeProvider.intType]); | 2449 .constructorElement(classElement, null, true, [typeProvider.intType]); |
| 2449 constructorElement.parameters[0] = | 2450 constructorElement.parameters[0] = |
| 2450 new FieldFormalParameterElementImpl(AstFactory.identifier3("x")); | 2451 new FieldFormalParameterElementImpl(AstFactory.identifier3("x")); |
| 2451 InstanceCreationExpression expression = AstFactory | 2452 InstanceCreationExpression expression = AstFactory |
| 2452 .instanceCreationExpression2(Keyword.CONST, | 2453 .instanceCreationExpression2(Keyword.CONST, |
| 2453 AstFactory.typeName4(className), [AstFactory.integer(0)]); | 2454 AstFactory.typeName4(className), [AstFactory.integer(0)]); |
| 2454 expression.staticElement = constructorElement; | 2455 expression.staticElement = constructorElement; |
| 2455 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2456 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2456 ErrorReporter errorReporter = | 2457 ErrorReporter errorReporter = |
| 2457 new ErrorReporter(errorListener, _dummySource()); | 2458 new ErrorReporter(errorListener, _dummySource()); |
| 2458 expression.accept(new ConstantVisitor(typeProvider, errorReporter)); | 2459 expression.accept(new ConstantVisitor( |
| 2460 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables()), |
| 2461 errorReporter)); |
| 2459 errorListener | 2462 errorListener |
| 2460 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | 2463 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); |
| 2461 } | 2464 } |
| 2462 | 2465 |
| 2463 void test_visitConditionalExpression_nonBooleanCondition() { | 2466 void test_visitConditionalExpression_nonBooleanCondition() { |
| 2464 Expression thenExpression = AstFactory.integer(1); | 2467 Expression thenExpression = AstFactory.integer(1); |
| 2465 Expression elseExpression = AstFactory.integer(0); | 2468 Expression elseExpression = AstFactory.integer(0); |
| 2466 NullLiteral conditionExpression = AstFactory.nullLiteral(); | 2469 NullLiteral conditionExpression = AstFactory.nullLiteral(); |
| 2467 ConditionalExpression expression = AstFactory.conditionalExpression( | 2470 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2468 conditionExpression, thenExpression, elseExpression); | 2471 conditionExpression, thenExpression, elseExpression); |
| 2469 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2472 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2470 ErrorReporter errorReporter = | 2473 ErrorReporter errorReporter = |
| 2471 new ErrorReporter(errorListener, _dummySource()); | 2474 new ErrorReporter(errorListener, _dummySource()); |
| 2472 DartObjectImpl result = expression | 2475 DartObjectImpl result = expression.accept(new ConstantVisitor( |
| 2473 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter)); | 2476 new ConstantEvaluationEngine( |
| 2477 new TestTypeProvider(), new DeclaredVariables()), errorReporter)); |
| 2474 expect(result, isNull); | 2478 expect(result, isNull); |
| 2475 errorListener | 2479 errorListener |
| 2476 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]); | 2480 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]); |
| 2477 } | 2481 } |
| 2478 | 2482 |
| 2479 void test_visitConditionalExpression_nonConstantElse() { | 2483 void test_visitConditionalExpression_nonConstantElse() { |
| 2480 Expression thenExpression = AstFactory.integer(1); | 2484 Expression thenExpression = AstFactory.integer(1); |
| 2481 Expression elseExpression = AstFactory.identifier3("x"); | 2485 Expression elseExpression = AstFactory.identifier3("x"); |
| 2482 ConditionalExpression expression = AstFactory.conditionalExpression( | 2486 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2483 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2487 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2484 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2488 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2485 ErrorReporter errorReporter = | 2489 ErrorReporter errorReporter = |
| 2486 new ErrorReporter(errorListener, _dummySource()); | 2490 new ErrorReporter(errorListener, _dummySource()); |
| 2487 DartObjectImpl result = expression | 2491 DartObjectImpl result = expression.accept(new ConstantVisitor( |
| 2488 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter)); | 2492 new ConstantEvaluationEngine( |
| 2493 new TestTypeProvider(), new DeclaredVariables()), errorReporter)); |
| 2489 expect(result, isNull); | 2494 expect(result, isNull); |
| 2490 errorListener | 2495 errorListener |
| 2491 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | 2496 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); |
| 2492 } | 2497 } |
| 2493 | 2498 |
| 2494 void test_visitConditionalExpression_nonConstantThen() { | 2499 void test_visitConditionalExpression_nonConstantThen() { |
| 2495 Expression thenExpression = AstFactory.identifier3("x"); | 2500 Expression thenExpression = AstFactory.identifier3("x"); |
| 2496 Expression elseExpression = AstFactory.integer(0); | 2501 Expression elseExpression = AstFactory.integer(0); |
| 2497 ConditionalExpression expression = AstFactory.conditionalExpression( | 2502 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2498 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2503 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2499 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2504 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2500 ErrorReporter errorReporter = | 2505 ErrorReporter errorReporter = |
| 2501 new ErrorReporter(errorListener, _dummySource()); | 2506 new ErrorReporter(errorListener, _dummySource()); |
| 2502 DartObjectImpl result = expression | 2507 DartObjectImpl result = expression.accept(new ConstantVisitor( |
| 2503 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter)); | 2508 new ConstantEvaluationEngine( |
| 2509 new TestTypeProvider(), new DeclaredVariables()), errorReporter)); |
| 2504 expect(result, isNull); | 2510 expect(result, isNull); |
| 2505 errorListener | 2511 errorListener |
| 2506 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | 2512 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); |
| 2507 } | 2513 } |
| 2508 | 2514 |
| 2509 void test_visitConditionalExpression_true() { | 2515 void test_visitConditionalExpression_true() { |
| 2510 Expression thenExpression = AstFactory.integer(1); | 2516 Expression thenExpression = AstFactory.integer(1); |
| 2511 Expression elseExpression = AstFactory.integer(0); | 2517 Expression elseExpression = AstFactory.integer(0); |
| 2512 ConditionalExpression expression = AstFactory.conditionalExpression( | 2518 ConditionalExpression expression = AstFactory.conditionalExpression( |
| 2513 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | 2519 AstFactory.booleanLiteral(true), thenExpression, elseExpression); |
| 2514 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2520 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2515 ErrorReporter errorReporter = | 2521 ErrorReporter errorReporter = |
| 2516 new ErrorReporter(errorListener, _dummySource()); | 2522 new ErrorReporter(errorListener, _dummySource()); |
| 2517 _assertValue(1, expression | 2523 _assertValue(1, expression.accept(new ConstantVisitor( |
| 2518 .accept(new ConstantVisitor(new TestTypeProvider(), errorReporter))); | 2524 new ConstantEvaluationEngine( |
| 2525 new TestTypeProvider(), new DeclaredVariables()), errorReporter))); |
| 2519 errorListener.assertNoErrors(); | 2526 errorListener.assertNoErrors(); |
| 2520 } | 2527 } |
| 2521 | 2528 |
| 2522 void test_visitSimpleIdentifier_className() { | 2529 void test_visitSimpleIdentifier_className() { |
| 2523 CompilationUnit compilationUnit = resolveSource(''' | 2530 CompilationUnit compilationUnit = resolveSource(''' |
| 2524 const a = C; | 2531 const a = C; |
| 2525 class C {} | 2532 class C {} |
| 2526 '''); | 2533 '''); |
| 2527 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); | 2534 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); |
| 2528 expect(result.type, typeProvider.typeType); | 2535 expect(result.type, typeProvider.typeType); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2579 } | 2586 } |
| 2580 | 2587 |
| 2581 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, | 2588 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, |
| 2582 Map<String, DartObjectImpl> lexicalEnvironment) { | 2589 Map<String, DartObjectImpl> lexicalEnvironment) { |
| 2583 Source source = compilationUnit.element.source; | 2590 Source source = compilationUnit.element.source; |
| 2584 Expression expression = | 2591 Expression expression = |
| 2585 findTopLevelConstantExpression(compilationUnit, name); | 2592 findTopLevelConstantExpression(compilationUnit, name); |
| 2586 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2593 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 2587 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | 2594 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); |
| 2588 DartObjectImpl result = expression.accept(new ConstantVisitor( | 2595 DartObjectImpl result = expression.accept(new ConstantVisitor( |
| 2589 typeProvider, errorReporter, lexicalEnvironment: lexicalEnvironment)); | 2596 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables()), |
| 2597 errorReporter, lexicalEnvironment: lexicalEnvironment)); |
| 2590 errorListener.assertNoErrors(); | 2598 errorListener.assertNoErrors(); |
| 2591 return result; | 2599 return result; |
| 2592 } | 2600 } |
| 2593 } | 2601 } |
| 2594 | 2602 |
| 2595 @reflectiveTest | 2603 @reflectiveTest |
| 2596 class ContentCacheTest { | 2604 class ContentCacheTest { |
| 2597 void test_setContents() { | 2605 void test_setContents() { |
| 2598 Source source = new TestSource(); | 2606 Source source = new TestSource(); |
| 2599 ContentCache cache = new ContentCache(); | 2607 ContentCache cache = new ContentCache(); |
| (...skipping 6203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8803 if (_expectedExternalScriptName == null) { | 8811 if (_expectedExternalScriptName == null) { |
| 8804 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 8812 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
| 8805 } else { | 8813 } else { |
| 8806 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 8814 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
| 8807 String actualExternalScriptName = scriptSource.shortName; | 8815 String actualExternalScriptName = scriptSource.shortName; |
| 8808 expect(actualExternalScriptName, _expectedExternalScriptName, | 8816 expect(actualExternalScriptName, _expectedExternalScriptName, |
| 8809 reason: "script $scriptIndex"); | 8817 reason: "script $scriptIndex"); |
| 8810 } | 8818 } |
| 8811 } | 8819 } |
| 8812 } | 8820 } |
| OLD | NEW |