| 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.generated.parser_test; | 5 library analyzer.test.generated.parser_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/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 main() { | 25 main() { |
| 26 defineReflectiveSuite(() { | 26 defineReflectiveSuite(() { |
| 27 defineReflectiveTests(ClassMemberParserTest); | 27 defineReflectiveTests(ClassMemberParserTest); |
| 28 defineReflectiveTests(ComplexParserTest); | 28 defineReflectiveTests(ComplexParserTest); |
| 29 defineReflectiveTests(ErrorParserTest); | 29 defineReflectiveTests(ErrorParserTest); |
| 30 defineReflectiveTests(ExpressionParserTest); | 30 defineReflectiveTests(ExpressionParserTest); |
| 31 defineReflectiveTests(FormalParameterParserTest); | 31 defineReflectiveTests(FormalParameterParserTest); |
| 32 defineReflectiveTests(NonErrorParserTest); | 32 defineReflectiveTests(NonErrorParserTest); |
| 33 defineReflectiveTests(RecoveryParserTest); | 33 defineReflectiveTests(RecoveryParserTest); |
| 34 defineReflectiveTests(SimpleParserTest); | 34 defineReflectiveTests(SimpleParserTest); |
| 35 defineReflectiveTests(StatementParserTest); |
| 35 defineReflectiveTests(TopLevelParserTest); | 36 defineReflectiveTests(TopLevelParserTest); |
| 36 }); | 37 }); |
| 37 } | 38 } |
| 38 | 39 |
| 39 /** | 40 /** |
| 40 * Abstract base class for parser tests, which does not make assumptions about | 41 * Abstract base class for parser tests, which does not make assumptions about |
| 41 * which parser is used. | 42 * which parser is used. |
| 42 */ | 43 */ |
| 43 abstract class AbstractParserTestCase implements ParserTestHelpers { | 44 abstract class AbstractParserTestCase implements ParserTestHelpers { |
| 44 void set enableAssertInitializer(bool value); | 45 void set enableAssertInitializer(bool value); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 Expression parsePrimaryExpression(String code); | 180 Expression parsePrimaryExpression(String code); |
| 180 | 181 |
| 181 Expression parseRelationalExpression(String code); | 182 Expression parseRelationalExpression(String code); |
| 182 | 183 |
| 183 RethrowExpression parseRethrowExpression(String code); | 184 RethrowExpression parseRethrowExpression(String code); |
| 184 | 185 |
| 185 BinaryExpression parseShiftExpression(String code); | 186 BinaryExpression parseShiftExpression(String code); |
| 186 | 187 |
| 187 SimpleIdentifier parseSimpleIdentifier(String code); | 188 SimpleIdentifier parseSimpleIdentifier(String code); |
| 188 | 189 |
| 189 Statement parseStatement(String source, | 190 Statement parseStatement(String source, [bool enableLazyAssignmentOperators]); |
| 190 [List<ErrorCode> errorCodes = const <ErrorCode>[], | |
| 191 bool enableLazyAssignmentOperators]); | |
| 192 | 191 |
| 193 Expression parseStringLiteral(String code); | 192 Expression parseStringLiteral(String code); |
| 194 | 193 |
| 195 SuperConstructorInvocation parseSuperConstructorInvocation(String code); | 194 SuperConstructorInvocation parseSuperConstructorInvocation(String code); |
| 196 | 195 |
| 197 SymbolLiteral parseSymbolLiteral(String code); | 196 SymbolLiteral parseSymbolLiteral(String code); |
| 198 | 197 |
| 199 Expression parseThrowExpression(String code); | 198 Expression parseThrowExpression(String code); |
| 200 | 199 |
| 201 Expression parseThrowExpressionWithoutCascade(String code); | 200 Expression parseThrowExpressionWithoutCascade(String code); |
| (...skipping 1719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 } | 1920 } |
| 1922 | 1921 |
| 1923 void test_breakOutsideOfLoop_breakInWhileStatement() { | 1922 void test_breakOutsideOfLoop_breakInWhileStatement() { |
| 1924 createParser('while (x) {break;}'); | 1923 createParser('while (x) {break;}'); |
| 1925 WhileStatement statement = parser.parseWhileStatement(); | 1924 WhileStatement statement = parser.parseWhileStatement(); |
| 1926 expectNotNullIfNoErrors(statement); | 1925 expectNotNullIfNoErrors(statement); |
| 1927 listener.assertNoErrors(); | 1926 listener.assertNoErrors(); |
| 1928 } | 1927 } |
| 1929 | 1928 |
| 1930 void test_breakOutsideOfLoop_functionExpression_inALoop() { | 1929 void test_breakOutsideOfLoop_functionExpression_inALoop() { |
| 1931 parseStatement( | 1930 parseStatement("for(; x;) {() {break;};}"); |
| 1932 "for(; x;) {() {break;};}", [ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); | 1931 assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); |
| 1933 } | 1932 } |
| 1934 | 1933 |
| 1935 void test_breakOutsideOfLoop_functionExpression_withALoop() { | 1934 void test_breakOutsideOfLoop_functionExpression_withALoop() { |
| 1936 parseStatement("() {for (; x;) {break;}};"); | 1935 parseStatement("() {for (; x;) {break;}};"); |
| 1937 } | 1936 } |
| 1938 | 1937 |
| 1939 void test_classInClass_abstract() { | 1938 void test_classInClass_abstract() { |
| 1940 parseCompilationUnit( | 1939 parseCompilationUnit( |
| 1941 "class C { abstract class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); | 1940 "class C { abstract class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); |
| 1942 } | 1941 } |
| 1943 | 1942 |
| 1944 void test_classInClass_nonAbstract() { | 1943 void test_classInClass_nonAbstract() { |
| 1945 parseCompilationUnit( | 1944 parseCompilationUnit( |
| 1946 "class C { class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); | 1945 "class C { class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); |
| 1947 } | 1946 } |
| 1948 | 1947 |
| 1949 void test_classTypeAlias_abstractAfterEq() { | 1948 void test_classTypeAlias_abstractAfterEq() { |
| 1950 // This syntax has been removed from the language in favor of | 1949 // This syntax has been removed from the language in favor of |
| 1951 // "abstract class A = B with C;" (issue 18098). | 1950 // "abstract class A = B with C;" (issue 18098). |
| 1952 createParser('class A = abstract B with C;'); | 1951 createParser('class A = abstract B with C;'); |
| 1953 CompilationUnitMember member = parseFullCompilationUnitMember(); | 1952 CompilationUnitMember member = parseFullCompilationUnitMember(); |
| 1954 expectNotNullIfNoErrors(member); | 1953 expectNotNullIfNoErrors(member); |
| 1955 listener.assertErrorsWithCodes( | 1954 listener.assertErrorsWithCodes( |
| 1956 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); | 1955 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); |
| 1957 } | 1956 } |
| 1958 | 1957 |
| 1959 void test_colonInPlaceOfIn() { | 1958 void test_colonInPlaceOfIn() { |
| 1960 parseStatement( | 1959 parseStatement("for (var x : list) {}"); |
| 1961 "for (var x : list) {}", [ParserErrorCode.COLON_IN_PLACE_OF_IN]); | 1960 assertErrorsWithCodes([ParserErrorCode.COLON_IN_PLACE_OF_IN]); |
| 1962 } | 1961 } |
| 1963 | 1962 |
| 1964 void test_constAndCovariant() { | 1963 void test_constAndCovariant() { |
| 1965 createParser('covariant const C f;'); | 1964 createParser('covariant const C f;'); |
| 1966 ClassMember member = parser.parseClassMember('C'); | 1965 ClassMember member = parser.parseClassMember('C'); |
| 1967 expectNotNullIfNoErrors(member); | 1966 expectNotNullIfNoErrors(member); |
| 1968 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_COVARIANT]); | 1967 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_COVARIANT]); |
| 1969 } | 1968 } |
| 1970 | 1969 |
| 1971 void test_constAndFinal() { | 1970 void test_constAndFinal() { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 } | 2060 } |
| 2062 | 2061 |
| 2063 void test_continueOutsideOfLoop_continueInWhileStatement() { | 2062 void test_continueOutsideOfLoop_continueInWhileStatement() { |
| 2064 createParser('while (x) {continue;}'); | 2063 createParser('while (x) {continue;}'); |
| 2065 WhileStatement statement = parser.parseWhileStatement(); | 2064 WhileStatement statement = parser.parseWhileStatement(); |
| 2066 expectNotNullIfNoErrors(statement); | 2065 expectNotNullIfNoErrors(statement); |
| 2067 listener.assertNoErrors(); | 2066 listener.assertNoErrors(); |
| 2068 } | 2067 } |
| 2069 | 2068 |
| 2070 void test_continueOutsideOfLoop_functionExpression_inALoop() { | 2069 void test_continueOutsideOfLoop_functionExpression_inALoop() { |
| 2071 parseStatement("for(; x;) {() {continue;};}", | 2070 parseStatement("for(; x;) {() {continue;};}"); |
| 2072 [ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); | 2071 assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| 2073 } | 2072 } |
| 2074 | 2073 |
| 2075 void test_continueOutsideOfLoop_functionExpression_withALoop() { | 2074 void test_continueOutsideOfLoop_functionExpression_withALoop() { |
| 2076 parseStatement("() {for (; x;) {continue;}};"); | 2075 parseStatement("() {for (; x;) {continue;}};"); |
| 2077 } | 2076 } |
| 2078 | 2077 |
| 2079 void test_continueWithoutLabelInCase_error() { | 2078 void test_continueWithoutLabelInCase_error() { |
| 2080 createParser('switch (x) {case 1: continue;}'); | 2079 createParser('switch (x) {case 1: continue;}'); |
| 2081 SwitchStatement statement = parser.parseSwitchStatement(); | 2080 SwitchStatement statement = parser.parseSwitchStatement(); |
| 2082 expectNotNullIfNoErrors(statement); | 2081 expectNotNullIfNoErrors(statement); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2384 } | 2383 } |
| 2385 | 2384 |
| 2386 void test_expectedToken_commaMissingInArgumentList() { | 2385 void test_expectedToken_commaMissingInArgumentList() { |
| 2387 createParser('(x, y z)'); | 2386 createParser('(x, y z)'); |
| 2388 ArgumentList list = parser.parseArgumentList(); | 2387 ArgumentList list = parser.parseArgumentList(); |
| 2389 expectNotNullIfNoErrors(list); | 2388 expectNotNullIfNoErrors(list); |
| 2390 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); | 2389 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 2391 } | 2390 } |
| 2392 | 2391 |
| 2393 void test_expectedToken_parseStatement_afterVoid() { | 2392 void test_expectedToken_parseStatement_afterVoid() { |
| 2394 parseStatement("void}", | 2393 parseStatement("void}"); |
| 2394 assertErrorsWithCodes( |
| 2395 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); | 2395 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); |
| 2396 } | 2396 } |
| 2397 | 2397 |
| 2398 void test_expectedToken_semicolonMissingAfterExport() { | 2398 void test_expectedToken_semicolonMissingAfterExport() { |
| 2399 CompilationUnit unit = parseCompilationUnit( | 2399 CompilationUnit unit = parseCompilationUnit( |
| 2400 "export '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); | 2400 "export '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); |
| 2401 ExportDirective directive = unit.directives[0] as ExportDirective; | 2401 ExportDirective directive = unit.directives[0] as ExportDirective; |
| 2402 Token semicolon = directive.semicolon; | 2402 Token semicolon = directive.semicolon; |
| 2403 expect(semicolon, isNotNull); | 2403 expect(semicolon, isNotNull); |
| 2404 expect(semicolon.isSynthetic, isTrue); | 2404 expect(semicolon.isSynthetic, isTrue); |
| 2405 } | 2405 } |
| 2406 | 2406 |
| 2407 void test_expectedToken_semicolonMissingAfterExpression() { | 2407 void test_expectedToken_semicolonMissingAfterExpression() { |
| 2408 parseStatement("x", [ParserErrorCode.EXPECTED_TOKEN]); | 2408 parseStatement("x"); |
| 2409 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 2409 } | 2410 } |
| 2410 | 2411 |
| 2411 void test_expectedToken_semicolonMissingAfterImport() { | 2412 void test_expectedToken_semicolonMissingAfterImport() { |
| 2412 CompilationUnit unit = parseCompilationUnit( | 2413 CompilationUnit unit = parseCompilationUnit( |
| 2413 "import '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); | 2414 "import '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); |
| 2414 ImportDirective directive = unit.directives[0] as ImportDirective; | 2415 ImportDirective directive = unit.directives[0] as ImportDirective; |
| 2415 Token semicolon = directive.semicolon; | 2416 Token semicolon = directive.semicolon; |
| 2416 expect(semicolon, isNotNull); | 2417 expect(semicolon, isNotNull); |
| 2417 expect(semicolon.isSynthetic, isTrue); | 2418 expect(semicolon.isSynthetic, isTrue); |
| 2418 } | 2419 } |
| 2419 | 2420 |
| 2420 void test_expectedToken_whileMissingInDoStatement() { | 2421 void test_expectedToken_whileMissingInDoStatement() { |
| 2421 parseStatement("do {} (x);", [ParserErrorCode.EXPECTED_TOKEN]); | 2422 parseStatement("do {} (x);"); |
| 2423 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 2422 } | 2424 } |
| 2423 | 2425 |
| 2424 void test_expectedTypeName_as() { | 2426 void test_expectedTypeName_as() { |
| 2425 parseExpression("x as", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 2427 parseExpression("x as", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 2426 } | 2428 } |
| 2427 | 2429 |
| 2428 void test_expectedTypeName_as_void() { | 2430 void test_expectedTypeName_as_void() { |
| 2429 parseExpression("x as void)", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 2431 parseExpression("x as void)", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 2430 } | 2432 } |
| 2431 | 2433 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2679 parseCompilationUnit( | 2681 parseCompilationUnit( |
| 2680 "void f(final x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); | 2682 "void f(final x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); |
| 2681 } | 2683 } |
| 2682 | 2684 |
| 2683 void test_functionTypedParameter_var() { | 2685 void test_functionTypedParameter_var() { |
| 2684 parseCompilationUnit( | 2686 parseCompilationUnit( |
| 2685 "void f(var x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); | 2687 "void f(var x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); |
| 2686 } | 2688 } |
| 2687 | 2689 |
| 2688 void test_getterInFunction_block_noReturnType() { | 2690 void test_getterInFunction_block_noReturnType() { |
| 2689 FunctionDeclarationStatement statement = parseStatement( | 2691 FunctionDeclarationStatement statement = |
| 2690 "get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); | 2692 parseStatement("get x { return _x; }"); |
| 2693 assertErrorsWithCodes([ParserErrorCode.GETTER_IN_FUNCTION]); |
| 2691 expect(statement.functionDeclaration.functionExpression.parameters, isNull); | 2694 expect(statement.functionDeclaration.functionExpression.parameters, isNull); |
| 2692 } | 2695 } |
| 2693 | 2696 |
| 2694 void test_getterInFunction_block_returnType() { | 2697 void test_getterInFunction_block_returnType() { |
| 2695 parseStatement( | 2698 parseStatement("int get x { return _x; }"); |
| 2696 "int get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); | 2699 assertErrorsWithCodes([ParserErrorCode.GETTER_IN_FUNCTION]); |
| 2697 } | 2700 } |
| 2698 | 2701 |
| 2699 void test_getterInFunction_expression_noReturnType() { | 2702 void test_getterInFunction_expression_noReturnType() { |
| 2700 parseStatement("get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); | 2703 parseStatement("get x => _x;"); |
| 2704 assertErrorsWithCodes([ParserErrorCode.GETTER_IN_FUNCTION]); |
| 2701 } | 2705 } |
| 2702 | 2706 |
| 2703 void test_getterInFunction_expression_returnType() { | 2707 void test_getterInFunction_expression_returnType() { |
| 2704 parseStatement("int get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); | 2708 parseStatement("int get x => _x;"); |
| 2709 assertErrorsWithCodes([ParserErrorCode.GETTER_IN_FUNCTION]); |
| 2705 } | 2710 } |
| 2706 | 2711 |
| 2707 void test_getterWithParameters() { | 2712 void test_getterWithParameters() { |
| 2708 createParser('int get x() {}'); | 2713 createParser('int get x() {}'); |
| 2709 ClassMember member = parser.parseClassMember('C'); | 2714 ClassMember member = parser.parseClassMember('C'); |
| 2710 expectNotNullIfNoErrors(member); | 2715 expectNotNullIfNoErrors(member); |
| 2711 listener.assertErrorsWithCodes([ParserErrorCode.GETTER_WITH_PARAMETERS]); | 2716 listener.assertErrorsWithCodes([ParserErrorCode.GETTER_WITH_PARAMETERS]); |
| 2712 } | 2717 } |
| 2713 | 2718 |
| 2714 void test_illegalAssignmentToNonAssignable_postfix_minusMinus_literal() { | 2719 void test_illegalAssignmentToNonAssignable_postfix_minusMinus_literal() { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2945 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); | 2950 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); |
| 2946 } | 2951 } |
| 2947 | 2952 |
| 2948 void test_libraryDirectiveNotFirst_afterPart() { | 2953 void test_libraryDirectiveNotFirst_afterPart() { |
| 2949 CompilationUnit unit = parseCompilationUnit("part 'a.dart';\nlibrary l;", | 2954 CompilationUnit unit = parseCompilationUnit("part 'a.dart';\nlibrary l;", |
| 2950 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); | 2955 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); |
| 2951 expect(unit, isNotNull); | 2956 expect(unit, isNotNull); |
| 2952 } | 2957 } |
| 2953 | 2958 |
| 2954 void test_localFunctionDeclarationModifier_abstract() { | 2959 void test_localFunctionDeclarationModifier_abstract() { |
| 2955 parseStatement("abstract f() {}", | 2960 parseStatement("abstract f() {}"); |
| 2961 assertErrorsWithCodes( |
| 2956 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 2962 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 2957 } | 2963 } |
| 2958 | 2964 |
| 2959 void test_localFunctionDeclarationModifier_external() { | 2965 void test_localFunctionDeclarationModifier_external() { |
| 2960 parseStatement("external f() {}", | 2966 parseStatement("external f() {}"); |
| 2967 assertErrorsWithCodes( |
| 2961 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 2968 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 2962 } | 2969 } |
| 2963 | 2970 |
| 2964 void test_localFunctionDeclarationModifier_factory() { | 2971 void test_localFunctionDeclarationModifier_factory() { |
| 2965 parseStatement("factory f() {}", | 2972 parseStatement("factory f() {}"); |
| 2973 assertErrorsWithCodes( |
| 2966 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 2974 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 2967 } | 2975 } |
| 2968 | 2976 |
| 2969 void test_localFunctionDeclarationModifier_static() { | 2977 void test_localFunctionDeclarationModifier_static() { |
| 2970 parseStatement( | 2978 parseStatement("static f() {}"); |
| 2971 "static f() {}", [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 2979 assertErrorsWithCodes( |
| 2980 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 2972 } | 2981 } |
| 2973 | 2982 |
| 2974 void test_method_invalidTypeParameterComments() { | 2983 void test_method_invalidTypeParameterComments() { |
| 2975 enableGenericMethodComments = true; | 2984 enableGenericMethodComments = true; |
| 2976 createParser('void m/*<E, hello!>*/() {}'); | 2985 createParser('void m/*<E, hello!>*/() {}'); |
| 2977 ClassMember member = parser.parseClassMember('C'); | 2986 ClassMember member = parser.parseClassMember('C'); |
| 2978 expectNotNullIfNoErrors(member); | 2987 expectNotNullIfNoErrors(member); |
| 2979 listener.assertErrorsWithCodes([ | 2988 listener.assertErrorsWithCodes([ |
| 2980 ParserErrorCode.EXPECTED_TOKEN /*>*/, | 2989 ParserErrorCode.EXPECTED_TOKEN /*>*/, |
| 2981 ParserErrorCode.MISSING_IDENTIFIER, | 2990 ParserErrorCode.MISSING_IDENTIFIER, |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3160 false, ParserErrorCode.MISSING_FUNCTION_BODY, false); | 3169 false, ParserErrorCode.MISSING_FUNCTION_BODY, false); |
| 3161 expectNotNullIfNoErrors(functionBody); | 3170 expectNotNullIfNoErrors(functionBody); |
| 3162 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_BODY]); | 3171 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_BODY]); |
| 3163 } | 3172 } |
| 3164 | 3173 |
| 3165 @failingTest | 3174 @failingTest |
| 3166 void test_missingFunctionParameters_local_nonVoid_block() { | 3175 void test_missingFunctionParameters_local_nonVoid_block() { |
| 3167 // The parser does not recognize this as a function declaration, so it tries | 3176 // The parser does not recognize this as a function declaration, so it tries |
| 3168 // to parse it as an expression statement. It isn't clear what the best | 3177 // to parse it as an expression statement. It isn't clear what the best |
| 3169 // error message is in this case. | 3178 // error message is in this case. |
| 3170 parseStatement( | 3179 parseStatement("int f { return x;}"); |
| 3171 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 3180 assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 3172 } | 3181 } |
| 3173 | 3182 |
| 3174 @failingTest | 3183 @failingTest |
| 3175 void test_missingFunctionParameters_local_nonVoid_expression() { | 3184 void test_missingFunctionParameters_local_nonVoid_expression() { |
| 3176 // The parser does not recognize this as a function declaration, so it tries | 3185 // The parser does not recognize this as a function declaration, so it tries |
| 3177 // to parse it as an expression statement. It isn't clear what the best | 3186 // to parse it as an expression statement. It isn't clear what the best |
| 3178 // error message is in this case. | 3187 // error message is in this case. |
| 3179 parseStatement( | 3188 parseStatement("int f => x;"); |
| 3180 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 3189 assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 3181 } | 3190 } |
| 3182 | 3191 |
| 3183 void test_missingFunctionParameters_local_void_block() { | 3192 void test_missingFunctionParameters_local_void_block() { |
| 3184 parseStatement( | 3193 parseStatement("void f { return x;}"); |
| 3185 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 3194 assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 3186 } | 3195 } |
| 3187 | 3196 |
| 3188 void test_missingFunctionParameters_local_void_expression() { | 3197 void test_missingFunctionParameters_local_void_expression() { |
| 3189 parseStatement( | 3198 parseStatement("void f => x;"); |
| 3190 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 3199 assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 3191 } | 3200 } |
| 3192 | 3201 |
| 3193 void test_missingFunctionParameters_topLevel_nonVoid_block() { | 3202 void test_missingFunctionParameters_topLevel_nonVoid_block() { |
| 3194 parseCompilationUnit( | 3203 parseCompilationUnit( |
| 3195 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 3204 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 3196 } | 3205 } |
| 3197 | 3206 |
| 3198 void test_missingFunctionParameters_topLevel_nonVoid_expression() { | 3207 void test_missingFunctionParameters_topLevel_nonVoid_expression() { |
| 3199 parseCompilationUnit( | 3208 parseCompilationUnit( |
| 3200 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 3209 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3357 } | 3366 } |
| 3358 | 3367 |
| 3359 void test_missingStartAfterSync() { | 3368 void test_missingStartAfterSync() { |
| 3360 createParser('sync {}'); | 3369 createParser('sync {}'); |
| 3361 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); | 3370 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 3362 expectNotNullIfNoErrors(functionBody); | 3371 expectNotNullIfNoErrors(functionBody); |
| 3363 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_STAR_AFTER_SYNC]); | 3372 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_STAR_AFTER_SYNC]); |
| 3364 } | 3373 } |
| 3365 | 3374 |
| 3366 void test_missingStatement() { | 3375 void test_missingStatement() { |
| 3367 parseStatement("is", [ParserErrorCode.MISSING_STATEMENT]); | 3376 parseStatement("is"); |
| 3377 assertErrorsWithCodes([ParserErrorCode.MISSING_STATEMENT]); |
| 3368 } | 3378 } |
| 3369 | 3379 |
| 3370 void test_missingStatement_afterVoid() { | 3380 void test_missingStatement_afterVoid() { |
| 3371 parseStatement("void;", [ParserErrorCode.MISSING_STATEMENT]); | 3381 parseStatement("void;"); |
| 3382 assertErrorsWithCodes([ParserErrorCode.MISSING_STATEMENT]); |
| 3372 } | 3383 } |
| 3373 | 3384 |
| 3374 void test_missingTerminatorForParameterGroup_named() { | 3385 void test_missingTerminatorForParameterGroup_named() { |
| 3375 createParser('(a, {b: 0)'); | 3386 createParser('(a, {b: 0)'); |
| 3376 FormalParameterList list = parser.parseFormalParameterList(); | 3387 FormalParameterList list = parser.parseFormalParameterList(); |
| 3377 expectNotNullIfNoErrors(list); | 3388 expectNotNullIfNoErrors(list); |
| 3378 listener.assertErrorsWithCodes( | 3389 listener.assertErrorsWithCodes( |
| 3379 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); | 3390 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 3380 } | 3391 } |
| 3381 | 3392 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3642 | 3653 |
| 3643 void test_redirectionInNonFactoryConstructor() { | 3654 void test_redirectionInNonFactoryConstructor() { |
| 3644 createParser('C() = D;'); | 3655 createParser('C() = D;'); |
| 3645 ClassMember member = parser.parseClassMember('C'); | 3656 ClassMember member = parser.parseClassMember('C'); |
| 3646 expectNotNullIfNoErrors(member); | 3657 expectNotNullIfNoErrors(member); |
| 3647 listener.assertErrorsWithCodes( | 3658 listener.assertErrorsWithCodes( |
| 3648 [ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR]); | 3659 [ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR]); |
| 3649 } | 3660 } |
| 3650 | 3661 |
| 3651 void test_setterInFunction_block() { | 3662 void test_setterInFunction_block() { |
| 3652 parseStatement("set x(v) {_x = v;}", [ParserErrorCode.SETTER_IN_FUNCTION]); | 3663 parseStatement("set x(v) {_x = v;}"); |
| 3664 assertErrorsWithCodes([ParserErrorCode.SETTER_IN_FUNCTION]); |
| 3653 } | 3665 } |
| 3654 | 3666 |
| 3655 void test_setterInFunction_expression() { | 3667 void test_setterInFunction_expression() { |
| 3656 parseStatement("set x(v) => _x = v;", [ParserErrorCode.SETTER_IN_FUNCTION]); | 3668 parseStatement("set x(v) => _x = v;"); |
| 3669 assertErrorsWithCodes([ParserErrorCode.SETTER_IN_FUNCTION]); |
| 3657 } | 3670 } |
| 3658 | 3671 |
| 3659 void test_staticAfterConst() { | 3672 void test_staticAfterConst() { |
| 3660 createParser('final static int f;'); | 3673 createParser('final static int f;'); |
| 3661 ClassMember member = parser.parseClassMember('C'); | 3674 ClassMember member = parser.parseClassMember('C'); |
| 3662 expectNotNullIfNoErrors(member); | 3675 expectNotNullIfNoErrors(member); |
| 3663 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_AFTER_FINAL]); | 3676 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_AFTER_FINAL]); |
| 3664 } | 3677 } |
| 3665 | 3678 |
| 3666 void test_staticAfterFinal() { | 3679 void test_staticAfterFinal() { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3854 | 3867 |
| 3855 void test_unexpectedTerminatorForParameterGroup_optional() { | 3868 void test_unexpectedTerminatorForParameterGroup_optional() { |
| 3856 createParser('(a, b])'); | 3869 createParser('(a, b])'); |
| 3857 FormalParameterList list = parser.parseFormalParameterList(); | 3870 FormalParameterList list = parser.parseFormalParameterList(); |
| 3858 expectNotNullIfNoErrors(list); | 3871 expectNotNullIfNoErrors(list); |
| 3859 listener.assertErrorsWithCodes( | 3872 listener.assertErrorsWithCodes( |
| 3860 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); | 3873 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 3861 } | 3874 } |
| 3862 | 3875 |
| 3863 void test_unexpectedToken_endOfFieldDeclarationStatement() { | 3876 void test_unexpectedToken_endOfFieldDeclarationStatement() { |
| 3864 parseStatement("String s = (null));", [ParserErrorCode.UNEXPECTED_TOKEN]); | 3877 parseStatement("String s = (null));"); |
| 3878 assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]); |
| 3865 } | 3879 } |
| 3866 | 3880 |
| 3867 @failingTest | 3881 @failingTest |
| 3868 void test_unexpectedToken_invalidPostfixExpression() { | 3882 void test_unexpectedToken_invalidPostfixExpression() { |
| 3869 // Note: this might not be the right error to produce, but some error should | 3883 // Note: this might not be the right error to produce, but some error should |
| 3870 // be produced | 3884 // be produced |
| 3871 parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); | 3885 parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 3872 } | 3886 } |
| 3873 | 3887 |
| 3874 void test_unexpectedToken_returnInExpressionFuntionBody() { | 3888 void test_unexpectedToken_returnInExpressionFuntionBody() { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3972 | 3986 |
| 3973 void test_varAndType_field() { | 3987 void test_varAndType_field() { |
| 3974 parseCompilationUnit( | 3988 parseCompilationUnit( |
| 3975 "class C { var int x; }", [ParserErrorCode.VAR_AND_TYPE]); | 3989 "class C { var int x; }", [ParserErrorCode.VAR_AND_TYPE]); |
| 3976 } | 3990 } |
| 3977 | 3991 |
| 3978 @failingTest | 3992 @failingTest |
| 3979 void test_varAndType_local() { | 3993 void test_varAndType_local() { |
| 3980 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but | 3994 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
| 3981 // this would be a better error message. | 3995 // this would be a better error message. |
| 3982 parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); | 3996 parseStatement("var int x;"); |
| 3997 assertErrorsWithCodes([ParserErrorCode.VAR_AND_TYPE]); |
| 3983 } | 3998 } |
| 3984 | 3999 |
| 3985 @failingTest | 4000 @failingTest |
| 3986 void test_varAndType_parameter() { | 4001 void test_varAndType_parameter() { |
| 3987 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but | 4002 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
| 3988 // this would be a better error message. | 4003 // this would be a better error message. |
| 3989 createParser('(var int x)'); | 4004 createParser('(var int x)'); |
| 3990 FormalParameterList list = parser.parseFormalParameterList(); | 4005 FormalParameterList list = parser.parseFormalParameterList(); |
| 3991 expectNotNullIfNoErrors(list); | 4006 expectNotNullIfNoErrors(list); |
| 3992 listener.assertErrorsWithCodes([ParserErrorCode.VAR_AND_TYPE]); | 4007 listener.assertErrorsWithCodes([ParserErrorCode.VAR_AND_TYPE]); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4056 } | 4071 } |
| 4057 | 4072 |
| 4058 void test_voidVariable_parseCompilationUnitMember_noInitializer() { | 4073 void test_voidVariable_parseCompilationUnitMember_noInitializer() { |
| 4059 createParser('void a;'); | 4074 createParser('void a;'); |
| 4060 CompilationUnitMember member = parseFullCompilationUnitMember(); | 4075 CompilationUnitMember member = parseFullCompilationUnitMember(); |
| 4061 expectNotNullIfNoErrors(member); | 4076 expectNotNullIfNoErrors(member); |
| 4062 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 4077 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 4063 } | 4078 } |
| 4064 | 4079 |
| 4065 void test_voidVariable_statement_initializer() { | 4080 void test_voidVariable_statement_initializer() { |
| 4066 parseStatement("void x = 0;", [ | 4081 parseStatement("void x = 0;"); |
| 4082 assertErrorsWithCodes([ |
| 4067 ParserErrorCode.VOID_VARIABLE, | 4083 ParserErrorCode.VOID_VARIABLE, |
| 4068 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 4084 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 4069 ]); | 4085 ]); |
| 4070 } | 4086 } |
| 4071 | 4087 |
| 4072 void test_voidVariable_statement_noInitializer() { | 4088 void test_voidVariable_statement_noInitializer() { |
| 4073 parseStatement("void x;", [ | 4089 parseStatement("void x;"); |
| 4090 assertErrorsWithCodes([ |
| 4074 ParserErrorCode.VOID_VARIABLE, | 4091 ParserErrorCode.VOID_VARIABLE, |
| 4075 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 4092 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 4076 ]); | 4093 ]); |
| 4077 } | 4094 } |
| 4078 | 4095 |
| 4079 void test_withBeforeExtends() { | 4096 void test_withBeforeExtends() { |
| 4080 parseCompilationUnit( | 4097 parseCompilationUnit( |
| 4081 "class A with B extends C {}", [ParserErrorCode.WITH_BEFORE_EXTENDS]); | 4098 "class A with B extends C {}", [ParserErrorCode.WITH_BEFORE_EXTENDS]); |
| 4082 } | 4099 } |
| 4083 | 4100 |
| (...skipping 4095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8179 return parser.parseShiftExpression(); | 8196 return parser.parseShiftExpression(); |
| 8180 } | 8197 } |
| 8181 | 8198 |
| 8182 @override | 8199 @override |
| 8183 SimpleIdentifier parseSimpleIdentifier(String code) { | 8200 SimpleIdentifier parseSimpleIdentifier(String code) { |
| 8184 createParser(code); | 8201 createParser(code); |
| 8185 return parser.parseSimpleIdentifier(); | 8202 return parser.parseSimpleIdentifier(); |
| 8186 } | 8203 } |
| 8187 | 8204 |
| 8188 /** | 8205 /** |
| 8189 * Parse the given [source] as a statement. The [errorCodes] are the error | 8206 * Parse the given [source] as a statement. If [enableLazyAssignmentOperators] |
| 8190 * codes of the errors that are expected to be found. If | 8207 * is `true`, then lazy assignment operators should be enabled. |
| 8191 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators | |
| 8192 * should be enabled. | |
| 8193 */ | 8208 */ |
| 8194 Statement parseStatement(String source, | 8209 Statement parseStatement(String source, |
| 8195 [List<ErrorCode> errorCodes = const <ErrorCode>[], | 8210 [bool enableLazyAssignmentOperators]) { |
| 8196 bool enableLazyAssignmentOperators]) { | 8211 listener = new GatheringErrorListener(); |
| 8197 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8198 Scanner scanner = | 8212 Scanner scanner = |
| 8199 new Scanner(null, new CharSequenceReader(source), listener); | 8213 new Scanner(null, new CharSequenceReader(source), listener); |
| 8214 scanner.scanGenericMethodComments = enableGenericMethodComments; |
| 8200 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; | 8215 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| 8201 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 8216 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 8202 Token token = scanner.tokenize(); | 8217 Token token = scanner.tokenize(); |
| 8203 Parser parser = new Parser(null, listener); | 8218 Parser parser = new Parser(null, listener); |
| 8219 parser.parseGenericMethodComments = enableGenericMethodComments; |
| 8204 Statement statement = parser.parseStatement(token); | 8220 Statement statement = parser.parseStatement(token); |
| 8205 expect(statement, isNotNull); | 8221 expect(statement, isNotNull); |
| 8206 listener.assertErrorsWithCodes(errorCodes); | |
| 8207 return statement; | 8222 return statement; |
| 8208 } | 8223 } |
| 8209 | 8224 |
| 8210 /** | 8225 /** |
| 8211 * Parse the given source as a sequence of statements. | 8226 * Parse the given source as a sequence of statements. |
| 8212 * | 8227 * |
| 8213 * @param source the source to be parsed | 8228 * @param source the source to be parsed |
| 8214 * @param expectedCount the number of statements that are expected | 8229 * @param expectedCount the number of statements that are expected |
| 8215 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 8230 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 8216 * @return the statements that were parsed | 8231 * @return the statements that were parsed |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9001 VariableDeclarationList fieldList = | 9016 VariableDeclarationList fieldList = |
| 9002 (classMember as FieldDeclaration).fields; | 9017 (classMember as FieldDeclaration).fields; |
| 9003 expect(fieldList.keyword.keyword, Keyword.VAR); | 9018 expect(fieldList.keyword.keyword, Keyword.VAR); |
| 9004 NodeList<VariableDeclaration> fields = fieldList.variables; | 9019 NodeList<VariableDeclaration> fields = fieldList.variables; |
| 9005 expect(fields, hasLength(1)); | 9020 expect(fields, hasLength(1)); |
| 9006 VariableDeclaration field = fields[0]; | 9021 VariableDeclaration field = fields[0]; |
| 9007 expect(field.name.isSynthetic, isTrue); | 9022 expect(field.name.isSynthetic, isTrue); |
| 9008 } | 9023 } |
| 9009 | 9024 |
| 9010 void test_incompleteForEach() { | 9025 void test_incompleteForEach() { |
| 9011 ForStatement statement = parseStatement('for (String item i) {}', | 9026 ForStatement statement = parseStatement('for (String item i) {}'); |
| 9027 assertErrorsWithCodes( |
| 9012 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); | 9028 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); |
| 9013 expect(statement, new isInstanceOf<ForStatement>()); | 9029 expect(statement, new isInstanceOf<ForStatement>()); |
| 9014 expect(statement.toSource(), 'for (String item; i;) {}'); | 9030 expect(statement.toSource(), 'for (String item; i;) {}'); |
| 9015 expect(statement.leftSeparator, isNotNull); | 9031 expect(statement.leftSeparator, isNotNull); |
| 9016 expect(statement.leftSeparator.type, TokenType.SEMICOLON); | 9032 expect(statement.leftSeparator.type, TokenType.SEMICOLON); |
| 9017 expect(statement.rightSeparator, isNotNull); | 9033 expect(statement.rightSeparator, isNotNull); |
| 9018 expect(statement.rightSeparator.type, TokenType.SEMICOLON); | 9034 expect(statement.rightSeparator.type, TokenType.SEMICOLON); |
| 9019 } | 9035 } |
| 9020 | 9036 |
| 9021 void test_incompleteLocalVariable_atTheEndOfBlock() { | 9037 void test_incompleteLocalVariable_atTheEndOfBlock() { |
| 9022 Statement statement = | 9038 Statement statement = parseStatement('String v }'); |
| 9023 parseStatement('String v }', [ParserErrorCode.EXPECTED_TOKEN]); | 9039 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 9024 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 9040 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 9025 expect(statement.toSource(), 'String v;'); | 9041 expect(statement.toSource(), 'String v;'); |
| 9026 } | 9042 } |
| 9027 | 9043 |
| 9028 void test_incompleteLocalVariable_beforeIdentifier() { | 9044 void test_incompleteLocalVariable_beforeIdentifier() { |
| 9029 Statement statement = | 9045 Statement statement = parseStatement('String v String v2;'); |
| 9030 parseStatement('String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]); | 9046 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 9031 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 9047 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 9032 expect(statement.toSource(), 'String v;'); | 9048 expect(statement.toSource(), 'String v;'); |
| 9033 } | 9049 } |
| 9034 | 9050 |
| 9035 void test_incompleteLocalVariable_beforeKeyword() { | 9051 void test_incompleteLocalVariable_beforeKeyword() { |
| 9036 Statement statement = parseStatement( | 9052 Statement statement = parseStatement('String v if (true) {}'); |
| 9037 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]); | 9053 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 9038 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 9054 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 9039 expect(statement.toSource(), 'String v;'); | 9055 expect(statement.toSource(), 'String v;'); |
| 9040 } | 9056 } |
| 9041 | 9057 |
| 9042 void test_incompleteLocalVariable_beforeNextBlock() { | 9058 void test_incompleteLocalVariable_beforeNextBlock() { |
| 9043 Statement statement = | 9059 Statement statement = parseStatement('String v {}'); |
| 9044 parseStatement('String v {}', [ParserErrorCode.EXPECTED_TOKEN]); | 9060 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 9045 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 9061 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 9046 expect(statement.toSource(), 'String v;'); | 9062 expect(statement.toSource(), 'String v;'); |
| 9047 } | 9063 } |
| 9048 | 9064 |
| 9049 void test_incompleteLocalVariable_parameterizedType() { | 9065 void test_incompleteLocalVariable_parameterizedType() { |
| 9050 Statement statement = | 9066 Statement statement = parseStatement('List<String> v {}'); |
| 9051 parseStatement('List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]); | 9067 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 9052 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 9068 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 9053 expect(statement.toSource(), 'List<String> v;'); | 9069 expect(statement.toSource(), 'List<String> v;'); |
| 9054 } | 9070 } |
| 9055 | 9071 |
| 9056 void test_incompleteTypeArguments_field() { | 9072 void test_incompleteTypeArguments_field() { |
| 9057 CompilationUnit unit = parseCompilationUnit( | 9073 CompilationUnit unit = parseCompilationUnit( |
| 9058 r''' | 9074 r''' |
| 9059 class C { | 9075 class C { |
| 9060 final List<int f; | 9076 final List<int f; |
| 9061 }''', | 9077 }''', |
| (...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9942 | 9958 |
| 9943 void test_parseArgumentList_trailing_comma() { | 9959 void test_parseArgumentList_trailing_comma() { |
| 9944 createParser('(x, y, z,)'); | 9960 createParser('(x, y, z,)'); |
| 9945 ArgumentList argumentList = parser.parseArgumentList(); | 9961 ArgumentList argumentList = parser.parseArgumentList(); |
| 9946 expectNotNullIfNoErrors(argumentList); | 9962 expectNotNullIfNoErrors(argumentList); |
| 9947 listener.assertNoErrors(); | 9963 listener.assertNoErrors(); |
| 9948 NodeList<Expression> arguments = argumentList.arguments; | 9964 NodeList<Expression> arguments = argumentList.arguments; |
| 9949 expect(arguments, hasLength(3)); | 9965 expect(arguments, hasLength(3)); |
| 9950 } | 9966 } |
| 9951 | 9967 |
| 9952 void test_parseAssertStatement() { | |
| 9953 createParser('assert (x);'); | |
| 9954 AssertStatement statement = parser.parseAssertStatement(); | |
| 9955 expectNotNullIfNoErrors(statement); | |
| 9956 listener.assertNoErrors(); | |
| 9957 expect(statement.assertKeyword, isNotNull); | |
| 9958 expect(statement.leftParenthesis, isNotNull); | |
| 9959 expect(statement.condition, isNotNull); | |
| 9960 expect(statement.comma, isNull); | |
| 9961 expect(statement.message, isNull); | |
| 9962 expect(statement.rightParenthesis, isNotNull); | |
| 9963 expect(statement.semicolon, isNotNull); | |
| 9964 } | |
| 9965 | |
| 9966 void test_parseAssertStatement_messageLowPrecedence() { | |
| 9967 // Using a throw expression as an assert message would be silly in | |
| 9968 // practice, but it's the lowest precedence expression type, so verifying | |
| 9969 // that it works should give us high confidence that other expression types | |
| 9970 // will work as well. | |
| 9971 createParser('assert (x, throw "foo");'); | |
| 9972 AssertStatement statement = parser.parseAssertStatement(); | |
| 9973 expectNotNullIfNoErrors(statement); | |
| 9974 listener.assertNoErrors(); | |
| 9975 expect(statement.assertKeyword, isNotNull); | |
| 9976 expect(statement.leftParenthesis, isNotNull); | |
| 9977 expect(statement.condition, isNotNull); | |
| 9978 expect(statement.comma, isNotNull); | |
| 9979 expect(statement.message, isNotNull); | |
| 9980 expect(statement.rightParenthesis, isNotNull); | |
| 9981 expect(statement.semicolon, isNotNull); | |
| 9982 } | |
| 9983 | |
| 9984 void test_parseAssertStatement_messageString() { | |
| 9985 createParser('assert (x, "foo");'); | |
| 9986 AssertStatement statement = parser.parseAssertStatement(); | |
| 9987 expectNotNullIfNoErrors(statement); | |
| 9988 listener.assertNoErrors(); | |
| 9989 expect(statement.assertKeyword, isNotNull); | |
| 9990 expect(statement.leftParenthesis, isNotNull); | |
| 9991 expect(statement.condition, isNotNull); | |
| 9992 expect(statement.comma, isNotNull); | |
| 9993 expect(statement.message, isNotNull); | |
| 9994 expect(statement.rightParenthesis, isNotNull); | |
| 9995 expect(statement.semicolon, isNotNull); | |
| 9996 } | |
| 9997 | |
| 9998 void test_parseBlock_empty() { | |
| 9999 createParser('{}'); | |
| 10000 Block block = parser.parseBlock(); | |
| 10001 expectNotNullIfNoErrors(block); | |
| 10002 listener.assertNoErrors(); | |
| 10003 expect(block.leftBracket, isNotNull); | |
| 10004 expect(block.statements, hasLength(0)); | |
| 10005 expect(block.rightBracket, isNotNull); | |
| 10006 } | |
| 10007 | |
| 10008 void test_parseBlock_nonEmpty() { | |
| 10009 createParser('{;}'); | |
| 10010 Block block = parser.parseBlock(); | |
| 10011 expectNotNullIfNoErrors(block); | |
| 10012 listener.assertNoErrors(); | |
| 10013 expect(block.leftBracket, isNotNull); | |
| 10014 expect(block.statements, hasLength(1)); | |
| 10015 expect(block.rightBracket, isNotNull); | |
| 10016 } | |
| 10017 | |
| 10018 void test_parseBreakStatement_label() { | |
| 10019 createParser('break foo;'); | |
| 10020 BreakStatement statement = parser.parseBreakStatement(); | |
| 10021 expectNotNullIfNoErrors(statement); | |
| 10022 listener.assertNoErrors(); | |
| 10023 expect(statement.breakKeyword, isNotNull); | |
| 10024 expect(statement.label, isNotNull); | |
| 10025 expect(statement.semicolon, isNotNull); | |
| 10026 } | |
| 10027 | |
| 10028 void test_parseBreakStatement_noLabel() { | |
| 10029 createParser('break;'); | |
| 10030 BreakStatement statement = parser.parseBreakStatement(); | |
| 10031 expectNotNullIfNoErrors(statement); | |
| 10032 listener.assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); | |
| 10033 expect(statement.breakKeyword, isNotNull); | |
| 10034 expect(statement.label, isNull); | |
| 10035 expect(statement.semicolon, isNotNull); | |
| 10036 } | |
| 10037 | |
| 10038 void test_parseCombinator_hide() { | 9968 void test_parseCombinator_hide() { |
| 10039 createParser('hide a;'); | 9969 createParser('hide a;'); |
| 10040 Combinator combinator = parser.parseCombinator(); | 9970 Combinator combinator = parser.parseCombinator(); |
| 10041 expectNotNullIfNoErrors(combinator); | 9971 expectNotNullIfNoErrors(combinator); |
| 10042 listener.assertNoErrors(); | 9972 listener.assertNoErrors(); |
| 10043 expect(combinator, new isInstanceOf<HideCombinator>()); | 9973 expect(combinator, new isInstanceOf<HideCombinator>()); |
| 10044 HideCombinator hideCombinator = combinator; | 9974 HideCombinator hideCombinator = combinator; |
| 10045 expect(hideCombinator.keyword, isNotNull); | 9975 expect(hideCombinator.keyword, isNotNull); |
| 10046 expect(hideCombinator.hiddenNames, hasLength(1)); | 9976 expect(hideCombinator.hiddenNames, hasLength(1)); |
| 10047 } | 9977 } |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10786 createParser('/// \n/// \n class'); | 10716 createParser('/// \n/// \n class'); |
| 10787 Comment comment = parser | 10717 Comment comment = parser |
| 10788 .parseDocumentationComment(parser.parseDocumentationCommentTokens()); | 10718 .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| 10789 expectNotNullIfNoErrors(comment); | 10719 expectNotNullIfNoErrors(comment); |
| 10790 listener.assertNoErrors(); | 10720 listener.assertNoErrors(); |
| 10791 expect(comment.isBlock, isFalse); | 10721 expect(comment.isBlock, isFalse); |
| 10792 expect(comment.isDocumentation, isTrue); | 10722 expect(comment.isDocumentation, isTrue); |
| 10793 expect(comment.isEndOfLine, isFalse); | 10723 expect(comment.isEndOfLine, isFalse); |
| 10794 } | 10724 } |
| 10795 | 10725 |
| 10796 void test_parseDoStatement() { | |
| 10797 createParser('do {} while (x);'); | |
| 10798 DoStatement statement = parser.parseDoStatement(); | |
| 10799 expectNotNullIfNoErrors(statement); | |
| 10800 listener.assertNoErrors(); | |
| 10801 expect(statement.doKeyword, isNotNull); | |
| 10802 expect(statement.body, isNotNull); | |
| 10803 expect(statement.whileKeyword, isNotNull); | |
| 10804 expect(statement.leftParenthesis, isNotNull); | |
| 10805 expect(statement.condition, isNotNull); | |
| 10806 expect(statement.rightParenthesis, isNotNull); | |
| 10807 expect(statement.semicolon, isNotNull); | |
| 10808 } | |
| 10809 | |
| 10810 void test_parseDottedName_multiple() { | 10726 void test_parseDottedName_multiple() { |
| 10811 createParser('a.b.c'); | 10727 createParser('a.b.c'); |
| 10812 DottedName name = parser.parseDottedName(); | 10728 DottedName name = parser.parseDottedName(); |
| 10813 expectNotNullIfNoErrors(name); | 10729 expectNotNullIfNoErrors(name); |
| 10814 listener.assertNoErrors(); | 10730 listener.assertNoErrors(); |
| 10815 expectDottedName(name, ["a", "b", "c"]); | 10731 expectDottedName(name, ["a", "b", "c"]); |
| 10816 } | 10732 } |
| 10817 | 10733 |
| 10818 void test_parseDottedName_single() { | 10734 void test_parseDottedName_single() { |
| 10819 createParser('a'); | 10735 createParser('a'); |
| 10820 DottedName name = parser.parseDottedName(); | 10736 DottedName name = parser.parseDottedName(); |
| 10821 expectNotNullIfNoErrors(name); | 10737 expectNotNullIfNoErrors(name); |
| 10822 listener.assertNoErrors(); | 10738 listener.assertNoErrors(); |
| 10823 expectDottedName(name, ["a"]); | 10739 expectDottedName(name, ["a"]); |
| 10824 } | 10740 } |
| 10825 | 10741 |
| 10826 void test_parseEmptyStatement() { | |
| 10827 createParser(';'); | |
| 10828 EmptyStatement statement = parser.parseEmptyStatement(); | |
| 10829 expectNotNullIfNoErrors(statement); | |
| 10830 listener.assertNoErrors(); | |
| 10831 expect(statement.semicolon, isNotNull); | |
| 10832 } | |
| 10833 | |
| 10834 void test_parseExtendsClause() { | 10742 void test_parseExtendsClause() { |
| 10835 createParser('extends B'); | 10743 createParser('extends B'); |
| 10836 ExtendsClause clause = parser.parseExtendsClause(); | 10744 ExtendsClause clause = parser.parseExtendsClause(); |
| 10837 expectNotNullIfNoErrors(clause); | 10745 expectNotNullIfNoErrors(clause); |
| 10838 listener.assertNoErrors(); | 10746 listener.assertNoErrors(); |
| 10839 expect(clause.extendsKeyword, isNotNull); | 10747 expect(clause.extendsKeyword, isNotNull); |
| 10840 expect(clause.superclass, isNotNull); | 10748 expect(clause.superclass, isNotNull); |
| 10841 expect(clause.superclass, new isInstanceOf<TypeName>()); | 10749 expect(clause.superclass, new isInstanceOf<TypeName>()); |
| 10842 } | 10750 } |
| 10843 | 10751 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11012 | 10920 |
| 11013 void test_parseFinalConstVarOrType_void_noIdentifier() { | 10921 void test_parseFinalConstVarOrType_void_noIdentifier() { |
| 11014 createParser('void,'); | 10922 createParser('void,'); |
| 11015 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); | 10923 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 11016 expectNotNullIfNoErrors(result); | 10924 expectNotNullIfNoErrors(result); |
| 11017 listener.assertNoErrors(); | 10925 listener.assertNoErrors(); |
| 11018 expect(result.keyword, isNull); | 10926 expect(result.keyword, isNull); |
| 11019 expect(result.type, isNotNull); | 10927 expect(result.type, isNotNull); |
| 11020 } | 10928 } |
| 11021 | 10929 |
| 11022 void test_parseForStatement_each_await() { | |
| 11023 createParser('await for (element in list) {}'); | |
| 11024 Statement statement = parser.parseForStatement(); | |
| 11025 expectNotNullIfNoErrors(statement); | |
| 11026 listener.assertNoErrors(); | |
| 11027 expect(statement, new isInstanceOf<ForEachStatement>()); | |
| 11028 ForEachStatement forStatement = statement; | |
| 11029 expect(forStatement.awaitKeyword, isNotNull); | |
| 11030 expect(forStatement.forKeyword, isNotNull); | |
| 11031 expect(forStatement.leftParenthesis, isNotNull); | |
| 11032 expect(forStatement.loopVariable, isNull); | |
| 11033 expect(forStatement.identifier, isNotNull); | |
| 11034 expect(forStatement.inKeyword, isNotNull); | |
| 11035 expect(forStatement.iterable, isNotNull); | |
| 11036 expect(forStatement.rightParenthesis, isNotNull); | |
| 11037 expect(forStatement.body, isNotNull); | |
| 11038 } | |
| 11039 | |
| 11040 void test_parseForStatement_each_identifier() { | |
| 11041 createParser('for (element in list) {}'); | |
| 11042 Statement statement = parser.parseForStatement(); | |
| 11043 expectNotNullIfNoErrors(statement); | |
| 11044 listener.assertNoErrors(); | |
| 11045 expect(statement, new isInstanceOf<ForEachStatement>()); | |
| 11046 ForEachStatement forStatement = statement; | |
| 11047 expect(forStatement.awaitKeyword, isNull); | |
| 11048 expect(forStatement.forKeyword, isNotNull); | |
| 11049 expect(forStatement.leftParenthesis, isNotNull); | |
| 11050 expect(forStatement.loopVariable, isNull); | |
| 11051 expect(forStatement.identifier, isNotNull); | |
| 11052 expect(forStatement.inKeyword, isNotNull); | |
| 11053 expect(forStatement.iterable, isNotNull); | |
| 11054 expect(forStatement.rightParenthesis, isNotNull); | |
| 11055 expect(forStatement.body, isNotNull); | |
| 11056 } | |
| 11057 | |
| 11058 void test_parseForStatement_each_noType_metadata() { | |
| 11059 createParser('for (@A var element in list) {}'); | |
| 11060 Statement statement = parser.parseForStatement(); | |
| 11061 expectNotNullIfNoErrors(statement); | |
| 11062 listener.assertNoErrors(); | |
| 11063 expect(statement, new isInstanceOf<ForEachStatement>()); | |
| 11064 ForEachStatement forStatement = statement; | |
| 11065 expect(forStatement.awaitKeyword, isNull); | |
| 11066 expect(forStatement.forKeyword, isNotNull); | |
| 11067 expect(forStatement.leftParenthesis, isNotNull); | |
| 11068 expect(forStatement.loopVariable, isNotNull); | |
| 11069 expect(forStatement.loopVariable.metadata, hasLength(1)); | |
| 11070 expect(forStatement.identifier, isNull); | |
| 11071 expect(forStatement.inKeyword, isNotNull); | |
| 11072 expect(forStatement.iterable, isNotNull); | |
| 11073 expect(forStatement.rightParenthesis, isNotNull); | |
| 11074 expect(forStatement.body, isNotNull); | |
| 11075 } | |
| 11076 | |
| 11077 void test_parseForStatement_each_type() { | |
| 11078 createParser('for (A element in list) {}'); | |
| 11079 Statement statement = parser.parseForStatement(); | |
| 11080 expectNotNullIfNoErrors(statement); | |
| 11081 listener.assertNoErrors(); | |
| 11082 expect(statement, new isInstanceOf<ForEachStatement>()); | |
| 11083 ForEachStatement forStatement = statement; | |
| 11084 expect(forStatement.awaitKeyword, isNull); | |
| 11085 expect(forStatement.forKeyword, isNotNull); | |
| 11086 expect(forStatement.leftParenthesis, isNotNull); | |
| 11087 expect(forStatement.loopVariable, isNotNull); | |
| 11088 expect(forStatement.identifier, isNull); | |
| 11089 expect(forStatement.inKeyword, isNotNull); | |
| 11090 expect(forStatement.iterable, isNotNull); | |
| 11091 expect(forStatement.rightParenthesis, isNotNull); | |
| 11092 expect(forStatement.body, isNotNull); | |
| 11093 } | |
| 11094 | |
| 11095 void test_parseForStatement_each_var() { | |
| 11096 createParser('for (var element in list) {}'); | |
| 11097 Statement statement = parser.parseForStatement(); | |
| 11098 expectNotNullIfNoErrors(statement); | |
| 11099 listener.assertNoErrors(); | |
| 11100 expect(statement, new isInstanceOf<ForEachStatement>()); | |
| 11101 ForEachStatement forStatement = statement; | |
| 11102 expect(forStatement.awaitKeyword, isNull); | |
| 11103 expect(forStatement.forKeyword, isNotNull); | |
| 11104 expect(forStatement.leftParenthesis, isNotNull); | |
| 11105 expect(forStatement.loopVariable, isNotNull); | |
| 11106 expect(forStatement.identifier, isNull); | |
| 11107 expect(forStatement.inKeyword, isNotNull); | |
| 11108 expect(forStatement.iterable, isNotNull); | |
| 11109 expect(forStatement.rightParenthesis, isNotNull); | |
| 11110 expect(forStatement.body, isNotNull); | |
| 11111 } | |
| 11112 | |
| 11113 void test_parseForStatement_loop_c() { | |
| 11114 createParser('for (; i < count;) {}'); | |
| 11115 Statement statement = parser.parseForStatement(); | |
| 11116 expectNotNullIfNoErrors(statement); | |
| 11117 listener.assertNoErrors(); | |
| 11118 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11119 ForStatement forStatement = statement; | |
| 11120 expect(forStatement.forKeyword, isNotNull); | |
| 11121 expect(forStatement.leftParenthesis, isNotNull); | |
| 11122 expect(forStatement.variables, isNull); | |
| 11123 expect(forStatement.initialization, isNull); | |
| 11124 expect(forStatement.leftSeparator, isNotNull); | |
| 11125 expect(forStatement.condition, isNotNull); | |
| 11126 expect(forStatement.rightSeparator, isNotNull); | |
| 11127 expect(forStatement.updaters, hasLength(0)); | |
| 11128 expect(forStatement.rightParenthesis, isNotNull); | |
| 11129 expect(forStatement.body, isNotNull); | |
| 11130 } | |
| 11131 | |
| 11132 void test_parseForStatement_loop_cu() { | |
| 11133 createParser('for (; i < count; i++) {}'); | |
| 11134 Statement statement = parser.parseForStatement(); | |
| 11135 expectNotNullIfNoErrors(statement); | |
| 11136 listener.assertNoErrors(); | |
| 11137 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11138 ForStatement forStatement = statement; | |
| 11139 expect(forStatement.forKeyword, isNotNull); | |
| 11140 expect(forStatement.leftParenthesis, isNotNull); | |
| 11141 expect(forStatement.variables, isNull); | |
| 11142 expect(forStatement.initialization, isNull); | |
| 11143 expect(forStatement.leftSeparator, isNotNull); | |
| 11144 expect(forStatement.condition, isNotNull); | |
| 11145 expect(forStatement.rightSeparator, isNotNull); | |
| 11146 expect(forStatement.updaters, hasLength(1)); | |
| 11147 expect(forStatement.rightParenthesis, isNotNull); | |
| 11148 expect(forStatement.body, isNotNull); | |
| 11149 } | |
| 11150 | |
| 11151 void test_parseForStatement_loop_ecu() { | |
| 11152 createParser('for (i--; i < count; i++) {}'); | |
| 11153 Statement statement = parser.parseForStatement(); | |
| 11154 expectNotNullIfNoErrors(statement); | |
| 11155 listener.assertNoErrors(); | |
| 11156 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11157 ForStatement forStatement = statement; | |
| 11158 expect(forStatement.forKeyword, isNotNull); | |
| 11159 expect(forStatement.leftParenthesis, isNotNull); | |
| 11160 expect(forStatement.variables, isNull); | |
| 11161 expect(forStatement.initialization, isNotNull); | |
| 11162 expect(forStatement.leftSeparator, isNotNull); | |
| 11163 expect(forStatement.condition, isNotNull); | |
| 11164 expect(forStatement.rightSeparator, isNotNull); | |
| 11165 expect(forStatement.updaters, hasLength(1)); | |
| 11166 expect(forStatement.rightParenthesis, isNotNull); | |
| 11167 expect(forStatement.body, isNotNull); | |
| 11168 } | |
| 11169 | |
| 11170 void test_parseForStatement_loop_i() { | |
| 11171 createParser('for (var i = 0;;) {}'); | |
| 11172 Statement statement = parser.parseForStatement(); | |
| 11173 expectNotNullIfNoErrors(statement); | |
| 11174 listener.assertNoErrors(); | |
| 11175 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11176 ForStatement forStatement = statement; | |
| 11177 expect(forStatement.forKeyword, isNotNull); | |
| 11178 expect(forStatement.leftParenthesis, isNotNull); | |
| 11179 VariableDeclarationList variables = forStatement.variables; | |
| 11180 expect(variables, isNotNull); | |
| 11181 expect(variables.metadata, hasLength(0)); | |
| 11182 expect(variables.variables, hasLength(1)); | |
| 11183 expect(forStatement.initialization, isNull); | |
| 11184 expect(forStatement.leftSeparator, isNotNull); | |
| 11185 expect(forStatement.condition, isNull); | |
| 11186 expect(forStatement.rightSeparator, isNotNull); | |
| 11187 expect(forStatement.updaters, hasLength(0)); | |
| 11188 expect(forStatement.rightParenthesis, isNotNull); | |
| 11189 expect(forStatement.body, isNotNull); | |
| 11190 } | |
| 11191 | |
| 11192 void test_parseForStatement_loop_i_withMetadata() { | |
| 11193 createParser('for (@A var i = 0;;) {}'); | |
| 11194 Statement statement = parser.parseForStatement(); | |
| 11195 expectNotNullIfNoErrors(statement); | |
| 11196 listener.assertNoErrors(); | |
| 11197 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11198 ForStatement forStatement = statement; | |
| 11199 expect(forStatement.forKeyword, isNotNull); | |
| 11200 expect(forStatement.leftParenthesis, isNotNull); | |
| 11201 VariableDeclarationList variables = forStatement.variables; | |
| 11202 expect(variables, isNotNull); | |
| 11203 expect(variables.metadata, hasLength(1)); | |
| 11204 expect(variables.variables, hasLength(1)); | |
| 11205 expect(forStatement.initialization, isNull); | |
| 11206 expect(forStatement.leftSeparator, isNotNull); | |
| 11207 expect(forStatement.condition, isNull); | |
| 11208 expect(forStatement.rightSeparator, isNotNull); | |
| 11209 expect(forStatement.updaters, hasLength(0)); | |
| 11210 expect(forStatement.rightParenthesis, isNotNull); | |
| 11211 expect(forStatement.body, isNotNull); | |
| 11212 } | |
| 11213 | |
| 11214 void test_parseForStatement_loop_ic() { | |
| 11215 createParser('for (var i = 0; i < count;) {}'); | |
| 11216 Statement statement = parser.parseForStatement(); | |
| 11217 expectNotNullIfNoErrors(statement); | |
| 11218 listener.assertNoErrors(); | |
| 11219 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11220 ForStatement forStatement = statement; | |
| 11221 expect(forStatement.forKeyword, isNotNull); | |
| 11222 expect(forStatement.leftParenthesis, isNotNull); | |
| 11223 VariableDeclarationList variables = forStatement.variables; | |
| 11224 expect(variables, isNotNull); | |
| 11225 expect(variables.variables, hasLength(1)); | |
| 11226 expect(forStatement.initialization, isNull); | |
| 11227 expect(forStatement.leftSeparator, isNotNull); | |
| 11228 expect(forStatement.condition, isNotNull); | |
| 11229 expect(forStatement.rightSeparator, isNotNull); | |
| 11230 expect(forStatement.updaters, hasLength(0)); | |
| 11231 expect(forStatement.rightParenthesis, isNotNull); | |
| 11232 expect(forStatement.body, isNotNull); | |
| 11233 } | |
| 11234 | |
| 11235 void test_parseForStatement_loop_icu() { | |
| 11236 createParser('for (var i = 0; i < count; i++) {}'); | |
| 11237 Statement statement = parser.parseForStatement(); | |
| 11238 expectNotNullIfNoErrors(statement); | |
| 11239 listener.assertNoErrors(); | |
| 11240 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11241 ForStatement forStatement = statement; | |
| 11242 expect(forStatement.forKeyword, isNotNull); | |
| 11243 expect(forStatement.leftParenthesis, isNotNull); | |
| 11244 VariableDeclarationList variables = forStatement.variables; | |
| 11245 expect(variables, isNotNull); | |
| 11246 expect(variables.variables, hasLength(1)); | |
| 11247 expect(forStatement.initialization, isNull); | |
| 11248 expect(forStatement.leftSeparator, isNotNull); | |
| 11249 expect(forStatement.condition, isNotNull); | |
| 11250 expect(forStatement.rightSeparator, isNotNull); | |
| 11251 expect(forStatement.updaters, hasLength(1)); | |
| 11252 expect(forStatement.rightParenthesis, isNotNull); | |
| 11253 expect(forStatement.body, isNotNull); | |
| 11254 } | |
| 11255 | |
| 11256 void test_parseForStatement_loop_iicuu() { | |
| 11257 createParser('for (int i = 0, j = count; i < j; i++, j--) {}'); | |
| 11258 Statement statement = parser.parseForStatement(); | |
| 11259 expectNotNullIfNoErrors(statement); | |
| 11260 listener.assertNoErrors(); | |
| 11261 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11262 ForStatement forStatement = statement; | |
| 11263 expect(forStatement.forKeyword, isNotNull); | |
| 11264 expect(forStatement.leftParenthesis, isNotNull); | |
| 11265 VariableDeclarationList variables = forStatement.variables; | |
| 11266 expect(variables, isNotNull); | |
| 11267 expect(variables.variables, hasLength(2)); | |
| 11268 expect(forStatement.initialization, isNull); | |
| 11269 expect(forStatement.leftSeparator, isNotNull); | |
| 11270 expect(forStatement.condition, isNotNull); | |
| 11271 expect(forStatement.rightSeparator, isNotNull); | |
| 11272 expect(forStatement.updaters, hasLength(2)); | |
| 11273 expect(forStatement.rightParenthesis, isNotNull); | |
| 11274 expect(forStatement.body, isNotNull); | |
| 11275 } | |
| 11276 | |
| 11277 void test_parseForStatement_loop_iu() { | |
| 11278 createParser('for (var i = 0;; i++) {}'); | |
| 11279 Statement statement = parser.parseForStatement(); | |
| 11280 expectNotNullIfNoErrors(statement); | |
| 11281 listener.assertNoErrors(); | |
| 11282 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11283 ForStatement forStatement = statement; | |
| 11284 expect(forStatement.forKeyword, isNotNull); | |
| 11285 expect(forStatement.leftParenthesis, isNotNull); | |
| 11286 VariableDeclarationList variables = forStatement.variables; | |
| 11287 expect(variables, isNotNull); | |
| 11288 expect(variables.variables, hasLength(1)); | |
| 11289 expect(forStatement.initialization, isNull); | |
| 11290 expect(forStatement.leftSeparator, isNotNull); | |
| 11291 expect(forStatement.condition, isNull); | |
| 11292 expect(forStatement.rightSeparator, isNotNull); | |
| 11293 expect(forStatement.updaters, hasLength(1)); | |
| 11294 expect(forStatement.rightParenthesis, isNotNull); | |
| 11295 expect(forStatement.body, isNotNull); | |
| 11296 } | |
| 11297 | |
| 11298 void test_parseForStatement_loop_u() { | |
| 11299 createParser('for (;; i++) {}'); | |
| 11300 Statement statement = parser.parseForStatement(); | |
| 11301 expectNotNullIfNoErrors(statement); | |
| 11302 listener.assertNoErrors(); | |
| 11303 expect(statement, new isInstanceOf<ForStatement>()); | |
| 11304 ForStatement forStatement = statement; | |
| 11305 expect(forStatement.forKeyword, isNotNull); | |
| 11306 expect(forStatement.leftParenthesis, isNotNull); | |
| 11307 expect(forStatement.variables, isNull); | |
| 11308 expect(forStatement.initialization, isNull); | |
| 11309 expect(forStatement.leftSeparator, isNotNull); | |
| 11310 expect(forStatement.condition, isNull); | |
| 11311 expect(forStatement.rightSeparator, isNotNull); | |
| 11312 expect(forStatement.updaters, hasLength(1)); | |
| 11313 expect(forStatement.rightParenthesis, isNotNull); | |
| 11314 expect(forStatement.body, isNotNull); | |
| 11315 } | |
| 11316 | |
| 11317 void test_parseFunctionBody_block() { | 10930 void test_parseFunctionBody_block() { |
| 11318 createParser('{}'); | 10931 createParser('{}'); |
| 11319 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); | 10932 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 11320 expectNotNullIfNoErrors(functionBody); | 10933 expectNotNullIfNoErrors(functionBody); |
| 11321 listener.assertNoErrors(); | 10934 listener.assertNoErrors(); |
| 11322 expect(functionBody, new isInstanceOf<BlockFunctionBody>()); | 10935 expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| 11323 BlockFunctionBody body = functionBody; | 10936 BlockFunctionBody body = functionBody; |
| 11324 expect(body.keyword, isNull); | 10937 expect(body.keyword, isNull); |
| 11325 expect(body.star, isNull); | 10938 expect(body.star, isNull); |
| 11326 expect(body.block, isNotNull); | 10939 expect(body.block, isNotNull); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11523 } | 11136 } |
| 11524 | 11137 |
| 11525 void test_parseIdentifierList_single() { | 11138 void test_parseIdentifierList_single() { |
| 11526 createParser('a'); | 11139 createParser('a'); |
| 11527 List<SimpleIdentifier> list = parser.parseIdentifierList(); | 11140 List<SimpleIdentifier> list = parser.parseIdentifierList(); |
| 11528 expectNotNullIfNoErrors(list); | 11141 expectNotNullIfNoErrors(list); |
| 11529 listener.assertNoErrors(); | 11142 listener.assertNoErrors(); |
| 11530 expect(list, hasLength(1)); | 11143 expect(list, hasLength(1)); |
| 11531 } | 11144 } |
| 11532 | 11145 |
| 11533 void test_parseIfStatement_else_block() { | |
| 11534 createParser('if (x) {} else {}'); | |
| 11535 IfStatement statement = parser.parseIfStatement(); | |
| 11536 expectNotNullIfNoErrors(statement); | |
| 11537 listener.assertNoErrors(); | |
| 11538 expect(statement.ifKeyword, isNotNull); | |
| 11539 expect(statement.leftParenthesis, isNotNull); | |
| 11540 expect(statement.condition, isNotNull); | |
| 11541 expect(statement.rightParenthesis, isNotNull); | |
| 11542 expect(statement.thenStatement, isNotNull); | |
| 11543 expect(statement.elseKeyword, isNotNull); | |
| 11544 expect(statement.elseStatement, isNotNull); | |
| 11545 } | |
| 11546 | |
| 11547 void test_parseIfStatement_else_statement() { | |
| 11548 createParser('if (x) f(x); else f(y);'); | |
| 11549 IfStatement statement = parser.parseIfStatement(); | |
| 11550 expectNotNullIfNoErrors(statement); | |
| 11551 listener.assertNoErrors(); | |
| 11552 expect(statement.ifKeyword, isNotNull); | |
| 11553 expect(statement.leftParenthesis, isNotNull); | |
| 11554 expect(statement.condition, isNotNull); | |
| 11555 expect(statement.rightParenthesis, isNotNull); | |
| 11556 expect(statement.thenStatement, isNotNull); | |
| 11557 expect(statement.elseKeyword, isNotNull); | |
| 11558 expect(statement.elseStatement, isNotNull); | |
| 11559 } | |
| 11560 | |
| 11561 void test_parseIfStatement_noElse_block() { | |
| 11562 createParser('if (x) {}'); | |
| 11563 IfStatement statement = parser.parseIfStatement(); | |
| 11564 expectNotNullIfNoErrors(statement); | |
| 11565 listener.assertNoErrors(); | |
| 11566 expect(statement.ifKeyword, isNotNull); | |
| 11567 expect(statement.leftParenthesis, isNotNull); | |
| 11568 expect(statement.condition, isNotNull); | |
| 11569 expect(statement.rightParenthesis, isNotNull); | |
| 11570 expect(statement.thenStatement, isNotNull); | |
| 11571 expect(statement.elseKeyword, isNull); | |
| 11572 expect(statement.elseStatement, isNull); | |
| 11573 } | |
| 11574 | |
| 11575 void test_parseIfStatement_noElse_statement() { | |
| 11576 createParser('if (x) f(x);'); | |
| 11577 IfStatement statement = parser.parseIfStatement(); | |
| 11578 expectNotNullIfNoErrors(statement); | |
| 11579 listener.assertNoErrors(); | |
| 11580 expect(statement.ifKeyword, isNotNull); | |
| 11581 expect(statement.leftParenthesis, isNotNull); | |
| 11582 expect(statement.condition, isNotNull); | |
| 11583 expect(statement.rightParenthesis, isNotNull); | |
| 11584 expect(statement.thenStatement, isNotNull); | |
| 11585 expect(statement.elseKeyword, isNull); | |
| 11586 expect(statement.elseStatement, isNull); | |
| 11587 } | |
| 11588 | |
| 11589 void test_parseImplementsClause_multiple() { | 11146 void test_parseImplementsClause_multiple() { |
| 11590 createParser('implements A, B, C'); | 11147 createParser('implements A, B, C'); |
| 11591 ImplementsClause clause = parser.parseImplementsClause(); | 11148 ImplementsClause clause = parser.parseImplementsClause(); |
| 11592 expectNotNullIfNoErrors(clause); | 11149 expectNotNullIfNoErrors(clause); |
| 11593 listener.assertNoErrors(); | 11150 listener.assertNoErrors(); |
| 11594 expect(clause.interfaces, hasLength(3)); | 11151 expect(clause.interfaces, hasLength(3)); |
| 11595 expect(clause.implementsKeyword, isNotNull); | 11152 expect(clause.implementsKeyword, isNotNull); |
| 11596 } | 11153 } |
| 11597 | 11154 |
| 11598 void test_parseImplementsClause_single() { | 11155 void test_parseImplementsClause_single() { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11679 } | 11236 } |
| 11680 | 11237 |
| 11681 void test_parseModifiers_var() { | 11238 void test_parseModifiers_var() { |
| 11682 createParser('var A'); | 11239 createParser('var A'); |
| 11683 Modifiers modifiers = parser.parseModifiers(); | 11240 Modifiers modifiers = parser.parseModifiers(); |
| 11684 expectNotNullIfNoErrors(modifiers); | 11241 expectNotNullIfNoErrors(modifiers); |
| 11685 listener.assertNoErrors(); | 11242 listener.assertNoErrors(); |
| 11686 expect(modifiers.varKeyword, isNotNull); | 11243 expect(modifiers.varKeyword, isNotNull); |
| 11687 } | 11244 } |
| 11688 | 11245 |
| 11689 void test_parseNonLabeledStatement_const_list_empty() { | |
| 11690 createParser('const [];'); | |
| 11691 Statement statement = parser.parseNonLabeledStatement(); | |
| 11692 expectNotNullIfNoErrors(statement); | |
| 11693 listener.assertNoErrors(); | |
| 11694 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11695 ExpressionStatement expressionStatement = statement; | |
| 11696 expect(expressionStatement.expression, isNotNull); | |
| 11697 } | |
| 11698 | |
| 11699 void test_parseNonLabeledStatement_const_list_nonEmpty() { | |
| 11700 createParser('const [1, 2];'); | |
| 11701 Statement statement = parser.parseNonLabeledStatement(); | |
| 11702 expectNotNullIfNoErrors(statement); | |
| 11703 listener.assertNoErrors(); | |
| 11704 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11705 ExpressionStatement expressionStatement = statement; | |
| 11706 expect(expressionStatement.expression, isNotNull); | |
| 11707 } | |
| 11708 | |
| 11709 void test_parseNonLabeledStatement_const_map_empty() { | |
| 11710 createParser('const {};'); | |
| 11711 Statement statement = parser.parseNonLabeledStatement(); | |
| 11712 expectNotNullIfNoErrors(statement); | |
| 11713 listener.assertNoErrors(); | |
| 11714 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11715 ExpressionStatement expressionStatement = statement; | |
| 11716 expect(expressionStatement.expression, isNotNull); | |
| 11717 } | |
| 11718 | |
| 11719 void test_parseNonLabeledStatement_const_map_nonEmpty() { | |
| 11720 // TODO(brianwilkerson) Implement more tests for this method. | |
| 11721 createParser("const {'a' : 1};"); | |
| 11722 Statement statement = parser.parseNonLabeledStatement(); | |
| 11723 expectNotNullIfNoErrors(statement); | |
| 11724 listener.assertNoErrors(); | |
| 11725 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11726 ExpressionStatement expressionStatement = statement; | |
| 11727 expect(expressionStatement.expression, isNotNull); | |
| 11728 } | |
| 11729 | |
| 11730 void test_parseNonLabeledStatement_const_object() { | |
| 11731 createParser('const A();'); | |
| 11732 Statement statement = parser.parseNonLabeledStatement(); | |
| 11733 expectNotNullIfNoErrors(statement); | |
| 11734 listener.assertNoErrors(); | |
| 11735 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11736 ExpressionStatement expressionStatement = statement; | |
| 11737 expect(expressionStatement.expression, isNotNull); | |
| 11738 } | |
| 11739 | |
| 11740 void test_parseNonLabeledStatement_const_object_named_typeParameters() { | |
| 11741 createParser('const A<B>.c();'); | |
| 11742 Statement statement = parser.parseNonLabeledStatement(); | |
| 11743 expectNotNullIfNoErrors(statement); | |
| 11744 listener.assertNoErrors(); | |
| 11745 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11746 ExpressionStatement expressionStatement = statement; | |
| 11747 expect(expressionStatement.expression, isNotNull); | |
| 11748 } | |
| 11749 | |
| 11750 void test_parseNonLabeledStatement_constructorInvocation() { | |
| 11751 createParser('new C().m();'); | |
| 11752 Statement statement = parser.parseNonLabeledStatement(); | |
| 11753 expectNotNullIfNoErrors(statement); | |
| 11754 listener.assertNoErrors(); | |
| 11755 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11756 ExpressionStatement expressionStatement = statement; | |
| 11757 expect(expressionStatement.expression, isNotNull); | |
| 11758 } | |
| 11759 | |
| 11760 void test_parseNonLabeledStatement_false() { | |
| 11761 createParser('false;'); | |
| 11762 Statement statement = parser.parseNonLabeledStatement(); | |
| 11763 expectNotNullIfNoErrors(statement); | |
| 11764 listener.assertNoErrors(); | |
| 11765 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11766 ExpressionStatement expressionStatement = statement; | |
| 11767 expect(expressionStatement.expression, isNotNull); | |
| 11768 } | |
| 11769 | |
| 11770 void test_parseNonLabeledStatement_functionDeclaration() { | |
| 11771 createParser('f() {};'); | |
| 11772 Statement statement = parser.parseNonLabeledStatement(); | |
| 11773 expectNotNullIfNoErrors(statement); | |
| 11774 listener.assertNoErrors(); | |
| 11775 } | |
| 11776 | |
| 11777 void test_parseNonLabeledStatement_functionDeclaration_arguments() { | |
| 11778 createParser('f(void g()) {};'); | |
| 11779 Statement statement = parser.parseNonLabeledStatement(); | |
| 11780 expectNotNullIfNoErrors(statement); | |
| 11781 listener.assertNoErrors(); | |
| 11782 } | |
| 11783 | |
| 11784 void test_parseNonLabeledStatement_functionExpressionIndex() { | |
| 11785 createParser('() {}[0] = null;'); | |
| 11786 Statement statement = parser.parseNonLabeledStatement(); | |
| 11787 expectNotNullIfNoErrors(statement); | |
| 11788 listener.assertNoErrors(); | |
| 11789 } | |
| 11790 | |
| 11791 void test_parseNonLabeledStatement_functionInvocation() { | |
| 11792 createParser('f();'); | |
| 11793 Statement statement = parser.parseNonLabeledStatement(); | |
| 11794 expectNotNullIfNoErrors(statement); | |
| 11795 listener.assertNoErrors(); | |
| 11796 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11797 ExpressionStatement expressionStatement = statement; | |
| 11798 expect(expressionStatement.expression, isNotNull); | |
| 11799 } | |
| 11800 | |
| 11801 void test_parseNonLabeledStatement_invokeFunctionExpression() { | |
| 11802 createParser('(a) {return a + a;} (3);'); | |
| 11803 Statement statement = parser.parseNonLabeledStatement(); | |
| 11804 expectNotNullIfNoErrors(statement); | |
| 11805 listener.assertNoErrors(); | |
| 11806 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11807 ExpressionStatement expressionStatement = statement; | |
| 11808 EngineTestCase.assertInstanceOf( | |
| 11809 (obj) => obj is FunctionExpressionInvocation, | |
| 11810 FunctionExpressionInvocation, | |
| 11811 expressionStatement.expression); | |
| 11812 FunctionExpressionInvocation invocation = | |
| 11813 expressionStatement.expression as FunctionExpressionInvocation; | |
| 11814 EngineTestCase.assertInstanceOf((obj) => obj is FunctionExpression, | |
| 11815 FunctionExpression, invocation.function); | |
| 11816 FunctionExpression expression = invocation.function as FunctionExpression; | |
| 11817 expect(expression.parameters, isNotNull); | |
| 11818 expect(expression.body, isNotNull); | |
| 11819 expect(invocation.typeArguments, isNull); | |
| 11820 ArgumentList list = invocation.argumentList; | |
| 11821 expect(list, isNotNull); | |
| 11822 expect(list.arguments, hasLength(1)); | |
| 11823 } | |
| 11824 | |
| 11825 void test_parseNonLabeledStatement_null() { | |
| 11826 createParser('null;'); | |
| 11827 Statement statement = parser.parseNonLabeledStatement(); | |
| 11828 expectNotNullIfNoErrors(statement); | |
| 11829 listener.assertNoErrors(); | |
| 11830 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11831 ExpressionStatement expressionStatement = statement; | |
| 11832 expect(expressionStatement.expression, isNotNull); | |
| 11833 } | |
| 11834 | |
| 11835 void test_parseNonLabeledStatement_startingWithBuiltInIdentifier() { | |
| 11836 createParser('library.getName();'); | |
| 11837 Statement statement = parser.parseNonLabeledStatement(); | |
| 11838 expectNotNullIfNoErrors(statement); | |
| 11839 listener.assertNoErrors(); | |
| 11840 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11841 ExpressionStatement expressionStatement = statement; | |
| 11842 expect(expressionStatement.expression, isNotNull); | |
| 11843 } | |
| 11844 | |
| 11845 void test_parseNonLabeledStatement_true() { | |
| 11846 createParser('true;'); | |
| 11847 Statement statement = parser.parseNonLabeledStatement(); | |
| 11848 expectNotNullIfNoErrors(statement); | |
| 11849 listener.assertNoErrors(); | |
| 11850 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11851 ExpressionStatement expressionStatement = statement; | |
| 11852 expect(expressionStatement.expression, isNotNull); | |
| 11853 } | |
| 11854 | |
| 11855 void test_parseNonLabeledStatement_typeCast() { | |
| 11856 createParser('double.NAN as num;'); | |
| 11857 Statement statement = parser.parseNonLabeledStatement(); | |
| 11858 expectNotNullIfNoErrors(statement); | |
| 11859 listener.assertNoErrors(); | |
| 11860 expect(statement, new isInstanceOf<ExpressionStatement>()); | |
| 11861 ExpressionStatement expressionStatement = statement; | |
| 11862 expect(expressionStatement.expression, isNotNull); | |
| 11863 } | |
| 11864 | |
| 11865 void test_parseNonLabeledStatement_variableDeclaration_final_namedFunction() { | 11246 void test_parseNonLabeledStatement_variableDeclaration_final_namedFunction() { |
| 11866 createParser('final int Function = 0;'); | 11247 createParser('final int Function = 0;'); |
| 11867 Statement statement = parser.parseNonLabeledStatement(); | 11248 Statement statement = parser.parseNonLabeledStatement(); |
| 11868 expectNotNullIfNoErrors(statement); | 11249 expectNotNullIfNoErrors(statement); |
| 11869 listener.assertNoErrors(); | 11250 listener.assertNoErrors(); |
| 11870 } | 11251 } |
| 11871 | 11252 |
| 11872 void test_parseOptionalReturnType() { | 11253 void test_parseOptionalReturnType() { |
| 11873 // TODO(brianwilkerson) Implement tests for this method. | 11254 // TODO(brianwilkerson) Implement tests for this method. |
| 11874 } | 11255 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11942 | 11323 |
| 11943 void test_parseReturnType_void() { | 11324 void test_parseReturnType_void() { |
| 11944 createParser('void'); | 11325 createParser('void'); |
| 11945 TypeName typeName = parser.parseReturnType(false); | 11326 TypeName typeName = parser.parseReturnType(false); |
| 11946 expectNotNullIfNoErrors(typeName); | 11327 expectNotNullIfNoErrors(typeName); |
| 11947 listener.assertNoErrors(); | 11328 listener.assertNoErrors(); |
| 11948 expect(typeName.name, isNotNull); | 11329 expect(typeName.name, isNotNull); |
| 11949 expect(typeName.typeArguments, isNull); | 11330 expect(typeName.typeArguments, isNull); |
| 11950 } | 11331 } |
| 11951 | 11332 |
| 11952 void test_parseStatement_emptyTypeArgumentList() { | |
| 11953 createParser('C<> c;'); | |
| 11954 Statement statement = parser.parseStatement2(); | |
| 11955 expectNotNullIfNoErrors(statement); | |
| 11956 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]); | |
| 11957 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | |
| 11958 VariableDeclarationStatement declaration = statement; | |
| 11959 VariableDeclarationList variables = declaration.variables; | |
| 11960 TypeName type = variables.type; | |
| 11961 TypeArgumentList argumentList = type.typeArguments; | |
| 11962 expect(argumentList.leftBracket, isNotNull); | |
| 11963 expect(argumentList.arguments, hasLength(1)); | |
| 11964 expect(argumentList.arguments[0].isSynthetic, isTrue); | |
| 11965 expect(argumentList.rightBracket, isNotNull); | |
| 11966 } | |
| 11967 | |
| 11968 void test_parseStatement_functionDeclaration_noReturnType() { | |
| 11969 createParser('f(a, b) {};'); | |
| 11970 Statement statement = parser.parseStatement2(); | |
| 11971 expectNotNullIfNoErrors(statement); | |
| 11972 listener.assertNoErrors(); | |
| 11973 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); | |
| 11974 FunctionDeclarationStatement declaration = statement; | |
| 11975 expect(declaration.functionDeclaration, isNotNull); | |
| 11976 } | |
| 11977 | |
| 11978 void | |
| 11979 test_parseStatement_functionDeclaration_noReturnType_typeParameterComments
() { | |
| 11980 enableGenericMethodComments = true; | |
| 11981 createParser('f/*<E>*/(a, b) {};'); | |
| 11982 Statement statement = parser.parseStatement2(); | |
| 11983 expectNotNullIfNoErrors(statement); | |
| 11984 listener.assertNoErrors(); | |
| 11985 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); | |
| 11986 FunctionDeclarationStatement declaration = statement; | |
| 11987 expect(declaration.functionDeclaration, isNotNull); | |
| 11988 expect(declaration.functionDeclaration.functionExpression.typeParameters, | |
| 11989 isNotNull); | |
| 11990 } | |
| 11991 | |
| 11992 void test_parseStatement_functionDeclaration_noReturnType_typeParameters() { | |
| 11993 createParser('f<E>(a, b) {};'); | |
| 11994 Statement statement = parser.parseStatement2(); | |
| 11995 expectNotNullIfNoErrors(statement); | |
| 11996 listener.assertNoErrors(); | |
| 11997 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); | |
| 11998 FunctionDeclarationStatement declaration = statement; | |
| 11999 expect(declaration.functionDeclaration, isNotNull); | |
| 12000 } | |
| 12001 | |
| 12002 void test_parseStatement_functionDeclaration_returnType() { | |
| 12003 // TODO(brianwilkerson) Implement more tests for this method. | |
| 12004 createParser('int f(a, b) {};'); | |
| 12005 Statement statement = parser.parseStatement2(); | |
| 12006 expectNotNullIfNoErrors(statement); | |
| 12007 listener.assertNoErrors(); | |
| 12008 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); | |
| 12009 FunctionDeclarationStatement declaration = statement; | |
| 12010 expect(declaration.functionDeclaration, isNotNull); | |
| 12011 } | |
| 12012 | |
| 12013 void test_parseStatement_functionDeclaration_returnType_typeParameters() { | |
| 12014 createParser('int f<E>(a, b) {};'); | |
| 12015 Statement statement = parser.parseStatement2(); | |
| 12016 expectNotNullIfNoErrors(statement); | |
| 12017 listener.assertNoErrors(); | |
| 12018 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); | |
| 12019 FunctionDeclarationStatement declaration = statement; | |
| 12020 expect(declaration.functionDeclaration, isNotNull); | |
| 12021 } | |
| 12022 | |
| 12023 void test_parseStatement_mulipleLabels() { | |
| 12024 createParser('l: m: return x;'); | |
| 12025 Statement statement = parser.parseStatement2(); | |
| 12026 expectNotNullIfNoErrors(statement); | |
| 12027 listener.assertNoErrors(); | |
| 12028 expect(statement, new isInstanceOf<LabeledStatement>()); | |
| 12029 LabeledStatement labeledStatement = statement; | |
| 12030 expect(labeledStatement.labels, hasLength(2)); | |
| 12031 expect(labeledStatement.statement, isNotNull); | |
| 12032 } | |
| 12033 | |
| 12034 void test_parseStatement_noLabels() { | |
| 12035 createParser('return x;'); | |
| 12036 Statement statement = parser.parseStatement2(); | |
| 12037 expectNotNullIfNoErrors(statement); | |
| 12038 listener.assertNoErrors(); | |
| 12039 } | |
| 12040 | |
| 12041 void test_parseStatement_singleLabel() { | |
| 12042 createParser('l: return x;'); | |
| 12043 Statement statement = parser.parseStatement2(); | |
| 12044 expectNotNullIfNoErrors(statement); | |
| 12045 listener.assertNoErrors(); | |
| 12046 expect(statement, new isInstanceOf<LabeledStatement>()); | |
| 12047 LabeledStatement labeledStatement = statement; | |
| 12048 expect(labeledStatement.labels, hasLength(1)); | |
| 12049 expect(labeledStatement.labels[0].label.inDeclarationContext(), isTrue); | |
| 12050 expect(labeledStatement.statement, isNotNull); | |
| 12051 } | |
| 12052 | |
| 12053 void test_parseStatements_multiple() { | 11333 void test_parseStatements_multiple() { |
| 12054 List<Statement> statements = parseStatements("return; return;", 2); | 11334 List<Statement> statements = parseStatements("return; return;", 2); |
| 12055 expect(statements, hasLength(2)); | 11335 expect(statements, hasLength(2)); |
| 12056 } | 11336 } |
| 12057 | 11337 |
| 12058 void test_parseStatements_single() { | 11338 void test_parseStatements_single() { |
| 12059 List<Statement> statements = parseStatements("return;", 1); | 11339 List<Statement> statements = parseStatements("return;", 1); |
| 12060 expect(statements, hasLength(1)); | 11340 expect(statements, hasLength(1)); |
| 12061 } | 11341 } |
| 12062 | 11342 |
| 12063 void test_parseSwitchStatement_case() { | |
| 12064 createParser('switch (a) {case 1: return "I";}'); | |
| 12065 SwitchStatement statement = parser.parseSwitchStatement(); | |
| 12066 expectNotNullIfNoErrors(statement); | |
| 12067 listener.assertNoErrors(); | |
| 12068 expect(statement.switchKeyword, isNotNull); | |
| 12069 expect(statement.leftParenthesis, isNotNull); | |
| 12070 expect(statement.expression, isNotNull); | |
| 12071 expect(statement.rightParenthesis, isNotNull); | |
| 12072 expect(statement.leftBracket, isNotNull); | |
| 12073 expect(statement.members, hasLength(1)); | |
| 12074 expect(statement.rightBracket, isNotNull); | |
| 12075 } | |
| 12076 | |
| 12077 void test_parseSwitchStatement_empty() { | |
| 12078 createParser('switch (a) {}'); | |
| 12079 SwitchStatement statement = parser.parseSwitchStatement(); | |
| 12080 expectNotNullIfNoErrors(statement); | |
| 12081 listener.assertNoErrors(); | |
| 12082 expect(statement.switchKeyword, isNotNull); | |
| 12083 expect(statement.leftParenthesis, isNotNull); | |
| 12084 expect(statement.expression, isNotNull); | |
| 12085 expect(statement.rightParenthesis, isNotNull); | |
| 12086 expect(statement.leftBracket, isNotNull); | |
| 12087 expect(statement.members, hasLength(0)); | |
| 12088 expect(statement.rightBracket, isNotNull); | |
| 12089 } | |
| 12090 | |
| 12091 void test_parseSwitchStatement_labeledCase() { | |
| 12092 createParser('switch (a) {l1: l2: l3: case(1):}'); | |
| 12093 SwitchStatement statement = parser.parseSwitchStatement(); | |
| 12094 expectNotNullIfNoErrors(statement); | |
| 12095 listener.assertNoErrors(); | |
| 12096 expect(statement.switchKeyword, isNotNull); | |
| 12097 expect(statement.leftParenthesis, isNotNull); | |
| 12098 expect(statement.expression, isNotNull); | |
| 12099 expect(statement.rightParenthesis, isNotNull); | |
| 12100 expect(statement.leftBracket, isNotNull); | |
| 12101 expect(statement.members, hasLength(1)); | |
| 12102 { | |
| 12103 List<Label> labels = statement.members[0].labels; | |
| 12104 expect(labels, hasLength(3)); | |
| 12105 expect(labels[0].label.inDeclarationContext(), isTrue); | |
| 12106 expect(labels[1].label.inDeclarationContext(), isTrue); | |
| 12107 expect(labels[2].label.inDeclarationContext(), isTrue); | |
| 12108 } | |
| 12109 expect(statement.rightBracket, isNotNull); | |
| 12110 } | |
| 12111 | |
| 12112 void test_parseSwitchStatement_labeledDefault() { | |
| 12113 createParser('switch (a) {l1: l2: l3: default:}'); | |
| 12114 SwitchStatement statement = parser.parseSwitchStatement(); | |
| 12115 expectNotNullIfNoErrors(statement); | |
| 12116 listener.assertNoErrors(); | |
| 12117 expect(statement.switchKeyword, isNotNull); | |
| 12118 expect(statement.leftParenthesis, isNotNull); | |
| 12119 expect(statement.expression, isNotNull); | |
| 12120 expect(statement.rightParenthesis, isNotNull); | |
| 12121 expect(statement.leftBracket, isNotNull); | |
| 12122 expect(statement.members, hasLength(1)); | |
| 12123 { | |
| 12124 List<Label> labels = statement.members[0].labels; | |
| 12125 expect(labels, hasLength(3)); | |
| 12126 expect(labels[0].label.inDeclarationContext(), isTrue); | |
| 12127 expect(labels[1].label.inDeclarationContext(), isTrue); | |
| 12128 expect(labels[2].label.inDeclarationContext(), isTrue); | |
| 12129 } | |
| 12130 expect(statement.rightBracket, isNotNull); | |
| 12131 } | |
| 12132 | |
| 12133 void test_parseSwitchStatement_labeledStatementInCase() { | |
| 12134 createParser('switch (a) {case 0: f(); l1: g(); break;}'); | |
| 12135 SwitchStatement statement = parser.parseSwitchStatement(); | |
| 12136 expectNotNullIfNoErrors(statement); | |
| 12137 listener.assertNoErrors(); | |
| 12138 expect(statement.switchKeyword, isNotNull); | |
| 12139 expect(statement.leftParenthesis, isNotNull); | |
| 12140 expect(statement.expression, isNotNull); | |
| 12141 expect(statement.rightParenthesis, isNotNull); | |
| 12142 expect(statement.leftBracket, isNotNull); | |
| 12143 expect(statement.members, hasLength(1)); | |
| 12144 expect(statement.members[0].statements, hasLength(3)); | |
| 12145 expect(statement.rightBracket, isNotNull); | |
| 12146 } | |
| 12147 | |
| 12148 void test_parseTryStatement_catch() { | |
| 12149 createParser('try {} catch (e) {}'); | |
| 12150 TryStatement statement = parser.parseTryStatement(); | |
| 12151 expectNotNullIfNoErrors(statement); | |
| 12152 listener.assertNoErrors(); | |
| 12153 expect(statement.tryKeyword, isNotNull); | |
| 12154 expect(statement.body, isNotNull); | |
| 12155 NodeList<CatchClause> catchClauses = statement.catchClauses; | |
| 12156 expect(catchClauses, hasLength(1)); | |
| 12157 CatchClause clause = catchClauses[0]; | |
| 12158 expect(clause.onKeyword, isNull); | |
| 12159 expect(clause.exceptionType, isNull); | |
| 12160 expect(clause.catchKeyword, isNotNull); | |
| 12161 expect(clause.exceptionParameter, isNotNull); | |
| 12162 expect(clause.comma, isNull); | |
| 12163 expect(clause.stackTraceParameter, isNull); | |
| 12164 expect(clause.body, isNotNull); | |
| 12165 expect(statement.finallyKeyword, isNull); | |
| 12166 expect(statement.finallyBlock, isNull); | |
| 12167 } | |
| 12168 | |
| 12169 void test_parseTryStatement_catch_finally() { | |
| 12170 createParser('try {} catch (e, s) {} finally {}'); | |
| 12171 TryStatement statement = parser.parseTryStatement(); | |
| 12172 expectNotNullIfNoErrors(statement); | |
| 12173 listener.assertNoErrors(); | |
| 12174 expect(statement.tryKeyword, isNotNull); | |
| 12175 expect(statement.body, isNotNull); | |
| 12176 NodeList<CatchClause> catchClauses = statement.catchClauses; | |
| 12177 expect(catchClauses, hasLength(1)); | |
| 12178 CatchClause clause = catchClauses[0]; | |
| 12179 expect(clause.onKeyword, isNull); | |
| 12180 expect(clause.exceptionType, isNull); | |
| 12181 expect(clause.catchKeyword, isNotNull); | |
| 12182 expect(clause.exceptionParameter, isNotNull); | |
| 12183 expect(clause.comma, isNotNull); | |
| 12184 expect(clause.stackTraceParameter, isNotNull); | |
| 12185 expect(clause.body, isNotNull); | |
| 12186 expect(statement.finallyKeyword, isNotNull); | |
| 12187 expect(statement.finallyBlock, isNotNull); | |
| 12188 } | |
| 12189 | |
| 12190 void test_parseTryStatement_finally() { | |
| 12191 createParser('try {} finally {}'); | |
| 12192 TryStatement statement = parser.parseTryStatement(); | |
| 12193 expectNotNullIfNoErrors(statement); | |
| 12194 listener.assertNoErrors(); | |
| 12195 expect(statement.tryKeyword, isNotNull); | |
| 12196 expect(statement.body, isNotNull); | |
| 12197 expect(statement.catchClauses, hasLength(0)); | |
| 12198 expect(statement.finallyKeyword, isNotNull); | |
| 12199 expect(statement.finallyBlock, isNotNull); | |
| 12200 } | |
| 12201 | |
| 12202 void test_parseTryStatement_multiple() { | |
| 12203 createParser('try {} on NPE catch (e) {} on Error {} catch (e) {}'); | |
| 12204 TryStatement statement = parser.parseTryStatement(); | |
| 12205 expectNotNullIfNoErrors(statement); | |
| 12206 listener.assertNoErrors(); | |
| 12207 expect(statement.tryKeyword, isNotNull); | |
| 12208 expect(statement.body, isNotNull); | |
| 12209 expect(statement.catchClauses, hasLength(3)); | |
| 12210 expect(statement.finallyKeyword, isNull); | |
| 12211 expect(statement.finallyBlock, isNull); | |
| 12212 } | |
| 12213 | |
| 12214 void test_parseTryStatement_on() { | |
| 12215 createParser('try {} on Error {}'); | |
| 12216 TryStatement statement = parser.parseTryStatement(); | |
| 12217 expectNotNullIfNoErrors(statement); | |
| 12218 listener.assertNoErrors(); | |
| 12219 expect(statement.tryKeyword, isNotNull); | |
| 12220 expect(statement.body, isNotNull); | |
| 12221 NodeList<CatchClause> catchClauses = statement.catchClauses; | |
| 12222 expect(catchClauses, hasLength(1)); | |
| 12223 CatchClause clause = catchClauses[0]; | |
| 12224 expect(clause.onKeyword, isNotNull); | |
| 12225 expect(clause.exceptionType, isNotNull); | |
| 12226 expect(clause.catchKeyword, isNull); | |
| 12227 expect(clause.exceptionParameter, isNull); | |
| 12228 expect(clause.comma, isNull); | |
| 12229 expect(clause.stackTraceParameter, isNull); | |
| 12230 expect(clause.body, isNotNull); | |
| 12231 expect(statement.finallyKeyword, isNull); | |
| 12232 expect(statement.finallyBlock, isNull); | |
| 12233 } | |
| 12234 | |
| 12235 void test_parseTryStatement_on_catch() { | |
| 12236 createParser('try {} on Error catch (e, s) {}'); | |
| 12237 TryStatement statement = parser.parseTryStatement(); | |
| 12238 expectNotNullIfNoErrors(statement); | |
| 12239 listener.assertNoErrors(); | |
| 12240 expect(statement.tryKeyword, isNotNull); | |
| 12241 expect(statement.body, isNotNull); | |
| 12242 NodeList<CatchClause> catchClauses = statement.catchClauses; | |
| 12243 expect(catchClauses, hasLength(1)); | |
| 12244 CatchClause clause = catchClauses[0]; | |
| 12245 expect(clause.onKeyword, isNotNull); | |
| 12246 expect(clause.exceptionType, isNotNull); | |
| 12247 expect(clause.catchKeyword, isNotNull); | |
| 12248 expect(clause.exceptionParameter, isNotNull); | |
| 12249 expect(clause.comma, isNotNull); | |
| 12250 expect(clause.stackTraceParameter, isNotNull); | |
| 12251 expect(clause.body, isNotNull); | |
| 12252 expect(statement.finallyKeyword, isNull); | |
| 12253 expect(statement.finallyBlock, isNull); | |
| 12254 } | |
| 12255 | |
| 12256 void test_parseTryStatement_on_catch_finally() { | |
| 12257 createParser('try {} on Error catch (e, s) {} finally {}'); | |
| 12258 TryStatement statement = parser.parseTryStatement(); | |
| 12259 expectNotNullIfNoErrors(statement); | |
| 12260 listener.assertNoErrors(); | |
| 12261 expect(statement.tryKeyword, isNotNull); | |
| 12262 expect(statement.body, isNotNull); | |
| 12263 NodeList<CatchClause> catchClauses = statement.catchClauses; | |
| 12264 expect(catchClauses, hasLength(1)); | |
| 12265 CatchClause clause = catchClauses[0]; | |
| 12266 expect(clause.onKeyword, isNotNull); | |
| 12267 expect(clause.exceptionType, isNotNull); | |
| 12268 expect(clause.catchKeyword, isNotNull); | |
| 12269 expect(clause.exceptionParameter, isNotNull); | |
| 12270 expect(clause.comma, isNotNull); | |
| 12271 expect(clause.stackTraceParameter, isNotNull); | |
| 12272 expect(clause.body, isNotNull); | |
| 12273 expect(statement.finallyKeyword, isNotNull); | |
| 12274 expect(statement.finallyBlock, isNotNull); | |
| 12275 } | |
| 12276 | |
| 12277 void test_parseTypeAnnotation_function_noReturnType_noParameters() { | 11343 void test_parseTypeAnnotation_function_noReturnType_noParameters() { |
| 12278 createParser('Function() v'); | 11344 createParser('Function() v'); |
| 12279 GenericFunctionType functionType = parser.parseTypeAnnotation(false); | 11345 GenericFunctionType functionType = parser.parseTypeAnnotation(false); |
| 12280 expectNotNullIfNoErrors(functionType); | 11346 expectNotNullIfNoErrors(functionType); |
| 12281 listener.assertNoErrors(); | 11347 listener.assertNoErrors(); |
| 12282 expect(functionType.returnType, isNull); | 11348 expect(functionType.returnType, isNull); |
| 12283 expect(functionType.functionKeyword, isNotNull); | 11349 expect(functionType.functionKeyword, isNotNull); |
| 12284 expect(functionType.typeParameters, isNull); | 11350 expect(functionType.typeParameters, isNull); |
| 12285 FormalParameterList parameterList = functionType.parameters; | 11351 FormalParameterList parameterList = functionType.parameters; |
| 12286 expect(parameterList, isNotNull); | 11352 expect(parameterList, isNotNull); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12839 createParser('var a, b, c'); | 11905 createParser('var a, b, c'); |
| 12840 VariableDeclarationList declarationList = | 11906 VariableDeclarationList declarationList = |
| 12841 parseFullVariableDeclarationList(); | 11907 parseFullVariableDeclarationList(); |
| 12842 expectNotNullIfNoErrors(declarationList); | 11908 expectNotNullIfNoErrors(declarationList); |
| 12843 listener.assertNoErrors(); | 11909 listener.assertNoErrors(); |
| 12844 expect(declarationList.keyword.lexeme, 'var'); | 11910 expect(declarationList.keyword.lexeme, 'var'); |
| 12845 expect(declarationList.type, isNull); | 11911 expect(declarationList.type, isNull); |
| 12846 expect(declarationList.variables, hasLength(3)); | 11912 expect(declarationList.variables, hasLength(3)); |
| 12847 } | 11913 } |
| 12848 | 11914 |
| 11915 void test_parseWithClause_multiple() { |
| 11916 createParser('with A, B, C'); |
| 11917 WithClause clause = parser.parseWithClause(); |
| 11918 expectNotNullIfNoErrors(clause); |
| 11919 listener.assertNoErrors(); |
| 11920 expect(clause.withKeyword, isNotNull); |
| 11921 expect(clause.mixinTypes, hasLength(3)); |
| 11922 } |
| 11923 |
| 11924 void test_parseWithClause_single() { |
| 11925 createParser('with M'); |
| 11926 WithClause clause = parser.parseWithClause(); |
| 11927 expectNotNullIfNoErrors(clause); |
| 11928 listener.assertNoErrors(); |
| 11929 expect(clause.withKeyword, isNotNull); |
| 11930 expect(clause.mixinTypes, hasLength(1)); |
| 11931 } |
| 11932 |
| 11933 void test_skipPrefixedIdentifier_invalid() { |
| 11934 createParser('+'); |
| 11935 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 11936 expect(following, isNull); |
| 11937 } |
| 11938 |
| 11939 void test_skipPrefixedIdentifier_notPrefixed() { |
| 11940 createParser('a +'); |
| 11941 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 11942 expect(following, isNotNull); |
| 11943 expect(following.type, TokenType.PLUS); |
| 11944 } |
| 11945 |
| 11946 void test_skipPrefixedIdentifier_prefixed() { |
| 11947 createParser('a.b +'); |
| 11948 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 11949 expect(following, isNotNull); |
| 11950 expect(following.type, TokenType.PLUS); |
| 11951 } |
| 11952 |
| 11953 void test_skipReturnType_invalid() { |
| 11954 createParser('+'); |
| 11955 Token following = parser.skipReturnType(parser.currentToken); |
| 11956 expect(following, isNull); |
| 11957 } |
| 11958 |
| 11959 void test_skipReturnType_type() { |
| 11960 createParser('C +'); |
| 11961 Token following = parser.skipReturnType(parser.currentToken); |
| 11962 expect(following, isNotNull); |
| 11963 expect(following.type, TokenType.PLUS); |
| 11964 } |
| 11965 |
| 11966 void test_skipReturnType_void() { |
| 11967 createParser('void +'); |
| 11968 Token following = parser.skipReturnType(parser.currentToken); |
| 11969 expect(following, isNotNull); |
| 11970 expect(following.type, TokenType.PLUS); |
| 11971 } |
| 11972 |
| 11973 void test_skipSimpleIdentifier_identifier() { |
| 11974 createParser('i +'); |
| 11975 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 11976 expect(following, isNotNull); |
| 11977 expect(following.type, TokenType.PLUS); |
| 11978 } |
| 11979 |
| 11980 void test_skipSimpleIdentifier_invalid() { |
| 11981 createParser('9 +'); |
| 11982 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 11983 expect(following, isNull); |
| 11984 } |
| 11985 |
| 11986 void test_skipSimpleIdentifier_pseudoKeyword() { |
| 11987 createParser('as +'); |
| 11988 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 11989 expect(following, isNotNull); |
| 11990 expect(following.type, TokenType.PLUS); |
| 11991 } |
| 11992 |
| 11993 void test_skipStringLiteral_adjacent() { |
| 11994 createParser("'a' 'b' +"); |
| 11995 Token following = parser.skipStringLiteral(parser.currentToken); |
| 11996 expect(following, isNotNull); |
| 11997 expect(following.type, TokenType.PLUS); |
| 11998 } |
| 11999 |
| 12000 void test_skipStringLiteral_interpolated() { |
| 12001 createParser("'a\${b}c' +"); |
| 12002 Token following = parser.skipStringLiteral(parser.currentToken); |
| 12003 expect(following, isNotNull); |
| 12004 expect(following.type, TokenType.PLUS); |
| 12005 } |
| 12006 |
| 12007 void test_skipStringLiteral_invalid() { |
| 12008 createParser('a'); |
| 12009 Token following = parser.skipStringLiteral(parser.currentToken); |
| 12010 expect(following, isNull); |
| 12011 } |
| 12012 |
| 12013 void test_skipStringLiteral_single() { |
| 12014 createParser("'a' +"); |
| 12015 Token following = parser.skipStringLiteral(parser.currentToken); |
| 12016 expect(following, isNotNull); |
| 12017 expect(following.type, TokenType.PLUS); |
| 12018 } |
| 12019 |
| 12020 void test_skipTypeArgumentList_invalid() { |
| 12021 createParser('+'); |
| 12022 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 12023 expect(following, isNull); |
| 12024 } |
| 12025 |
| 12026 void test_skipTypeArgumentList_multiple() { |
| 12027 createParser('<E, F, G> +'); |
| 12028 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 12029 expect(following, isNotNull); |
| 12030 expect(following.type, TokenType.PLUS); |
| 12031 } |
| 12032 |
| 12033 void test_skipTypeArgumentList_single() { |
| 12034 createParser('<E> +'); |
| 12035 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 12036 expect(following, isNotNull); |
| 12037 expect(following.type, TokenType.PLUS); |
| 12038 } |
| 12039 |
| 12040 void test_skipTypeName_invalid() { |
| 12041 createParser('+'); |
| 12042 Token following = parser.skipTypeName(parser.currentToken); |
| 12043 expect(following, isNull); |
| 12044 } |
| 12045 |
| 12046 void test_skipTypeName_parameterized() { |
| 12047 createParser('C<E<F<G>>> +'); |
| 12048 Token following = parser.skipTypeName(parser.currentToken); |
| 12049 expect(following, isNotNull); |
| 12050 expect(following.type, TokenType.PLUS); |
| 12051 } |
| 12052 |
| 12053 void test_skipTypeName_simple() { |
| 12054 createParser('C +'); |
| 12055 Token following = parser.skipTypeName(parser.currentToken); |
| 12056 expect(following, isNotNull); |
| 12057 expect(following.type, TokenType.PLUS); |
| 12058 } |
| 12059 |
| 12060 /** |
| 12061 * Invoke the method [Parser.computeStringValue] with the given argument. |
| 12062 * |
| 12063 * @param lexeme the argument to the method |
| 12064 * @param first `true` if this is the first token in a string literal |
| 12065 * @param last `true` if this is the last token in a string literal |
| 12066 * @return the result of invoking the method |
| 12067 * @throws Exception if the method could not be invoked or throws an exception |
| 12068 */ |
| 12069 String _computeStringValue(String lexeme, bool first, bool last) { |
| 12070 createParser(''); |
| 12071 String value = parser.computeStringValue(lexeme, first, last); |
| 12072 listener.assertNoErrors(); |
| 12073 return value; |
| 12074 } |
| 12075 |
| 12076 /** |
| 12077 * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the
token |
| 12078 * stream produced by scanning the given source. |
| 12079 * |
| 12080 * @param source the source to be scanned to produce the token stream being te
sted |
| 12081 * @return the result of invoking the method |
| 12082 * @throws Exception if the method could not be invoked or throws an exception |
| 12083 */ |
| 12084 bool _isFunctionDeclaration(String source) { |
| 12085 createParser(source); |
| 12086 bool result = parser.isFunctionDeclaration(); |
| 12087 expectNotNullIfNoErrors(result); |
| 12088 return result; |
| 12089 } |
| 12090 |
| 12091 /** |
| 12092 * Invoke the method [Parser.isFunctionExpression] with the parser set to the
token stream |
| 12093 * produced by scanning the given source. |
| 12094 * |
| 12095 * @param source the source to be scanned to produce the token stream being te
sted |
| 12096 * @return the result of invoking the method |
| 12097 * @throws Exception if the method could not be invoked or throws an exception |
| 12098 */ |
| 12099 bool _isFunctionExpression(String source) { |
| 12100 createParser(source); |
| 12101 return parser.isFunctionExpression(parser.currentToken); |
| 12102 } |
| 12103 |
| 12104 /** |
| 12105 * Invoke the method [Parser.isInitializedVariableDeclaration] with the parser
set to the |
| 12106 * token stream produced by scanning the given source. |
| 12107 * |
| 12108 * @param source the source to be scanned to produce the token stream being te
sted |
| 12109 * @return the result of invoking the method |
| 12110 * @throws Exception if the method could not be invoked or throws an exception |
| 12111 */ |
| 12112 bool _isInitializedVariableDeclaration(String source) { |
| 12113 createParser(source); |
| 12114 bool result = parser.isInitializedVariableDeclaration(); |
| 12115 expectNotNullIfNoErrors(result); |
| 12116 return result; |
| 12117 } |
| 12118 |
| 12119 /** |
| 12120 * Invoke the method [Parser.isSwitchMember] with the parser set to the token
stream |
| 12121 * produced by scanning the given source. |
| 12122 * |
| 12123 * @param source the source to be scanned to produce the token stream being te
sted |
| 12124 * @return the result of invoking the method |
| 12125 * @throws Exception if the method could not be invoked or throws an exception |
| 12126 */ |
| 12127 bool _isSwitchMember(String source) { |
| 12128 createParser(source); |
| 12129 bool result = parser.isSwitchMember(); |
| 12130 expectNotNullIfNoErrors(result); |
| 12131 return result; |
| 12132 } |
| 12133 } |
| 12134 |
| 12135 @reflectiveTest |
| 12136 class StatementParserTest extends ParserTestCase with StatementParserTestMixin { |
| 12137 } |
| 12138 |
| 12139 /** |
| 12140 * The class [FormalParameterParserTestMixin] defines parser tests that test |
| 12141 * the parsing statements. |
| 12142 */ |
| 12143 abstract class StatementParserTestMixin implements AbstractParserTestCase { |
| 12144 void test_parseAssertStatement() { |
| 12145 var statement = parseStatement('assert (x);') as AssertStatement; |
| 12146 assertNoErrors(); |
| 12147 expect(statement.assertKeyword, isNotNull); |
| 12148 expect(statement.leftParenthesis, isNotNull); |
| 12149 expect(statement.condition, isNotNull); |
| 12150 expect(statement.comma, isNull); |
| 12151 expect(statement.message, isNull); |
| 12152 expect(statement.rightParenthesis, isNotNull); |
| 12153 expect(statement.semicolon, isNotNull); |
| 12154 } |
| 12155 |
| 12156 void test_parseAssertStatement_messageLowPrecedence() { |
| 12157 // Using a throw expression as an assert message would be silly in |
| 12158 // practice, but it's the lowest precedence expression type, so verifying |
| 12159 // that it works should give us high confidence that other expression types |
| 12160 // will work as well. |
| 12161 var statement = |
| 12162 parseStatement('assert (x, throw "foo");') as AssertStatement; |
| 12163 assertNoErrors(); |
| 12164 expect(statement.assertKeyword, isNotNull); |
| 12165 expect(statement.leftParenthesis, isNotNull); |
| 12166 expect(statement.condition, isNotNull); |
| 12167 expect(statement.comma, isNotNull); |
| 12168 expect(statement.message, isNotNull); |
| 12169 expect(statement.rightParenthesis, isNotNull); |
| 12170 expect(statement.semicolon, isNotNull); |
| 12171 } |
| 12172 |
| 12173 void test_parseAssertStatement_messageString() { |
| 12174 var statement = parseStatement('assert (x, "foo");') as AssertStatement; |
| 12175 assertNoErrors(); |
| 12176 expect(statement.assertKeyword, isNotNull); |
| 12177 expect(statement.leftParenthesis, isNotNull); |
| 12178 expect(statement.condition, isNotNull); |
| 12179 expect(statement.comma, isNotNull); |
| 12180 expect(statement.message, isNotNull); |
| 12181 expect(statement.rightParenthesis, isNotNull); |
| 12182 expect(statement.semicolon, isNotNull); |
| 12183 } |
| 12184 |
| 12185 void test_parseBlock_empty() { |
| 12186 var block = parseStatement('{}') as Block; |
| 12187 assertNoErrors(); |
| 12188 expect(block.leftBracket, isNotNull); |
| 12189 expect(block.statements, hasLength(0)); |
| 12190 expect(block.rightBracket, isNotNull); |
| 12191 } |
| 12192 |
| 12193 void test_parseBlock_nonEmpty() { |
| 12194 var block = parseStatement('{;}') as Block; |
| 12195 assertNoErrors(); |
| 12196 expect(block.leftBracket, isNotNull); |
| 12197 expect(block.statements, hasLength(1)); |
| 12198 expect(block.rightBracket, isNotNull); |
| 12199 } |
| 12200 |
| 12201 void test_parseBreakStatement_label() { |
| 12202 var statement = parseStatement('break foo;') as BreakStatement; |
| 12203 assertNoErrors(); |
| 12204 expect(statement.breakKeyword, isNotNull); |
| 12205 expect(statement.label, isNotNull); |
| 12206 expect(statement.semicolon, isNotNull); |
| 12207 } |
| 12208 |
| 12209 void test_parseBreakStatement_noLabel() { |
| 12210 var statement = parseStatement('break;') as BreakStatement; |
| 12211 assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); |
| 12212 expect(statement.breakKeyword, isNotNull); |
| 12213 expect(statement.label, isNull); |
| 12214 expect(statement.semicolon, isNotNull); |
| 12215 } |
| 12216 |
| 12217 void test_parseDoStatement() { |
| 12218 var statement = parseStatement('do {} while (x);') as DoStatement; |
| 12219 assertNoErrors(); |
| 12220 expect(statement.doKeyword, isNotNull); |
| 12221 expect(statement.body, isNotNull); |
| 12222 expect(statement.whileKeyword, isNotNull); |
| 12223 expect(statement.leftParenthesis, isNotNull); |
| 12224 expect(statement.condition, isNotNull); |
| 12225 expect(statement.rightParenthesis, isNotNull); |
| 12226 expect(statement.semicolon, isNotNull); |
| 12227 } |
| 12228 |
| 12229 void test_parseEmptyStatement() { |
| 12230 var statement = parseStatement(';') as EmptyStatement; |
| 12231 assertNoErrors(); |
| 12232 expect(statement.semicolon, isNotNull); |
| 12233 } |
| 12234 |
| 12235 void test_parseForStatement_each_await() { |
| 12236 String code = 'await for (element in list) {}'; |
| 12237 var forStatement = _parseAsyncStatement(code) as ForEachStatement; |
| 12238 assertNoErrors(); |
| 12239 expect(forStatement.awaitKeyword, isNotNull); |
| 12240 expect(forStatement.forKeyword, isNotNull); |
| 12241 expect(forStatement.leftParenthesis, isNotNull); |
| 12242 expect(forStatement.loopVariable, isNull); |
| 12243 expect(forStatement.identifier, isNotNull); |
| 12244 expect(forStatement.inKeyword, isNotNull); |
| 12245 expect(forStatement.iterable, isNotNull); |
| 12246 expect(forStatement.rightParenthesis, isNotNull); |
| 12247 expect(forStatement.body, isNotNull); |
| 12248 } |
| 12249 |
| 12250 void test_parseForStatement_each_identifier() { |
| 12251 var forStatement = |
| 12252 parseStatement('for (element in list) {}') as ForEachStatement; |
| 12253 assertNoErrors(); |
| 12254 expect(forStatement.awaitKeyword, isNull); |
| 12255 expect(forStatement.forKeyword, isNotNull); |
| 12256 expect(forStatement.leftParenthesis, isNotNull); |
| 12257 expect(forStatement.loopVariable, isNull); |
| 12258 expect(forStatement.identifier, isNotNull); |
| 12259 expect(forStatement.inKeyword, isNotNull); |
| 12260 expect(forStatement.iterable, isNotNull); |
| 12261 expect(forStatement.rightParenthesis, isNotNull); |
| 12262 expect(forStatement.body, isNotNull); |
| 12263 } |
| 12264 |
| 12265 void test_parseForStatement_each_noType_metadata() { |
| 12266 var forStatement = |
| 12267 parseStatement('for (@A var element in list) {}') as ForEachStatement; |
| 12268 assertNoErrors(); |
| 12269 expect(forStatement.awaitKeyword, isNull); |
| 12270 expect(forStatement.forKeyword, isNotNull); |
| 12271 expect(forStatement.leftParenthesis, isNotNull); |
| 12272 expect(forStatement.loopVariable, isNotNull); |
| 12273 expect(forStatement.loopVariable.metadata, hasLength(1)); |
| 12274 expect(forStatement.identifier, isNull); |
| 12275 expect(forStatement.inKeyword, isNotNull); |
| 12276 expect(forStatement.iterable, isNotNull); |
| 12277 expect(forStatement.rightParenthesis, isNotNull); |
| 12278 expect(forStatement.body, isNotNull); |
| 12279 } |
| 12280 |
| 12281 void test_parseForStatement_each_type() { |
| 12282 var forStatement = |
| 12283 parseStatement('for (A element in list) {}') as ForEachStatement; |
| 12284 assertNoErrors(); |
| 12285 expect(forStatement.awaitKeyword, isNull); |
| 12286 expect(forStatement.forKeyword, isNotNull); |
| 12287 expect(forStatement.leftParenthesis, isNotNull); |
| 12288 expect(forStatement.loopVariable, isNotNull); |
| 12289 expect(forStatement.identifier, isNull); |
| 12290 expect(forStatement.inKeyword, isNotNull); |
| 12291 expect(forStatement.iterable, isNotNull); |
| 12292 expect(forStatement.rightParenthesis, isNotNull); |
| 12293 expect(forStatement.body, isNotNull); |
| 12294 } |
| 12295 |
| 12296 void test_parseForStatement_each_var() { |
| 12297 var forStatement = |
| 12298 parseStatement('for (var element in list) {}') as ForEachStatement; |
| 12299 assertNoErrors(); |
| 12300 expect(forStatement.awaitKeyword, isNull); |
| 12301 expect(forStatement.forKeyword, isNotNull); |
| 12302 expect(forStatement.leftParenthesis, isNotNull); |
| 12303 expect(forStatement.loopVariable, isNotNull); |
| 12304 expect(forStatement.identifier, isNull); |
| 12305 expect(forStatement.inKeyword, isNotNull); |
| 12306 expect(forStatement.iterable, isNotNull); |
| 12307 expect(forStatement.rightParenthesis, isNotNull); |
| 12308 expect(forStatement.body, isNotNull); |
| 12309 } |
| 12310 |
| 12311 void test_parseForStatement_loop_c() { |
| 12312 var forStatement = parseStatement('for (; i < count;) {}') as ForStatement; |
| 12313 assertNoErrors(); |
| 12314 expect(forStatement.forKeyword, isNotNull); |
| 12315 expect(forStatement.leftParenthesis, isNotNull); |
| 12316 expect(forStatement.variables, isNull); |
| 12317 expect(forStatement.initialization, isNull); |
| 12318 expect(forStatement.leftSeparator, isNotNull); |
| 12319 expect(forStatement.condition, isNotNull); |
| 12320 expect(forStatement.rightSeparator, isNotNull); |
| 12321 expect(forStatement.updaters, hasLength(0)); |
| 12322 expect(forStatement.rightParenthesis, isNotNull); |
| 12323 expect(forStatement.body, isNotNull); |
| 12324 } |
| 12325 |
| 12326 void test_parseForStatement_loop_cu() { |
| 12327 var forStatement = |
| 12328 parseStatement('for (; i < count; i++) {}') as ForStatement; |
| 12329 assertNoErrors(); |
| 12330 expect(forStatement.forKeyword, isNotNull); |
| 12331 expect(forStatement.leftParenthesis, isNotNull); |
| 12332 expect(forStatement.variables, isNull); |
| 12333 expect(forStatement.initialization, isNull); |
| 12334 expect(forStatement.leftSeparator, isNotNull); |
| 12335 expect(forStatement.condition, isNotNull); |
| 12336 expect(forStatement.rightSeparator, isNotNull); |
| 12337 expect(forStatement.updaters, hasLength(1)); |
| 12338 expect(forStatement.rightParenthesis, isNotNull); |
| 12339 expect(forStatement.body, isNotNull); |
| 12340 } |
| 12341 |
| 12342 void test_parseForStatement_loop_ecu() { |
| 12343 var forStatement = |
| 12344 parseStatement('for (i--; i < count; i++) {}') as ForStatement; |
| 12345 assertNoErrors(); |
| 12346 expect(forStatement.forKeyword, isNotNull); |
| 12347 expect(forStatement.leftParenthesis, isNotNull); |
| 12348 expect(forStatement.variables, isNull); |
| 12349 expect(forStatement.initialization, isNotNull); |
| 12350 expect(forStatement.leftSeparator, isNotNull); |
| 12351 expect(forStatement.condition, isNotNull); |
| 12352 expect(forStatement.rightSeparator, isNotNull); |
| 12353 expect(forStatement.updaters, hasLength(1)); |
| 12354 expect(forStatement.rightParenthesis, isNotNull); |
| 12355 expect(forStatement.body, isNotNull); |
| 12356 } |
| 12357 |
| 12358 void test_parseForStatement_loop_i() { |
| 12359 var forStatement = parseStatement('for (var i = 0;;) {}') as ForStatement; |
| 12360 assertNoErrors(); |
| 12361 expect(forStatement.forKeyword, isNotNull); |
| 12362 expect(forStatement.leftParenthesis, isNotNull); |
| 12363 VariableDeclarationList variables = forStatement.variables; |
| 12364 expect(variables, isNotNull); |
| 12365 expect(variables.metadata, hasLength(0)); |
| 12366 expect(variables.variables, hasLength(1)); |
| 12367 expect(forStatement.initialization, isNull); |
| 12368 expect(forStatement.leftSeparator, isNotNull); |
| 12369 expect(forStatement.condition, isNull); |
| 12370 expect(forStatement.rightSeparator, isNotNull); |
| 12371 expect(forStatement.updaters, hasLength(0)); |
| 12372 expect(forStatement.rightParenthesis, isNotNull); |
| 12373 expect(forStatement.body, isNotNull); |
| 12374 } |
| 12375 |
| 12376 void test_parseForStatement_loop_i_withMetadata() { |
| 12377 var forStatement = |
| 12378 parseStatement('for (@A var i = 0;;) {}') as ForStatement; |
| 12379 assertNoErrors(); |
| 12380 expect(forStatement.forKeyword, isNotNull); |
| 12381 expect(forStatement.leftParenthesis, isNotNull); |
| 12382 VariableDeclarationList variables = forStatement.variables; |
| 12383 expect(variables, isNotNull); |
| 12384 expect(variables.metadata, hasLength(1)); |
| 12385 expect(variables.variables, hasLength(1)); |
| 12386 expect(forStatement.initialization, isNull); |
| 12387 expect(forStatement.leftSeparator, isNotNull); |
| 12388 expect(forStatement.condition, isNull); |
| 12389 expect(forStatement.rightSeparator, isNotNull); |
| 12390 expect(forStatement.updaters, hasLength(0)); |
| 12391 expect(forStatement.rightParenthesis, isNotNull); |
| 12392 expect(forStatement.body, isNotNull); |
| 12393 } |
| 12394 |
| 12395 void test_parseForStatement_loop_ic() { |
| 12396 var forStatement = |
| 12397 parseStatement('for (var i = 0; i < count;) {}') as ForStatement; |
| 12398 assertNoErrors(); |
| 12399 expect(forStatement.forKeyword, isNotNull); |
| 12400 expect(forStatement.leftParenthesis, isNotNull); |
| 12401 VariableDeclarationList variables = forStatement.variables; |
| 12402 expect(variables, isNotNull); |
| 12403 expect(variables.variables, hasLength(1)); |
| 12404 expect(forStatement.initialization, isNull); |
| 12405 expect(forStatement.leftSeparator, isNotNull); |
| 12406 expect(forStatement.condition, isNotNull); |
| 12407 expect(forStatement.rightSeparator, isNotNull); |
| 12408 expect(forStatement.updaters, hasLength(0)); |
| 12409 expect(forStatement.rightParenthesis, isNotNull); |
| 12410 expect(forStatement.body, isNotNull); |
| 12411 } |
| 12412 |
| 12413 void test_parseForStatement_loop_icu() { |
| 12414 var forStatement = |
| 12415 parseStatement('for (var i = 0; i < count; i++) {}') as ForStatement; |
| 12416 assertNoErrors(); |
| 12417 expect(forStatement.forKeyword, isNotNull); |
| 12418 expect(forStatement.leftParenthesis, isNotNull); |
| 12419 VariableDeclarationList variables = forStatement.variables; |
| 12420 expect(variables, isNotNull); |
| 12421 expect(variables.variables, hasLength(1)); |
| 12422 expect(forStatement.initialization, isNull); |
| 12423 expect(forStatement.leftSeparator, isNotNull); |
| 12424 expect(forStatement.condition, isNotNull); |
| 12425 expect(forStatement.rightSeparator, isNotNull); |
| 12426 expect(forStatement.updaters, hasLength(1)); |
| 12427 expect(forStatement.rightParenthesis, isNotNull); |
| 12428 expect(forStatement.body, isNotNull); |
| 12429 } |
| 12430 |
| 12431 void test_parseForStatement_loop_iicuu() { |
| 12432 var forStatement = |
| 12433 parseStatement('for (int i = 0, j = count; i < j; i++, j--) {}') |
| 12434 as ForStatement; |
| 12435 assertNoErrors(); |
| 12436 expect(forStatement.forKeyword, isNotNull); |
| 12437 expect(forStatement.leftParenthesis, isNotNull); |
| 12438 VariableDeclarationList variables = forStatement.variables; |
| 12439 expect(variables, isNotNull); |
| 12440 expect(variables.variables, hasLength(2)); |
| 12441 expect(forStatement.initialization, isNull); |
| 12442 expect(forStatement.leftSeparator, isNotNull); |
| 12443 expect(forStatement.condition, isNotNull); |
| 12444 expect(forStatement.rightSeparator, isNotNull); |
| 12445 expect(forStatement.updaters, hasLength(2)); |
| 12446 expect(forStatement.rightParenthesis, isNotNull); |
| 12447 expect(forStatement.body, isNotNull); |
| 12448 } |
| 12449 |
| 12450 void test_parseForStatement_loop_iu() { |
| 12451 var forStatement = |
| 12452 parseStatement('for (var i = 0;; i++) {}') as ForStatement; |
| 12453 assertNoErrors(); |
| 12454 expect(forStatement.forKeyword, isNotNull); |
| 12455 expect(forStatement.leftParenthesis, isNotNull); |
| 12456 VariableDeclarationList variables = forStatement.variables; |
| 12457 expect(variables, isNotNull); |
| 12458 expect(variables.variables, hasLength(1)); |
| 12459 expect(forStatement.initialization, isNull); |
| 12460 expect(forStatement.leftSeparator, isNotNull); |
| 12461 expect(forStatement.condition, isNull); |
| 12462 expect(forStatement.rightSeparator, isNotNull); |
| 12463 expect(forStatement.updaters, hasLength(1)); |
| 12464 expect(forStatement.rightParenthesis, isNotNull); |
| 12465 expect(forStatement.body, isNotNull); |
| 12466 } |
| 12467 |
| 12468 void test_parseForStatement_loop_u() { |
| 12469 var forStatement = parseStatement('for (;; i++) {}') as ForStatement; |
| 12470 assertNoErrors(); |
| 12471 expect(forStatement.forKeyword, isNotNull); |
| 12472 expect(forStatement.leftParenthesis, isNotNull); |
| 12473 expect(forStatement.variables, isNull); |
| 12474 expect(forStatement.initialization, isNull); |
| 12475 expect(forStatement.leftSeparator, isNotNull); |
| 12476 expect(forStatement.condition, isNull); |
| 12477 expect(forStatement.rightSeparator, isNotNull); |
| 12478 expect(forStatement.updaters, hasLength(1)); |
| 12479 expect(forStatement.rightParenthesis, isNotNull); |
| 12480 expect(forStatement.body, isNotNull); |
| 12481 } |
| 12482 |
| 12483 void test_parseIfStatement_else_block() { |
| 12484 var statement = parseStatement('if (x) {} else {}') as IfStatement; |
| 12485 assertNoErrors(); |
| 12486 expect(statement.ifKeyword, isNotNull); |
| 12487 expect(statement.leftParenthesis, isNotNull); |
| 12488 expect(statement.condition, isNotNull); |
| 12489 expect(statement.rightParenthesis, isNotNull); |
| 12490 expect(statement.thenStatement, isNotNull); |
| 12491 expect(statement.elseKeyword, isNotNull); |
| 12492 expect(statement.elseStatement, isNotNull); |
| 12493 } |
| 12494 |
| 12495 void test_parseIfStatement_else_statement() { |
| 12496 var statement = parseStatement('if (x) f(x); else f(y);') as IfStatement; |
| 12497 assertNoErrors(); |
| 12498 expect(statement.ifKeyword, isNotNull); |
| 12499 expect(statement.leftParenthesis, isNotNull); |
| 12500 expect(statement.condition, isNotNull); |
| 12501 expect(statement.rightParenthesis, isNotNull); |
| 12502 expect(statement.thenStatement, isNotNull); |
| 12503 expect(statement.elseKeyword, isNotNull); |
| 12504 expect(statement.elseStatement, isNotNull); |
| 12505 } |
| 12506 |
| 12507 void test_parseIfStatement_noElse_block() { |
| 12508 var statement = parseStatement('if (x) {}') as IfStatement; |
| 12509 assertNoErrors(); |
| 12510 expect(statement.ifKeyword, isNotNull); |
| 12511 expect(statement.leftParenthesis, isNotNull); |
| 12512 expect(statement.condition, isNotNull); |
| 12513 expect(statement.rightParenthesis, isNotNull); |
| 12514 expect(statement.thenStatement, isNotNull); |
| 12515 expect(statement.elseKeyword, isNull); |
| 12516 expect(statement.elseStatement, isNull); |
| 12517 } |
| 12518 |
| 12519 void test_parseIfStatement_noElse_statement() { |
| 12520 var statement = parseStatement('if (x) f(x);') as IfStatement; |
| 12521 assertNoErrors(); |
| 12522 expect(statement.ifKeyword, isNotNull); |
| 12523 expect(statement.leftParenthesis, isNotNull); |
| 12524 expect(statement.condition, isNotNull); |
| 12525 expect(statement.rightParenthesis, isNotNull); |
| 12526 expect(statement.thenStatement, isNotNull); |
| 12527 expect(statement.elseKeyword, isNull); |
| 12528 expect(statement.elseStatement, isNull); |
| 12529 } |
| 12530 |
| 12531 void test_parseNonLabeledStatement_const_list_empty() { |
| 12532 var statement = parseStatement('const [];') as ExpressionStatement; |
| 12533 assertNoErrors(); |
| 12534 expect(statement.expression, isNotNull); |
| 12535 } |
| 12536 |
| 12537 void test_parseNonLabeledStatement_const_list_nonEmpty() { |
| 12538 var statement = parseStatement('const [1, 2];') as ExpressionStatement; |
| 12539 assertNoErrors(); |
| 12540 expect(statement.expression, isNotNull); |
| 12541 } |
| 12542 |
| 12543 void test_parseNonLabeledStatement_const_map_empty() { |
| 12544 var statement = parseStatement('const {};') as ExpressionStatement; |
| 12545 assertNoErrors(); |
| 12546 expect(statement.expression, isNotNull); |
| 12547 } |
| 12548 |
| 12549 void test_parseNonLabeledStatement_const_map_nonEmpty() { |
| 12550 // TODO(brianwilkerson) Implement more tests for this method. |
| 12551 var statement = parseStatement("const {'a' : 1};") as ExpressionStatement; |
| 12552 assertNoErrors(); |
| 12553 expect(statement.expression, isNotNull); |
| 12554 } |
| 12555 |
| 12556 void test_parseNonLabeledStatement_const_object() { |
| 12557 var statement = parseStatement('const A();') as ExpressionStatement; |
| 12558 assertNoErrors(); |
| 12559 expect(statement.expression, isNotNull); |
| 12560 } |
| 12561 |
| 12562 void test_parseNonLabeledStatement_const_object_named_typeParameters() { |
| 12563 var statement = parseStatement('const A<B>.c();') as ExpressionStatement; |
| 12564 assertNoErrors(); |
| 12565 expect(statement.expression, isNotNull); |
| 12566 } |
| 12567 |
| 12568 void test_parseNonLabeledStatement_constructorInvocation() { |
| 12569 var statement = parseStatement('new C().m();') as ExpressionStatement; |
| 12570 assertNoErrors(); |
| 12571 expect(statement.expression, isNotNull); |
| 12572 } |
| 12573 |
| 12574 void test_parseNonLabeledStatement_false() { |
| 12575 var statement = parseStatement('false;') as ExpressionStatement; |
| 12576 assertNoErrors(); |
| 12577 expect(statement.expression, isNotNull); |
| 12578 } |
| 12579 |
| 12580 void test_parseNonLabeledStatement_functionDeclaration() { |
| 12581 var statement = parseStatement('f() {};') as FunctionDeclarationStatement; |
| 12582 assertNoErrors(); |
| 12583 var function = statement.functionDeclaration.functionExpression; |
| 12584 expect(function.parameters.parameters, isEmpty); |
| 12585 expect(function.body, isNotNull); |
| 12586 } |
| 12587 |
| 12588 void test_parseNonLabeledStatement_functionDeclaration_arguments() { |
| 12589 var statement = |
| 12590 parseStatement('f(void g()) {};') as FunctionDeclarationStatement; |
| 12591 assertNoErrors(); |
| 12592 var function = statement.functionDeclaration.functionExpression; |
| 12593 expect(function.parameters.parameters, hasLength(1)); |
| 12594 expect(function.body, isNotNull); |
| 12595 } |
| 12596 |
| 12597 void test_parseNonLabeledStatement_functionExpressionIndex() { |
| 12598 var statement = parseStatement('() {}[0] = null;') as ExpressionStatement; |
| 12599 assertNoErrors(); |
| 12600 expect(statement, isNotNull); |
| 12601 } |
| 12602 |
| 12603 void test_parseNonLabeledStatement_functionInvocation() { |
| 12604 var statement = parseStatement('f();') as ExpressionStatement; |
| 12605 assertNoErrors(); |
| 12606 expect(statement.expression, isNotNull); |
| 12607 } |
| 12608 |
| 12609 void test_parseNonLabeledStatement_invokeFunctionExpression() { |
| 12610 var statement = |
| 12611 parseStatement('(a) {return a + a;} (3);') as ExpressionStatement; |
| 12612 assertNoErrors(); |
| 12613 var invocation = statement.expression as FunctionExpressionInvocation; |
| 12614 |
| 12615 FunctionExpression expression = invocation.function as FunctionExpression; |
| 12616 expect(expression.parameters, isNotNull); |
| 12617 expect(expression.body, isNotNull); |
| 12618 expect(invocation.typeArguments, isNull); |
| 12619 expect(invocation.argumentList.arguments, hasLength(1)); |
| 12620 } |
| 12621 |
| 12622 void test_parseNonLabeledStatement_null() { |
| 12623 var statement = parseStatement('null;') as ExpressionStatement; |
| 12624 assertNoErrors(); |
| 12625 expect(statement.expression, isNotNull); |
| 12626 } |
| 12627 |
| 12628 void test_parseNonLabeledStatement_startingWithBuiltInIdentifier() { |
| 12629 var statement = parseStatement('library.getName();') as ExpressionStatement; |
| 12630 assertNoErrors(); |
| 12631 expect(statement.expression, isNotNull); |
| 12632 } |
| 12633 |
| 12634 void test_parseNonLabeledStatement_true() { |
| 12635 var statement = parseStatement('true;') as ExpressionStatement; |
| 12636 assertNoErrors(); |
| 12637 expect(statement.expression, isNotNull); |
| 12638 } |
| 12639 |
| 12640 void test_parseNonLabeledStatement_typeCast() { |
| 12641 var statement = parseStatement('double.NAN as num;') as ExpressionStatement; |
| 12642 assertNoErrors(); |
| 12643 expect(statement.expression, isNotNull); |
| 12644 } |
| 12645 |
| 12646 void test_parseStatement_emptyTypeArgumentList() { |
| 12647 var declaration = parseStatement('C<> c;') as VariableDeclarationStatement; |
| 12648 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 12649 VariableDeclarationList variables = declaration.variables; |
| 12650 TypeName type = variables.type; |
| 12651 TypeArgumentList argumentList = type.typeArguments; |
| 12652 expect(argumentList.leftBracket, isNotNull); |
| 12653 expect(argumentList.arguments, hasLength(1)); |
| 12654 expect(argumentList.arguments[0].isSynthetic, isTrue); |
| 12655 expect(argumentList.rightBracket, isNotNull); |
| 12656 } |
| 12657 |
| 12658 void test_parseStatement_functionDeclaration_noReturnType() { |
| 12659 var statement = parseStatement('true;') as ExpressionStatement; |
| 12660 assertNoErrors(); |
| 12661 expect(statement.expression, isNotNull); |
| 12662 } |
| 12663 |
| 12664 void |
| 12665 test_parseStatement_functionDeclaration_noReturnType_typeParameterComments
() { |
| 12666 enableGenericMethodComments = true; |
| 12667 var statement = |
| 12668 parseStatement('f/*<E>*/(a, b) {};') as FunctionDeclarationStatement; |
| 12669 assertNoErrors(); |
| 12670 expect(statement.functionDeclaration, isNotNull); |
| 12671 expect(statement.functionDeclaration.functionExpression.typeParameters, |
| 12672 isNotNull); |
| 12673 } |
| 12674 |
| 12675 void test_parseStatement_functionDeclaration_noReturnType_typeParameters() { |
| 12676 var statement = |
| 12677 parseStatement('f<E>(a, b) {};') as FunctionDeclarationStatement; |
| 12678 assertNoErrors(); |
| 12679 expect(statement.functionDeclaration, isNotNull); |
| 12680 } |
| 12681 |
| 12682 void test_parseStatement_functionDeclaration_returnType() { |
| 12683 // TODO(brianwilkerson) Implement more tests for this method. |
| 12684 var statement = |
| 12685 parseStatement('int f(a, b) {};') as FunctionDeclarationStatement; |
| 12686 assertNoErrors(); |
| 12687 expect(statement.functionDeclaration, isNotNull); |
| 12688 } |
| 12689 |
| 12690 void test_parseStatement_functionDeclaration_returnType_typeParameters() { |
| 12691 var statement = |
| 12692 parseStatement('int f<E>(a, b) {};') as FunctionDeclarationStatement; |
| 12693 assertNoErrors(); |
| 12694 expect(statement.functionDeclaration, isNotNull); |
| 12695 } |
| 12696 |
| 12697 void test_parseStatement_multipleLabels() { |
| 12698 var statement = parseStatement('l: m: return x;') as LabeledStatement; |
| 12699 expect(statement.labels, hasLength(2)); |
| 12700 expect(statement.statement, isNotNull); |
| 12701 } |
| 12702 |
| 12703 void test_parseStatement_noLabels() { |
| 12704 var statement = parseStatement('return x;') as ReturnStatement; |
| 12705 assertNoErrors(); |
| 12706 expect(statement, isNotNull); |
| 12707 } |
| 12708 |
| 12709 void test_parseStatement_singleLabel() { |
| 12710 var statement = parseStatement('l: return x;') as LabeledStatement; |
| 12711 assertNoErrors(); |
| 12712 expect(statement.labels, hasLength(1)); |
| 12713 expect(statement.labels[0].label.inDeclarationContext(), isTrue); |
| 12714 expect(statement.statement, isNotNull); |
| 12715 } |
| 12716 |
| 12717 void test_parseSwitchStatement_case() { |
| 12718 var statement = |
| 12719 parseStatement('switch (a) {case 1: return "I";}') as SwitchStatement; |
| 12720 assertNoErrors(); |
| 12721 expect(statement.switchKeyword, isNotNull); |
| 12722 expect(statement.leftParenthesis, isNotNull); |
| 12723 expect(statement.expression, isNotNull); |
| 12724 expect(statement.rightParenthesis, isNotNull); |
| 12725 expect(statement.leftBracket, isNotNull); |
| 12726 expect(statement.members, hasLength(1)); |
| 12727 expect(statement.rightBracket, isNotNull); |
| 12728 } |
| 12729 |
| 12730 void test_parseSwitchStatement_empty() { |
| 12731 var statement = parseStatement('switch (a) {}') as SwitchStatement; |
| 12732 assertNoErrors(); |
| 12733 expect(statement.switchKeyword, isNotNull); |
| 12734 expect(statement.leftParenthesis, isNotNull); |
| 12735 expect(statement.expression, isNotNull); |
| 12736 expect(statement.rightParenthesis, isNotNull); |
| 12737 expect(statement.leftBracket, isNotNull); |
| 12738 expect(statement.members, hasLength(0)); |
| 12739 expect(statement.rightBracket, isNotNull); |
| 12740 } |
| 12741 |
| 12742 void test_parseSwitchStatement_labeledCase() { |
| 12743 var statement = |
| 12744 parseStatement('switch (a) {l1: l2: l3: case(1):}') as SwitchStatement; |
| 12745 assertNoErrors(); |
| 12746 expect(statement.switchKeyword, isNotNull); |
| 12747 expect(statement.leftParenthesis, isNotNull); |
| 12748 expect(statement.expression, isNotNull); |
| 12749 expect(statement.rightParenthesis, isNotNull); |
| 12750 expect(statement.leftBracket, isNotNull); |
| 12751 expect(statement.members, hasLength(1)); |
| 12752 { |
| 12753 List<Label> labels = statement.members[0].labels; |
| 12754 expect(labels, hasLength(3)); |
| 12755 expect(labels[0].label.inDeclarationContext(), isTrue); |
| 12756 expect(labels[1].label.inDeclarationContext(), isTrue); |
| 12757 expect(labels[2].label.inDeclarationContext(), isTrue); |
| 12758 } |
| 12759 expect(statement.rightBracket, isNotNull); |
| 12760 } |
| 12761 |
| 12762 void test_parseSwitchStatement_labeledDefault() { |
| 12763 var statement = |
| 12764 parseStatement('switch (a) {l1: l2: l3: default:}') as SwitchStatement; |
| 12765 assertNoErrors(); |
| 12766 expect(statement.switchKeyword, isNotNull); |
| 12767 expect(statement.leftParenthesis, isNotNull); |
| 12768 expect(statement.expression, isNotNull); |
| 12769 expect(statement.rightParenthesis, isNotNull); |
| 12770 expect(statement.leftBracket, isNotNull); |
| 12771 expect(statement.members, hasLength(1)); |
| 12772 { |
| 12773 List<Label> labels = statement.members[0].labels; |
| 12774 expect(labels, hasLength(3)); |
| 12775 expect(labels[0].label.inDeclarationContext(), isTrue); |
| 12776 expect(labels[1].label.inDeclarationContext(), isTrue); |
| 12777 expect(labels[2].label.inDeclarationContext(), isTrue); |
| 12778 } |
| 12779 expect(statement.rightBracket, isNotNull); |
| 12780 } |
| 12781 |
| 12782 void test_parseSwitchStatement_labeledStatementInCase() { |
| 12783 var statement = parseStatement('switch (a) {case 0: f(); l1: g(); break;}') |
| 12784 as SwitchStatement; |
| 12785 assertNoErrors(); |
| 12786 expect(statement.switchKeyword, isNotNull); |
| 12787 expect(statement.leftParenthesis, isNotNull); |
| 12788 expect(statement.expression, isNotNull); |
| 12789 expect(statement.rightParenthesis, isNotNull); |
| 12790 expect(statement.leftBracket, isNotNull); |
| 12791 expect(statement.members, hasLength(1)); |
| 12792 expect(statement.members[0].statements, hasLength(3)); |
| 12793 expect(statement.rightBracket, isNotNull); |
| 12794 } |
| 12795 |
| 12796 void test_parseTryStatement_catch() { |
| 12797 var statement = parseStatement('try {} catch (e) {}') as TryStatement; |
| 12798 assertNoErrors(); |
| 12799 expect(statement.tryKeyword, isNotNull); |
| 12800 expect(statement.body, isNotNull); |
| 12801 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 12802 expect(catchClauses, hasLength(1)); |
| 12803 CatchClause clause = catchClauses[0]; |
| 12804 expect(clause.onKeyword, isNull); |
| 12805 expect(clause.exceptionType, isNull); |
| 12806 expect(clause.catchKeyword, isNotNull); |
| 12807 expect(clause.exceptionParameter, isNotNull); |
| 12808 expect(clause.comma, isNull); |
| 12809 expect(clause.stackTraceParameter, isNull); |
| 12810 expect(clause.body, isNotNull); |
| 12811 expect(statement.finallyKeyword, isNull); |
| 12812 expect(statement.finallyBlock, isNull); |
| 12813 } |
| 12814 |
| 12815 void test_parseTryStatement_catch_finally() { |
| 12816 var statement = |
| 12817 parseStatement('try {} catch (e, s) {} finally {}') as TryStatement; |
| 12818 assertNoErrors(); |
| 12819 expect(statement.tryKeyword, isNotNull); |
| 12820 expect(statement.body, isNotNull); |
| 12821 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 12822 expect(catchClauses, hasLength(1)); |
| 12823 CatchClause clause = catchClauses[0]; |
| 12824 expect(clause.onKeyword, isNull); |
| 12825 expect(clause.exceptionType, isNull); |
| 12826 expect(clause.catchKeyword, isNotNull); |
| 12827 expect(clause.exceptionParameter, isNotNull); |
| 12828 expect(clause.comma, isNotNull); |
| 12829 expect(clause.stackTraceParameter, isNotNull); |
| 12830 expect(clause.body, isNotNull); |
| 12831 expect(statement.finallyKeyword, isNotNull); |
| 12832 expect(statement.finallyBlock, isNotNull); |
| 12833 } |
| 12834 |
| 12835 void test_parseTryStatement_finally() { |
| 12836 var statement = parseStatement('try {} finally {}') as TryStatement; |
| 12837 assertNoErrors(); |
| 12838 expect(statement.tryKeyword, isNotNull); |
| 12839 expect(statement.body, isNotNull); |
| 12840 expect(statement.catchClauses, hasLength(0)); |
| 12841 expect(statement.finallyKeyword, isNotNull); |
| 12842 expect(statement.finallyBlock, isNotNull); |
| 12843 } |
| 12844 |
| 12845 void test_parseTryStatement_multiple() { |
| 12846 var statement = |
| 12847 parseStatement('try {} on NPE catch (e) {} on Error {} catch (e) {}') |
| 12848 as TryStatement; |
| 12849 assertNoErrors(); |
| 12850 expect(statement.tryKeyword, isNotNull); |
| 12851 expect(statement.body, isNotNull); |
| 12852 expect(statement.catchClauses, hasLength(3)); |
| 12853 expect(statement.finallyKeyword, isNull); |
| 12854 expect(statement.finallyBlock, isNull); |
| 12855 } |
| 12856 |
| 12857 void test_parseTryStatement_on() { |
| 12858 var statement = parseStatement('try {} on Error {}') as TryStatement; |
| 12859 assertNoErrors(); |
| 12860 expect(statement.tryKeyword, isNotNull); |
| 12861 expect(statement.body, isNotNull); |
| 12862 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 12863 expect(catchClauses, hasLength(1)); |
| 12864 CatchClause clause = catchClauses[0]; |
| 12865 expect(clause.onKeyword, isNotNull); |
| 12866 expect(clause.exceptionType, isNotNull); |
| 12867 expect(clause.catchKeyword, isNull); |
| 12868 expect(clause.exceptionParameter, isNull); |
| 12869 expect(clause.comma, isNull); |
| 12870 expect(clause.stackTraceParameter, isNull); |
| 12871 expect(clause.body, isNotNull); |
| 12872 expect(statement.finallyKeyword, isNull); |
| 12873 expect(statement.finallyBlock, isNull); |
| 12874 } |
| 12875 |
| 12876 void test_parseTryStatement_on_catch() { |
| 12877 var statement = |
| 12878 parseStatement('try {} on Error catch (e, s) {}') as TryStatement; |
| 12879 assertNoErrors(); |
| 12880 expect(statement.tryKeyword, isNotNull); |
| 12881 expect(statement.body, isNotNull); |
| 12882 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 12883 expect(catchClauses, hasLength(1)); |
| 12884 CatchClause clause = catchClauses[0]; |
| 12885 expect(clause.onKeyword, isNotNull); |
| 12886 expect(clause.exceptionType, isNotNull); |
| 12887 expect(clause.catchKeyword, isNotNull); |
| 12888 expect(clause.exceptionParameter, isNotNull); |
| 12889 expect(clause.comma, isNotNull); |
| 12890 expect(clause.stackTraceParameter, isNotNull); |
| 12891 expect(clause.body, isNotNull); |
| 12892 expect(statement.finallyKeyword, isNull); |
| 12893 expect(statement.finallyBlock, isNull); |
| 12894 } |
| 12895 |
| 12896 void test_parseTryStatement_on_catch_finally() { |
| 12897 var statement = parseStatement('try {} on Error catch (e, s) {} finally {}') |
| 12898 as TryStatement; |
| 12899 assertNoErrors(); |
| 12900 expect(statement.tryKeyword, isNotNull); |
| 12901 expect(statement.body, isNotNull); |
| 12902 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 12903 expect(catchClauses, hasLength(1)); |
| 12904 CatchClause clause = catchClauses[0]; |
| 12905 expect(clause.onKeyword, isNotNull); |
| 12906 expect(clause.exceptionType, isNotNull); |
| 12907 expect(clause.catchKeyword, isNotNull); |
| 12908 expect(clause.exceptionParameter, isNotNull); |
| 12909 expect(clause.comma, isNotNull); |
| 12910 expect(clause.stackTraceParameter, isNotNull); |
| 12911 expect(clause.body, isNotNull); |
| 12912 expect(statement.finallyKeyword, isNotNull); |
| 12913 expect(statement.finallyBlock, isNotNull); |
| 12914 } |
| 12915 |
| 12849 void test_parseVariableDeclarationStatementAfterMetadata_multiple() { | 12916 void test_parseVariableDeclarationStatementAfterMetadata_multiple() { |
| 12850 createParser('var x, y, z;'); | 12917 var statement = |
| 12851 VariableDeclarationStatement statement = parser.parseStatement2(); | 12918 parseStatement('var x, y, z;') as VariableDeclarationStatement; |
| 12852 expectNotNullIfNoErrors(statement); | 12919 assertNoErrors(); |
| 12853 listener.assertNoErrors(); | |
| 12854 expect(statement.semicolon, isNotNull); | 12920 expect(statement.semicolon, isNotNull); |
| 12855 VariableDeclarationList variableList = statement.variables; | 12921 VariableDeclarationList variableList = statement.variables; |
| 12856 expect(variableList, isNotNull); | 12922 expect(variableList, isNotNull); |
| 12857 expect(variableList.variables, hasLength(3)); | 12923 expect(variableList.variables, hasLength(3)); |
| 12858 } | 12924 } |
| 12859 | 12925 |
| 12860 void test_parseVariableDeclarationStatementAfterMetadata_single() { | 12926 void test_parseVariableDeclarationStatementAfterMetadata_single() { |
| 12861 createParser('var x;'); | 12927 var statement = parseStatement('var x;') as VariableDeclarationStatement; |
| 12862 VariableDeclarationStatement statement = parser.parseStatement2(); | 12928 assertNoErrors(); |
| 12863 expectNotNullIfNoErrors(statement); | |
| 12864 listener.assertNoErrors(); | |
| 12865 expect(statement.semicolon, isNotNull); | 12929 expect(statement.semicolon, isNotNull); |
| 12866 VariableDeclarationList variableList = statement.variables; | 12930 VariableDeclarationList variableList = statement.variables; |
| 12867 expect(variableList, isNotNull); | 12931 expect(variableList, isNotNull); |
| 12868 expect(variableList.variables, hasLength(1)); | 12932 expect(variableList.variables, hasLength(1)); |
| 12869 } | 12933 } |
| 12870 | 12934 |
| 12871 void test_parseWhileStatement() { | 12935 void test_parseWhileStatement() { |
| 12872 createParser('while (x) {}'); | 12936 var statement = parseStatement('while (x) {}') as WhileStatement; |
| 12873 WhileStatement statement = parser.parseWhileStatement(); | 12937 assertNoErrors(); |
| 12874 expectNotNullIfNoErrors(statement); | |
| 12875 listener.assertNoErrors(); | |
| 12876 expect(statement.whileKeyword, isNotNull); | 12938 expect(statement.whileKeyword, isNotNull); |
| 12877 expect(statement.leftParenthesis, isNotNull); | 12939 expect(statement.leftParenthesis, isNotNull); |
| 12878 expect(statement.condition, isNotNull); | 12940 expect(statement.condition, isNotNull); |
| 12879 expect(statement.rightParenthesis, isNotNull); | 12941 expect(statement.rightParenthesis, isNotNull); |
| 12880 expect(statement.body, isNotNull); | 12942 expect(statement.body, isNotNull); |
| 12881 } | 12943 } |
| 12882 | 12944 |
| 12883 void test_parseWithClause_multiple() { | |
| 12884 createParser('with A, B, C'); | |
| 12885 WithClause clause = parser.parseWithClause(); | |
| 12886 expectNotNullIfNoErrors(clause); | |
| 12887 listener.assertNoErrors(); | |
| 12888 expect(clause.withKeyword, isNotNull); | |
| 12889 expect(clause.mixinTypes, hasLength(3)); | |
| 12890 } | |
| 12891 | |
| 12892 void test_parseWithClause_single() { | |
| 12893 createParser('with M'); | |
| 12894 WithClause clause = parser.parseWithClause(); | |
| 12895 expectNotNullIfNoErrors(clause); | |
| 12896 listener.assertNoErrors(); | |
| 12897 expect(clause.withKeyword, isNotNull); | |
| 12898 expect(clause.mixinTypes, hasLength(1)); | |
| 12899 } | |
| 12900 | |
| 12901 void test_parseYieldStatement_each() { | 12945 void test_parseYieldStatement_each() { |
| 12902 createParser('yield* x;'); | 12946 var statement = |
| 12903 YieldStatement statement = parser.parseYieldStatement(); | 12947 _parseAsyncStatement('yield* x;', isGenerator: true) as YieldStatement; |
| 12904 expectNotNullIfNoErrors(statement); | 12948 assertNoErrors(); |
| 12905 listener.assertNoErrors(); | |
| 12906 expect(statement.yieldKeyword, isNotNull); | 12949 expect(statement.yieldKeyword, isNotNull); |
| 12907 expect(statement.star, isNotNull); | 12950 expect(statement.star, isNotNull); |
| 12908 expect(statement.expression, isNotNull); | 12951 expect(statement.expression, isNotNull); |
| 12909 expect(statement.semicolon, isNotNull); | 12952 expect(statement.semicolon, isNotNull); |
| 12910 } | 12953 } |
| 12911 | 12954 |
| 12912 void test_parseYieldStatement_normal() { | 12955 void test_parseYieldStatement_normal() { |
| 12913 createParser('yield x;'); | 12956 var statement = |
| 12914 YieldStatement statement = parser.parseYieldStatement(); | 12957 _parseAsyncStatement('yield x;', isGenerator: true) as YieldStatement; |
| 12915 expectNotNullIfNoErrors(statement); | 12958 assertNoErrors(); |
| 12916 listener.assertNoErrors(); | |
| 12917 expect(statement.yieldKeyword, isNotNull); | 12959 expect(statement.yieldKeyword, isNotNull); |
| 12918 expect(statement.star, isNull); | 12960 expect(statement.star, isNull); |
| 12919 expect(statement.expression, isNotNull); | 12961 expect(statement.expression, isNotNull); |
| 12920 expect(statement.semicolon, isNotNull); | 12962 expect(statement.semicolon, isNotNull); |
| 12921 } | 12963 } |
| 12922 | 12964 |
| 12923 void test_skipPrefixedIdentifier_invalid() { | 12965 Statement _parseAsyncStatement(String code, {bool isGenerator: false}) { |
| 12924 createParser('+'); | 12966 var star = isGenerator ? '*' : ''; |
| 12925 Token following = parser.skipPrefixedIdentifier(parser.currentToken); | 12967 var localFunction = parseStatement('wrapper() async$star { $code };') |
| 12926 expect(following, isNull); | 12968 as FunctionDeclarationStatement; |
| 12927 } | 12969 var localBody = localFunction.functionDeclaration.functionExpression.body |
| 12928 | 12970 as BlockFunctionBody; |
| 12929 void test_skipPrefixedIdentifier_notPrefixed() { | 12971 return localBody.block.statements.single; |
| 12930 createParser('a +'); | |
| 12931 Token following = parser.skipPrefixedIdentifier(parser.currentToken); | |
| 12932 expect(following, isNotNull); | |
| 12933 expect(following.type, TokenType.PLUS); | |
| 12934 } | |
| 12935 | |
| 12936 void test_skipPrefixedIdentifier_prefixed() { | |
| 12937 createParser('a.b +'); | |
| 12938 Token following = parser.skipPrefixedIdentifier(parser.currentToken); | |
| 12939 expect(following, isNotNull); | |
| 12940 expect(following.type, TokenType.PLUS); | |
| 12941 } | |
| 12942 | |
| 12943 void test_skipReturnType_invalid() { | |
| 12944 createParser('+'); | |
| 12945 Token following = parser.skipReturnType(parser.currentToken); | |
| 12946 expect(following, isNull); | |
| 12947 } | |
| 12948 | |
| 12949 void test_skipReturnType_type() { | |
| 12950 createParser('C +'); | |
| 12951 Token following = parser.skipReturnType(parser.currentToken); | |
| 12952 expect(following, isNotNull); | |
| 12953 expect(following.type, TokenType.PLUS); | |
| 12954 } | |
| 12955 | |
| 12956 void test_skipReturnType_void() { | |
| 12957 createParser('void +'); | |
| 12958 Token following = parser.skipReturnType(parser.currentToken); | |
| 12959 expect(following, isNotNull); | |
| 12960 expect(following.type, TokenType.PLUS); | |
| 12961 } | |
| 12962 | |
| 12963 void test_skipSimpleIdentifier_identifier() { | |
| 12964 createParser('i +'); | |
| 12965 Token following = parser.skipSimpleIdentifier(parser.currentToken); | |
| 12966 expect(following, isNotNull); | |
| 12967 expect(following.type, TokenType.PLUS); | |
| 12968 } | |
| 12969 | |
| 12970 void test_skipSimpleIdentifier_invalid() { | |
| 12971 createParser('9 +'); | |
| 12972 Token following = parser.skipSimpleIdentifier(parser.currentToken); | |
| 12973 expect(following, isNull); | |
| 12974 } | |
| 12975 | |
| 12976 void test_skipSimpleIdentifier_pseudoKeyword() { | |
| 12977 createParser('as +'); | |
| 12978 Token following = parser.skipSimpleIdentifier(parser.currentToken); | |
| 12979 expect(following, isNotNull); | |
| 12980 expect(following.type, TokenType.PLUS); | |
| 12981 } | |
| 12982 | |
| 12983 void test_skipStringLiteral_adjacent() { | |
| 12984 createParser("'a' 'b' +"); | |
| 12985 Token following = parser.skipStringLiteral(parser.currentToken); | |
| 12986 expect(following, isNotNull); | |
| 12987 expect(following.type, TokenType.PLUS); | |
| 12988 } | |
| 12989 | |
| 12990 void test_skipStringLiteral_interpolated() { | |
| 12991 createParser("'a\${b}c' +"); | |
| 12992 Token following = parser.skipStringLiteral(parser.currentToken); | |
| 12993 expect(following, isNotNull); | |
| 12994 expect(following.type, TokenType.PLUS); | |
| 12995 } | |
| 12996 | |
| 12997 void test_skipStringLiteral_invalid() { | |
| 12998 createParser('a'); | |
| 12999 Token following = parser.skipStringLiteral(parser.currentToken); | |
| 13000 expect(following, isNull); | |
| 13001 } | |
| 13002 | |
| 13003 void test_skipStringLiteral_single() { | |
| 13004 createParser("'a' +"); | |
| 13005 Token following = parser.skipStringLiteral(parser.currentToken); | |
| 13006 expect(following, isNotNull); | |
| 13007 expect(following.type, TokenType.PLUS); | |
| 13008 } | |
| 13009 | |
| 13010 void test_skipTypeArgumentList_invalid() { | |
| 13011 createParser('+'); | |
| 13012 Token following = parser.skipTypeArgumentList(parser.currentToken); | |
| 13013 expect(following, isNull); | |
| 13014 } | |
| 13015 | |
| 13016 void test_skipTypeArgumentList_multiple() { | |
| 13017 createParser('<E, F, G> +'); | |
| 13018 Token following = parser.skipTypeArgumentList(parser.currentToken); | |
| 13019 expect(following, isNotNull); | |
| 13020 expect(following.type, TokenType.PLUS); | |
| 13021 } | |
| 13022 | |
| 13023 void test_skipTypeArgumentList_single() { | |
| 13024 createParser('<E> +'); | |
| 13025 Token following = parser.skipTypeArgumentList(parser.currentToken); | |
| 13026 expect(following, isNotNull); | |
| 13027 expect(following.type, TokenType.PLUS); | |
| 13028 } | |
| 13029 | |
| 13030 void test_skipTypeName_invalid() { | |
| 13031 createParser('+'); | |
| 13032 Token following = parser.skipTypeName(parser.currentToken); | |
| 13033 expect(following, isNull); | |
| 13034 } | |
| 13035 | |
| 13036 void test_skipTypeName_parameterized() { | |
| 13037 createParser('C<E<F<G>>> +'); | |
| 13038 Token following = parser.skipTypeName(parser.currentToken); | |
| 13039 expect(following, isNotNull); | |
| 13040 expect(following.type, TokenType.PLUS); | |
| 13041 } | |
| 13042 | |
| 13043 void test_skipTypeName_simple() { | |
| 13044 createParser('C +'); | |
| 13045 Token following = parser.skipTypeName(parser.currentToken); | |
| 13046 expect(following, isNotNull); | |
| 13047 expect(following.type, TokenType.PLUS); | |
| 13048 } | |
| 13049 | |
| 13050 /** | |
| 13051 * Invoke the method [Parser.computeStringValue] with the given argument. | |
| 13052 * | |
| 13053 * @param lexeme the argument to the method | |
| 13054 * @param first `true` if this is the first token in a string literal | |
| 13055 * @param last `true` if this is the last token in a string literal | |
| 13056 * @return the result of invoking the method | |
| 13057 * @throws Exception if the method could not be invoked or throws an exception | |
| 13058 */ | |
| 13059 String _computeStringValue(String lexeme, bool first, bool last) { | |
| 13060 createParser(''); | |
| 13061 String value = parser.computeStringValue(lexeme, first, last); | |
| 13062 listener.assertNoErrors(); | |
| 13063 return value; | |
| 13064 } | |
| 13065 | |
| 13066 /** | |
| 13067 * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the
token | |
| 13068 * stream produced by scanning the given source. | |
| 13069 * | |
| 13070 * @param source the source to be scanned to produce the token stream being te
sted | |
| 13071 * @return the result of invoking the method | |
| 13072 * @throws Exception if the method could not be invoked or throws an exception | |
| 13073 */ | |
| 13074 bool _isFunctionDeclaration(String source) { | |
| 13075 createParser(source); | |
| 13076 bool result = parser.isFunctionDeclaration(); | |
| 13077 expectNotNullIfNoErrors(result); | |
| 13078 return result; | |
| 13079 } | |
| 13080 | |
| 13081 /** | |
| 13082 * Invoke the method [Parser.isFunctionExpression] with the parser set to the
token stream | |
| 13083 * produced by scanning the given source. | |
| 13084 * | |
| 13085 * @param source the source to be scanned to produce the token stream being te
sted | |
| 13086 * @return the result of invoking the method | |
| 13087 * @throws Exception if the method could not be invoked or throws an exception | |
| 13088 */ | |
| 13089 bool _isFunctionExpression(String source) { | |
| 13090 createParser(source); | |
| 13091 return parser.isFunctionExpression(parser.currentToken); | |
| 13092 } | |
| 13093 | |
| 13094 /** | |
| 13095 * Invoke the method [Parser.isInitializedVariableDeclaration] with the parser
set to the | |
| 13096 * token stream produced by scanning the given source. | |
| 13097 * | |
| 13098 * @param source the source to be scanned to produce the token stream being te
sted | |
| 13099 * @return the result of invoking the method | |
| 13100 * @throws Exception if the method could not be invoked or throws an exception | |
| 13101 */ | |
| 13102 bool _isInitializedVariableDeclaration(String source) { | |
| 13103 createParser(source); | |
| 13104 bool result = parser.isInitializedVariableDeclaration(); | |
| 13105 expectNotNullIfNoErrors(result); | |
| 13106 return result; | |
| 13107 } | |
| 13108 | |
| 13109 /** | |
| 13110 * Invoke the method [Parser.isSwitchMember] with the parser set to the token
stream | |
| 13111 * produced by scanning the given source. | |
| 13112 * | |
| 13113 * @param source the source to be scanned to produce the token stream being te
sted | |
| 13114 * @return the result of invoking the method | |
| 13115 * @throws Exception if the method could not be invoked or throws an exception | |
| 13116 */ | |
| 13117 bool _isSwitchMember(String source) { | |
| 13118 createParser(source); | |
| 13119 bool result = parser.isSwitchMember(); | |
| 13120 expectNotNullIfNoErrors(result); | |
| 13121 return result; | |
| 13122 } | 12972 } |
| 13123 } | 12973 } |
| 13124 | 12974 |
| 13125 @reflectiveTest | 12975 @reflectiveTest |
| 13126 class TopLevelParserTest extends ParserTestCase with TopLevelParserTestMixin {} | 12976 class TopLevelParserTest extends ParserTestCase with TopLevelParserTestMixin {} |
| 13127 | 12977 |
| 13128 /** | 12978 /** |
| 13129 * Tests which exercise the parser using a complete compilation unit or | 12979 * Tests which exercise the parser using a complete compilation unit or |
| 13130 * compilation unit member. | 12980 * compilation unit member. |
| 13131 */ | 12981 */ |
| (...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14883 expectCommentText(typeAlias.documentationComment, '/// Doc'); | 14733 expectCommentText(typeAlias.documentationComment, '/// Doc'); |
| 14884 } | 14734 } |
| 14885 | 14735 |
| 14886 /** | 14736 /** |
| 14887 * Assert that the given [name] is in declaration context. | 14737 * Assert that the given [name] is in declaration context. |
| 14888 */ | 14738 */ |
| 14889 void _assertIsDeclarationName(SimpleIdentifier name) { | 14739 void _assertIsDeclarationName(SimpleIdentifier name) { |
| 14890 expect(name.inDeclarationContext(), isTrue); | 14740 expect(name.inDeclarationContext(), isTrue); |
| 14891 } | 14741 } |
| 14892 } | 14742 } |
| OLD | NEW |