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

Unified Diff: pkg/analyzer/test/src/dart/ast/utilities_test.dart

Issue 1612933006: Moved the AST related tests to their new locations (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/test/src/dart/ast/test_all.dart ('k') | pkg/analyzer/test/src/dart/element/element_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/dart/ast/utilities_test.dart
diff --git a/pkg/analyzer/test/generated/ast_test.dart b/pkg/analyzer/test/src/dart/ast/utilities_test.dart
similarity index 64%
rename from pkg/analyzer/test/generated/ast_test.dart
rename to pkg/analyzer/test/src/dart/ast/utilities_test.dart
index c4e4a684881d367142aea03cf76589300bc4dcc6..8531637beb8b09ffa7953272f014716bc8e5d0be 100644
--- a/pkg/analyzer/test/generated/ast_test.dart
+++ b/pkg/analyzer/test/src/dart/ast/utilities_test.dart
@@ -2,10 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library analyzer.test.generated.ast_test;
+library analyzer.test.src.dart.ast.utilities_test;
import 'package:analyzer/dart/ast/ast.dart';
-import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/java_engine.dart' show Predicate;
@@ -15,211 +14,17 @@ import 'package:analyzer/src/generated/testing/ast_factory.dart';
import 'package:analyzer/src/generated/testing/token_factory.dart';
import 'package:unittest/unittest.dart';
-import '../reflective_tests.dart';
-import '../utils.dart';
-import 'parser_test.dart' show ParserTestCase;
-import 'test_support.dart';
+import '../../../generated/parser_test.dart' show ParserTestCase;
+import '../../../generated/test_support.dart';
+import '../../../reflective_tests.dart';
+import '../../../utils.dart';
main() {
initializeTestEnvironment();
- runReflectiveTests(BreadthFirstVisitorTest);
- runReflectiveTests(ClassDeclarationTest);
- runReflectiveTests(ClassTypeAliasTest);
runReflectiveTests(ConstantEvaluatorTest);
- runReflectiveTests(ConstructorDeclarationTest);
- runReflectiveTests(FieldFormalParameterTest);
- runReflectiveTests(IndexExpressionTest);
- runReflectiveTests(NodeListTest);
runReflectiveTests(NodeLocatorTest);
runReflectiveTests(NodeLocator2Test);
- runReflectiveTests(SimpleIdentifierTest);
- runReflectiveTests(SimpleStringLiteralTest);
- runReflectiveTests(StringInterpolationTest);
runReflectiveTests(ToSourceVisitorTest);
- runReflectiveTests(VariableDeclarationTest);
-}
-
-class AssignmentKind extends Enum<AssignmentKind> {
- static const AssignmentKind BINARY = const AssignmentKind('BINARY', 0);
-
- static const AssignmentKind COMPOUND_LEFT =
- const AssignmentKind('COMPOUND_LEFT', 1);
-
- static const AssignmentKind COMPOUND_RIGHT =
- const AssignmentKind('COMPOUND_RIGHT', 2);
-
- static const AssignmentKind POSTFIX_INC =
- const AssignmentKind('POSTFIX_INC', 3);
-
- static const AssignmentKind PREFIX_DEC =
- const AssignmentKind('PREFIX_DEC', 4);
-
- static const AssignmentKind PREFIX_INC =
- const AssignmentKind('PREFIX_INC', 5);
-
- static const AssignmentKind PREFIX_NOT =
- const AssignmentKind('PREFIX_NOT', 6);
-
- static const AssignmentKind SIMPLE_LEFT =
- const AssignmentKind('SIMPLE_LEFT', 7);
-
- static const AssignmentKind SIMPLE_RIGHT =
- const AssignmentKind('SIMPLE_RIGHT', 8);
-
- static const AssignmentKind NONE = const AssignmentKind('NONE', 9);
-
- static const List<AssignmentKind> values = const [
- BINARY,
- COMPOUND_LEFT,
- COMPOUND_RIGHT,
- POSTFIX_INC,
- PREFIX_DEC,
- PREFIX_INC,
- PREFIX_NOT,
- SIMPLE_LEFT,
- SIMPLE_RIGHT,
- NONE
- ];
-
- const AssignmentKind(String name, int ordinal) : super(name, ordinal);
-}
-
-class BreadthFirstVisitor_BreadthFirstVisitorTest_testIt
- extends BreadthFirstVisitor<Object> {
- List<AstNode> nodes;
-
- BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(this.nodes) : super();
-
- @override
- Object visitNode(AstNode node) {
- nodes.add(node);
- return super.visitNode(node);
- }
-}
-
-@reflectiveTest
-class BreadthFirstVisitorTest extends ParserTestCase {
- void test_it() {
- String source = r'''
-class A {
- bool get g => true;
-}
-class B {
- int f() {
- num q() {
- return 3;
- }
- return q() + 4;
- }
-}
-A f(var p) {
- if ((p as A).g) {
- return p;
- } else {
- return null;
- }
-}''';
- CompilationUnit unit = ParserTestCase.parseCompilationUnit(source);
- List<AstNode> nodes = new List<AstNode>();
- BreadthFirstVisitor<Object> visitor =
- new BreadthFirstVisitor_BreadthFirstVisitorTest_testIt(nodes);
- visitor.visitAllNodes(unit);
- expect(nodes, hasLength(59));
- EngineTestCase.assertInstanceOf(
- (obj) => obj is CompilationUnit, CompilationUnit, nodes[0]);
- EngineTestCase.assertInstanceOf(
- (obj) => obj is ClassDeclaration, ClassDeclaration, nodes[2]);
- EngineTestCase.assertInstanceOf(
- (obj) => obj is FunctionDeclaration, FunctionDeclaration, nodes[3]);
- EngineTestCase.assertInstanceOf(
- (obj) => obj is FunctionDeclarationStatement,
- FunctionDeclarationStatement,
- nodes[27]);
- EngineTestCase.assertInstanceOf(
- (obj) => obj is IntegerLiteral, IntegerLiteral, nodes[58]);
- //3
- }
-}
-
-@reflectiveTest
-class ClassDeclarationTest extends ParserTestCase {
- void test_getConstructor() {
- List<ConstructorInitializer> initializers =
- new List<ConstructorInitializer>();
- ConstructorDeclaration defaultConstructor =
- AstFactory.constructorDeclaration(AstFactory.identifier3("Test"), null,
- AstFactory.formalParameterList(), initializers);
- ConstructorDeclaration aConstructor = AstFactory.constructorDeclaration(
- AstFactory.identifier3("Test"),
- "a",
- AstFactory.formalParameterList(),
- initializers);
- ConstructorDeclaration bConstructor = AstFactory.constructorDeclaration(
- AstFactory.identifier3("Test"),
- "b",
- AstFactory.formalParameterList(),
- initializers);
- ClassDeclaration clazz = AstFactory.classDeclaration(null, "Test", null,
- null, null, null, [defaultConstructor, aConstructor, bConstructor]);
- expect(clazz.getConstructor(null), same(defaultConstructor));
- expect(clazz.getConstructor("a"), same(aConstructor));
- expect(clazz.getConstructor("b"), same(bConstructor));
- expect(clazz.getConstructor("noSuchConstructor"), same(null));
- }
-
- void test_getField() {
- VariableDeclaration aVar = AstFactory.variableDeclaration("a");
- VariableDeclaration bVar = AstFactory.variableDeclaration("b");
- VariableDeclaration cVar = AstFactory.variableDeclaration("c");
- ClassDeclaration clazz =
- AstFactory.classDeclaration(null, "Test", null, null, null, null, [
- AstFactory.fieldDeclaration2(false, null, [aVar]),
- AstFactory.fieldDeclaration2(false, null, [bVar, cVar])
- ]);
- expect(clazz.getField("a"), same(aVar));
- expect(clazz.getField("b"), same(bVar));
- expect(clazz.getField("c"), same(cVar));
- expect(clazz.getField("noSuchField"), same(null));
- }
-
- void test_getMethod() {
- MethodDeclaration aMethod = AstFactory.methodDeclaration(null, null, null,
- null, AstFactory.identifier3("a"), AstFactory.formalParameterList());
- MethodDeclaration bMethod = AstFactory.methodDeclaration(null, null, null,
- null, AstFactory.identifier3("b"), AstFactory.formalParameterList());
- ClassDeclaration clazz = AstFactory.classDeclaration(
- null, "Test", null, null, null, null, [aMethod, bMethod]);
- expect(clazz.getMethod("a"), same(aMethod));
- expect(clazz.getMethod("b"), same(bMethod));
- expect(clazz.getMethod("noSuchMethod"), same(null));
- }
-
- void test_isAbstract() {
- expect(
- AstFactory
- .classDeclaration(null, "A", null, null, null, null)
- .isAbstract,
- isFalse);
- expect(
- AstFactory
- .classDeclaration(Keyword.ABSTRACT, "B", null, null, null, null)
- .isAbstract,
- isTrue);
- }
-}
-
-@reflectiveTest
-class ClassTypeAliasTest extends ParserTestCase {
- void test_isAbstract() {
- expect(
- AstFactory.classTypeAlias("A", null, null, null, null, null).isAbstract,
- isFalse);
- expect(
- AstFactory
- .classTypeAlias("B", null, Keyword.ABSTRACT, null, null, null)
- .isAbstract,
- isTrue);
- }
}
@reflectiveTest
@@ -527,427 +332,6 @@ class ConstantEvaluatorTest extends ParserTestCase {
}
@reflectiveTest
-class ConstructorDeclarationTest extends EngineTestCase {
- void test_firstTokenAfterCommentAndMetadata_all_inverted() {
- Token externalKeyword = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
- externalKeyword.offset = 14;
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- Keyword.CONST,
- Keyword.FACTORY,
- AstFactory.identifier3('int'),
- null,
- null,
- null,
- null);
- declaration.externalKeyword = externalKeyword;
- declaration.constKeyword.offset = 8;
- Token factoryKeyword = declaration.factoryKeyword;
- factoryKeyword.offset = 0;
- expect(declaration.firstTokenAfterCommentAndMetadata, factoryKeyword);
- }
-
- void test_firstTokenAfterCommentAndMetadata_all_normal() {
- Token token = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
- token.offset = 0;
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- Keyword.CONST,
- Keyword.FACTORY,
- AstFactory.identifier3('int'),
- null,
- null,
- null,
- null);
- declaration.externalKeyword = token;
- declaration.constKeyword.offset = 9;
- declaration.factoryKeyword.offset = 15;
- expect(declaration.firstTokenAfterCommentAndMetadata, token);
- }
-
- void test_firstTokenAfterCommentAndMetadata_constOnly() {
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- Keyword.CONST,
- null,
- AstFactory.identifier3('int'),
- null,
- null,
- null,
- null);
- expect(declaration.firstTokenAfterCommentAndMetadata,
- declaration.constKeyword);
- }
-
- void test_firstTokenAfterCommentAndMetadata_externalOnly() {
- Token externalKeyword = TokenFactory.tokenFromKeyword(Keyword.EXTERNAL);
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- null, null, AstFactory.identifier3('int'), null, null, null, null);
- declaration.externalKeyword = externalKeyword;
- expect(declaration.firstTokenAfterCommentAndMetadata, externalKeyword);
- }
-
- void test_firstTokenAfterCommentAndMetadata_factoryOnly() {
- ConstructorDeclaration declaration = AstFactory.constructorDeclaration2(
- null,
- Keyword.FACTORY,
- AstFactory.identifier3('int'),
- null,
- null,
- null,
- null);
- expect(declaration.firstTokenAfterCommentAndMetadata,
- declaration.factoryKeyword);
- }
-}
-
-@reflectiveTest
-class FieldFormalParameterTest extends EngineTestCase {
- void test_endToken_noParameters() {
- FieldFormalParameter parameter = AstFactory.fieldFormalParameter2('field');
- expect(parameter.endToken, parameter.identifier.endToken);
- }
-
- void test_endToken_parameters() {
- FieldFormalParameter parameter = AstFactory.fieldFormalParameter(
- null, null, 'field', AstFactory.formalParameterList([]));
- expect(parameter.endToken, parameter.parameters.endToken);
- }
-}
-
-@reflectiveTest
-class IndexExpressionTest extends EngineTestCase {
- void test_inGetterContext_assignment_compound_left() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] += c
- AstFactory.assignmentExpression(
- expression, TokenType.PLUS_EQ, AstFactory.identifier3("c"));
- expect(expression.inGetterContext(), isTrue);
- }
-
- void test_inGetterContext_assignment_simple_left() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] = c
- AstFactory.assignmentExpression(
- expression, TokenType.EQ, AstFactory.identifier3("c"));
- expect(expression.inGetterContext(), isFalse);
- }
-
- void test_inGetterContext_nonAssignment() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] + c
- AstFactory.binaryExpression(
- expression, TokenType.PLUS, AstFactory.identifier3("c"));
- expect(expression.inGetterContext(), isTrue);
- }
-
- void test_inSetterContext_assignment_compound_left() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] += c
- AstFactory.assignmentExpression(
- expression, TokenType.PLUS_EQ, AstFactory.identifier3("c"));
- expect(expression.inSetterContext(), isTrue);
- }
-
- void test_inSetterContext_assignment_compound_right() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // c += a[b]
- AstFactory.assignmentExpression(
- AstFactory.identifier3("c"), TokenType.PLUS_EQ, expression);
- expect(expression.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext_assignment_simple_left() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // a[b] = c
- AstFactory.assignmentExpression(
- expression, TokenType.EQ, AstFactory.identifier3("c"));
- expect(expression.inSetterContext(), isTrue);
- }
-
- void test_inSetterContext_assignment_simple_right() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // c = a[b]
- AstFactory.assignmentExpression(
- AstFactory.identifier3("c"), TokenType.EQ, expression);
- expect(expression.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext_nonAssignment() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- AstFactory.binaryExpression(
- expression, TokenType.PLUS, AstFactory.identifier3("c"));
- // a[b] + cc
- expect(expression.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext_postfix() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
- // a[b]++
- expect(expression.inSetterContext(), isTrue);
- }
-
- void test_inSetterContext_prefix_bang() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // !a[b]
- AstFactory.prefixExpression(TokenType.BANG, expression);
- expect(expression.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext_prefix_minusMinus() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // --a[b]
- AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
- expect(expression.inSetterContext(), isTrue);
- }
-
- void test_inSetterContext_prefix_plusPlus() {
- IndexExpression expression = AstFactory.indexExpression(
- AstFactory.identifier3("a"), AstFactory.identifier3("b"));
- // ++a[b]
- AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
- expect(expression.inSetterContext(), isTrue);
- }
-}
-
-@reflectiveTest
-class NodeListTest extends EngineTestCase {
- void test_add() {
- AstNode parent = AstFactory.argumentList();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- NodeList<AstNode> list = new NodeList<AstNode>(parent);
- list.insert(0, secondNode);
- list.insert(0, firstNode);
- expect(list, hasLength(2));
- expect(list[0], same(firstNode));
- expect(list[1], same(secondNode));
- expect(firstNode.parent, same(parent));
- expect(secondNode.parent, same(parent));
- AstNode thirdNode = AstFactory.booleanLiteral(false);
- list.insert(1, thirdNode);
- expect(list, hasLength(3));
- expect(list[0], same(firstNode));
- expect(list[1], same(thirdNode));
- expect(list[2], same(secondNode));
- expect(firstNode.parent, same(parent));
- expect(secondNode.parent, same(parent));
- expect(thirdNode.parent, same(parent));
- }
-
- void test_add_negative() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list.insert(-1, AstFactory.booleanLiteral(true));
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_add_tooBig() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list.insert(1, AstFactory.booleanLiteral(true));
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_addAll() {
- AstNode parent = AstFactory.argumentList();
- List<AstNode> firstNodes = new List<AstNode>();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- firstNodes.add(firstNode);
- firstNodes.add(secondNode);
- NodeList<AstNode> list = new NodeList<AstNode>(parent);
- list.addAll(firstNodes);
- expect(list, hasLength(2));
- expect(list[0], same(firstNode));
- expect(list[1], same(secondNode));
- expect(firstNode.parent, same(parent));
- expect(secondNode.parent, same(parent));
- List<AstNode> secondNodes = new List<AstNode>();
- AstNode thirdNode = AstFactory.booleanLiteral(true);
- AstNode fourthNode = AstFactory.booleanLiteral(false);
- secondNodes.add(thirdNode);
- secondNodes.add(fourthNode);
- list.addAll(secondNodes);
- expect(list, hasLength(4));
- expect(list[0], same(firstNode));
- expect(list[1], same(secondNode));
- expect(list[2], same(thirdNode));
- expect(list[3], same(fourthNode));
- expect(firstNode.parent, same(parent));
- expect(secondNode.parent, same(parent));
- expect(thirdNode.parent, same(parent));
- expect(fourthNode.parent, same(parent));
- }
-
- void test_creation() {
- AstNode owner = AstFactory.argumentList();
- NodeList<AstNode> list = new NodeList<AstNode>(owner);
- expect(list, isNotNull);
- expect(list, hasLength(0));
- expect(list.owner, same(owner));
- }
-
- void test_get_negative() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list[-1];
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_get_tooBig() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list[1];
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_getBeginToken_empty() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- expect(list.beginToken, isNull);
- }
-
- void test_getBeginToken_nonEmpty() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- AstNode node =
- AstFactory.parenthesizedExpression(AstFactory.booleanLiteral(true));
- list.add(node);
- expect(list.beginToken, same(node.beginToken));
- }
-
- void test_getEndToken_empty() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- expect(list.endToken, isNull);
- }
-
- void test_getEndToken_nonEmpty() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- AstNode node =
- AstFactory.parenthesizedExpression(AstFactory.booleanLiteral(true));
- list.add(node);
- expect(list.endToken, same(node.endToken));
- }
-
- void test_indexOf() {
- List<AstNode> nodes = new List<AstNode>();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- AstNode thirdNode = AstFactory.booleanLiteral(true);
- AstNode fourthNode = AstFactory.booleanLiteral(false);
- nodes.add(firstNode);
- nodes.add(secondNode);
- nodes.add(thirdNode);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- list.addAll(nodes);
- expect(list, hasLength(3));
- expect(list.indexOf(firstNode), 0);
- expect(list.indexOf(secondNode), 1);
- expect(list.indexOf(thirdNode), 2);
- expect(list.indexOf(fourthNode), -1);
- expect(list.indexOf(null), -1);
- }
-
- void test_remove() {
- List<AstNode> nodes = new List<AstNode>();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- AstNode thirdNode = AstFactory.booleanLiteral(true);
- nodes.add(firstNode);
- nodes.add(secondNode);
- nodes.add(thirdNode);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- list.addAll(nodes);
- expect(list, hasLength(3));
- expect(list.removeAt(1), same(secondNode));
- expect(list, hasLength(2));
- expect(list[0], same(firstNode));
- expect(list[1], same(thirdNode));
- }
-
- void test_remove_negative() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list.removeAt(-1);
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_remove_tooBig() {
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- list.removeAt(1);
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_set() {
- List<AstNode> nodes = new List<AstNode>();
- AstNode firstNode = AstFactory.booleanLiteral(true);
- AstNode secondNode = AstFactory.booleanLiteral(false);
- AstNode thirdNode = AstFactory.booleanLiteral(true);
- nodes.add(firstNode);
- nodes.add(secondNode);
- nodes.add(thirdNode);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- list.addAll(nodes);
- expect(list, hasLength(3));
- AstNode fourthNode = AstFactory.integer(0);
- expect(javaListSet(list, 1, fourthNode), same(secondNode));
- expect(list, hasLength(3));
- expect(list[0], same(firstNode));
- expect(list[1], same(fourthNode));
- expect(list[2], same(thirdNode));
- }
-
- void test_set_negative() {
- AstNode node = AstFactory.booleanLiteral(true);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- javaListSet(list, -1, node);
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-
- void test_set_tooBig() {
- AstNode node = AstFactory.booleanLiteral(true);
- NodeList<AstNode> list = new NodeList<AstNode>(AstFactory.argumentList());
- try {
- javaListSet(list, 1, node);
- fail("Expected IndexOutOfBoundsException");
- } on RangeError {
- // Expected
- }
- }
-}
-
-@reflectiveTest
class NodeLocator2Test extends ParserTestCase {
void test_onlyStartOffset() {
String code = ' int vv; ';
@@ -1044,669 +428,6 @@ class B {}''');
}
@reflectiveTest
-class SimpleIdentifierTest extends ParserTestCase {
- void test_inDeclarationContext_catch_exception() {
- SimpleIdentifier identifier =
- AstFactory.catchClause("e").exceptionParameter;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_catch_stack() {
- SimpleIdentifier identifier =
- AstFactory.catchClause2("e", "s").stackTraceParameter;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_classDeclaration() {
- SimpleIdentifier identifier =
- AstFactory.classDeclaration(null, "C", null, null, null, null).name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_classTypeAlias() {
- SimpleIdentifier identifier =
- AstFactory.classTypeAlias("C", null, null, null, null, null).name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_constructorDeclaration() {
- SimpleIdentifier identifier = AstFactory
- .constructorDeclaration(AstFactory.identifier3("C"), "c", null, null)
- .name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_declaredIdentifier() {
- DeclaredIdentifier declaredIdentifier = AstFactory.declaredIdentifier3("v");
- SimpleIdentifier identifier = declaredIdentifier.identifier;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_enumConstantDeclaration() {
- EnumDeclaration enumDeclaration =
- AstFactory.enumDeclaration2('MyEnum', ['CONST']);
- SimpleIdentifier identifier = enumDeclaration.constants[0].name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_enumDeclaration() {
- EnumDeclaration enumDeclaration =
- AstFactory.enumDeclaration2('MyEnum', ['A', 'B', 'C']);
- SimpleIdentifier identifier = enumDeclaration.name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_fieldFormalParameter() {
- SimpleIdentifier identifier =
- AstFactory.fieldFormalParameter2("p").identifier;
- expect(identifier.inDeclarationContext(), isFalse);
- }
-
- void test_inDeclarationContext_functionDeclaration() {
- SimpleIdentifier identifier =
- AstFactory.functionDeclaration(null, null, "f", null).name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_functionTypeAlias() {
- SimpleIdentifier identifier =
- AstFactory.typeAlias(null, "F", null, null).name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_label_false() {
- SimpleIdentifier identifier =
- AstFactory.namedExpression2("l", AstFactory.integer(0)).name.label;
- expect(identifier.inDeclarationContext(), isFalse);
- }
-
- void test_inDeclarationContext_label_true() {
- Label label = AstFactory.label2("l");
- SimpleIdentifier identifier = label.label;
- AstFactory.labeledStatement([label], AstFactory.emptyStatement());
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_methodDeclaration() {
- SimpleIdentifier identifier = AstFactory.identifier3("m");
- AstFactory.methodDeclaration2(
- null, null, null, null, identifier, null, null);
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_prefix() {
- SimpleIdentifier identifier =
- AstFactory.importDirective3("uri", "pref").prefix;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_simpleFormalParameter() {
- SimpleIdentifier identifier =
- AstFactory.simpleFormalParameter3("p").identifier;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_typeParameter_bound() {
- TypeName bound = AstFactory.typeName4("A");
- SimpleIdentifier identifier = bound.name as SimpleIdentifier;
- AstFactory.typeParameter2("E", bound);
- expect(identifier.inDeclarationContext(), isFalse);
- }
-
- void test_inDeclarationContext_typeParameter_name() {
- SimpleIdentifier identifier = AstFactory.typeParameter("E").name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inDeclarationContext_variableDeclaration() {
- SimpleIdentifier identifier = AstFactory.variableDeclaration("v").name;
- expect(identifier.inDeclarationContext(), isTrue);
- }
-
- void test_inGetterContext() {
- for (WrapperKind wrapper in WrapperKind.values) {
- for (AssignmentKind assignment in AssignmentKind.values) {
- SimpleIdentifier identifier = _createIdentifier(wrapper, assignment);
- if (assignment == AssignmentKind.SIMPLE_LEFT &&
- wrapper != WrapperKind.PREFIXED_LEFT &&
- wrapper != WrapperKind.PROPERTY_LEFT) {
- if (identifier.inGetterContext()) {
- fail("Expected ${_topMostNode(identifier).toSource()} to be false");
- }
- } else {
- if (!identifier.inGetterContext()) {
- fail("Expected ${_topMostNode(identifier).toSource()} to be true");
- }
- }
- }
- }
- }
-
- void test_inGetterContext_forEachLoop() {
- SimpleIdentifier identifier = AstFactory.identifier3("a");
- Expression iterator = AstFactory.listLiteral();
- Statement body = AstFactory.block();
- AstFactory.forEachStatement2(identifier, iterator, body);
- expect(identifier.inGetterContext(), isFalse);
- }
-
- void test_inReferenceContext() {
- SimpleIdentifier identifier = AstFactory.identifier3("id");
- AstFactory.namedExpression(
- AstFactory.label(identifier), AstFactory.identifier3("_"));
- expect(identifier.inGetterContext(), isFalse);
- expect(identifier.inSetterContext(), isFalse);
- }
-
- void test_inSetterContext() {
- for (WrapperKind wrapper in WrapperKind.values) {
- for (AssignmentKind assignment in AssignmentKind.values) {
- SimpleIdentifier identifier = _createIdentifier(wrapper, assignment);
- if (wrapper == WrapperKind.PREFIXED_LEFT ||
- wrapper == WrapperKind.PROPERTY_LEFT ||
- assignment == AssignmentKind.BINARY ||
- assignment == AssignmentKind.COMPOUND_RIGHT ||
- assignment == AssignmentKind.PREFIX_NOT ||
- assignment == AssignmentKind.SIMPLE_RIGHT ||
- assignment == AssignmentKind.NONE) {
- if (identifier.inSetterContext()) {
- fail("Expected ${_topMostNode(identifier).toSource()} to be false");
- }
- } else {
- if (!identifier.inSetterContext()) {
- fail("Expected ${_topMostNode(identifier).toSource()} to be true");
- }
- }
- }
- }
- }
-
- void test_inSetterContext_forEachLoop() {
- SimpleIdentifier identifier = AstFactory.identifier3("a");
- Expression iterator = AstFactory.listLiteral();
- Statement body = AstFactory.block();
- AstFactory.forEachStatement2(identifier, iterator, body);
- expect(identifier.inSetterContext(), isTrue);
- }
-
- void test_isQualified_inMethodInvocation_noTarget() {
- MethodInvocation invocation =
- AstFactory.methodInvocation2("test", [AstFactory.identifier3("arg0")]);
- SimpleIdentifier identifier = invocation.methodName;
- expect(identifier.isQualified, isFalse);
- }
-
- void test_isQualified_inMethodInvocation_withTarget() {
- MethodInvocation invocation = AstFactory.methodInvocation(
- AstFactory.identifier3("target"),
- "test",
- [AstFactory.identifier3("arg0")]);
- SimpleIdentifier identifier = invocation.methodName;
- expect(identifier.isQualified, isTrue);
- }
-
- void test_isQualified_inPrefixedIdentifier_name() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.identifier4("prefix", identifier);
- expect(identifier.isQualified, isTrue);
- }
-
- void test_isQualified_inPrefixedIdentifier_prefix() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.identifier(identifier, AstFactory.identifier3("name"));
- expect(identifier.isQualified, isFalse);
- }
-
- void test_isQualified_inPropertyAccess_name() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.propertyAccess(AstFactory.identifier3("target"), identifier);
- expect(identifier.isQualified, isTrue);
- }
-
- void test_isQualified_inPropertyAccess_target() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.propertyAccess(identifier, AstFactory.identifier3("name"));
- expect(identifier.isQualified, isFalse);
- }
-
- void test_isQualified_inReturnStatement() {
- SimpleIdentifier identifier = AstFactory.identifier3("test");
- AstFactory.returnStatement2(identifier);
- expect(identifier.isQualified, isFalse);
- }
-
- SimpleIdentifier _createIdentifier(
- WrapperKind wrapper, AssignmentKind assignment) {
- SimpleIdentifier identifier = AstFactory.identifier3("a");
- Expression expression = identifier;
- while (true) {
- if (wrapper == WrapperKind.PREFIXED_LEFT) {
- expression =
- AstFactory.identifier(identifier, AstFactory.identifier3("_"));
- } else if (wrapper == WrapperKind.PREFIXED_RIGHT) {
- expression =
- AstFactory.identifier(AstFactory.identifier3("_"), identifier);
- } else if (wrapper == WrapperKind.PROPERTY_LEFT) {
- expression = AstFactory.propertyAccess2(expression, "_");
- } else if (wrapper == WrapperKind.PROPERTY_RIGHT) {
- expression =
- AstFactory.propertyAccess(AstFactory.identifier3("_"), identifier);
- } else if (wrapper == WrapperKind.NONE) {}
- break;
- }
- while (true) {
- if (assignment == AssignmentKind.BINARY) {
- AstFactory.binaryExpression(
- expression, TokenType.PLUS, AstFactory.identifier3("_"));
- } else if (assignment == AssignmentKind.COMPOUND_LEFT) {
- AstFactory.assignmentExpression(
- expression, TokenType.PLUS_EQ, AstFactory.identifier3("_"));
- } else if (assignment == AssignmentKind.COMPOUND_RIGHT) {
- AstFactory.assignmentExpression(
- AstFactory.identifier3("_"), TokenType.PLUS_EQ, expression);
- } else if (assignment == AssignmentKind.POSTFIX_INC) {
- AstFactory.postfixExpression(expression, TokenType.PLUS_PLUS);
- } else if (assignment == AssignmentKind.PREFIX_DEC) {
- AstFactory.prefixExpression(TokenType.MINUS_MINUS, expression);
- } else if (assignment == AssignmentKind.PREFIX_INC) {
- AstFactory.prefixExpression(TokenType.PLUS_PLUS, expression);
- } else if (assignment == AssignmentKind.PREFIX_NOT) {
- AstFactory.prefixExpression(TokenType.BANG, expression);
- } else if (assignment == AssignmentKind.SIMPLE_LEFT) {
- AstFactory.assignmentExpression(
- expression, TokenType.EQ, AstFactory.identifier3("_"));
- } else if (assignment == AssignmentKind.SIMPLE_RIGHT) {
- AstFactory.assignmentExpression(
- AstFactory.identifier3("_"), TokenType.EQ, expression);
- } else if (assignment == AssignmentKind.NONE) {}
- break;
- }
- return identifier;
- }
-
- /**
- * Return the top-most node in the AST structure containing the given identifier.
- *
- * @param identifier the identifier in the AST structure being traversed
- * @return the root of the AST structure containing the identifier
- */
- AstNode _topMostNode(SimpleIdentifier identifier) {
- AstNode child = identifier;
- AstNode parent = identifier.parent;
- while (parent != null) {
- child = parent;
- parent = parent.parent;
- }
- return child;
- }
-}
-
-@reflectiveTest
-class SimpleStringLiteralTest extends ParserTestCase {
- void test_contentsEnd() {
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
- .contentsEnd,
- 2);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('"X"'), "X")
- .contentsEnd,
- 2);
-
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('"""X"""'), "X")
- .contentsEnd,
- 4);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
- .contentsEnd,
- 4);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("''' \nX'''"), "X")
- .contentsEnd,
- 7);
-
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
- .contentsEnd,
- 3);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('r"X"'), "X")
- .contentsEnd,
- 3);
-
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString('r"""X"""'), "X")
- .contentsEnd,
- 5);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
- .contentsEnd,
- 5);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("r''' \nX'''"), "X")
- .contentsEnd,
- 8);
- }
-
- void test_contentsOffset() {
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
- .contentsOffset,
- 1);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
- .contentsOffset,
- 1);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X")
- .contentsOffset,
- 3);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
- .contentsOffset,
- 3);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
- .contentsOffset,
- 2);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
- .contentsOffset,
- 2);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X")
- .contentsOffset,
- 4);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
- .contentsOffset,
- 4);
- // leading whitespace
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("''' \ \nX''"), "X")
- .contentsOffset,
- 6);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString('r""" \ \nX"""'), "X")
- .contentsOffset,
- 7);
- }
-
- void test_isMultiline() {
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X")
- .isMultiline,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
- .isMultiline,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
- .isMultiline,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
- .isMultiline,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
- .isMultiline,
- isTrue);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
- .isMultiline,
- isTrue);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X")
- .isMultiline,
- isTrue);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X")
- .isMultiline,
- isTrue);
- }
-
- void test_isRaw() {
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'X'"), "X").isRaw,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("\"X\""), "X")
- .isRaw,
- isFalse);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("\"\"\"X\"\"\""), "X")
- .isRaw,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("'''X'''"), "X")
- .isRaw,
- isFalse);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'X'"), "X")
- .isRaw,
- isTrue);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r\"X\""), "X")
- .isRaw,
- isTrue);
- expect(
- new SimpleStringLiteral(
- TokenFactory.tokenFromString("r\"\"\"X\"\"\""), "X")
- .isRaw,
- isTrue);
- expect(
- new SimpleStringLiteral(TokenFactory.tokenFromString("r'''X'''"), "X")
- .isRaw,
- isTrue);
- }
-
- void test_isSingleQuoted() {
- // '
- {
- var token = TokenFactory.tokenFromString("'X'");
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isTrue);
- }
- // '''
- {
- var token = TokenFactory.tokenFromString("'''X'''");
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isTrue);
- }
- // "
- {
- var token = TokenFactory.tokenFromString('"X"');
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isFalse);
- }
- // """
- {
- var token = TokenFactory.tokenFromString('"""X"""');
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isFalse);
- }
- }
-
- void test_isSingleQuoted_raw() {
- // r'
- {
- var token = TokenFactory.tokenFromString("r'X'");
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isTrue);
- }
- // r'''
- {
- var token = TokenFactory.tokenFromString("r'''X'''");
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isTrue);
- }
- // r"
- {
- var token = TokenFactory.tokenFromString('r"X"');
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isFalse);
- }
- // r"""
- {
- var token = TokenFactory.tokenFromString('r"""X"""');
- var node = new SimpleStringLiteral(token, null);
- expect(node.isSingleQuoted, isFalse);
- }
- }
-
- void test_simple() {
- Token token = TokenFactory.tokenFromString("'value'");
- SimpleStringLiteral stringLiteral = new SimpleStringLiteral(token, "value");
- expect(stringLiteral.literal, same(token));
- expect(stringLiteral.beginToken, same(token));
- expect(stringLiteral.endToken, same(token));
- expect(stringLiteral.value, "value");
- }
-}
-
-@reflectiveTest
-class StringInterpolationTest extends ParserTestCase {
- void test_contentsOffsetEnd() {
- AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
- // 'a${bb}ccc'
- {
- var ae = AstFactory.interpolationString("'a", "a");
- var cToken = new StringToken(TokenType.STRING, "ccc'", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 1);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // '''a${bb}ccc'''
- {
- var ae = AstFactory.interpolationString("'''a", "a");
- var cToken = new StringToken(TokenType.STRING, "ccc'''", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 3);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // """a${bb}ccc"""
- {
- var ae = AstFactory.interpolationString('"""a', "a");
- var cToken = new StringToken(TokenType.STRING, 'ccc"""', 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 3);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // r'a${bb}ccc'
- {
- var ae = AstFactory.interpolationString("r'a", "a");
- var cToken = new StringToken(TokenType.STRING, "ccc'", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 2);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // r'''a${bb}ccc'''
- {
- var ae = AstFactory.interpolationString("r'''a", "a");
- var cToken = new StringToken(TokenType.STRING, "ccc'''", 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 4);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- // r"""a${bb}ccc"""
- {
- var ae = AstFactory.interpolationString('r"""a', "a");
- var cToken = new StringToken(TokenType.STRING, 'ccc"""', 10);
- var cElement = new InterpolationString(cToken, 'ccc');
- StringInterpolation node = AstFactory.string([ae, ae, cElement]);
- expect(node.contentsOffset, 4);
- expect(node.contentsEnd, 10 + 4 - 1);
- }
- }
-
- void test_isMultiline() {
- var b = AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
- // '
- {
- var a = AstFactory.interpolationString("'a", "a");
- var c = AstFactory.interpolationString("ccc'", "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isMultiline, isFalse);
- }
- // '''
- {
- var a = AstFactory.interpolationString("'''a", "a");
- var c = AstFactory.interpolationString("ccc'''", "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isMultiline, isTrue);
- }
- // "
- {
- var a = AstFactory.interpolationString('"a', "a");
- var c = AstFactory.interpolationString('ccc"', "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isMultiline, isFalse);
- }
- // """
- {
- var a = AstFactory.interpolationString('"""a', "a");
- var c = AstFactory.interpolationString('ccc"""', "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isMultiline, isTrue);
- }
- }
-
- void test_isRaw() {
- StringInterpolation node = AstFactory.string();
- expect(node.isRaw, isFalse);
- }
-
- void test_isSingleQuoted() {
- var b = AstFactory.interpolationExpression(AstFactory.identifier3('bb'));
- // "
- {
- var a = AstFactory.interpolationString('"a', "a");
- var c = AstFactory.interpolationString('ccc"', "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isSingleQuoted, isFalse);
- }
- // """
- {
- var a = AstFactory.interpolationString('"""a', "a");
- var c = AstFactory.interpolationString('ccc"""', "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isSingleQuoted, isFalse);
- }
- // '
- {
- var a = AstFactory.interpolationString("'a", "a");
- var c = AstFactory.interpolationString("ccc'", "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isSingleQuoted, isTrue);
- }
- // '''
- {
- var a = AstFactory.interpolationString("'''a", "a");
- var c = AstFactory.interpolationString("ccc'''", "ccc");
- StringInterpolation node = AstFactory.string([a, b, c]);
- expect(node.isSingleQuoted, isTrue);
- }
- }
-}
-
-@reflectiveTest
class ToSourceVisitorTest extends EngineTestCase {
void test_visitAdjacentStrings() {
_assertSource(
@@ -3944,50 +2665,3 @@ class ToSourceVisitorTest extends EngineTestCase {
expect(writer.toString(), expectedSource);
}
}
-
-@reflectiveTest
-class VariableDeclarationTest extends ParserTestCase {
- void test_getDocumentationComment_onGrandParent() {
- VariableDeclaration varDecl = AstFactory.variableDeclaration("a");
- TopLevelVariableDeclaration decl =
- AstFactory.topLevelVariableDeclaration2(Keyword.VAR, [varDecl]);
- Comment comment = Comment.createDocumentationComment(new List<Token>(0));
- expect(varDecl.documentationComment, isNull);
- decl.documentationComment = comment;
- expect(varDecl.documentationComment, isNotNull);
- expect(decl.documentationComment, isNotNull);
- }
-
- void test_getDocumentationComment_onNode() {
- VariableDeclaration decl = AstFactory.variableDeclaration("a");
- Comment comment = Comment.createDocumentationComment(new List<Token>(0));
- decl.documentationComment = comment;
- expect(decl.documentationComment, isNotNull);
- }
-}
-
-class WrapperKind extends Enum<WrapperKind> {
- static const WrapperKind PREFIXED_LEFT =
- const WrapperKind('PREFIXED_LEFT', 0);
-
- static const WrapperKind PREFIXED_RIGHT =
- const WrapperKind('PREFIXED_RIGHT', 1);
-
- static const WrapperKind PROPERTY_LEFT =
- const WrapperKind('PROPERTY_LEFT', 2);
-
- static const WrapperKind PROPERTY_RIGHT =
- const WrapperKind('PROPERTY_RIGHT', 3);
-
- static const WrapperKind NONE = const WrapperKind('NONE', 4);
-
- static const List<WrapperKind> values = const [
- PREFIXED_LEFT,
- PREFIXED_RIGHT,
- PROPERTY_LEFT,
- PROPERTY_RIGHT,
- NONE
- ];
-
- const WrapperKind(String name, int ordinal) : super(name, ordinal);
-}
« no previous file with comments | « pkg/analyzer/test/src/dart/ast/test_all.dart ('k') | pkg/analyzer/test/src/dart/element/element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698