| 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.parser_test; | 5 library engine.parser_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 parse3("parseClassMember", <Object>["C"], "int +() {}", | 1552 parse3("parseClassMember", <Object>["C"], "int +() {}", |
| 1553 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); | 1553 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); |
| 1554 } | 1554 } |
| 1555 | 1555 |
| 1556 void test_missingKeywordOperator_parseClassMember_afterVoid() { | 1556 void test_missingKeywordOperator_parseClassMember_afterVoid() { |
| 1557 parse3("parseClassMember", <Object>["C"], "void +() {}", | 1557 parse3("parseClassMember", <Object>["C"], "void +() {}", |
| 1558 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); | 1558 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); |
| 1559 } | 1559 } |
| 1560 | 1560 |
| 1561 void test_missingMethodParameters_void_block() { | 1561 void test_missingMethodParameters_void_block() { |
| 1562 MethodDeclaration method = parse3("parseClassMember", | 1562 MethodDeclaration method = parse3("parseClassMember", <Object>["C"], |
| 1563 <Object>["C"], "void m {} }", | 1563 "void m {} }", [ParserErrorCode.MISSING_METHOD_PARAMETERS]); |
| 1564 [ParserErrorCode.MISSING_METHOD_PARAMETERS]); | |
| 1565 expect(method.parameters, hasLength(0)); | 1564 expect(method.parameters, hasLength(0)); |
| 1566 } | 1565 } |
| 1567 | 1566 |
| 1568 void test_missingMethodParameters_void_expression() { | 1567 void test_missingMethodParameters_void_expression() { |
| 1569 parse3("parseClassMember", <Object>["C"], "void m => null; }", | 1568 parse3("parseClassMember", <Object>["C"], "void m => null; }", |
| 1570 [ParserErrorCode.MISSING_METHOD_PARAMETERS]); | 1569 [ParserErrorCode.MISSING_METHOD_PARAMETERS]); |
| 1571 } | 1570 } |
| 1572 | 1571 |
| 1573 void test_missingNameInLibraryDirective() { | 1572 void test_missingNameInLibraryDirective() { |
| 1574 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 1573 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 parse4("parseSwitchStatement", | 1858 parse4("parseSwitchStatement", |
| 1860 "switch (a) {default: return 0; default: return 1; default: return 2;}", | 1859 "switch (a) {default: return 0; default: return 1; default: return 2;}", |
| 1861 [ | 1860 [ |
| 1862 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, | 1861 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, |
| 1863 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES | 1862 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES |
| 1864 ]); | 1863 ]); |
| 1865 } | 1864 } |
| 1866 | 1865 |
| 1867 void test_topLevel_getter() { | 1866 void test_topLevel_getter() { |
| 1868 FunctionDeclaration funct = parse3("parseCompilationUnitMember", | 1867 FunctionDeclaration funct = parse3("parseCompilationUnitMember", |
| 1869 <Object>[emptyCommentAndMetadata()], | 1868 <Object>[emptyCommentAndMetadata()], "get x => 7;"); |
| 1870 "get x => 7;"); | |
| 1871 expect(funct.functionExpression.parameters, isNull); | 1869 expect(funct.functionExpression.parameters, isNull); |
| 1872 } | 1870 } |
| 1873 | 1871 |
| 1874 void test_topLevelOperator_withoutType() { | 1872 void test_topLevelOperator_withoutType() { |
| 1875 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], | 1873 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], |
| 1876 "operator +(bool x, bool y) => x | y;", | 1874 "operator +(bool x, bool y) => x | y;", |
| 1877 [ParserErrorCode.TOP_LEVEL_OPERATOR]); | 1875 [ParserErrorCode.TOP_LEVEL_OPERATOR]); |
| 1878 } | 1876 } |
| 1879 | 1877 |
| 1880 void test_topLevelOperator_withType() { | 1878 void test_topLevelOperator_withType() { |
| (...skipping 7068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8949 void test_parseStringLiteral_adjacent() { | 8947 void test_parseStringLiteral_adjacent() { |
| 8950 AdjacentStrings literal = parse4("parseStringLiteral", "'a' 'b'"); | 8948 AdjacentStrings literal = parse4("parseStringLiteral", "'a' 'b'"); |
| 8951 NodeList<StringLiteral> strings = literal.strings; | 8949 NodeList<StringLiteral> strings = literal.strings; |
| 8952 expect(strings, hasLength(2)); | 8950 expect(strings, hasLength(2)); |
| 8953 StringLiteral firstString = strings[0]; | 8951 StringLiteral firstString = strings[0]; |
| 8954 StringLiteral secondString = strings[1]; | 8952 StringLiteral secondString = strings[1]; |
| 8955 expect((firstString as SimpleStringLiteral).value, "a"); | 8953 expect((firstString as SimpleStringLiteral).value, "a"); |
| 8956 expect((secondString as SimpleStringLiteral).value, "b"); | 8954 expect((secondString as SimpleStringLiteral).value, "b"); |
| 8957 } | 8955 } |
| 8958 | 8956 |
| 8957 void test_parseStringLiteral_endsWithInterpolation() { |
| 8958 StringLiteral literal = parse4('parseStringLiteral', r"'x$y'"); |
| 8959 expect(literal, new isInstanceOf<StringInterpolation>()); |
| 8960 StringInterpolation interpolation = literal; |
| 8961 expect(interpolation.elements, hasLength(3)); |
| 8962 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 8963 InterpolationString element0 = interpolation.elements[0]; |
| 8964 expect(element0.value, 'x'); |
| 8965 expect( |
| 8966 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 8967 InterpolationExpression element1 = interpolation.elements[1]; |
| 8968 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 8969 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 8970 InterpolationString element2 = interpolation.elements[2]; |
| 8971 expect(element2.value, ''); |
| 8972 } |
| 8973 |
| 8959 void test_parseStringLiteral_interpolated() { | 8974 void test_parseStringLiteral_interpolated() { |
| 8960 StringInterpolation literal = | 8975 StringInterpolation literal = |
| 8961 parse4("parseStringLiteral", "'a \${b} c \$this d'"); | 8976 parse4("parseStringLiteral", "'a \${b} c \$this d'"); |
| 8962 NodeList<InterpolationElement> elements = literal.elements; | 8977 NodeList<InterpolationElement> elements = literal.elements; |
| 8963 expect(elements, hasLength(5)); | 8978 expect(elements, hasLength(5)); |
| 8964 expect(elements[0] is InterpolationString, isTrue); | 8979 expect(elements[0] is InterpolationString, isTrue); |
| 8965 expect(elements[1] is InterpolationExpression, isTrue); | 8980 expect(elements[1] is InterpolationExpression, isTrue); |
| 8966 expect(elements[2] is InterpolationString, isTrue); | 8981 expect(elements[2] is InterpolationString, isTrue); |
| 8967 expect(elements[3] is InterpolationExpression, isTrue); | 8982 expect(elements[3] is InterpolationExpression, isTrue); |
| 8968 expect(elements[4] is InterpolationString, isTrue); | 8983 expect(elements[4] is InterpolationString, isTrue); |
| 8969 } | 8984 } |
| 8970 | 8985 |
| 8971 void test_parseStringLiteral_multiline_encodedSpace() { | 8986 void test_parseStringLiteral_multiline_encodedSpace() { |
| 8972 SimpleStringLiteral literal = | 8987 SimpleStringLiteral literal = |
| 8973 parse4("parseStringLiteral", "'''\\x20\na'''"); | 8988 parse4("parseStringLiteral", "'''\\x20\na'''"); |
| 8974 expect(literal.literal, isNotNull); | 8989 expect(literal.literal, isNotNull); |
| 8975 expect(literal.value, " \na"); | 8990 expect(literal.value, " \na"); |
| 8976 } | 8991 } |
| 8977 | 8992 |
| 8993 void test_parseStringLiteral_multiline_endsWithInterpolation() { |
| 8994 StringLiteral literal = parse4('parseStringLiteral', r"'''x$y'''"); |
| 8995 expect(literal, new isInstanceOf<StringInterpolation>()); |
| 8996 StringInterpolation interpolation = literal; |
| 8997 expect(interpolation.elements, hasLength(3)); |
| 8998 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 8999 InterpolationString element0 = interpolation.elements[0]; |
| 9000 expect(element0.value, 'x'); |
| 9001 expect( |
| 9002 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9003 InterpolationExpression element1 = interpolation.elements[1]; |
| 9004 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9005 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9006 InterpolationString element2 = interpolation.elements[2]; |
| 9007 expect(element2.value, ''); |
| 9008 } |
| 9009 |
| 8978 void test_parseStringLiteral_multiline_escapedBackslash() { | 9010 void test_parseStringLiteral_multiline_escapedBackslash() { |
| 8979 SimpleStringLiteral literal = parse4("parseStringLiteral", "'''\\\\\na'''"); | 9011 SimpleStringLiteral literal = parse4("parseStringLiteral", "'''\\\\\na'''"); |
| 8980 expect(literal.literal, isNotNull); | 9012 expect(literal.literal, isNotNull); |
| 8981 expect(literal.value, "\\\na"); | 9013 expect(literal.value, "\\\na"); |
| 8982 } | 9014 } |
| 8983 | 9015 |
| 8984 void test_parseStringLiteral_multiline_escapedBackslash_raw() { | 9016 void test_parseStringLiteral_multiline_escapedBackslash_raw() { |
| 8985 SimpleStringLiteral literal = | 9017 SimpleStringLiteral literal = |
| 8986 parse4("parseStringLiteral", "r'''\\\\\na'''"); | 9018 parse4("parseStringLiteral", "r'''\\\\\na'''"); |
| 8987 expect(literal.literal, isNotNull); | 9019 expect(literal.literal, isNotNull); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9019 expect(literal.literal, isNotNull); | 9051 expect(literal.literal, isNotNull); |
| 9020 expect(literal.value, "\t\na"); | 9052 expect(literal.value, "\t\na"); |
| 9021 } | 9053 } |
| 9022 | 9054 |
| 9023 void test_parseStringLiteral_multiline_escapedTab_raw() { | 9055 void test_parseStringLiteral_multiline_escapedTab_raw() { |
| 9024 SimpleStringLiteral literal = parse4("parseStringLiteral", "r'''\\t\na'''"); | 9056 SimpleStringLiteral literal = parse4("parseStringLiteral", "r'''\\t\na'''"); |
| 9025 expect(literal.literal, isNotNull); | 9057 expect(literal.literal, isNotNull); |
| 9026 expect(literal.value, "\\t\na"); | 9058 expect(literal.value, "\\t\na"); |
| 9027 } | 9059 } |
| 9028 | 9060 |
| 9061 void test_parseStringLiteral_multiline_quoteAfterInterpolation() { |
| 9062 StringLiteral literal = parse4('parseStringLiteral', r"""'''$x'y'''"""); |
| 9063 expect(literal, new isInstanceOf<StringInterpolation>()); |
| 9064 StringInterpolation interpolation = literal; |
| 9065 expect(interpolation.elements, hasLength(3)); |
| 9066 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9067 InterpolationString element0 = interpolation.elements[0]; |
| 9068 expect(element0.value, ''); |
| 9069 expect( |
| 9070 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9071 InterpolationExpression element1 = interpolation.elements[1]; |
| 9072 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9073 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9074 InterpolationString element2 = interpolation.elements[2]; |
| 9075 expect(element2.value, "'y"); |
| 9076 } |
| 9077 |
| 9078 void test_parseStringLiteral_multiline_startsWithInterpolation() { |
| 9079 StringLiteral literal = parse4('parseStringLiteral', r"'''${x}y'''"); |
| 9080 expect(literal, new isInstanceOf<StringInterpolation>()); |
| 9081 StringInterpolation interpolation = literal; |
| 9082 expect(interpolation.elements, hasLength(3)); |
| 9083 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9084 InterpolationString element0 = interpolation.elements[0]; |
| 9085 expect(element0.value, ''); |
| 9086 expect( |
| 9087 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9088 InterpolationExpression element1 = interpolation.elements[1]; |
| 9089 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9090 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9091 InterpolationString element2 = interpolation.elements[2]; |
| 9092 expect(element2.value, 'y'); |
| 9093 } |
| 9094 |
| 9029 void test_parseStringLiteral_multiline_twoSpaces() { | 9095 void test_parseStringLiteral_multiline_twoSpaces() { |
| 9030 SimpleStringLiteral literal = parse4("parseStringLiteral", "''' \na'''"); | 9096 SimpleStringLiteral literal = parse4("parseStringLiteral", "''' \na'''"); |
| 9031 expect(literal.literal, isNotNull); | 9097 expect(literal.literal, isNotNull); |
| 9032 expect(literal.value, "a"); | 9098 expect(literal.value, "a"); |
| 9033 } | 9099 } |
| 9034 | 9100 |
| 9035 void test_parseStringLiteral_multiline_twoSpaces_raw() { | 9101 void test_parseStringLiteral_multiline_twoSpaces_raw() { |
| 9036 SimpleStringLiteral literal = parse4("parseStringLiteral", "r''' \na'''"); | 9102 SimpleStringLiteral literal = parse4("parseStringLiteral", "r''' \na'''"); |
| 9037 expect(literal.literal, isNotNull); | 9103 expect(literal.literal, isNotNull); |
| 9038 expect(literal.value, "a"); | 9104 expect(literal.value, "a"); |
| 9039 } | 9105 } |
| 9040 | 9106 |
| 9041 void test_parseStringLiteral_multiline_untrimmed() { | 9107 void test_parseStringLiteral_multiline_untrimmed() { |
| 9042 SimpleStringLiteral literal = parse4("parseStringLiteral", "''' a\nb'''"); | 9108 SimpleStringLiteral literal = parse4("parseStringLiteral", "''' a\nb'''"); |
| 9043 expect(literal.literal, isNotNull); | 9109 expect(literal.literal, isNotNull); |
| 9044 expect(literal.value, " a\nb"); | 9110 expect(literal.value, " a\nb"); |
| 9045 } | 9111 } |
| 9046 | 9112 |
| 9113 void test_parseStringLiteral_quoteAfterInterpolation() { |
| 9114 StringLiteral literal = parse4('parseStringLiteral', r"""'$x"'"""); |
| 9115 expect(literal, new isInstanceOf<StringInterpolation>()); |
| 9116 StringInterpolation interpolation = literal; |
| 9117 expect(interpolation.elements, hasLength(3)); |
| 9118 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9119 InterpolationString element0 = interpolation.elements[0]; |
| 9120 expect(element0.value, ''); |
| 9121 expect( |
| 9122 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9123 InterpolationExpression element1 = interpolation.elements[1]; |
| 9124 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9125 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9126 InterpolationString element2 = interpolation.elements[2]; |
| 9127 expect(element2.value, '"'); |
| 9128 } |
| 9129 |
| 9047 void test_parseStringLiteral_single() { | 9130 void test_parseStringLiteral_single() { |
| 9048 SimpleStringLiteral literal = parse4("parseStringLiteral", "'a'"); | 9131 SimpleStringLiteral literal = parse4("parseStringLiteral", "'a'"); |
| 9049 expect(literal.literal, isNotNull); | 9132 expect(literal.literal, isNotNull); |
| 9050 expect(literal.value, "a"); | 9133 expect(literal.value, "a"); |
| 9051 } | 9134 } |
| 9052 | 9135 |
| 9136 void test_parseStringLiteral_startsWithInterpolation() { |
| 9137 StringLiteral literal = parse4('parseStringLiteral', r"'${x}y'"); |
| 9138 expect(literal, new isInstanceOf<StringInterpolation>()); |
| 9139 StringInterpolation interpolation = literal; |
| 9140 expect(interpolation.elements, hasLength(3)); |
| 9141 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9142 InterpolationString element0 = interpolation.elements[0]; |
| 9143 expect(element0.value, ''); |
| 9144 expect( |
| 9145 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9146 InterpolationExpression element1 = interpolation.elements[1]; |
| 9147 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9148 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9149 InterpolationString element2 = interpolation.elements[2]; |
| 9150 expect(element2.value, 'y'); |
| 9151 } |
| 9152 |
| 9053 void test_parseSuperConstructorInvocation_named() { | 9153 void test_parseSuperConstructorInvocation_named() { |
| 9054 SuperConstructorInvocation invocation = | 9154 SuperConstructorInvocation invocation = |
| 9055 parse4("parseSuperConstructorInvocation", "super.a()"); | 9155 parse4("parseSuperConstructorInvocation", "super.a()"); |
| 9056 expect(invocation.argumentList, isNotNull); | 9156 expect(invocation.argumentList, isNotNull); |
| 9057 expect(invocation.constructorName, isNotNull); | 9157 expect(invocation.constructorName, isNotNull); |
| 9058 expect(invocation.superKeyword, isNotNull); | 9158 expect(invocation.superKeyword, isNotNull); |
| 9059 expect(invocation.period, isNotNull); | 9159 expect(invocation.period, isNotNull); |
| 9060 } | 9160 } |
| 9061 | 9161 |
| 9062 void test_parseSuperConstructorInvocation_unnamed() { | 9162 void test_parseSuperConstructorInvocation_unnamed() { |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10035 new Scanner(null, new CharSequenceReader(source), listener); | 10135 new Scanner(null, new CharSequenceReader(source), listener); |
| 10036 Token tokenStream = scanner.tokenize(); | 10136 Token tokenStream = scanner.tokenize(); |
| 10037 // | 10137 // |
| 10038 // Parse the source. | 10138 // Parse the source. |
| 10039 // | 10139 // |
| 10040 Parser parser = new Parser(null, listener); | 10140 Parser parser = new Parser(null, listener); |
| 10041 return invokeParserMethodImpl( | 10141 return invokeParserMethodImpl( |
| 10042 parser, methodName, <Object>[tokenStream], tokenStream) as Token; | 10142 parser, methodName, <Object>[tokenStream], tokenStream) as Token; |
| 10043 } | 10143 } |
| 10044 } | 10144 } |
| OLD | NEW |