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 engine.all_the_rest_test; | 5 library engine.all_the_rest_test; |
6 | 6 |
7 import 'package:analyzer/file_system/physical_file_system.dart'; | 7 import 'package:analyzer/file_system/physical_file_system.dart'; |
8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 602 |
603 void test_divide_double_double() { | 603 void test_divide_double_double() { |
604 _assertValue2(3.2 / 2.3, "3.2 / 2.3"); | 604 _assertValue2(3.2 / 2.3, "3.2 / 2.3"); |
605 } | 605 } |
606 | 606 |
607 void test_divide_double_double_byZero() { | 607 void test_divide_double_double_byZero() { |
608 EvaluationResult result = _getExpressionValue("3.2 / 0.0"); | 608 EvaluationResult result = _getExpressionValue("3.2 / 0.0"); |
609 expect(result.isValid, isTrue); | 609 expect(result.isValid, isTrue); |
610 DartObject value = result.value; | 610 DartObject value = result.value; |
611 expect(value.type.name, "double"); | 611 expect(value.type.name, "double"); |
612 expect(value.doubleValue.isInfinite, isTrue); | 612 expect(value.toDoubleValue().isInfinite, isTrue); |
613 } | 613 } |
614 | 614 |
615 void test_divide_int_int() { | 615 void test_divide_int_int() { |
616 _assertValue2(1.5, "3 / 2"); | 616 _assertValue2(1.5, "3 / 2"); |
617 } | 617 } |
618 | 618 |
619 void test_divide_int_int_byZero() { | 619 void test_divide_int_int_byZero() { |
620 EvaluationResult result = _getExpressionValue("3 / 0"); | 620 EvaluationResult result = _getExpressionValue("3 / 0"); |
621 expect(result.isValid, isTrue); | 621 expect(result.isValid, isTrue); |
622 } | 622 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 } | 818 } |
819 | 819 |
820 void test_truncatingDivide_int_int() { | 820 void test_truncatingDivide_int_int() { |
821 _assertValue3(3, "10 ~/ 3"); | 821 _assertValue3(3, "10 ~/ 3"); |
822 } | 822 } |
823 | 823 |
824 void _assertValue(bool expectedValue, String contents) { | 824 void _assertValue(bool expectedValue, String contents) { |
825 EvaluationResult result = _getExpressionValue(contents); | 825 EvaluationResult result = _getExpressionValue(contents); |
826 DartObject value = result.value; | 826 DartObject value = result.value; |
827 expect(value.type.name, "bool"); | 827 expect(value.type.name, "bool"); |
828 expect(value.boolValue, expectedValue); | 828 expect(value.toBoolValue(), expectedValue); |
829 } | 829 } |
830 | 830 |
831 void _assertValue2(double expectedValue, String contents) { | 831 void _assertValue2(double expectedValue, String contents) { |
832 EvaluationResult result = _getExpressionValue(contents); | 832 EvaluationResult result = _getExpressionValue(contents); |
833 expect(result.isValid, isTrue); | 833 expect(result.isValid, isTrue); |
834 DartObject value = result.value; | 834 DartObject value = result.value; |
835 expect(value.type.name, "double"); | 835 expect(value.type.name, "double"); |
836 expect(value.doubleValue, expectedValue); | 836 expect(value.toDoubleValue(), expectedValue); |
837 } | 837 } |
838 | 838 |
839 void _assertValue3(int expectedValue, String contents) { | 839 void _assertValue3(int expectedValue, String contents) { |
840 EvaluationResult result = _getExpressionValue(contents); | 840 EvaluationResult result = _getExpressionValue(contents); |
841 expect(result.isValid, isTrue); | 841 expect(result.isValid, isTrue); |
842 DartObject value = result.value; | 842 DartObject value = result.value; |
843 expect(value.type.name, "int"); | 843 expect(value.type.name, "int"); |
844 expect(value.intValue, expectedValue); | 844 expect(value.toIntValue(), expectedValue); |
845 } | 845 } |
846 | 846 |
847 void _assertValue4(String expectedValue, String contents) { | 847 void _assertValue4(String expectedValue, String contents) { |
848 EvaluationResult result = _getExpressionValue(contents); | 848 EvaluationResult result = _getExpressionValue(contents); |
849 DartObject value = result.value; | 849 DartObject value = result.value; |
850 expect(value, isNotNull); | 850 expect(value, isNotNull); |
851 ParameterizedType type = value.type; | 851 ParameterizedType type = value.type; |
852 expect(type, isNotNull); | 852 expect(type, isNotNull); |
853 expect(type.name, "String"); | 853 expect(type.name, "String"); |
854 expect(value.stringValue, expectedValue); | 854 expect(value.toStringValue(), expectedValue); |
855 } | 855 } |
856 | 856 |
857 EvaluationResult _getExpressionValue(String contents) { | 857 EvaluationResult _getExpressionValue(String contents) { |
858 Source source = addSource("var x = $contents;"); | 858 Source source = addSource("var x = $contents;"); |
859 LibraryElement library = resolve2(source); | 859 LibraryElement library = resolve2(source); |
860 CompilationUnit unit = | 860 CompilationUnit unit = |
861 analysisContext.resolveCompilationUnit(source, library); | 861 analysisContext.resolveCompilationUnit(source, library); |
862 expect(unit, isNotNull); | 862 expect(unit, isNotNull); |
863 NodeList<CompilationUnitMember> declarations = unit.declarations; | 863 NodeList<CompilationUnitMember> declarations = unit.declarations; |
864 expect(declarations, hasLength(1)); | 864 expect(declarations, hasLength(1)); |
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2158 String expectedType) { | 2158 String expectedType) { |
2159 DartObjectImpl field = fields[fieldName]; | 2159 DartObjectImpl field = fields[fieldName]; |
2160 expect(field.type.displayName, expectedType); | 2160 expect(field.type.displayName, expectedType); |
2161 return field.fields; | 2161 return field.fields; |
2162 } | 2162 } |
2163 | 2163 |
2164 void _assertIntField( | 2164 void _assertIntField( |
2165 Map<String, DartObjectImpl> fields, String fieldName, int expectedValue) { | 2165 Map<String, DartObjectImpl> fields, String fieldName, int expectedValue) { |
2166 DartObjectImpl field = fields[fieldName]; | 2166 DartObjectImpl field = fields[fieldName]; |
2167 expect(field.type.name, "int"); | 2167 expect(field.type.name, "int"); |
2168 expect(field.intValue, expectedValue); | 2168 expect(field.toIntValue(), expectedValue); |
2169 } | 2169 } |
2170 | 2170 |
2171 void _assertNullField(Map<String, DartObjectImpl> fields, String fieldName) { | 2171 void _assertNullField(Map<String, DartObjectImpl> fields, String fieldName) { |
2172 DartObjectImpl field = fields[fieldName]; | 2172 DartObjectImpl field = fields[fieldName]; |
2173 expect(field.isNull, isTrue); | 2173 expect(field.isNull, isTrue); |
2174 } | 2174 } |
2175 | 2175 |
2176 void _assertProperDependencies(String sourceText, | 2176 void _assertProperDependencies(String sourceText, |
2177 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { | 2177 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { |
2178 Source source = addSource(sourceText); | 2178 Source source = addSource(sourceText); |
(...skipping 12 matching lines...) Expand all Loading... |
2191 expect(result.value, isNotNull); | 2191 expect(result.value, isNotNull); |
2192 DartObjectImpl value = result.value; | 2192 DartObjectImpl value = result.value; |
2193 expect(value.type.displayName, typeName); | 2193 expect(value.type.displayName, typeName); |
2194 return value.fields; | 2194 return value.fields; |
2195 } | 2195 } |
2196 | 2196 |
2197 bool _assertValidBool(EvaluationResultImpl result) { | 2197 bool _assertValidBool(EvaluationResultImpl result) { |
2198 expect(result.value, isNotNull); | 2198 expect(result.value, isNotNull); |
2199 DartObjectImpl value = result.value; | 2199 DartObjectImpl value = result.value; |
2200 expect(value.type, typeProvider.boolType); | 2200 expect(value.type, typeProvider.boolType); |
2201 bool boolValue = value.boolValue; | 2201 bool boolValue = value.toBoolValue(); |
2202 expect(boolValue, isNotNull); | 2202 expect(boolValue, isNotNull); |
2203 return boolValue; | 2203 return boolValue; |
2204 } | 2204 } |
2205 | 2205 |
2206 int _assertValidInt(EvaluationResultImpl result) { | 2206 int _assertValidInt(EvaluationResultImpl result) { |
2207 expect(result.value, isNotNull); | 2207 expect(result.value, isNotNull); |
2208 DartObjectImpl value = result.value; | 2208 DartObjectImpl value = result.value; |
2209 expect(value.type, typeProvider.intType); | 2209 expect(value.type, typeProvider.intType); |
2210 return value.intValue; | 2210 return value.toIntValue(); |
2211 } | 2211 } |
2212 | 2212 |
2213 void _assertValidNull(EvaluationResultImpl result) { | 2213 void _assertValidNull(EvaluationResultImpl result) { |
2214 expect(result.value, isNotNull); | 2214 expect(result.value, isNotNull); |
2215 DartObjectImpl value = result.value; | 2215 DartObjectImpl value = result.value; |
2216 expect(value.type, typeProvider.nullType); | 2216 expect(value.type, typeProvider.nullType); |
2217 } | 2217 } |
2218 | 2218 |
2219 String _assertValidString(EvaluationResultImpl result) { | 2219 String _assertValidString(EvaluationResultImpl result) { |
2220 expect(result.value, isNotNull); | 2220 expect(result.value, isNotNull); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2520 void test_visitSimpleIdentifier_withoutEnvironment() { | 2520 void test_visitSimpleIdentifier_withoutEnvironment() { |
2521 CompilationUnit compilationUnit = resolveSource(r''' | 2521 CompilationUnit compilationUnit = resolveSource(r''' |
2522 const a = b; | 2522 const a = b; |
2523 const b = 3;'''); | 2523 const b = 3;'''); |
2524 _assertValue(3, _evaluateConstant(compilationUnit, "a", null)); | 2524 _assertValue(3, _evaluateConstant(compilationUnit, "a", null)); |
2525 } | 2525 } |
2526 | 2526 |
2527 void _assertValue(int expectedValue, DartObjectImpl result) { | 2527 void _assertValue(int expectedValue, DartObjectImpl result) { |
2528 expect(result, isNotNull); | 2528 expect(result, isNotNull); |
2529 expect(result.type.name, "int"); | 2529 expect(result.type.name, "int"); |
2530 expect(result.intValue, expectedValue); | 2530 expect(result.toIntValue(), expectedValue); |
2531 } | 2531 } |
2532 | 2532 |
2533 NonExistingSource _dummySource() { | 2533 NonExistingSource _dummySource() { |
2534 String path = '/test.dart'; | 2534 String path = '/test.dart'; |
2535 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); | 2535 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); |
2536 } | 2536 } |
2537 | 2537 |
2538 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, | 2538 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, |
2539 Map<String, DartObjectImpl> lexicalEnvironment) { | 2539 Map<String, DartObjectImpl> lexicalEnvironment) { |
2540 Source source = compilationUnit.element.source; | 2540 Source source = compilationUnit.element.source; |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3133 | 3133 |
3134 void test_greaterThanOrEqual_unknownInt_knownDouble() { | 3134 void test_greaterThanOrEqual_unknownInt_knownDouble() { |
3135 _assertGreaterThanOrEqual( | 3135 _assertGreaterThanOrEqual( |
3136 _boolValue(null), _intValue(null), _doubleValue(2.0)); | 3136 _boolValue(null), _intValue(null), _doubleValue(2.0)); |
3137 } | 3137 } |
3138 | 3138 |
3139 void test_greaterThanOrEqual_unknownInt_knownInt() { | 3139 void test_greaterThanOrEqual_unknownInt_knownInt() { |
3140 _assertGreaterThanOrEqual(_boolValue(null), _intValue(null), _intValue(2)); | 3140 _assertGreaterThanOrEqual(_boolValue(null), _intValue(null), _intValue(2)); |
3141 } | 3141 } |
3142 | 3142 |
3143 void test_hasExactValue_bool_false() { | 3143 void test_hasKnownValue_bool_false() { |
3144 expect(_boolValue(false).hasExactValue, isTrue); | 3144 expect(_boolValue(false).hasKnownValue, isTrue); |
3145 } | 3145 } |
3146 | 3146 |
3147 void test_hasExactValue_bool_true() { | 3147 void test_hasKnownValue_bool_true() { |
3148 expect(_boolValue(true).hasExactValue, isTrue); | 3148 expect(_boolValue(true).hasKnownValue, isTrue); |
3149 } | 3149 } |
3150 | 3150 |
3151 void test_hasExactValue_bool_unknown() { | 3151 void test_hasKnownValue_bool_unknown() { |
3152 expect(_boolValue(null).hasExactValue, isTrue); | 3152 expect(_boolValue(null).hasKnownValue, isFalse); |
3153 } | 3153 } |
3154 | 3154 |
3155 void test_hasExactValue_double_known() { | 3155 void test_hasKnownValue_double_known() { |
3156 expect(_doubleValue(2.3).hasExactValue, isTrue); | 3156 expect(_doubleValue(2.3).hasKnownValue, isTrue); |
3157 } | 3157 } |
3158 | 3158 |
3159 void test_hasExactValue_double_unknown() { | 3159 void test_hasKnownValue_double_unknown() { |
3160 expect(_doubleValue(null).hasExactValue, isTrue); | 3160 expect(_doubleValue(null).hasKnownValue, isFalse); |
3161 } | 3161 } |
3162 | 3162 |
3163 void test_hasExactValue_dynamic() { | 3163 void test_hasKnownValue_dynamic() { |
3164 expect(_dynamicValue().hasExactValue, isFalse); | 3164 expect(_dynamicValue().hasKnownValue, isTrue); |
3165 } | 3165 } |
3166 | 3166 |
3167 void test_hasExactValue_int_known() { | 3167 void test_hasKnownValue_int_known() { |
3168 expect(_intValue(23).hasExactValue, isTrue); | 3168 expect(_intValue(23).hasKnownValue, isTrue); |
3169 } | 3169 } |
3170 | 3170 |
3171 void test_hasExactValue_int_unknown() { | 3171 void test_hasKnownValue_int_unknown() { |
3172 expect(_intValue(null).hasExactValue, isTrue); | 3172 expect(_intValue(null).hasKnownValue, isFalse); |
3173 } | 3173 } |
3174 | 3174 |
3175 void test_hasExactValue_list_empty() { | 3175 void test_hasKnownValue_list_empty() { |
3176 expect(_listValue().hasExactValue, isTrue); | 3176 expect(_listValue().hasKnownValue, isTrue); |
3177 } | 3177 } |
3178 | 3178 |
3179 void test_hasExactValue_list_invalid() { | 3179 void test_hasKnownValue_list_invalidElement() { |
3180 expect(_dynamicValue().hasExactValue, isFalse); | 3180 expect(_listValue([_dynamicValue]).hasKnownValue, isTrue); |
3181 } | 3181 } |
3182 | 3182 |
3183 void test_hasExactValue_list_valid() { | 3183 void test_hasKnownValue_list_valid() { |
3184 expect(_listValue([_intValue(23)]).hasExactValue, isTrue); | 3184 expect(_listValue([_intValue(23)]).hasKnownValue, isTrue); |
3185 } | 3185 } |
3186 | 3186 |
3187 void test_hasExactValue_map_empty() { | 3187 void test_hasKnownValue_map_empty() { |
3188 expect(_mapValue().hasExactValue, isTrue); | 3188 expect(_mapValue().hasKnownValue, isTrue); |
3189 } | 3189 } |
3190 | 3190 |
3191 void test_hasExactValue_map_invalidKey() { | 3191 void test_hasKnownValue_map_invalidKey() { |
3192 expect(_mapValue([_dynamicValue(), _stringValue("value")]).hasExactValue, | 3192 expect(_mapValue([_dynamicValue(), _stringValue("value")]).hasKnownValue, |
3193 isFalse); | |
3194 } | |
3195 | |
3196 void test_hasExactValue_map_invalidValue() { | |
3197 expect(_mapValue([_stringValue("key"), _dynamicValue()]).hasExactValue, | |
3198 isFalse); | |
3199 } | |
3200 | |
3201 void test_hasExactValue_map_valid() { | |
3202 expect( | |
3203 _mapValue([_stringValue("key"), _stringValue("value")]).hasExactValue, | |
3204 isTrue); | 3193 isTrue); |
3205 } | 3194 } |
3206 | 3195 |
3207 void test_hasExactValue_null() { | 3196 void test_hasKnownValue_map_invalidValue() { |
3208 expect(_nullValue().hasExactValue, isTrue); | 3197 expect(_mapValue([_stringValue("key"), _dynamicValue()]).hasKnownValue, |
| 3198 isTrue); |
3209 } | 3199 } |
3210 | 3200 |
3211 void test_hasExactValue_num() { | 3201 void test_hasKnownValue_map_valid() { |
3212 expect(_numValue().hasExactValue, isFalse); | 3202 expect( |
| 3203 _mapValue([_stringValue("key"), _stringValue("value")]).hasKnownValue, |
| 3204 isTrue); |
3213 } | 3205 } |
3214 | 3206 |
3215 void test_hasExactValue_string_known() { | 3207 void test_hasKnownValue_null() { |
3216 expect(_stringValue("twenty-three").hasExactValue, isTrue); | 3208 expect(_nullValue().hasKnownValue, isTrue); |
3217 } | 3209 } |
3218 | 3210 |
3219 void test_hasExactValue_string_unknown() { | 3211 void test_hasKnownValue_num() { |
3220 expect(_stringValue(null).hasExactValue, isTrue); | 3212 expect(_numValue().hasKnownValue, isFalse); |
| 3213 } |
| 3214 |
| 3215 void test_hasKnownValue_string_known() { |
| 3216 expect(_stringValue("twenty-three").hasKnownValue, isTrue); |
| 3217 } |
| 3218 |
| 3219 void test_hasKnownValue_string_unknown() { |
| 3220 expect(_stringValue(null).hasKnownValue, isFalse); |
3221 } | 3221 } |
3222 | 3222 |
3223 void test_identical_bool_false() { | 3223 void test_identical_bool_false() { |
3224 _assertIdentical(_boolValue(false), _boolValue(false), _boolValue(true)); | 3224 _assertIdentical(_boolValue(false), _boolValue(false), _boolValue(true)); |
3225 } | 3225 } |
3226 | 3226 |
3227 void test_identical_bool_true() { | 3227 void test_identical_bool_true() { |
3228 _assertIdentical(_boolValue(true), _boolValue(true), _boolValue(true)); | 3228 _assertIdentical(_boolValue(true), _boolValue(true), _boolValue(true)); |
3229 } | 3229 } |
3230 | 3230 |
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4767 | 4767 |
4768 @reflectiveTest | 4768 @reflectiveTest |
4769 class DeclaredVariablesTest extends EngineTestCase { | 4769 class DeclaredVariablesTest extends EngineTestCase { |
4770 void test_getBool_false() { | 4770 void test_getBool_false() { |
4771 TestTypeProvider typeProvider = new TestTypeProvider(); | 4771 TestTypeProvider typeProvider = new TestTypeProvider(); |
4772 String variableName = "var"; | 4772 String variableName = "var"; |
4773 DeclaredVariables variables = new DeclaredVariables(); | 4773 DeclaredVariables variables = new DeclaredVariables(); |
4774 variables.define(variableName, "false"); | 4774 variables.define(variableName, "false"); |
4775 DartObject object = variables.getBool(typeProvider, variableName); | 4775 DartObject object = variables.getBool(typeProvider, variableName); |
4776 expect(object, isNotNull); | 4776 expect(object, isNotNull); |
4777 expect(object.boolValue, false); | 4777 expect(object.toBoolValue(), false); |
4778 } | 4778 } |
4779 | 4779 |
4780 void test_getBool_invalid() { | 4780 void test_getBool_invalid() { |
4781 TestTypeProvider typeProvider = new TestTypeProvider(); | 4781 TestTypeProvider typeProvider = new TestTypeProvider(); |
4782 String variableName = "var"; | 4782 String variableName = "var"; |
4783 DeclaredVariables variables = new DeclaredVariables(); | 4783 DeclaredVariables variables = new DeclaredVariables(); |
4784 variables.define(variableName, "not true"); | 4784 variables.define(variableName, "not true"); |
4785 _assertNullDartObject( | 4785 _assertNullDartObject( |
4786 typeProvider, variables.getBool(typeProvider, variableName)); | 4786 typeProvider, variables.getBool(typeProvider, variableName)); |
4787 } | 4787 } |
4788 | 4788 |
4789 void test_getBool_true() { | 4789 void test_getBool_true() { |
4790 TestTypeProvider typeProvider = new TestTypeProvider(); | 4790 TestTypeProvider typeProvider = new TestTypeProvider(); |
4791 String variableName = "var"; | 4791 String variableName = "var"; |
4792 DeclaredVariables variables = new DeclaredVariables(); | 4792 DeclaredVariables variables = new DeclaredVariables(); |
4793 variables.define(variableName, "true"); | 4793 variables.define(variableName, "true"); |
4794 DartObject object = variables.getBool(typeProvider, variableName); | 4794 DartObject object = variables.getBool(typeProvider, variableName); |
4795 expect(object, isNotNull); | 4795 expect(object, isNotNull); |
4796 expect(object.boolValue, true); | 4796 expect(object.toBoolValue(), true); |
4797 } | 4797 } |
4798 | 4798 |
4799 void test_getBool_undefined() { | 4799 void test_getBool_undefined() { |
4800 TestTypeProvider typeProvider = new TestTypeProvider(); | 4800 TestTypeProvider typeProvider = new TestTypeProvider(); |
4801 String variableName = "var"; | 4801 String variableName = "var"; |
4802 DeclaredVariables variables = new DeclaredVariables(); | 4802 DeclaredVariables variables = new DeclaredVariables(); |
4803 _assertUnknownDartObject( | 4803 _assertUnknownDartObject( |
4804 typeProvider.boolType, variables.getBool(typeProvider, variableName)); | 4804 typeProvider.boolType, variables.getBool(typeProvider, variableName)); |
4805 } | 4805 } |
4806 | 4806 |
(...skipping 14 matching lines...) Expand all Loading... |
4821 typeProvider.intType, variables.getInt(typeProvider, variableName)); | 4821 typeProvider.intType, variables.getInt(typeProvider, variableName)); |
4822 } | 4822 } |
4823 | 4823 |
4824 void test_getInt_valid() { | 4824 void test_getInt_valid() { |
4825 TestTypeProvider typeProvider = new TestTypeProvider(); | 4825 TestTypeProvider typeProvider = new TestTypeProvider(); |
4826 String variableName = "var"; | 4826 String variableName = "var"; |
4827 DeclaredVariables variables = new DeclaredVariables(); | 4827 DeclaredVariables variables = new DeclaredVariables(); |
4828 variables.define(variableName, "23"); | 4828 variables.define(variableName, "23"); |
4829 DartObject object = variables.getInt(typeProvider, variableName); | 4829 DartObject object = variables.getInt(typeProvider, variableName); |
4830 expect(object, isNotNull); | 4830 expect(object, isNotNull); |
4831 expect(object.intValue, 23); | 4831 expect(object.toIntValue(), 23); |
4832 } | 4832 } |
4833 | 4833 |
4834 void test_getString_defined() { | 4834 void test_getString_defined() { |
4835 TestTypeProvider typeProvider = new TestTypeProvider(); | 4835 TestTypeProvider typeProvider = new TestTypeProvider(); |
4836 String variableName = "var"; | 4836 String variableName = "var"; |
4837 String value = "value"; | 4837 String value = "value"; |
4838 DeclaredVariables variables = new DeclaredVariables(); | 4838 DeclaredVariables variables = new DeclaredVariables(); |
4839 variables.define(variableName, value); | 4839 variables.define(variableName, value); |
4840 DartObject object = variables.getString(typeProvider, variableName); | 4840 DartObject object = variables.getString(typeProvider, variableName); |
4841 expect(object, isNotNull); | 4841 expect(object, isNotNull); |
4842 expect(object.stringValue, value); | 4842 expect(object.toStringValue(), value); |
4843 } | 4843 } |
4844 | 4844 |
4845 void test_getString_undefined() { | 4845 void test_getString_undefined() { |
4846 TestTypeProvider typeProvider = new TestTypeProvider(); | 4846 TestTypeProvider typeProvider = new TestTypeProvider(); |
4847 String variableName = "var"; | 4847 String variableName = "var"; |
4848 DeclaredVariables variables = new DeclaredVariables(); | 4848 DeclaredVariables variables = new DeclaredVariables(); |
4849 _assertUnknownDartObject(typeProvider.stringType, | 4849 _assertUnknownDartObject(typeProvider.stringType, |
4850 variables.getString(typeProvider, variableName)); | 4850 variables.getString(typeProvider, variableName)); |
4851 } | 4851 } |
4852 | 4852 |
(...skipping 1813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6666 expect(variable.initializer, isNotNull); | 6666 expect(variable.initializer, isNotNull); |
6667 expect(variable.name, variableName); | 6667 expect(variable.name, variableName); |
6668 expect(variable.hasImplicitType, isTrue); | 6668 expect(variable.hasImplicitType, isTrue); |
6669 expect(variable.isConst, isTrue); | 6669 expect(variable.isConst, isTrue); |
6670 expect(variable.isFinal, isFalse); | 6670 expect(variable.isFinal, isFalse); |
6671 expect(variable.isSynthetic, isFalse); | 6671 expect(variable.isSynthetic, isFalse); |
6672 expect(variable.getter, isNotNull); | 6672 expect(variable.getter, isNotNull); |
6673 expect(variable.setter, isNull); | 6673 expect(variable.setter, isNull); |
6674 } | 6674 } |
6675 | 6675 |
| 6676 void test_visitVariableDeclaration_top_docRange() { |
| 6677 // final a, b; |
| 6678 ElementHolder holder = new ElementHolder(); |
| 6679 ElementBuilder builder = new ElementBuilder(holder); |
| 6680 VariableDeclaration variableDeclaration1 = |
| 6681 AstFactory.variableDeclaration('a'); |
| 6682 VariableDeclaration variableDeclaration2 = |
| 6683 AstFactory.variableDeclaration('b'); |
| 6684 TopLevelVariableDeclaration topLevelVariableDeclaration = AstFactory |
| 6685 .topLevelVariableDeclaration( |
| 6686 Keyword.FINAL, null, [variableDeclaration1, variableDeclaration2]); |
| 6687 topLevelVariableDeclaration.documentationComment = AstFactory |
| 6688 .documentationComment( |
| 6689 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 6690 |
| 6691 topLevelVariableDeclaration.accept(builder); |
| 6692 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
| 6693 expect(variables, hasLength(2)); |
| 6694 |
| 6695 TopLevelVariableElement variable1 = variables[0]; |
| 6696 expect(variable1, isNotNull); |
| 6697 _assertHasDocRange(variable1, 50, 7); |
| 6698 |
| 6699 TopLevelVariableElement variable2 = variables[1]; |
| 6700 expect(variable2, isNotNull); |
| 6701 _assertHasDocRange(variable2, 50, 7); |
| 6702 } |
| 6703 |
6676 void test_visitVariableDeclaration_top_final() { | 6704 void test_visitVariableDeclaration_top_final() { |
6677 // final v; | 6705 // final v; |
6678 ElementHolder holder = new ElementHolder(); | 6706 ElementHolder holder = new ElementHolder(); |
6679 ElementBuilder builder = new ElementBuilder(holder); | 6707 ElementBuilder builder = new ElementBuilder(holder); |
6680 String variableName = "v"; | 6708 String variableName = "v"; |
6681 VariableDeclaration variableDeclaration = | 6709 VariableDeclaration variableDeclaration = |
6682 AstFactory.variableDeclaration2(variableName, null); | 6710 AstFactory.variableDeclaration2(variableName, null); |
6683 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]); | 6711 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]); |
6684 variableDeclaration.accept(builder); | 6712 variableDeclaration.accept(builder); |
6685 List<TopLevelVariableElement> variables = holder.topLevelVariables; | 6713 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
(...skipping 2251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8937 | 8965 |
8938 @reflectiveTest | 8966 @reflectiveTest |
8939 class SDKLibrariesReaderTest extends EngineTestCase { | 8967 class SDKLibrariesReaderTest extends EngineTestCase { |
8940 void test_readFrom_dart2js() { | 8968 void test_readFrom_dart2js() { |
8941 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( | 8969 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( |
8942 FileUtilities2.createFile("/libs.dart"), | 8970 FileUtilities2.createFile("/libs.dart"), |
8943 r''' | 8971 r''' |
8944 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 8972 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
8945 'first' : const LibraryInfo( | 8973 'first' : const LibraryInfo( |
8946 'first/first.dart', | 8974 'first/first.dart', |
8947 category: 'First', | 8975 categories: 'Client', |
8948 documented: true, | 8976 documented: true, |
8949 platforms: VM_PLATFORM, | 8977 platforms: VM_PLATFORM, |
8950 dart2jsPath: 'first/first_dart2js.dart'), | 8978 dart2jsPath: 'first/first_dart2js.dart'), |
8951 };'''); | 8979 };'''); |
8952 expect(libraryMap, isNotNull); | 8980 expect(libraryMap, isNotNull); |
8953 expect(libraryMap.size(), 1); | 8981 expect(libraryMap.size(), 1); |
8954 SdkLibrary first = libraryMap.getLibrary("dart:first"); | 8982 SdkLibrary first = libraryMap.getLibrary("dart:first"); |
8955 expect(first, isNotNull); | 8983 expect(first, isNotNull); |
8956 expect(first.category, "First"); | 8984 expect(first.category, "Client"); |
8957 expect(first.path, "first/first_dart2js.dart"); | 8985 expect(first.path, "first/first_dart2js.dart"); |
8958 expect(first.shortName, "dart:first"); | 8986 expect(first.shortName, "dart:first"); |
8959 expect(first.isDart2JsLibrary, false); | 8987 expect(first.isDart2JsLibrary, false); |
8960 expect(first.isDocumented, true); | 8988 expect(first.isDocumented, true); |
8961 expect(first.isImplementation, false); | 8989 expect(first.isImplementation, false); |
8962 expect(first.isVmLibrary, true); | 8990 expect(first.isVmLibrary, true); |
8963 } | 8991 } |
8964 | 8992 |
8965 void test_readFrom_empty() { | 8993 void test_readFrom_empty() { |
8966 LibraryMap libraryMap = new SdkLibrariesReader(false) | 8994 LibraryMap libraryMap = new SdkLibrariesReader(false) |
8967 .readFromFile(FileUtilities2.createFile("/libs.dart"), ""); | 8995 .readFromFile(FileUtilities2.createFile("/libs.dart"), ""); |
8968 expect(libraryMap, isNotNull); | 8996 expect(libraryMap, isNotNull); |
8969 expect(libraryMap.size(), 0); | 8997 expect(libraryMap.size(), 0); |
8970 } | 8998 } |
8971 | 8999 |
8972 void test_readFrom_normal() { | 9000 void test_readFrom_normal() { |
8973 LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile( | 9001 LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile( |
8974 FileUtilities2.createFile("/libs.dart"), | 9002 FileUtilities2.createFile("/libs.dart"), |
8975 r''' | 9003 r''' |
8976 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 9004 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
8977 'first' : const LibraryInfo( | 9005 'first' : const LibraryInfo( |
8978 'first/first.dart', | 9006 'first/first.dart', |
8979 category: 'First', | 9007 categories: 'Client', |
8980 documented: true, | 9008 documented: true, |
8981 platforms: VM_PLATFORM), | 9009 platforms: VM_PLATFORM), |
8982 | 9010 |
8983 'second' : const LibraryInfo( | 9011 'second' : const LibraryInfo( |
8984 'second/second.dart', | 9012 'second/second.dart', |
8985 category: 'Second', | 9013 categories: 'Server', |
8986 documented: false, | 9014 documented: false, |
8987 implementation: true, | 9015 implementation: true, |
8988 platforms: 0), | 9016 platforms: 0), |
8989 };'''); | 9017 };'''); |
8990 expect(libraryMap, isNotNull); | 9018 expect(libraryMap, isNotNull); |
8991 expect(libraryMap.size(), 2); | 9019 expect(libraryMap.size(), 2); |
8992 SdkLibrary first = libraryMap.getLibrary("dart:first"); | 9020 SdkLibrary first = libraryMap.getLibrary("dart:first"); |
8993 expect(first, isNotNull); | 9021 expect(first, isNotNull); |
8994 expect(first.category, "First"); | 9022 expect(first.category, "Client"); |
8995 expect(first.path, "first/first.dart"); | 9023 expect(first.path, "first/first.dart"); |
8996 expect(first.shortName, "dart:first"); | 9024 expect(first.shortName, "dart:first"); |
8997 expect(first.isDart2JsLibrary, false); | 9025 expect(first.isDart2JsLibrary, false); |
8998 expect(first.isDocumented, true); | 9026 expect(first.isDocumented, true); |
8999 expect(first.isImplementation, false); | 9027 expect(first.isImplementation, false); |
9000 expect(first.isVmLibrary, true); | 9028 expect(first.isVmLibrary, true); |
9001 SdkLibrary second = libraryMap.getLibrary("dart:second"); | 9029 SdkLibrary second = libraryMap.getLibrary("dart:second"); |
9002 expect(second, isNotNull); | 9030 expect(second, isNotNull); |
9003 expect(second.category, "Second"); | 9031 expect(second.category, "Server"); |
9004 expect(second.path, "second/second.dart"); | 9032 expect(second.path, "second/second.dart"); |
9005 expect(second.shortName, "dart:second"); | 9033 expect(second.shortName, "dart:second"); |
9006 expect(second.isDart2JsLibrary, false); | 9034 expect(second.isDart2JsLibrary, false); |
9007 expect(second.isDocumented, false); | 9035 expect(second.isDocumented, false); |
9008 expect(second.isImplementation, true); | 9036 expect(second.isImplementation, true); |
9009 expect(second.isVmLibrary, false); | 9037 expect(second.isVmLibrary, false); |
9010 } | 9038 } |
9011 } | 9039 } |
9012 | 9040 |
9013 @reflectiveTest | 9041 @reflectiveTest |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9363 if (_expectedExternalScriptName == null) { | 9391 if (_expectedExternalScriptName == null) { |
9364 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 9392 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
9365 } else { | 9393 } else { |
9366 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 9394 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
9367 String actualExternalScriptName = scriptSource.shortName; | 9395 String actualExternalScriptName = scriptSource.shortName; |
9368 expect(actualExternalScriptName, _expectedExternalScriptName, | 9396 expect(actualExternalScriptName, _expectedExternalScriptName, |
9369 reason: "script $scriptIndex"); | 9397 reason: "script $scriptIndex"); |
9370 } | 9398 } |
9371 } | 9399 } |
9372 } | 9400 } |
OLD | NEW |