| 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 library analyzer.test.src.dart.ast.utilities_test; | 5 library analyzer.test.src.dart.ast.utilities_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 void test_binary_notEqual_invalidRight() { | 189 void test_binary_notEqual_invalidRight() { |
| 190 Object value = _getConstantValue("2 != a"); | 190 Object value = _getConstantValue("2 != a"); |
| 191 expect(value, ConstantEvaluator.NOT_A_CONSTANT); | 191 expect(value, ConstantEvaluator.NOT_A_CONSTANT); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void test_binary_notEqual_string() { | 194 void test_binary_notEqual_string() { |
| 195 Object value = _getConstantValue("'a' != 'b'"); | 195 Object value = _getConstantValue("'a' != 'b'"); |
| 196 expect(value, true); | 196 expect(value, true); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void test_binary_plus_string() { | |
| 200 Object value = _getConstantValue("'hello ' + 'world'"); | |
| 201 expect(value, 'hello world'); | |
| 202 } | |
| 203 | |
| 204 void test_binary_plus_double() { | 199 void test_binary_plus_double() { |
| 205 Object value = _getConstantValue("2.3 + 3.2"); | 200 Object value = _getConstantValue("2.3 + 3.2"); |
| 206 expect(value, 2.3 + 3.2); | 201 expect(value, 2.3 + 3.2); |
| 207 } | 202 } |
| 208 | 203 |
| 209 void test_binary_plus_integer() { | 204 void test_binary_plus_double_string() { |
| 210 Object value = _getConstantValue("2 + 3"); | 205 Object value = _getConstantValue("'world' + 5.5"); |
| 211 expect(value, 5); | |
| 212 } | |
| 213 | |
| 214 void test_binary_plus_string_int() { | |
| 215 Object value = _getConstantValue("5 + 'world'"); | |
| 216 expect(value, ConstantEvaluator.NOT_A_CONSTANT); | 206 expect(value, ConstantEvaluator.NOT_A_CONSTANT); |
| 217 } | 207 } |
| 218 | 208 |
| 219 void test_binary_plus_int_string() { | 209 void test_binary_plus_int_string() { |
| 220 Object value = _getConstantValue("'world' + 5"); | 210 Object value = _getConstantValue("'world' + 5"); |
| 221 expect(value, ConstantEvaluator.NOT_A_CONSTANT); | 211 expect(value, ConstantEvaluator.NOT_A_CONSTANT); |
| 222 } | 212 } |
| 223 | 213 |
| 224 void test_binary_plus_double_string() { | 214 void test_binary_plus_integer() { |
| 225 Object value = _getConstantValue("'world' + 5.5"); | 215 Object value = _getConstantValue("2 + 3"); |
| 226 expect(value, ConstantEvaluator.NOT_A_CONSTANT); | 216 expect(value, 5); |
| 217 } |
| 218 |
| 219 void test_binary_plus_string() { |
| 220 Object value = _getConstantValue("'hello ' + 'world'"); |
| 221 expect(value, 'hello world'); |
| 227 } | 222 } |
| 228 | 223 |
| 229 void test_binary_plus_string_double() { | 224 void test_binary_plus_string_double() { |
| 230 Object value = _getConstantValue("5.5 + 'world'"); | 225 Object value = _getConstantValue("5.5 + 'world'"); |
| 231 expect(value, ConstantEvaluator.NOT_A_CONSTANT); | 226 expect(value, ConstantEvaluator.NOT_A_CONSTANT); |
| 232 } | 227 } |
| 233 | 228 |
| 229 void test_binary_plus_string_int() { |
| 230 Object value = _getConstantValue("5 + 'world'"); |
| 231 expect(value, ConstantEvaluator.NOT_A_CONSTANT); |
| 232 } |
| 233 |
| 234 void test_binary_remainder_double() { | 234 void test_binary_remainder_double() { |
| 235 Object value = _getConstantValue("3.2 % 2.3"); | 235 Object value = _getConstantValue("3.2 % 2.3"); |
| 236 expect(value, 3.2 % 2.3); | 236 expect(value, 3.2 % 2.3); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void test_binary_remainder_integer() { | 239 void test_binary_remainder_integer() { |
| 240 Object value = _getConstantValue("8 % 3"); | 240 Object value = _getConstantValue("8 % 3"); |
| 241 expect(value, 2); | 241 expect(value, 2); |
| 242 } | 242 } |
| 243 | 243 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 } | 365 } |
| 366 | 366 |
| 367 @reflectiveTest | 367 @reflectiveTest |
| 368 class NodeLocator2Test extends ParserTestCase { | 368 class NodeLocator2Test extends ParserTestCase { |
| 369 void test_onlyStartOffset() { | 369 void test_onlyStartOffset() { |
| 370 String code = ' int vv; '; | 370 String code = ' int vv; '; |
| 371 // 012345678 | 371 // 012345678 |
| 372 CompilationUnit unit = ParserTestCase.parseCompilationUnit(code); | 372 CompilationUnit unit = ParserTestCase.parseCompilationUnit(code); |
| 373 TopLevelVariableDeclaration declaration = unit.declarations[0]; | 373 TopLevelVariableDeclaration declaration = unit.declarations[0]; |
| 374 VariableDeclarationList variableList = declaration.variables; | 374 VariableDeclarationList variableList = declaration.variables; |
| 375 Identifier typeName = variableList.type.name; | 375 Identifier typeName = (variableList.type as TypeName).name; |
| 376 SimpleIdentifier varName = variableList.variables[0].name; | 376 SimpleIdentifier varName = variableList.variables[0].name; |
| 377 expect(new NodeLocator2(0).searchWithin(unit), same(unit)); | 377 expect(new NodeLocator2(0).searchWithin(unit), same(unit)); |
| 378 expect(new NodeLocator2(1).searchWithin(unit), same(typeName)); | 378 expect(new NodeLocator2(1).searchWithin(unit), same(typeName)); |
| 379 expect(new NodeLocator2(2).searchWithin(unit), same(typeName)); | 379 expect(new NodeLocator2(2).searchWithin(unit), same(typeName)); |
| 380 expect(new NodeLocator2(3).searchWithin(unit), same(typeName)); | 380 expect(new NodeLocator2(3).searchWithin(unit), same(typeName)); |
| 381 expect(new NodeLocator2(4).searchWithin(unit), same(variableList)); | 381 expect(new NodeLocator2(4).searchWithin(unit), same(variableList)); |
| 382 expect(new NodeLocator2(5).searchWithin(unit), same(varName)); | 382 expect(new NodeLocator2(5).searchWithin(unit), same(varName)); |
| 383 expect(new NodeLocator2(6).searchWithin(unit), same(varName)); | 383 expect(new NodeLocator2(6).searchWithin(unit), same(varName)); |
| 384 expect(new NodeLocator2(7).searchWithin(unit), same(declaration)); | 384 expect(new NodeLocator2(7).searchWithin(unit), same(declaration)); |
| 385 expect(new NodeLocator2(8).searchWithin(unit), same(unit)); | 385 expect(new NodeLocator2(8).searchWithin(unit), same(unit)); |
| 386 expect(new NodeLocator2(9).searchWithin(unit), isNull); | 386 expect(new NodeLocator2(9).searchWithin(unit), isNull); |
| 387 expect(new NodeLocator2(100).searchWithin(unit), isNull); | 387 expect(new NodeLocator2(100).searchWithin(unit), isNull); |
| 388 } | 388 } |
| 389 | 389 |
| 390 void test_startEndOffset() { | 390 void test_startEndOffset() { |
| 391 String code = ' int vv; '; | 391 String code = ' int vv; '; |
| 392 // 012345678 | 392 // 012345678 |
| 393 CompilationUnit unit = ParserTestCase.parseCompilationUnit(code); | 393 CompilationUnit unit = ParserTestCase.parseCompilationUnit(code); |
| 394 TopLevelVariableDeclaration declaration = unit.declarations[0]; | 394 TopLevelVariableDeclaration declaration = unit.declarations[0]; |
| 395 VariableDeclarationList variableList = declaration.variables; | 395 VariableDeclarationList variableList = declaration.variables; |
| 396 Identifier typeName = variableList.type.name; | 396 Identifier typeName = (variableList.type as TypeName).name; |
| 397 SimpleIdentifier varName = variableList.variables[0].name; | 397 SimpleIdentifier varName = variableList.variables[0].name; |
| 398 expect(new NodeLocator2(-1, 2).searchWithin(unit), isNull); | 398 expect(new NodeLocator2(-1, 2).searchWithin(unit), isNull); |
| 399 expect(new NodeLocator2(0, 2).searchWithin(unit), same(unit)); | 399 expect(new NodeLocator2(0, 2).searchWithin(unit), same(unit)); |
| 400 expect(new NodeLocator2(1, 2).searchWithin(unit), same(typeName)); | 400 expect(new NodeLocator2(1, 2).searchWithin(unit), same(typeName)); |
| 401 expect(new NodeLocator2(1, 3).searchWithin(unit), same(typeName)); | 401 expect(new NodeLocator2(1, 3).searchWithin(unit), same(typeName)); |
| 402 expect(new NodeLocator2(1, 4).searchWithin(unit), same(variableList)); | 402 expect(new NodeLocator2(1, 4).searchWithin(unit), same(variableList)); |
| 403 expect(new NodeLocator2(5, 6).searchWithin(unit), same(varName)); | 403 expect(new NodeLocator2(5, 6).searchWithin(unit), same(varName)); |
| 404 expect(new NodeLocator2(5, 7).searchWithin(unit), same(declaration)); | 404 expect(new NodeLocator2(5, 7).searchWithin(unit), same(declaration)); |
| 405 expect(new NodeLocator2(5, 8).searchWithin(unit), same(unit)); | 405 expect(new NodeLocator2(5, 8).searchWithin(unit), same(unit)); |
| 406 expect(new NodeLocator2(5, 100).searchWithin(unit), isNull); | 406 expect(new NodeLocator2(5, 100).searchWithin(unit), isNull); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 MethodElement propagatedElement = ElementFactory.methodElement( | 689 MethodElement propagatedElement = ElementFactory.methodElement( |
| 690 "m", ElementFactory.classElement2("C").type); | 690 "m", ElementFactory.classElement2("C").type); |
| 691 fromNode.propagatedElement = propagatedElement; | 691 fromNode.propagatedElement = propagatedElement; |
| 692 MethodElement staticElement = ElementFactory.methodElement( | 692 MethodElement staticElement = ElementFactory.methodElement( |
| 693 "m", ElementFactory.classElement2("C").type); | 693 "m", ElementFactory.classElement2("C").type); |
| 694 fromNode.staticElement = staticElement; | 694 fromNode.staticElement = staticElement; |
| 695 FunctionExpressionInvocation toNode = AstTestFactory | 695 FunctionExpressionInvocation toNode = AstTestFactory |
| 696 .functionExpressionInvocation(AstTestFactory.identifier3("f")); | 696 .functionExpressionInvocation(AstTestFactory.identifier3("f")); |
| 697 ClassElement elementT = ElementFactory.classElement2('T'); | 697 ClassElement elementT = ElementFactory.classElement2('T'); |
| 698 fromNode.typeArguments = AstTestFactory | 698 fromNode.typeArguments = AstTestFactory |
| 699 .typeArgumentList(<TypeName>[AstTestFactory.typeName(elementT)]); | 699 .typeArgumentList(<TypeAnnotation>[AstTestFactory.typeName(elementT)]); |
| 700 toNode.typeArguments = AstTestFactory | 700 toNode.typeArguments = AstTestFactory |
| 701 .typeArgumentList(<TypeName>[AstTestFactory.typeName4('T')]); | 701 .typeArgumentList(<TypeAnnotation>[AstTestFactory.typeName4('T')]); |
| 702 | 702 |
| 703 _copyAndVerifyInvocation(fromNode, toNode); | 703 _copyAndVerifyInvocation(fromNode, toNode); |
| 704 | 704 |
| 705 expect(toNode.propagatedElement, same(propagatedElement)); | 705 expect(toNode.propagatedElement, same(propagatedElement)); |
| 706 expect(toNode.staticElement, same(staticElement)); | 706 expect(toNode.staticElement, same(staticElement)); |
| 707 } | 707 } |
| 708 | 708 |
| 709 void test_visitImportDirective() { | 709 void test_visitImportDirective() { |
| 710 ImportDirective fromNode = | 710 ImportDirective fromNode = |
| 711 AstTestFactory.importDirective3("dart:uri", null); | 711 AstTestFactory.importDirective3("dart:uri", null); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 ResolutionCopier.copyResolutionData(fromNode, toNode); | 824 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 825 expect(toNode.propagatedType, same(propagatedType)); | 825 expect(toNode.propagatedType, same(propagatedType)); |
| 826 expect(toNode.staticType, same(staticType)); | 826 expect(toNode.staticType, same(staticType)); |
| 827 } | 827 } |
| 828 | 828 |
| 829 void test_visitMethodInvocation() { | 829 void test_visitMethodInvocation() { |
| 830 MethodInvocation fromNode = AstTestFactory.methodInvocation2("m"); | 830 MethodInvocation fromNode = AstTestFactory.methodInvocation2("m"); |
| 831 MethodInvocation toNode = AstTestFactory.methodInvocation2("m"); | 831 MethodInvocation toNode = AstTestFactory.methodInvocation2("m"); |
| 832 ClassElement elementT = ElementFactory.classElement2('T'); | 832 ClassElement elementT = ElementFactory.classElement2('T'); |
| 833 fromNode.typeArguments = AstTestFactory | 833 fromNode.typeArguments = AstTestFactory |
| 834 .typeArgumentList(<TypeName>[AstTestFactory.typeName(elementT)]); | 834 .typeArgumentList(<TypeAnnotation>[AstTestFactory.typeName(elementT)]); |
| 835 toNode.typeArguments = AstTestFactory | 835 toNode.typeArguments = AstTestFactory |
| 836 .typeArgumentList(<TypeName>[AstTestFactory.typeName4('T')]); | 836 .typeArgumentList(<TypeAnnotation>[AstTestFactory.typeName4('T')]); |
| 837 _copyAndVerifyInvocation(fromNode, toNode); | 837 _copyAndVerifyInvocation(fromNode, toNode); |
| 838 } | 838 } |
| 839 | 839 |
| 840 void test_visitNamedExpression() { | 840 void test_visitNamedExpression() { |
| 841 NamedExpression fromNode = | 841 NamedExpression fromNode = |
| 842 AstTestFactory.namedExpression2("n", AstTestFactory.integer(0)); | 842 AstTestFactory.namedExpression2("n", AstTestFactory.integer(0)); |
| 843 DartType propagatedType = ElementFactory.classElement2("C").type; | 843 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 844 fromNode.propagatedType = propagatedType; | 844 fromNode.propagatedType = propagatedType; |
| 845 DartType staticType = ElementFactory.classElement2("C").type; | 845 DartType staticType = ElementFactory.classElement2("C").type; |
| 846 fromNode.staticType = staticType; | 846 fromNode.staticType = staticType; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 DartType propagatedInvokeType = ElementFactory.classElement2("C").type; | 1123 DartType propagatedInvokeType = ElementFactory.classElement2("C").type; |
| 1124 fromNode.propagatedInvokeType = propagatedInvokeType; | 1124 fromNode.propagatedInvokeType = propagatedInvokeType; |
| 1125 DartType staticInvokeType = ElementFactory.classElement2("C").type; | 1125 DartType staticInvokeType = ElementFactory.classElement2("C").type; |
| 1126 fromNode.staticInvokeType = staticInvokeType; | 1126 fromNode.staticInvokeType = staticInvokeType; |
| 1127 | 1127 |
| 1128 ResolutionCopier.copyResolutionData(fromNode, toNode); | 1128 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1129 expect(toNode.propagatedType, same(propagatedType)); | 1129 expect(toNode.propagatedType, same(propagatedType)); |
| 1130 expect(toNode.staticType, same(staticType)); | 1130 expect(toNode.staticType, same(staticType)); |
| 1131 expect(toNode.propagatedInvokeType, same(propagatedInvokeType)); | 1131 expect(toNode.propagatedInvokeType, same(propagatedInvokeType)); |
| 1132 expect(toNode.staticInvokeType, same(staticInvokeType)); | 1132 expect(toNode.staticInvokeType, same(staticInvokeType)); |
| 1133 List<TypeName> fromTypeArguments = toNode.typeArguments.arguments; | 1133 List<TypeAnnotation> fromTypeArguments = toNode.typeArguments.arguments; |
| 1134 List<TypeName> toTypeArguments = fromNode.typeArguments.arguments; | 1134 List<TypeAnnotation> toTypeArguments = fromNode.typeArguments.arguments; |
| 1135 if (fromTypeArguments != null) { | 1135 if (fromTypeArguments != null) { |
| 1136 for (int i = 0; i < fromTypeArguments.length; i++) { | 1136 for (int i = 0; i < fromTypeArguments.length; i++) { |
| 1137 TypeName toArgument = fromTypeArguments[i]; | 1137 TypeAnnotation toArgument = fromTypeArguments[i]; |
| 1138 TypeName fromArgument = toTypeArguments[i]; | 1138 TypeAnnotation fromArgument = toTypeArguments[i]; |
| 1139 expect(toArgument.type, same(fromArgument.type)); | 1139 expect(toArgument.type, same(fromArgument.type)); |
| 1140 } | 1140 } |
| 1141 } | 1141 } |
| 1142 } | 1142 } |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 @reflectiveTest | 1145 @reflectiveTest |
| 1146 class ToSourceVisitor2Test extends EngineTestCase { | 1146 class ToSourceVisitor2Test extends EngineTestCase { |
| 1147 void test_visitAdjacentStrings() { | 1147 void test_visitAdjacentStrings() { |
| 1148 _assertSource( | 1148 _assertSource( |
| (...skipping 4644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5793 /** | 5793 /** |
| 5794 * Assert that a `ToSourceVisitor` will produce the [expectedSource] when | 5794 * Assert that a `ToSourceVisitor` will produce the [expectedSource] when |
| 5795 * visiting the given [node]. | 5795 * visiting the given [node]. |
| 5796 */ | 5796 */ |
| 5797 void _assertSource(String expectedSource, AstNode node) { | 5797 void _assertSource(String expectedSource, AstNode node) { |
| 5798 PrintStringWriter writer = new PrintStringWriter(); | 5798 PrintStringWriter writer = new PrintStringWriter(); |
| 5799 node.accept(new ToSourceVisitor(writer)); | 5799 node.accept(new ToSourceVisitor(writer)); |
| 5800 expect(writer.toString(), expectedSource); | 5800 expect(writer.toString(), expectedSource); |
| 5801 } | 5801 } |
| 5802 } | 5802 } |
| OLD | NEW |