Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: pkg/analyzer/test/generated/parser_test.dart

Issue 3005973002: Fix and triage more tests (Closed)
Patch Set: address comments Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
7 import 'package:analyzer/dart/ast/token.dart'; 7 import 'package:analyzer/dart/ast/token.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/error/error.dart'; 9 import 'package:analyzer/error/error.dart';
10 import 'package:analyzer/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
(...skipping 2157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 parseCompilationUnit("enum E { @override C }", 2168 parseCompilationUnit("enum E { @override C }",
2169 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); 2169 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]);
2170 } 2170 }
2171 2171
2172 void test_annotationOnEnumConstant_middle() { 2172 void test_annotationOnEnumConstant_middle() {
2173 parseCompilationUnit("enum E { C, @override D, E }", 2173 parseCompilationUnit("enum E { C, @override D, E }",
2174 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); 2174 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]);
2175 } 2175 }
2176 2176
2177 void test_breakOutsideOfLoop_breakInDoStatement() { 2177 void test_breakOutsideOfLoop_breakInDoStatement() {
2178 createParser('do {break;} while (x);'); 2178 DoStatement statement = parseStatement('do {break;} while (x);');
2179 DoStatement statement = parser.parseDoStatement();
2180 expectNotNullIfNoErrors(statement); 2179 expectNotNullIfNoErrors(statement);
2181 listener.assertNoErrors(); 2180 listener.assertNoErrors();
2182 } 2181 }
2183 2182
2184 void test_breakOutsideOfLoop_breakInForStatement() { 2183 void test_breakOutsideOfLoop_breakInForStatement() {
2185 createParser('for (; x;) {break;}'); 2184 Statement statement = parseStatement('for (; x;) {break;}');
2186 Statement statement = parser.parseForStatement();
2187 expectNotNullIfNoErrors(statement); 2185 expectNotNullIfNoErrors(statement);
2188 listener.assertNoErrors(); 2186 listener.assertNoErrors();
2189 } 2187 }
2190 2188
2191 void test_breakOutsideOfLoop_breakInIfStatement() { 2189 void test_breakOutsideOfLoop_breakInIfStatement() {
2192 createParser('if (x) {break;}'); 2190 IfStatement statement = parseStatement('if (x) {break;}');
2193 IfStatement statement = parser.parseIfStatement();
2194 expectNotNullIfNoErrors(statement); 2191 expectNotNullIfNoErrors(statement);
2195 listener.assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); 2192 listener.assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]);
2196 } 2193 }
2197 2194
2198 void test_breakOutsideOfLoop_breakInSwitchStatement() { 2195 void test_breakOutsideOfLoop_breakInSwitchStatement() {
2199 createParser('switch (x) {case 1: break;}'); 2196 SwitchStatement statement = parseStatement('switch (x) {case 1: break;}');
2200 SwitchStatement statement = parser.parseSwitchStatement();
2201 expectNotNullIfNoErrors(statement); 2197 expectNotNullIfNoErrors(statement);
2202 listener.assertNoErrors(); 2198 listener.assertNoErrors();
2203 } 2199 }
2204 2200
2205 void test_breakOutsideOfLoop_breakInWhileStatement() { 2201 void test_breakOutsideOfLoop_breakInWhileStatement() {
2206 createParser('while (x) {break;}'); 2202 WhileStatement statement = parseStatement('while (x) {break;}');
2207 WhileStatement statement = parser.parseWhileStatement();
2208 expectNotNullIfNoErrors(statement); 2203 expectNotNullIfNoErrors(statement);
2209 listener.assertNoErrors(); 2204 listener.assertNoErrors();
2210 } 2205 }
2211 2206
2212 void test_breakOutsideOfLoop_functionExpression_inALoop() { 2207 void test_breakOutsideOfLoop_functionExpression_inALoop() {
2213 parseStatement("for(; x;) {() {break;};}"); 2208 parseStatement("for(; x;) {() {break;};}");
2214 assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); 2209 assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]);
2215 } 2210 }
2216 2211
2217 void test_breakOutsideOfLoop_functionExpression_withALoop() { 2212 void test_breakOutsideOfLoop_functionExpression_withALoop() {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 expectNotNullIfNoErrors(member); 2303 expectNotNullIfNoErrors(member);
2309 listener 2304 listener
2310 .assertErrorsWithCodes([ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE]); 2305 .assertErrorsWithCodes([ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE]);
2311 } 2306 }
2312 2307
2313 void test_constTypedef() { 2308 void test_constTypedef() {
2314 parseCompilationUnit("const typedef F();", [ParserErrorCode.CONST_TYPEDEF]); 2309 parseCompilationUnit("const typedef F();", [ParserErrorCode.CONST_TYPEDEF]);
2315 } 2310 }
2316 2311
2317 void test_continueOutsideOfLoop_continueInDoStatement() { 2312 void test_continueOutsideOfLoop_continueInDoStatement() {
2318 createParser('do {continue;} while (x);'); 2313 DoStatement statement = parseStatement('do {continue;} while (x);');
2319 DoStatement statement = parser.parseDoStatement();
2320 expectNotNullIfNoErrors(statement); 2314 expectNotNullIfNoErrors(statement);
2321 listener.assertNoErrors(); 2315 listener.assertNoErrors();
2322 } 2316 }
2323 2317
2324 void test_continueOutsideOfLoop_continueInForStatement() { 2318 void test_continueOutsideOfLoop_continueInForStatement() {
2325 createParser('for (; x;) {continue;}'); 2319 Statement statement = parseStatement('for (; x;) {continue;}');
2326 Statement statement = parser.parseForStatement();
2327 expectNotNullIfNoErrors(statement); 2320 expectNotNullIfNoErrors(statement);
2328 listener.assertNoErrors(); 2321 listener.assertNoErrors();
2329 } 2322 }
2330 2323
2331 void test_continueOutsideOfLoop_continueInIfStatement() { 2324 void test_continueOutsideOfLoop_continueInIfStatement() {
2332 createParser('if (x) {continue;}'); 2325 IfStatement statement = parseStatement('if (x) {continue;}');
2333 IfStatement statement = parser.parseIfStatement();
2334 expectNotNullIfNoErrors(statement); 2326 expectNotNullIfNoErrors(statement);
2335 listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); 2327 listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]);
2336 } 2328 }
2337 2329
2338 void test_continueOutsideOfLoop_continueInSwitchStatement() { 2330 void test_continueOutsideOfLoop_continueInSwitchStatement() {
2339 createParser('switch (x) {case 1: continue a;}'); 2331 SwitchStatement statement =
2340 SwitchStatement statement = parser.parseSwitchStatement(); 2332 parseStatement('switch (x) {case 1: continue a;}');
2341 expectNotNullIfNoErrors(statement); 2333 expectNotNullIfNoErrors(statement);
2342 listener.assertNoErrors(); 2334 listener.assertNoErrors();
2343 } 2335 }
2344 2336
2345 void test_continueOutsideOfLoop_continueInWhileStatement() { 2337 void test_continueOutsideOfLoop_continueInWhileStatement() {
2346 createParser('while (x) {continue;}'); 2338 WhileStatement statement = parseStatement('while (x) {continue;}');
2347 WhileStatement statement = parser.parseWhileStatement();
2348 expectNotNullIfNoErrors(statement); 2339 expectNotNullIfNoErrors(statement);
2349 listener.assertNoErrors(); 2340 listener.assertNoErrors();
2350 } 2341 }
2351 2342
2352 void test_continueOutsideOfLoop_functionExpression_inALoop() { 2343 void test_continueOutsideOfLoop_functionExpression_inALoop() {
2353 parseStatement("for(; x;) {() {continue;};}"); 2344 parseStatement("for(; x;) {() {continue;};}");
2354 assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); 2345 assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]);
2355 } 2346 }
2356 2347
2357 void test_continueOutsideOfLoop_functionExpression_withALoop() { 2348 void test_continueOutsideOfLoop_functionExpression_withALoop() {
2358 parseStatement("() {for (; x;) {continue;}};"); 2349 parseStatement("() {for (; x;) {continue;}};");
2359 } 2350 }
2360 2351
2361 void test_continueWithoutLabelInCase_error() { 2352 void test_continueWithoutLabelInCase_error() {
2362 createParser('switch (x) {case 1: continue;}'); 2353 SwitchStatement statement =
2363 SwitchStatement statement = parser.parseSwitchStatement(); 2354 parseStatement('switch (x) {case 1: continue;}');
2364 expectNotNullIfNoErrors(statement); 2355 expectNotNullIfNoErrors(statement);
2365 listener.assertErrorsWithCodes( 2356 listener.assertErrorsWithCodes(
2366 [ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE]); 2357 [ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE]);
2367 } 2358 }
2368 2359
2369 void test_continueWithoutLabelInCase_noError() { 2360 void test_continueWithoutLabelInCase_noError() {
2370 createParser('switch (x) {case 1: continue a;}'); 2361 SwitchStatement statement =
2371 SwitchStatement statement = parser.parseSwitchStatement(); 2362 parseStatement('switch (x) {case 1: continue a;}');
2372 expectNotNullIfNoErrors(statement); 2363 expectNotNullIfNoErrors(statement);
2373 listener.assertNoErrors(); 2364 listener.assertNoErrors();
2374 } 2365 }
2375 2366
2376 void test_continueWithoutLabelInCase_noError_switchInLoop() { 2367 void test_continueWithoutLabelInCase_noError_switchInLoop() {
2377 createParser('while (a) { switch (b) {default: continue;}}'); 2368 WhileStatement statement =
2378 WhileStatement statement = parser.parseWhileStatement(); 2369 parseStatement('while (a) { switch (b) {default: continue;}}');
2379 expectNotNullIfNoErrors(statement); 2370 expectNotNullIfNoErrors(statement);
2380 listener.assertNoErrors(); 2371 listener.assertNoErrors();
2381 } 2372 }
2382 2373
2383 void test_covariantAfterVar() { 2374 void test_covariantAfterVar() {
2384 createParser('var covariant f;'); 2375 createParser('var covariant f;');
2385 ClassMember member = parser.parseClassMember('C'); 2376 ClassMember member = parser.parseClassMember('C');
2386 expectNotNullIfNoErrors(member); 2377 expectNotNullIfNoErrors(member);
2387 listener.assertErrorsWithCodes([ParserErrorCode.COVARIANT_AFTER_VAR]); 2378 listener.assertErrorsWithCodes([ParserErrorCode.COVARIANT_AFTER_VAR]);
2388 } 2379 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 listener.assertErrorsWithCodes( 2428 listener.assertErrorsWithCodes(
2438 [ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION]); 2429 [ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION]);
2439 } 2430 }
2440 2431
2441 void test_covariantTopLevelDeclaration_typedef() { 2432 void test_covariantTopLevelDeclaration_typedef() {
2442 parseCompilationUnit("covariant typedef F();", 2433 parseCompilationUnit("covariant typedef F();",
2443 [ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION]); 2434 [ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION]);
2444 } 2435 }
2445 2436
2446 void test_defaultValueInFunctionType_named_colon() { 2437 void test_defaultValueInFunctionType_named_colon() {
2447 createParser('int x : 0'); 2438 createParser('({int x : 0})');
2448 FormalParameter parameter = 2439 FormalParameter parameter =
2449 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true); 2440 parser.parseFormalParameterList(inFunctionType: true).parameters[0];
2450 expectNotNullIfNoErrors(parameter); 2441 expectNotNullIfNoErrors(parameter);
2451 listener.assertErrorsWithCodes( 2442 listener.assertErrorsWithCodes(
2452 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]); 2443 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]);
2453 } 2444 }
2454 2445
2455 void test_defaultValueInFunctionType_named_equal() { 2446 void test_defaultValueInFunctionType_named_equal() {
2456 createParser('int x = 0'); 2447 createParser('({int x = 0})');
2457 FormalParameter parameter = 2448 FormalParameter parameter =
2458 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true); 2449 parser.parseFormalParameterList(inFunctionType: true).parameters[0];
2459 expectNotNullIfNoErrors(parameter); 2450 expectNotNullIfNoErrors(parameter);
2460 listener.assertErrorsWithCodes( 2451 listener.assertErrorsWithCodes(
2461 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]); 2452 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]);
2462 } 2453 }
2463 2454
2464 void test_defaultValueInFunctionType_positional() { 2455 void test_defaultValueInFunctionType_positional() {
2465 createParser('int x = 0'); 2456 createParser('([int x = 0])');
2466 FormalParameter parameter = parser 2457 FormalParameter parameter =
2467 .parseFormalParameter(ParameterKind.POSITIONAL, inFunctionType: true); 2458 parser.parseFormalParameterList(inFunctionType: true).parameters[0];
2468 expectNotNullIfNoErrors(parameter); 2459 expectNotNullIfNoErrors(parameter);
2469 listener.assertErrorsWithCodes( 2460 listener.assertErrorsWithCodes(
2470 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]); 2461 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]);
2471 } 2462 }
2472 2463
2473 void test_directiveAfterDeclaration_classBeforeDirective() { 2464 void test_directiveAfterDeclaration_classBeforeDirective() {
2474 CompilationUnit unit = parseCompilationUnit("class Foo{} library l;", 2465 CompilationUnit unit = parseCompilationUnit("class Foo{} library l;",
2475 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); 2466 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
2476 expect(unit, isNotNull); 2467 expect(unit, isNotNull);
2477 } 2468 }
(...skipping 12949 matching lines...) Expand 10 before | Expand all | Expand 10 after
15427 expectCommentText(typeVariable.documentationComment, '/// Doc'); 15418 expectCommentText(typeVariable.documentationComment, '/// Doc');
15428 } 15419 }
15429 15420
15430 /** 15421 /**
15431 * Assert that the given [name] is in declaration context. 15422 * Assert that the given [name] is in declaration context.
15432 */ 15423 */
15433 void _assertIsDeclarationName(SimpleIdentifier name) { 15424 void _assertIsDeclarationName(SimpleIdentifier name) {
15434 expect(name.inDeclarationContext(), isTrue); 15425 expect(name.inDeclarationContext(), isTrue);
15435 } 15426 }
15436 } 15427 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698