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

Unified Diff: pkg/analyzer/test/generated/parser_test.dart

Issue 1406253004: Lexical support for configurable imports (DEP 40) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
Index: pkg/analyzer/test/generated/parser_test.dart
diff --git a/pkg/analyzer/test/generated/parser_test.dart b/pkg/analyzer/test/generated/parser_test.dart
index 51e49416a3f3ff135984b366eafa3e9cab210d78..8053a55a74d4c9a3691d98d878e7d579d9b81422 100644
--- a/pkg/analyzer/test/generated/parser_test.dart
+++ b/pkg/analyzer/test/generated/parser_test.dart
@@ -16,7 +16,7 @@ import 'package:analyzer/src/generated/testing/ast_factory.dart';
import 'package:analyzer/src/generated/testing/element_factory.dart';
import 'package:analyzer/src/generated/testing/token_factory.dart';
import 'package:analyzer/src/generated/utilities_dart.dart';
-import 'package:unittest/unittest.dart';
+import 'package:unittest/unittest.dart' hide Configuration;
import '../reflective_tests.dart';
import '../utils.dart';
@@ -2590,6 +2590,12 @@ class ParserTestCase extends EngineTestCase {
static bool parseFunctionBodies = true;
/**
+ * A flag indicating whether conditional directives support should be enabled
+ * for a specific test.
+ */
+ bool enableConditionalDirectives = false;
+
+ /**
* A flag indicating whether generic method support should be enabled for a
* specific test.
*/
@@ -2644,6 +2650,7 @@ class ParserTestCase extends EngineTestCase {
// Parse the source.
//
Parser parser = createParser(listener);
+ parser.parseConditionalDirectives = enableConditionalDirectives;
parser.parseGenericMethods = enableGenericMethods;
parser.parseFunctionBodies = parseFunctionBodies;
Object result =
@@ -6887,6 +6894,54 @@ void''');
expect(expression.elseExpression, isNotNull);
}
+ void test_parseConfiguration_noOperator_dottedIdentifier() {
+ Configuration configuration =
+ parse4('parseConfiguration', "if (a.b) 'c.dart'");
+ expect(configuration.ifKeyword, isNotNull);
+ expect(configuration.leftParenthesis, isNotNull);
+ _expectDottedName(configuration.name, ["a", "b"]);
+ expect(configuration.equalToken, isNull);
+ expect(configuration.value, isNull);
+ expect(configuration.rightParenthesis, isNotNull);
+ expect(configuration.libraryUri, isNotNull);
+ }
+
+ void test_parseConfiguration_noOperator_simpleIdentifier() {
+ Configuration configuration =
+ parse4('parseConfiguration', "if (a) 'b.dart'");
+ expect(configuration.ifKeyword, isNotNull);
+ expect(configuration.leftParenthesis, isNotNull);
+ _expectDottedName(configuration.name, ["a"]);
+ expect(configuration.equalToken, isNull);
+ expect(configuration.value, isNull);
+ expect(configuration.rightParenthesis, isNotNull);
+ expect(configuration.libraryUri, isNotNull);
+ }
+
+ void test_parseConfiguration_operator_dottedIdentifier() {
+ Configuration configuration =
+ parse4('parseConfiguration', "if (a.b == 'c') 'd.dart'");
+ expect(configuration.ifKeyword, isNotNull);
+ expect(configuration.leftParenthesis, isNotNull);
+ _expectDottedName(configuration.name, ["a", "b"]);
+ expect(configuration.equalToken, isNotNull);
+ expect(configuration.value, isNotNull);
+ expect(configuration.rightParenthesis, isNotNull);
+ expect(configuration.libraryUri, isNotNull);
+ }
+
+ void test_parseConfiguration_operator_simpleIdentifier() {
+ Configuration configuration =
+ parse4('parseConfiguration', "if (a == 'b') 'c.dart'");
+ expect(configuration.ifKeyword, isNotNull);
+ expect(configuration.leftParenthesis, isNotNull);
+ _expectDottedName(configuration.name, ["a"]);
+ expect(configuration.equalToken, isNotNull);
+ expect(configuration.value, isNotNull);
+ expect(configuration.rightParenthesis, isNotNull);
+ expect(configuration.libraryUri, isNotNull);
+ }
+
void test_parseConstExpression_instanceCreation() {
InstanceCreationExpression expression =
parse4("parseConstExpression", "const A()");
@@ -7152,6 +7207,16 @@ void''');
expect(statement.semicolon, isNotNull);
}
+ void test_parseDottedName_multiple() {
+ DottedName name = parse4("parseDottedName", "a.b.c");
+ _expectDottedName(name, ["a", "b", "c"]);
+ }
+
+ void test_parseDottedName_single() {
+ DottedName name = parse4("parseDottedName", "a");
+ _expectDottedName(name, ["a"]);
+ }
+
void test_parseEmptyStatement() {
EmptyStatement statement = parse4("parseEmptyStatement", ";");
expect(statement.semicolon, isNotNull);
@@ -7208,6 +7273,32 @@ void''');
expect(expression.rightOperand, isNotNull);
}
+ void test_parseExportDirective_configuration_multiple() {
+ enableConditionalDirectives = true;
+ ExportDirective directive = parse(
+ "parseExportDirective",
+ <Object>[emptyCommentAndMetadata()],
+ "export 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';");
+ expect(directive.keyword, isNotNull);
+ expect(directive.uri, isNotNull);
+ // TODO(brianwilkerson) Test the configurations.
Paul Berry 2015/10/21 17:10:47 I'd recommend resolving these testing TODOs before
Brian Wilkerson 2015/10/21 20:05:23 Done
+ expect(directive.combinators, hasLength(0));
+ expect(directive.semicolon, isNotNull);
+ }
+
+ void test_parseExportDirective_configuration_single() {
+ enableConditionalDirectives = true;
+ ExportDirective directive = parse(
+ "parseExportDirective",
+ <Object>[emptyCommentAndMetadata()],
+ "export 'lib/lib.dart' if (a.b == 'c.dart') '';");
+ expect(directive.keyword, isNotNull);
+ expect(directive.uri, isNotNull);
+ // TODO(brianwilkerson) Test the configurations.
+ expect(directive.combinators, hasLength(0));
+ expect(directive.semicolon, isNotNull);
+ }
+
void test_parseExportDirective_hide() {
ExportDirective directive = parse(
"parseExportDirective",
@@ -8318,6 +8409,38 @@ void''');
expect(clause.implementsKeyword, isNotNull);
}
+ void test_parseImportDirective_configuration_multiple() {
+ enableConditionalDirectives = true;
+ ImportDirective directive = parse(
+ "parseImportDirective",
+ <Object>[emptyCommentAndMetadata()],
+ "import 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';");
+ expect(directive.keyword, isNotNull);
+ expect(directive.uri, isNotNull);
+ // TODO(brianwilkerson) Test the configurations.
+ expect(directive.deferredKeyword, isNull);
+ expect(directive.asKeyword, isNull);
+ expect(directive.prefix, isNull);
+ expect(directive.combinators, hasLength(0));
+ expect(directive.semicolon, isNotNull);
+ }
+
+ void test_parseImportDirective_configuration_single() {
+ enableConditionalDirectives = true;
+ ImportDirective directive = parse(
+ "parseImportDirective",
+ <Object>[emptyCommentAndMetadata()],
+ "import 'lib/lib.dart' if (a.b == 'c.dart') '';");
+ expect(directive.keyword, isNotNull);
+ expect(directive.uri, isNotNull);
+ // TODO(brianwilkerson) Test the configurations.
+ expect(directive.deferredKeyword, isNull);
+ expect(directive.asKeyword, isNull);
+ expect(directive.prefix, isNull);
+ expect(directive.combinators, hasLength(0));
+ expect(directive.semicolon, isNotNull);
+ }
+
void test_parseImportDirective_deferred() {
ImportDirective directive = parse(
"parseImportDirective",
@@ -10623,6 +10746,17 @@ void''');
return invokeParserMethod2("createSyntheticStringLiteral", "", listener);
}
+ void _expectDottedName(DottedName name, List<String> expectedComponents) {
+ int count = expectedComponents.length;
+ NodeList<SimpleIdentifier> components = name.components;
+ expect(components, hasLength(count));
+ for (int i = 0; i < count; i++) {
+ SimpleIdentifier component = components[i];
+ expect(component, isNotNull);
+ expect(component.name, expectedComponents[i]);
+ }
+ }
+
/**
* Invoke the method [Parser.isFunctionDeclaration] with the parser set to the token
* stream produced by scanning the given source.
« pkg/analyzer/lib/src/generated/parser.dart ('K') | « pkg/analyzer/lib/src/generated/visitors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698