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

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

Issue 1309543011: Add support for assert statements with messages to the analyzer. Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address review comments. Created 5 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
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 library engine.parser_test; 5 library engine.parser_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 3203 matching lines...) Expand 10 before | Expand all | Expand 10 after
3214 } 3214 }
3215 3215
3216 void test_conditionalExpression_missingThen() { 3216 void test_conditionalExpression_missingThen() {
3217 ConditionalExpression expression = parse4("parseConditionalExpression", 3217 ConditionalExpression expression = parse4("parseConditionalExpression",
3218 "x ? : z", [ParserErrorCode.MISSING_IDENTIFIER]); 3218 "x ? : z", [ParserErrorCode.MISSING_IDENTIFIER]);
3219 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 3219 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3220 SimpleIdentifier, expression.thenExpression); 3220 SimpleIdentifier, expression.thenExpression);
3221 expect(expression.thenExpression.isSynthetic, isTrue); 3221 expect(expression.thenExpression.isSynthetic, isTrue);
3222 } 3222 }
3223 3223
3224 void test_declarationBeforeDirective() {
3225 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
3226 "class foo { } import 'bar.dart';",
3227 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
3228 expect(unit.directives, hasLength(1));
3229 expect(unit.declarations, hasLength(1));
3230 ClassDeclaration classDecl = unit.childEntities.first;
3231 expect(classDecl, isNotNull);
3232 expect(classDecl.name.name, 'foo');
3233 }
3234
3224 void test_equalityExpression_missing_LHS() { 3235 void test_equalityExpression_missing_LHS() {
3225 BinaryExpression expression = 3236 BinaryExpression expression =
3226 parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]); 3237 parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]);
3227 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 3238 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3228 SimpleIdentifier, expression.leftOperand); 3239 SimpleIdentifier, expression.leftOperand);
3229 expect(expression.leftOperand.isSynthetic, isTrue); 3240 expect(expression.leftOperand.isSynthetic, isTrue);
3230 } 3241 }
3231 3242
3232 void test_equalityExpression_missing_LHS_RHS() { 3243 void test_equalityExpression_missing_LHS_RHS() {
3233 BinaryExpression expression = parseExpression("==", [ 3244 BinaryExpression expression = parseExpression("==", [
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3331 NodeList<VariableDeclaration> vars = 3342 NodeList<VariableDeclaration> vars =
3332 (fieldDecl as FieldDeclaration).fields.variables; 3343 (fieldDecl as FieldDeclaration).fields.variables;
3333 expect(vars, hasLength(1)); 3344 expect(vars, hasLength(1));
3334 expect(vars[0].name.name, "v"); 3345 expect(vars[0].name.name, "v");
3335 } 3346 }
3336 3347
3337 void test_functionExpression_named() { 3348 void test_functionExpression_named() {
3338 parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]); 3349 parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]);
3339 } 3350 }
3340 3351
3341 void test_declarationBeforeDirective() {
3342 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
3343 "class foo { } import 'bar.dart';",
3344 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
3345 expect(unit.directives, hasLength(1));
3346 expect(unit.declarations, hasLength(1));
3347 ClassDeclaration classDecl = unit.childEntities.first;
3348 expect(classDecl, isNotNull);
3349 expect(classDecl.name.name, 'foo');
3350 }
3351
3352 void test_importDirectivePartial_as() { 3352 void test_importDirectivePartial_as() {
3353 CompilationUnit unit = ParserTestCase.parseCompilationUnit( 3353 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
3354 "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]); 3354 "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]);
3355 ImportDirective importDirective = unit.childEntities.first; 3355 ImportDirective importDirective = unit.childEntities.first;
3356 expect(importDirective.asKeyword, isNotNull); 3356 expect(importDirective.asKeyword, isNotNull);
3357 expect(unit.directives, hasLength(1)); 3357 expect(unit.directives, hasLength(1));
3358 expect(unit.declarations, hasLength(0)); 3358 expect(unit.declarations, hasLength(0));
3359 } 3359 }
3360 3360
3361 void test_importDirectivePartial_hide() { 3361 void test_importDirectivePartial_hide() {
(...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after
5038 ArgumentList argumentList = parse4("parseArgumentList", "(x: x, y: y)"); 5038 ArgumentList argumentList = parse4("parseArgumentList", "(x: x, y: y)");
5039 NodeList<Expression> arguments = argumentList.arguments; 5039 NodeList<Expression> arguments = argumentList.arguments;
5040 expect(arguments, hasLength(2)); 5040 expect(arguments, hasLength(2));
5041 } 5041 }
5042 5042
5043 void test_parseAssertStatement() { 5043 void test_parseAssertStatement() {
5044 AssertStatement statement = parse4("parseAssertStatement", "assert (x);"); 5044 AssertStatement statement = parse4("parseAssertStatement", "assert (x);");
5045 expect(statement.assertKeyword, isNotNull); 5045 expect(statement.assertKeyword, isNotNull);
5046 expect(statement.leftParenthesis, isNotNull); 5046 expect(statement.leftParenthesis, isNotNull);
5047 expect(statement.condition, isNotNull); 5047 expect(statement.condition, isNotNull);
5048 expect(statement.comma, isNull);
5049 expect(statement.message, isNull);
5048 expect(statement.rightParenthesis, isNotNull); 5050 expect(statement.rightParenthesis, isNotNull);
5049 expect(statement.semicolon, isNotNull); 5051 expect(statement.semicolon, isNotNull);
5050 } 5052 }
5053
5054 void test_parseAssertStatement_messageLowPrecedence() {
5055 // Using a throw expression as an assert message would be silly in
5056 // practice, but it's the lowest precedence expression type, so verifying
5057 // that it works should give us high confidence that other expression types
5058 // will work as well.
5059 AssertStatement statement =
5060 parse4('parseAssertStatement', 'assert (x, throw "foo");');
5061 expect(statement.assertKeyword, isNotNull);
5062 expect(statement.leftParenthesis, isNotNull);
5063 expect(statement.condition, isNotNull);
5064 expect(statement.comma, isNotNull);
5065 expect(statement.message, isNotNull);
5066 expect(statement.rightParenthesis, isNotNull);
5067 expect(statement.semicolon, isNotNull);
5068 }
5069
5070 void test_parseAssertStatement_messageString() {
5071 AssertStatement statement =
5072 parse4('parseAssertStatement', 'assert (x, "foo");');
5073 expect(statement.assertKeyword, isNotNull);
5074 expect(statement.leftParenthesis, isNotNull);
5075 expect(statement.condition, isNotNull);
5076 expect(statement.comma, isNotNull);
5077 expect(statement.message, isNotNull);
5078 expect(statement.rightParenthesis, isNotNull);
5079 expect(statement.semicolon, isNotNull);
5080 }
5051 5081
5052 void test_parseAssignableExpression_expression_args_dot() { 5082 void test_parseAssignableExpression_expression_args_dot() {
5053 PropertyAccess propertyAccess = 5083 PropertyAccess propertyAccess =
5054 parse("parseAssignableExpression", <Object>[false], "(x)(y).z"); 5084 parse("parseAssignableExpression", <Object>[false], "(x)(y).z");
5055 FunctionExpressionInvocation invocation = 5085 FunctionExpressionInvocation invocation =
5056 propertyAccess.target as FunctionExpressionInvocation; 5086 propertyAccess.target as FunctionExpressionInvocation;
5057 expect(invocation.function, isNotNull); 5087 expect(invocation.function, isNotNull);
5058 expect(invocation.typeArguments, isNull); 5088 expect(invocation.typeArguments, isNull);
5059 ArgumentList argumentList = invocation.argumentList; 5089 ArgumentList argumentList = invocation.argumentList;
5060 expect(argumentList, isNotNull); 5090 expect(argumentList, isNotNull);
(...skipping 5624 matching lines...) Expand 10 before | Expand all | Expand 10 after
10685 new Scanner(null, new CharSequenceReader(source), listener); 10715 new Scanner(null, new CharSequenceReader(source), listener);
10686 Token tokenStream = scanner.tokenize(); 10716 Token tokenStream = scanner.tokenize();
10687 // 10717 //
10688 // Parse the source. 10718 // Parse the source.
10689 // 10719 //
10690 Parser parser = new Parser(null, listener); 10720 Parser parser = new Parser(null, listener);
10691 return invokeParserMethodImpl( 10721 return invokeParserMethodImpl(
10692 parser, methodName, <Object>[tokenStream], tokenStream) as Token; 10722 parser, methodName, <Object>[tokenStream], tokenStream) as Token;
10693 } 10723 }
10694 } 10724 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698