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

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

Issue 3011553002: Add simple tests for Fasta parser (Closed)
Patch Set: Created 3 years, 4 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 08f0f7fde7c72dbcda2ed43493608964b831ef2b..adf2761ee91223cbb92a2dee687aa95861503d64 100644
--- a/pkg/analyzer/test/generated/parser_test.dart
+++ b/pkg/analyzer/test/generated/parser_test.dart
@@ -8728,7 +8728,9 @@ class ParserTestCase extends EngineTestCase
Scanner scanner =
new Scanner(null, new CharSequenceReader(source), listener);
scanner.scanGenericMethodComments = enableGenericMethodComments;
- scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators;
+ if (enableLazyAssignmentOperators != null) {
+ scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators;
+ }
listener.setLineInfo(new TestSource(), scanner.lineStarts);
Token token = scanner.tokenize();
Parser parser = new Parser(null, listener);
@@ -8833,13 +8835,16 @@ class ParserTestHelpers {
}
/**
- * The class `RecoveryParserTest` defines parser tests that test the parsing of
- * invalid code sequences to ensure that the correct recovery steps are taken in
- * the parser.
+ * Tests of the analyzer parser based on [RecoveryParserTestMixin].
*/
@reflectiveTest
class RecoveryParserTest extends ParserTestCase with RecoveryParserTestMixin {}
+/**
+ * The class `RecoveryParserTest` defines parser tests that test the parsing of
+ * invalid code sequences to ensure that the correct recovery steps are taken in
+ * the parser.
+ */
abstract class RecoveryParserTestMixin implements AbstractParserTestCase {
void test_additiveExpression_missing_LHS() {
BinaryExpression expression =
@@ -10036,14 +10041,10 @@ class C {
}
/**
- * The class `SimpleParserTest` defines parser tests that test individual parsing method. The
- * code fragments should be as minimal as possible in order to test the method, but should not test
- * the interactions between the method under test and other methods.
- *
- * More complex tests should be defined in the class [ComplexParserTest].
+ * Tests of the analyzer parser based on [SimpleParserTestMixin].
*/
@reflectiveTest
-class SimpleParserTest extends ParserTestCase {
+class SimpleParserTest extends ParserTestCase with SimpleParserTestMixin {
void test_computeStringValue_emptyInterpolationPrefix() {
expect(_computeStringValue("'''", true, false), "");
}
@@ -10332,745 +10333,975 @@ class SimpleParserTest extends ParserTestCase {
expect(_isSwitchMember("break;"), isFalse);
}
- void test_parseAnnotation_n1() {
- createParser('@A');
- Annotation annotation = parser.parseAnnotation();
- expectNotNullIfNoErrors(annotation);
- listener.assertNoErrors();
- expect(annotation.atSign, isNotNull);
- expect(annotation.name, isNotNull);
- expect(annotation.period, isNull);
- expect(annotation.constructorName, isNull);
- expect(annotation.arguments, isNull);
- }
-
- void test_parseAnnotation_n1_a() {
- createParser('@A(x,y)');
- Annotation annotation = parser.parseAnnotation();
- expectNotNullIfNoErrors(annotation);
- listener.assertNoErrors();
- expect(annotation.atSign, isNotNull);
- expect(annotation.name, isNotNull);
- expect(annotation.period, isNull);
- expect(annotation.constructorName, isNull);
- expect(annotation.arguments, isNotNull);
- }
-
- void test_parseAnnotation_n2() {
- createParser('@A.B');
- Annotation annotation = parser.parseAnnotation();
- expectNotNullIfNoErrors(annotation);
+ void test_parseCommentReference_new_prefixed() {
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('new a.b', 7);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- expect(annotation.atSign, isNotNull);
- expect(annotation.name, isNotNull);
- expect(annotation.period, isNull);
- expect(annotation.constructorName, isNull);
- expect(annotation.arguments, isNull);
+ expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>());
+ PrefixedIdentifier prefixedIdentifier = reference.identifier;
+ SimpleIdentifier prefix = prefixedIdentifier.prefix;
+ expect(prefix.token, isNotNull);
+ expect(prefix.name, "a");
+ expect(prefix.offset, 11);
+ expect(prefixedIdentifier.period, isNotNull);
+ SimpleIdentifier identifier = prefixedIdentifier.identifier;
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "b");
+ expect(identifier.offset, 13);
}
- void test_parseAnnotation_n2_a() {
- createParser('@A.B(x,y)');
- Annotation annotation = parser.parseAnnotation();
- expectNotNullIfNoErrors(annotation);
+ void test_parseCommentReference_new_simple() {
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('new a', 5);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- expect(annotation.atSign, isNotNull);
- expect(annotation.name, isNotNull);
- expect(annotation.period, isNull);
- expect(annotation.constructorName, isNull);
- expect(annotation.arguments, isNotNull);
+ expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
+ SimpleIdentifier identifier = reference.identifier;
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "a");
+ expect(identifier.offset, 9);
}
- void test_parseAnnotation_n3() {
- createParser('@A.B.C');
- Annotation annotation = parser.parseAnnotation();
- expectNotNullIfNoErrors(annotation);
+ void test_parseCommentReference_operator_withKeyword_notPrefixed() {
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('operator ==', 5);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- expect(annotation.atSign, isNotNull);
- expect(annotation.name, isNotNull);
- expect(annotation.period, isNotNull);
- expect(annotation.constructorName, isNotNull);
- expect(annotation.arguments, isNull);
+ expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
+ SimpleIdentifier identifier = reference.identifier;
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "==");
+ expect(identifier.offset, 14);
}
- void test_parseAnnotation_n3_a() {
- createParser('@A.B.C(x,y)');
- Annotation annotation = parser.parseAnnotation();
- expectNotNullIfNoErrors(annotation);
+ void test_parseCommentReference_operator_withKeyword_prefixed() {
+ createParser('');
+ CommentReference reference =
+ parser.parseCommentReference('Object.operator==', 7);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- expect(annotation.atSign, isNotNull);
- expect(annotation.name, isNotNull);
- expect(annotation.period, isNotNull);
- expect(annotation.constructorName, isNotNull);
- expect(annotation.arguments, isNotNull);
+ expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>());
+ PrefixedIdentifier prefixedIdentifier = reference.identifier;
+ SimpleIdentifier prefix = prefixedIdentifier.prefix;
+ expect(prefix.token, isNotNull);
+ expect(prefix.name, "Object");
+ expect(prefix.offset, 7);
+ expect(prefixedIdentifier.period, isNotNull);
+ SimpleIdentifier identifier = prefixedIdentifier.identifier;
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "==");
+ expect(identifier.offset, 22);
}
- void test_parseArgument_named() {
- createParser('n: x');
- Expression expression = parser.parseArgument();
- expectNotNullIfNoErrors(expression);
+ void test_parseCommentReference_operator_withoutKeyword_notPrefixed() {
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('==', 5);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- expect(expression, new isInstanceOf<NamedExpression>());
- NamedExpression namedExpression = expression;
- Label name = namedExpression.name;
- expect(name, isNotNull);
- expect(name.label, isNotNull);
- expect(name.colon, isNotNull);
- expect(namedExpression.expression, isNotNull);
+ expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
+ SimpleIdentifier identifier = reference.identifier;
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "==");
+ expect(identifier.offset, 5);
}
- void test_parseArgument_unnamed() {
- String lexeme = "x";
- createParser(lexeme);
- Expression expression = parser.parseArgument();
- expectNotNullIfNoErrors(expression);
+ void test_parseCommentReference_operator_withoutKeyword_prefixed() {
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('Object.==', 7);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- var identifier = expression as SimpleIdentifier;
- expect(identifier.name, lexeme);
+ expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>());
+ PrefixedIdentifier prefixedIdentifier = reference.identifier;
+ SimpleIdentifier prefix = prefixedIdentifier.prefix;
+ expect(prefix.token, isNotNull);
+ expect(prefix.name, "Object");
+ expect(prefix.offset, 7);
+ expect(prefixedIdentifier.period, isNotNull);
+ SimpleIdentifier identifier = prefixedIdentifier.identifier;
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "==");
+ expect(identifier.offset, 14);
}
- void test_parseArgumentList_empty() {
- createParser('()');
- ArgumentList argumentList = parser.parseArgumentList();
- expectNotNullIfNoErrors(argumentList);
+ void test_parseCommentReference_prefixed() {
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('a.b', 7);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- NodeList<Expression> arguments = argumentList.arguments;
- expect(arguments, hasLength(0));
+ expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>());
+ PrefixedIdentifier prefixedIdentifier = reference.identifier;
+ SimpleIdentifier prefix = prefixedIdentifier.prefix;
+ expect(prefix.token, isNotNull);
+ expect(prefix.name, "a");
+ expect(prefix.offset, 7);
+ expect(prefixedIdentifier.period, isNotNull);
+ SimpleIdentifier identifier = prefixedIdentifier.identifier;
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "b");
+ expect(identifier.offset, 9);
}
- void test_parseArgumentList_mixed() {
- createParser('(w, x, y: y, z: z)');
- ArgumentList argumentList = parser.parseArgumentList();
- expectNotNullIfNoErrors(argumentList);
+ void test_parseCommentReference_simple() {
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('a', 5);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- NodeList<Expression> arguments = argumentList.arguments;
- expect(arguments, hasLength(4));
+ expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
+ SimpleIdentifier identifier = reference.identifier;
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "a");
+ expect(identifier.offset, 5);
}
- void test_parseArgumentList_noNamed() {
- createParser('(x, y, z)');
- ArgumentList argumentList = parser.parseArgumentList();
- expectNotNullIfNoErrors(argumentList);
+ void test_parseCommentReference_synthetic() {
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('', 5);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- NodeList<Expression> arguments = argumentList.arguments;
- expect(arguments, hasLength(3));
+ expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
+ SimpleIdentifier identifier = reference.identifier;
+ expect(identifier, isNotNull);
+ expect(identifier.isSynthetic, isTrue);
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "");
+ expect(identifier.offset, 5);
+ // Should end with EOF token.
+ Token nextToken = identifier.token.next;
+ expect(nextToken, isNotNull);
+ expect(nextToken.type, TokenType.EOF);
}
- void test_parseArgumentList_onlyNamed() {
- createParser('(x: x, y: y)');
- ArgumentList argumentList = parser.parseArgumentList();
- expectNotNullIfNoErrors(argumentList);
+ @failingTest
+ void test_parseCommentReference_this() {
+ // This fails because we are returning null from the method and asserting
+ // that the return value is not null.
+ createParser('');
+ CommentReference reference = parser.parseCommentReference('this', 5);
+ expectNotNullIfNoErrors(reference);
listener.assertNoErrors();
- NodeList<Expression> arguments = argumentList.arguments;
- expect(arguments, hasLength(2));
+ SimpleIdentifier identifier = EngineTestCase.assertInstanceOf(
+ (obj) => obj is SimpleIdentifier,
+ SimpleIdentifier,
+ reference.identifier);
+ expect(identifier.token, isNotNull);
+ expect(identifier.name, "a");
+ expect(identifier.offset, 5);
}
- void test_parseArgumentList_trailing_comma() {
- createParser('(x, y, z,)');
- ArgumentList argumentList = parser.parseArgumentList();
- expectNotNullIfNoErrors(argumentList);
+ void test_parseCommentReferences_multiLine() {
+ DocumentationCommentToken token = new DocumentationCommentToken(
+ TokenType.MULTI_LINE_COMMENT, "/** xxx [a] yyy [bb] zzz */", 3);
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[token];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
listener.assertNoErrors();
- NodeList<Expression> arguments = argumentList.arguments;
- expect(arguments, hasLength(3));
- }
-
- void test_parseCombinator_hide() {
- createParser('hide a;');
- Combinator combinator = parser.parseCombinator();
- expectNotNullIfNoErrors(combinator);
+ List<Token> tokenReferences = token.references;
+ expect(references, hasLength(2));
+ expect(tokenReferences, hasLength(2));
+ {
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 12);
+ // the reference is recorded in the comment token
+ Token referenceToken = tokenReferences[0];
+ expect(referenceToken.offset, 12);
+ expect(referenceToken.lexeme, 'a');
+ }
+ {
+ CommentReference reference = references[1];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 20);
+ // the reference is recorded in the comment token
+ Token referenceToken = tokenReferences[1];
+ expect(referenceToken.offset, 20);
+ expect(referenceToken.lexeme, 'bb');
+ }
+ }
+
+ void test_parseCommentReferences_notClosed_noIdentifier() {
+ DocumentationCommentToken docToken = new DocumentationCommentToken(
+ TokenType.MULTI_LINE_COMMENT, "/** [ some text", 5);
+ createParser('');
+ List<CommentReference> references =
+ parser.parseCommentReferences(<DocumentationCommentToken>[docToken]);
+ expectNotNullIfNoErrors(references);
listener.assertNoErrors();
- expect(combinator, new isInstanceOf<HideCombinator>());
- HideCombinator hideCombinator = combinator;
- expect(hideCombinator.keyword, isNotNull);
- expect(hideCombinator.hiddenNames, hasLength(1));
+ expect(docToken.references, hasLength(1));
+ expect(references, hasLength(1));
+ Token referenceToken = docToken.references[0];
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(docToken.references[0], same(reference.beginToken));
+ expect(reference.identifier, isNotNull);
+ expect(reference.identifier.isSynthetic, isTrue);
+ expect(reference.identifier.name, "");
+ // Should end with EOF token.
+ Token nextToken = referenceToken.next;
+ expect(nextToken, isNotNull);
+ expect(nextToken.type, TokenType.EOF);
}
- void test_parseCombinator_show() {
- createParser('show a;');
- Combinator combinator = parser.parseCombinator();
- expectNotNullIfNoErrors(combinator);
+ void test_parseCommentReferences_notClosed_withIdentifier() {
+ DocumentationCommentToken docToken = new DocumentationCommentToken(
+ TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some text", 5);
+ createParser('');
+ List<CommentReference> references =
+ parser.parseCommentReferences(<DocumentationCommentToken>[docToken]);
+ expectNotNullIfNoErrors(references);
listener.assertNoErrors();
- expect(combinator, new isInstanceOf<ShowCombinator>());
- ShowCombinator showCombinator = combinator;
- expect(showCombinator.keyword, isNotNull);
- expect(showCombinator.shownNames, hasLength(1));
+ expect(docToken.references, hasLength(1));
+ expect(references, hasLength(1));
+ Token referenceToken = docToken.references[0];
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(referenceToken, same(reference.beginToken));
+ expect(reference.identifier, isNotNull);
+ expect(reference.identifier.isSynthetic, isFalse);
+ expect(reference.identifier.name, "namePrefix");
+ // Should end with EOF token.
+ Token nextToken = referenceToken.next;
+ expect(nextToken, isNotNull);
+ expect(nextToken.type, TokenType.EOF);
+ }
+
+ void test_parseCommentReferences_singleLine() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(
+ TokenType.SINGLE_LINE_COMMENT, "/// xxx [a] yyy [b] zzz", 3),
+ new DocumentationCommentToken(
+ TokenType.SINGLE_LINE_COMMENT, "/// x [c]", 28)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, hasLength(3));
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 12);
+ reference = references[1];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 20);
+ reference = references[2];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 35);
+ }
+
+ void test_parseCommentReferences_skipCodeBlock_4spaces_block() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT,
+ "/**\n * a[i]\n * non-code line\n */", 3)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, isEmpty);
+ }
+
+ void test_parseCommentReferences_skipCodeBlock_4spaces_lines() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(
+ TokenType.SINGLE_LINE_COMMENT, "/// Code block:", 0),
+ new DocumentationCommentToken(
+ TokenType.SINGLE_LINE_COMMENT, "/// a[i] == b[i]", 0)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, isEmpty);
+ }
+
+ void test_parseCommentReferences_skipCodeBlock_bracketed() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(
+ TokenType.MULTI_LINE_COMMENT, "/** [:xxx [a] yyy:] [b] zzz */", 3)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, hasLength(1));
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 24);
+ }
+
+ void test_parseCommentReferences_skipCodeBlock_gitHub() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(
+ TokenType.MULTI_LINE_COMMENT, "/** `a[i]` and [b] */", 0)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, hasLength(1));
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 16);
+ }
+
+ void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(
+ TokenType.MULTI_LINE_COMMENT,
+ r'''
+/**
+ * First.
+ * ```dart
+ * Some [int] reference.
+ * ```
+ * Last.
+ */
+''',
+ 3)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, isEmpty);
+ }
+
+ void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine_lines() {
+ String commentText = r'''
+/// First.
+/// ```dart
+/// Some [int] reference.
+/// ```
+/// Last.
+''';
+ List<DocumentationCommentToken> tokens = commentText
+ .split('\n')
+ .map((line) => new DocumentationCommentToken(
+ TokenType.SINGLE_LINE_COMMENT, line, 0))
+ .toList();
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, isEmpty);
+ }
+
+ void test_parseCommentReferences_skipCodeBlock_gitHub_notTerminated() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(
+ TokenType.MULTI_LINE_COMMENT, "/** `a[i] and [b] */", 0)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, hasLength(2));
+ }
+
+ void test_parseCommentReferences_skipCodeBlock_spaces() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT,
+ "/**\n * a[i]\n * xxx [i] zzz\n */", 3)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, hasLength(1));
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 27);
+ }
+
+ void test_parseCommentReferences_skipLinkDefinition() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT,
+ "/** [a]: http://www.google.com (Google) [b] zzz */", 3)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, hasLength(1));
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 44);
+ }
+
+ void test_parseCommentReferences_skipLinked() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT,
+ "/** [a](http://www.google.com) [b] zzz */", 3)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, hasLength(1));
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 35);
+ }
+
+ void test_parseCommentReferences_skipReferenceLink() {
+ List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
+ new DocumentationCommentToken(
+ TokenType.MULTI_LINE_COMMENT, "/** [a][c] [b] zzz */", 3)
+ ];
+ createParser('');
+ List<CommentReference> references = parser.parseCommentReferences(tokens);
+ expectNotNullIfNoErrors(references);
+ listener.assertNoErrors();
+ expect(references, hasLength(1));
+ CommentReference reference = references[0];
+ expect(reference, isNotNull);
+ expect(reference.identifier, isNotNull);
+ expect(reference.offset, 15);
+ }
+
+ void test_Parser() {
+ expect(new Parser(null, null), isNotNull);
+ }
+
+ void test_skipPrefixedIdentifier_invalid() {
+ createParser('+');
+ Token following = parser.skipPrefixedIdentifier(parser.currentToken);
+ expect(following, isNull);
+ }
+
+ void test_skipPrefixedIdentifier_notPrefixed() {
+ createParser('a +');
+ Token following = parser.skipPrefixedIdentifier(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
+ }
+
+ void test_skipPrefixedIdentifier_prefixed() {
+ createParser('a.b +');
+ Token following = parser.skipPrefixedIdentifier(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
+ }
+
+ void test_skipReturnType_invalid() {
+ // TODO(eernst): `skipReturnType` eliminated, delete this test?
+ createParser('+');
+ Token following = parser.skipTypeAnnotation(parser.currentToken);
+ expect(following, isNull);
+ }
+
+ void test_skipReturnType_type() {
+ // TODO(eernst): `skipReturnType` eliminated, delete this test?
+ createParser('C +');
+ Token following = parser.skipTypeAnnotation(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
+ }
+
+ void test_skipReturnType_void() {
+ // TODO(eernst): `skipReturnType` eliminated, delete this test?
+ createParser('void +');
+ Token following = parser.skipTypeAnnotation(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
+ }
+
+ void test_skipSimpleIdentifier_identifier() {
+ createParser('i +');
+ Token following = parser.skipSimpleIdentifier(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
+ }
+
+ void test_skipSimpleIdentifier_invalid() {
+ createParser('9 +');
+ Token following = parser.skipSimpleIdentifier(parser.currentToken);
+ expect(following, isNull);
+ }
+
+ void test_skipSimpleIdentifier_pseudoKeyword() {
+ createParser('as +');
+ Token following = parser.skipSimpleIdentifier(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
+ }
+
+ void test_skipStringLiteral_adjacent() {
+ createParser("'a' 'b' +");
+ Token following = parser.skipStringLiteral(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
+ }
+
+ void test_skipStringLiteral_interpolated() {
+ createParser("'a\${b}c' +");
+ Token following = parser.skipStringLiteral(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
}
- void test_parseCombinators_h() {
- createParser('hide a;');
- List<Combinator> combinators = parser.parseCombinators();
- expectNotNullIfNoErrors(combinators);
- listener.assertNoErrors();
- expect(combinators, hasLength(1));
- HideCombinator combinator = combinators[0] as HideCombinator;
- expect(combinator, isNotNull);
- expect(combinator.keyword, isNotNull);
- expect(combinator.hiddenNames, hasLength(1));
+ void test_skipStringLiteral_invalid() {
+ createParser('a');
+ Token following = parser.skipStringLiteral(parser.currentToken);
+ expect(following, isNull);
}
- void test_parseCombinators_hs() {
- createParser('hide a show b;');
- List<Combinator> combinators = parser.parseCombinators();
- expectNotNullIfNoErrors(combinators);
- listener.assertNoErrors();
- expect(combinators, hasLength(2));
- HideCombinator hideCombinator = combinators[0] as HideCombinator;
- expect(hideCombinator, isNotNull);
- expect(hideCombinator.keyword, isNotNull);
- expect(hideCombinator.hiddenNames, hasLength(1));
- ShowCombinator showCombinator = combinators[1] as ShowCombinator;
- expect(showCombinator, isNotNull);
- expect(showCombinator.keyword, isNotNull);
- expect(showCombinator.shownNames, hasLength(1));
+ void test_skipStringLiteral_single() {
+ createParser("'a' +");
+ Token following = parser.skipStringLiteral(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
}
- void test_parseCombinators_hshs() {
- createParser('hide a show b hide c show d;');
- List<Combinator> combinators = parser.parseCombinators();
- expectNotNullIfNoErrors(combinators);
- listener.assertNoErrors();
- expect(combinators, hasLength(4));
+ void test_skipTypeArgumentList_invalid() {
+ createParser('+');
+ Token following = parser.skipTypeArgumentList(parser.currentToken);
+ expect(following, isNull);
}
- void test_parseCombinators_s() {
- createParser('show a;');
- List<Combinator> combinators = parser.parseCombinators();
- expectNotNullIfNoErrors(combinators);
- listener.assertNoErrors();
- expect(combinators, hasLength(1));
- ShowCombinator combinator = combinators[0] as ShowCombinator;
- expect(combinator, isNotNull);
- expect(combinator.keyword, isNotNull);
- expect(combinator.shownNames, hasLength(1));
+ void test_skipTypeArgumentList_multiple() {
+ createParser('<E, F, G> +');
+ Token following = parser.skipTypeArgumentList(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
}
- void test_parseCommentAndMetadata_c() {
- createParser('/** 1 */ void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
- listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNotNull);
- expect(commentAndMetadata.metadata, isNull);
+ void test_skipTypeArgumentList_single() {
+ createParser('<E> +');
+ Token following = parser.skipTypeArgumentList(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
}
- void test_parseCommentAndMetadata_cmc() {
- createParser('/** 1 */ @A /** 2 */ void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
- listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNotNull);
- expect(commentAndMetadata.metadata, hasLength(1));
+ void test_skipTypeName_invalid() {
+ createParser('+');
+ Token following = parser.skipTypeName(parser.currentToken);
+ expect(following, isNull);
}
- void test_parseCommentAndMetadata_cmcm() {
- createParser('/** 1 */ @A /** 2 */ @B void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
- listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNotNull);
- expect(commentAndMetadata.metadata, hasLength(2));
+ void test_skipTypeName_parameterized() {
+ createParser('C<E<F<G>>> +');
+ Token following = parser.skipTypeName(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
}
- void test_parseCommentAndMetadata_cmm() {
- createParser('/** 1 */ @A @B void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
- listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNotNull);
- expect(commentAndMetadata.metadata, hasLength(2));
+ void test_skipTypeName_simple() {
+ createParser('C +');
+ Token following = parser.skipTypeName(parser.currentToken);
+ expect(following, isNotNull);
+ expect(following.type, TokenType.PLUS);
}
- void test_parseCommentAndMetadata_m() {
- createParser('@A void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
+ /**
+ * Invoke the method [Parser.computeStringValue] with the given argument.
+ *
+ * @param lexeme the argument to the method
+ * @param first `true` if this is the first token in a string literal
+ * @param last `true` if this is the last token in a string literal
+ * @return the result of invoking the method
+ * @throws Exception if the method could not be invoked or throws an exception
+ */
+ String _computeStringValue(String lexeme, bool first, bool last) {
+ createParser('');
+ String value = parser.computeStringValue(lexeme, first, last);
listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNull);
- expect(commentAndMetadata.metadata, hasLength(1));
+ return value;
}
- void test_parseCommentAndMetadata_mcm() {
- createParser('@A /** 1 */ @B void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
- listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNotNull);
- expect(commentAndMetadata.metadata, hasLength(2));
+ /**
+ * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the token
+ * stream produced by scanning the given source.
+ *
+ * @param source the source to be scanned to produce the token stream being tested
+ * @return the result of invoking the method
+ * @throws Exception if the method could not be invoked or throws an exception
+ */
+ bool _isFunctionDeclaration(String source) {
+ createParser(source);
+ bool result = parser.isFunctionDeclaration();
+ expectNotNullIfNoErrors(result);
+ return result;
}
- void test_parseCommentAndMetadata_mcmc() {
- createParser('@A /** 1 */ @B /** 2 */ void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
- listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNotNull);
- expect(commentAndMetadata.metadata, hasLength(2));
+ /**
+ * Invoke the method [Parser.isFunctionExpression] with the parser set to the token stream
+ * produced by scanning the given source.
+ *
+ * @param source the source to be scanned to produce the token stream being tested
+ * @return the result of invoking the method
+ * @throws Exception if the method could not be invoked or throws an exception
+ */
+ bool _isFunctionExpression(String source) {
+ createParser(source);
+ return parser.isFunctionExpression(parser.currentToken);
}
- void test_parseCommentAndMetadata_mm() {
- createParser('@A @B(x) void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
- listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNull);
- expect(commentAndMetadata.metadata, hasLength(2));
+ /**
+ * Invoke the method [Parser.isInitializedVariableDeclaration] with the parser set to the
+ * token stream produced by scanning the given source.
+ *
+ * @param source the source to be scanned to produce the token stream being tested
+ * @return the result of invoking the method
+ * @throws Exception if the method could not be invoked or throws an exception
+ */
+ bool _isInitializedVariableDeclaration(String source) {
+ createParser(source);
+ bool result = parser.isInitializedVariableDeclaration();
+ expectNotNullIfNoErrors(result);
+ return result;
}
- void test_parseCommentAndMetadata_none() {
- createParser('void');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
- listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNull);
- expect(commentAndMetadata.metadata, isNull);
+ /**
+ * Invoke the method [Parser.isSwitchMember] with the parser set to the token stream
+ * produced by scanning the given source.
+ *
+ * @param source the source to be scanned to produce the token stream being tested
+ * @return the result of invoking the method
+ * @throws Exception if the method could not be invoked or throws an exception
+ */
+ bool _isSwitchMember(String source) {
+ createParser(source);
+ bool result = parser.isSwitchMember();
+ expectNotNullIfNoErrors(result);
+ return result;
}
+}
- void test_parseCommentAndMetadata_singleLine() {
- createParser(r'''
-/// 1
-/// 2
-void''');
- CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
- expectNotNullIfNoErrors(commentAndMetadata);
+/**
+ * Parser tests that test individual parsing methods. The code fragments should
+ * be as minimal as possible in order to test the method, but should not test
+ * the interactions between the method under test and other methods.
+ *
+ * More complex tests should be defined in the class [ComplexParserTest].
+ */
+abstract class SimpleParserTestMixin implements AbstractParserTestCase {
+ /**
+ * Parse the given [content] as a sequence of statements by enclosing it in a
+ * block. The [expectedCount] is the number of statements that are expected to
+ * be parsed. If [errorCodes] are provided, verify that the error codes of the
+ * errors that are expected are found.
+ */
+ void parseStatementList(String content, int expectedCount) {
+ Statement statement = parseStatement('{$content}');
+ expect(statement, new isInstanceOf<Block>());
+ Block block = statement;
+ expect(block.statements, hasLength(expectedCount));
+ }
+
+ void test_parseAnnotation_n1() {
+ createParser('@A');
+ Annotation annotation = parser.parseAnnotation();
+ expectNotNullIfNoErrors(annotation);
listener.assertNoErrors();
- expect(commentAndMetadata.comment, isNotNull);
- expect(commentAndMetadata.metadata, isNull);
+ expect(annotation.atSign, isNotNull);
+ expect(annotation.name, isNotNull);
+ expect(annotation.period, isNull);
+ expect(annotation.constructorName, isNull);
+ expect(annotation.arguments, isNull);
}
- void test_parseCommentReference_new_prefixed() {
- createParser('');
- CommentReference reference = parser.parseCommentReference('new a.b', 7);
- expectNotNullIfNoErrors(reference);
+ void test_parseAnnotation_n1_a() {
+ createParser('@A(x,y)');
+ Annotation annotation = parser.parseAnnotation();
+ expectNotNullIfNoErrors(annotation);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>());
- PrefixedIdentifier prefixedIdentifier = reference.identifier;
- SimpleIdentifier prefix = prefixedIdentifier.prefix;
- expect(prefix.token, isNotNull);
- expect(prefix.name, "a");
- expect(prefix.offset, 11);
- expect(prefixedIdentifier.period, isNotNull);
- SimpleIdentifier identifier = prefixedIdentifier.identifier;
- expect(identifier.token, isNotNull);
- expect(identifier.name, "b");
- expect(identifier.offset, 13);
+ expect(annotation.atSign, isNotNull);
+ expect(annotation.name, isNotNull);
+ expect(annotation.period, isNull);
+ expect(annotation.constructorName, isNull);
+ expect(annotation.arguments, isNotNull);
}
- void test_parseCommentReference_new_simple() {
- createParser('');
- CommentReference reference = parser.parseCommentReference('new a', 5);
- expectNotNullIfNoErrors(reference);
+ void test_parseAnnotation_n2() {
+ createParser('@A.B');
+ Annotation annotation = parser.parseAnnotation();
+ expectNotNullIfNoErrors(annotation);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
- SimpleIdentifier identifier = reference.identifier;
- expect(identifier.token, isNotNull);
- expect(identifier.name, "a");
- expect(identifier.offset, 9);
+ expect(annotation.atSign, isNotNull);
+ expect(annotation.name, isNotNull);
+ expect(annotation.period, isNull);
+ expect(annotation.constructorName, isNull);
+ expect(annotation.arguments, isNull);
}
- void test_parseCommentReference_operator_withKeyword_notPrefixed() {
- createParser('');
- CommentReference reference = parser.parseCommentReference('operator ==', 5);
- expectNotNullIfNoErrors(reference);
+ void test_parseAnnotation_n2_a() {
+ createParser('@A.B(x,y)');
+ Annotation annotation = parser.parseAnnotation();
+ expectNotNullIfNoErrors(annotation);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
- SimpleIdentifier identifier = reference.identifier;
- expect(identifier.token, isNotNull);
- expect(identifier.name, "==");
- expect(identifier.offset, 14);
+ expect(annotation.atSign, isNotNull);
+ expect(annotation.name, isNotNull);
+ expect(annotation.period, isNull);
+ expect(annotation.constructorName, isNull);
+ expect(annotation.arguments, isNotNull);
}
- void test_parseCommentReference_operator_withKeyword_prefixed() {
- createParser('');
- CommentReference reference =
- parser.parseCommentReference('Object.operator==', 7);
- expectNotNullIfNoErrors(reference);
+ void test_parseAnnotation_n3() {
+ createParser('@A.B.C');
+ Annotation annotation = parser.parseAnnotation();
+ expectNotNullIfNoErrors(annotation);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>());
- PrefixedIdentifier prefixedIdentifier = reference.identifier;
- SimpleIdentifier prefix = prefixedIdentifier.prefix;
- expect(prefix.token, isNotNull);
- expect(prefix.name, "Object");
- expect(prefix.offset, 7);
- expect(prefixedIdentifier.period, isNotNull);
- SimpleIdentifier identifier = prefixedIdentifier.identifier;
- expect(identifier.token, isNotNull);
- expect(identifier.name, "==");
- expect(identifier.offset, 22);
+ expect(annotation.atSign, isNotNull);
+ expect(annotation.name, isNotNull);
+ expect(annotation.period, isNotNull);
+ expect(annotation.constructorName, isNotNull);
+ expect(annotation.arguments, isNull);
}
- void test_parseCommentReference_operator_withoutKeyword_notPrefixed() {
- createParser('');
- CommentReference reference = parser.parseCommentReference('==', 5);
- expectNotNullIfNoErrors(reference);
+ void test_parseAnnotation_n3_a() {
+ createParser('@A.B.C(x,y)');
+ Annotation annotation = parser.parseAnnotation();
+ expectNotNullIfNoErrors(annotation);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
- SimpleIdentifier identifier = reference.identifier;
- expect(identifier.token, isNotNull);
- expect(identifier.name, "==");
- expect(identifier.offset, 5);
+ expect(annotation.atSign, isNotNull);
+ expect(annotation.name, isNotNull);
+ expect(annotation.period, isNotNull);
+ expect(annotation.constructorName, isNotNull);
+ expect(annotation.arguments, isNotNull);
}
- void test_parseCommentReference_operator_withoutKeyword_prefixed() {
- createParser('');
- CommentReference reference = parser.parseCommentReference('Object.==', 7);
- expectNotNullIfNoErrors(reference);
+ void test_parseArgument_named() {
+ createParser('n: x');
+ Expression expression = parser.parseArgument();
+ expectNotNullIfNoErrors(expression);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>());
- PrefixedIdentifier prefixedIdentifier = reference.identifier;
- SimpleIdentifier prefix = prefixedIdentifier.prefix;
- expect(prefix.token, isNotNull);
- expect(prefix.name, "Object");
- expect(prefix.offset, 7);
- expect(prefixedIdentifier.period, isNotNull);
- SimpleIdentifier identifier = prefixedIdentifier.identifier;
- expect(identifier.token, isNotNull);
- expect(identifier.name, "==");
- expect(identifier.offset, 14);
+ expect(expression, new isInstanceOf<NamedExpression>());
+ NamedExpression namedExpression = expression;
+ Label name = namedExpression.name;
+ expect(name, isNotNull);
+ expect(name.label, isNotNull);
+ expect(name.colon, isNotNull);
+ expect(namedExpression.expression, isNotNull);
}
- void test_parseCommentReference_prefixed() {
- createParser('');
- CommentReference reference = parser.parseCommentReference('a.b', 7);
- expectNotNullIfNoErrors(reference);
+ void test_parseArgument_unnamed() {
+ String lexeme = "x";
+ createParser(lexeme);
+ Expression expression = parser.parseArgument();
+ expectNotNullIfNoErrors(expression);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>());
- PrefixedIdentifier prefixedIdentifier = reference.identifier;
- SimpleIdentifier prefix = prefixedIdentifier.prefix;
- expect(prefix.token, isNotNull);
- expect(prefix.name, "a");
- expect(prefix.offset, 7);
- expect(prefixedIdentifier.period, isNotNull);
- SimpleIdentifier identifier = prefixedIdentifier.identifier;
- expect(identifier.token, isNotNull);
- expect(identifier.name, "b");
- expect(identifier.offset, 9);
+ var identifier = expression as SimpleIdentifier;
+ expect(identifier.name, lexeme);
}
- void test_parseCommentReference_simple() {
- createParser('');
- CommentReference reference = parser.parseCommentReference('a', 5);
- expectNotNullIfNoErrors(reference);
+ void test_parseArgumentList_empty() {
+ createParser('()');
+ ArgumentList argumentList = parser.parseArgumentList();
+ expectNotNullIfNoErrors(argumentList);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
- SimpleIdentifier identifier = reference.identifier;
- expect(identifier.token, isNotNull);
- expect(identifier.name, "a");
- expect(identifier.offset, 5);
+ NodeList<Expression> arguments = argumentList.arguments;
+ expect(arguments, hasLength(0));
}
- void test_parseCommentReference_synthetic() {
- createParser('');
- CommentReference reference = parser.parseCommentReference('', 5);
- expectNotNullIfNoErrors(reference);
+ void test_parseArgumentList_mixed() {
+ createParser('(w, x, y: y, z: z)');
+ ArgumentList argumentList = parser.parseArgumentList();
+ expectNotNullIfNoErrors(argumentList);
listener.assertNoErrors();
- expect(reference.identifier, new isInstanceOf<SimpleIdentifier>());
- SimpleIdentifier identifier = reference.identifier;
- expect(identifier, isNotNull);
- expect(identifier.isSynthetic, isTrue);
- expect(identifier.token, isNotNull);
- expect(identifier.name, "");
- expect(identifier.offset, 5);
- // Should end with EOF token.
- Token nextToken = identifier.token.next;
- expect(nextToken, isNotNull);
- expect(nextToken.type, TokenType.EOF);
+ NodeList<Expression> arguments = argumentList.arguments;
+ expect(arguments, hasLength(4));
}
- @failingTest
- void test_parseCommentReference_this() {
- // This fails because we are returning null from the method and asserting
- // that the return value is not null.
- createParser('');
- CommentReference reference = parser.parseCommentReference('this', 5);
- expectNotNullIfNoErrors(reference);
+ void test_parseArgumentList_noNamed() {
+ createParser('(x, y, z)');
+ ArgumentList argumentList = parser.parseArgumentList();
+ expectNotNullIfNoErrors(argumentList);
listener.assertNoErrors();
- SimpleIdentifier identifier = EngineTestCase.assertInstanceOf(
- (obj) => obj is SimpleIdentifier,
- SimpleIdentifier,
- reference.identifier);
- expect(identifier.token, isNotNull);
- expect(identifier.name, "a");
- expect(identifier.offset, 5);
+ NodeList<Expression> arguments = argumentList.arguments;
+ expect(arguments, hasLength(3));
}
- void test_parseCommentReferences_multiLine() {
- DocumentationCommentToken token = new DocumentationCommentToken(
- TokenType.MULTI_LINE_COMMENT, "/** xxx [a] yyy [bb] zzz */", 3);
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[token];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseArgumentList_onlyNamed() {
+ createParser('(x: x, y: y)');
+ ArgumentList argumentList = parser.parseArgumentList();
+ expectNotNullIfNoErrors(argumentList);
listener.assertNoErrors();
- List<Token> tokenReferences = token.references;
- expect(references, hasLength(2));
- expect(tokenReferences, hasLength(2));
- {
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 12);
- // the reference is recorded in the comment token
- Token referenceToken = tokenReferences[0];
- expect(referenceToken.offset, 12);
- expect(referenceToken.lexeme, 'a');
- }
- {
- CommentReference reference = references[1];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 20);
- // the reference is recorded in the comment token
- Token referenceToken = tokenReferences[1];
- expect(referenceToken.offset, 20);
- expect(referenceToken.lexeme, 'bb');
- }
+ NodeList<Expression> arguments = argumentList.arguments;
+ expect(arguments, hasLength(2));
}
- void test_parseCommentReferences_notClosed_noIdentifier() {
- DocumentationCommentToken docToken = new DocumentationCommentToken(
- TokenType.MULTI_LINE_COMMENT, "/** [ some text", 5);
- createParser('');
- List<CommentReference> references =
- parser.parseCommentReferences(<DocumentationCommentToken>[docToken]);
- expectNotNullIfNoErrors(references);
+ void test_parseArgumentList_trailing_comma() {
+ createParser('(x, y, z,)');
+ ArgumentList argumentList = parser.parseArgumentList();
+ expectNotNullIfNoErrors(argumentList);
listener.assertNoErrors();
- expect(docToken.references, hasLength(1));
- expect(references, hasLength(1));
- Token referenceToken = docToken.references[0];
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(docToken.references[0], same(reference.beginToken));
- expect(reference.identifier, isNotNull);
- expect(reference.identifier.isSynthetic, isTrue);
- expect(reference.identifier.name, "");
- // Should end with EOF token.
- Token nextToken = referenceToken.next;
- expect(nextToken, isNotNull);
- expect(nextToken.type, TokenType.EOF);
+ NodeList<Expression> arguments = argumentList.arguments;
+ expect(arguments, hasLength(3));
+ }
+
+ void test_parseCombinator_hide() {
+ createParser('hide a;');
+ Combinator combinator = parser.parseCombinator();
+ expectNotNullIfNoErrors(combinator);
+ listener.assertNoErrors();
+ expect(combinator, new isInstanceOf<HideCombinator>());
+ HideCombinator hideCombinator = combinator;
+ expect(hideCombinator.keyword, isNotNull);
+ expect(hideCombinator.hiddenNames, hasLength(1));
}
- void test_parseCommentReferences_notClosed_withIdentifier() {
- DocumentationCommentToken docToken = new DocumentationCommentToken(
- TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some text", 5);
- createParser('');
- List<CommentReference> references =
- parser.parseCommentReferences(<DocumentationCommentToken>[docToken]);
- expectNotNullIfNoErrors(references);
+ void test_parseCombinator_show() {
+ createParser('show a;');
+ Combinator combinator = parser.parseCombinator();
+ expectNotNullIfNoErrors(combinator);
listener.assertNoErrors();
- expect(docToken.references, hasLength(1));
- expect(references, hasLength(1));
- Token referenceToken = docToken.references[0];
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(referenceToken, same(reference.beginToken));
- expect(reference.identifier, isNotNull);
- expect(reference.identifier.isSynthetic, isFalse);
- expect(reference.identifier.name, "namePrefix");
- // Should end with EOF token.
- Token nextToken = referenceToken.next;
- expect(nextToken, isNotNull);
- expect(nextToken.type, TokenType.EOF);
+ expect(combinator, new isInstanceOf<ShowCombinator>());
+ ShowCombinator showCombinator = combinator;
+ expect(showCombinator.keyword, isNotNull);
+ expect(showCombinator.shownNames, hasLength(1));
}
- void test_parseCommentReferences_singleLine() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(
- TokenType.SINGLE_LINE_COMMENT, "/// xxx [a] yyy [b] zzz", 3),
- new DocumentationCommentToken(
- TokenType.SINGLE_LINE_COMMENT, "/// x [c]", 28)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCombinators_h() {
+ createParser('hide a;');
+ List<Combinator> combinators = parser.parseCombinators();
+ expectNotNullIfNoErrors(combinators);
listener.assertNoErrors();
- expect(references, hasLength(3));
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 12);
- reference = references[1];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 20);
- reference = references[2];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 35);
+ expect(combinators, hasLength(1));
+ HideCombinator combinator = combinators[0] as HideCombinator;
+ expect(combinator, isNotNull);
+ expect(combinator.keyword, isNotNull);
+ expect(combinator.hiddenNames, hasLength(1));
}
- void test_parseCommentReferences_skipCodeBlock_4spaces_block() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT,
- "/**\n * a[i]\n * non-code line\n */", 3)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCombinators_hs() {
+ createParser('hide a show b;');
+ List<Combinator> combinators = parser.parseCombinators();
+ expectNotNullIfNoErrors(combinators);
listener.assertNoErrors();
- expect(references, isEmpty);
+ expect(combinators, hasLength(2));
+ HideCombinator hideCombinator = combinators[0] as HideCombinator;
+ expect(hideCombinator, isNotNull);
+ expect(hideCombinator.keyword, isNotNull);
+ expect(hideCombinator.hiddenNames, hasLength(1));
+ ShowCombinator showCombinator = combinators[1] as ShowCombinator;
+ expect(showCombinator, isNotNull);
+ expect(showCombinator.keyword, isNotNull);
+ expect(showCombinator.shownNames, hasLength(1));
}
- void test_parseCommentReferences_skipCodeBlock_4spaces_lines() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(
- TokenType.SINGLE_LINE_COMMENT, "/// Code block:", 0),
- new DocumentationCommentToken(
- TokenType.SINGLE_LINE_COMMENT, "/// a[i] == b[i]", 0)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCombinators_hshs() {
+ createParser('hide a show b hide c show d;');
+ List<Combinator> combinators = parser.parseCombinators();
+ expectNotNullIfNoErrors(combinators);
listener.assertNoErrors();
- expect(references, isEmpty);
+ expect(combinators, hasLength(4));
}
- void test_parseCommentReferences_skipCodeBlock_bracketed() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(
- TokenType.MULTI_LINE_COMMENT, "/** [:xxx [a] yyy:] [b] zzz */", 3)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCombinators_s() {
+ createParser('show a;');
+ List<Combinator> combinators = parser.parseCombinators();
+ expectNotNullIfNoErrors(combinators);
listener.assertNoErrors();
- expect(references, hasLength(1));
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 24);
+ expect(combinators, hasLength(1));
+ ShowCombinator combinator = combinators[0] as ShowCombinator;
+ expect(combinator, isNotNull);
+ expect(combinator.keyword, isNotNull);
+ expect(combinator.shownNames, hasLength(1));
}
- void test_parseCommentReferences_skipCodeBlock_gitHub() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(
- TokenType.MULTI_LINE_COMMENT, "/** `a[i]` and [b] */", 0)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCommentAndMetadata_c() {
+ createParser('/** 1 */ void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
listener.assertNoErrors();
- expect(references, hasLength(1));
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 16);
+ expect(commentAndMetadata.comment, isNotNull);
+ expect(commentAndMetadata.metadata, isNull);
}
- void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(
- TokenType.MULTI_LINE_COMMENT,
- r'''
-/**
- * First.
- * ```dart
- * Some [int] reference.
- * ```
- * Last.
- */
-''',
- 3)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCommentAndMetadata_cmc() {
+ createParser('/** 1 */ @A /** 2 */ void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
listener.assertNoErrors();
- expect(references, isEmpty);
+ expect(commentAndMetadata.comment, isNotNull);
+ expect(commentAndMetadata.metadata, hasLength(1));
}
- void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine_lines() {
- String commentText = r'''
-/// First.
-/// ```dart
-/// Some [int] reference.
-/// ```
-/// Last.
-''';
- List<DocumentationCommentToken> tokens = commentText
- .split('\n')
- .map((line) => new DocumentationCommentToken(
- TokenType.SINGLE_LINE_COMMENT, line, 0))
- .toList();
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCommentAndMetadata_cmcm() {
+ createParser('/** 1 */ @A /** 2 */ @B void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
listener.assertNoErrors();
- expect(references, isEmpty);
+ expect(commentAndMetadata.comment, isNotNull);
+ expect(commentAndMetadata.metadata, hasLength(2));
}
- void test_parseCommentReferences_skipCodeBlock_gitHub_notTerminated() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(
- TokenType.MULTI_LINE_COMMENT, "/** `a[i] and [b] */", 0)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCommentAndMetadata_cmm() {
+ createParser('/** 1 */ @A @B void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
listener.assertNoErrors();
- expect(references, hasLength(2));
+ expect(commentAndMetadata.comment, isNotNull);
+ expect(commentAndMetadata.metadata, hasLength(2));
}
- void test_parseCommentReferences_skipCodeBlock_spaces() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT,
- "/**\n * a[i]\n * xxx [i] zzz\n */", 3)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCommentAndMetadata_m() {
+ createParser('@A void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
listener.assertNoErrors();
- expect(references, hasLength(1));
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 27);
+ expect(commentAndMetadata.comment, isNull);
+ expect(commentAndMetadata.metadata, hasLength(1));
}
- void test_parseCommentReferences_skipLinkDefinition() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT,
- "/** [a]: http://www.google.com (Google) [b] zzz */", 3)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCommentAndMetadata_mcm() {
+ createParser('@A /** 1 */ @B void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
listener.assertNoErrors();
- expect(references, hasLength(1));
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 44);
+ expect(commentAndMetadata.comment, isNotNull);
+ expect(commentAndMetadata.metadata, hasLength(2));
+ }
+
+ void test_parseCommentAndMetadata_mcmc() {
+ createParser('@A /** 1 */ @B /** 2 */ void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
+ listener.assertNoErrors();
+ expect(commentAndMetadata.comment, isNotNull);
+ expect(commentAndMetadata.metadata, hasLength(2));
+ }
+
+ void test_parseCommentAndMetadata_mm() {
+ createParser('@A @B(x) void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
+ listener.assertNoErrors();
+ expect(commentAndMetadata.comment, isNull);
+ expect(commentAndMetadata.metadata, hasLength(2));
}
- void test_parseCommentReferences_skipLinked() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT,
- "/** [a](http://www.google.com) [b] zzz */", 3)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCommentAndMetadata_none() {
+ createParser('void');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
listener.assertNoErrors();
- expect(references, hasLength(1));
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 35);
+ expect(commentAndMetadata.comment, isNull);
+ expect(commentAndMetadata.metadata, isNull);
}
- void test_parseCommentReferences_skipReferenceLink() {
- List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[
- new DocumentationCommentToken(
- TokenType.MULTI_LINE_COMMENT, "/** [a][c] [b] zzz */", 3)
- ];
- createParser('');
- List<CommentReference> references = parser.parseCommentReferences(tokens);
- expectNotNullIfNoErrors(references);
+ void test_parseCommentAndMetadata_singleLine() {
+ createParser(r'''
+/// 1
+/// 2
+void''');
+ CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata();
+ expectNotNullIfNoErrors(commentAndMetadata);
listener.assertNoErrors();
- expect(references, hasLength(1));
- CommentReference reference = references[0];
- expect(reference, isNotNull);
- expect(reference.identifier, isNotNull);
- expect(reference.offset, 15);
+ expect(commentAndMetadata.comment, isNotNull);
+ expect(commentAndMetadata.metadata, isNull);
}
void test_parseConfiguration_noOperator_dottedIdentifier() {
@@ -11129,10 +11360,6 @@ void''');
expect(configuration.uri, isNotNull);
}
- void test_parseConstructor() {
- // TODO(brianwilkerson) Implement tests for this method.
- }
-
void test_parseConstructorName_named_noPrefix() {
createParser('A.n;');
ConstructorName name = parser.parseConstructorName();
@@ -11689,10 +11916,6 @@ void''');
// TODO(brianwilkerson) Implement tests for this method.
}
- void test_Parser() {
- expect(new Parser(null, null), isNotNull);
- }
-
void test_parseReturnStatement_noValue() {
createParser('return;');
ReturnStatement statement = parser.parseReturnStatement();
@@ -11759,13 +11982,11 @@ Function<A>(core.List<core.int> x) m() => null;
}
void test_parseStatements_multiple() {
- List<Statement> statements = parseStatements("return; return;", 2);
- expect(statements, hasLength(2));
+ parseStatementList("return; return;", 2);
}
void test_parseStatements_single() {
- List<Statement> statements = parseStatements("return;", 1);
- expect(statements, hasLength(1));
+ parseStatementList("return;", 1);
}
void test_parseTypeAnnotation_function_noReturnType_noParameters() {
@@ -12225,210 +12446,6 @@ Function<A>(core.List<core.int> x) m() => null;
expect(clause.withKeyword, isNotNull);
expect(clause.mixinTypes, hasLength(1));
}
-
- void test_skipPrefixedIdentifier_invalid() {
- createParser('+');
- Token following = parser.skipPrefixedIdentifier(parser.currentToken);
- expect(following, isNull);
- }
-
- void test_skipPrefixedIdentifier_notPrefixed() {
- createParser('a +');
- Token following = parser.skipPrefixedIdentifier(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipPrefixedIdentifier_prefixed() {
- createParser('a.b +');
- Token following = parser.skipPrefixedIdentifier(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipReturnType_invalid() {
- // TODO(eernst): `skipReturnType` eliminated, delete this test?
- createParser('+');
- Token following = parser.skipTypeAnnotation(parser.currentToken);
- expect(following, isNull);
- }
-
- void test_skipReturnType_type() {
- // TODO(eernst): `skipReturnType` eliminated, delete this test?
- createParser('C +');
- Token following = parser.skipTypeAnnotation(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipReturnType_void() {
- // TODO(eernst): `skipReturnType` eliminated, delete this test?
- createParser('void +');
- Token following = parser.skipTypeAnnotation(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipSimpleIdentifier_identifier() {
- createParser('i +');
- Token following = parser.skipSimpleIdentifier(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipSimpleIdentifier_invalid() {
- createParser('9 +');
- Token following = parser.skipSimpleIdentifier(parser.currentToken);
- expect(following, isNull);
- }
-
- void test_skipSimpleIdentifier_pseudoKeyword() {
- createParser('as +');
- Token following = parser.skipSimpleIdentifier(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipStringLiteral_adjacent() {
- createParser("'a' 'b' +");
- Token following = parser.skipStringLiteral(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipStringLiteral_interpolated() {
- createParser("'a\${b}c' +");
- Token following = parser.skipStringLiteral(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipStringLiteral_invalid() {
- createParser('a');
- Token following = parser.skipStringLiteral(parser.currentToken);
- expect(following, isNull);
- }
-
- void test_skipStringLiteral_single() {
- createParser("'a' +");
- Token following = parser.skipStringLiteral(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipTypeArgumentList_invalid() {
- createParser('+');
- Token following = parser.skipTypeArgumentList(parser.currentToken);
- expect(following, isNull);
- }
-
- void test_skipTypeArgumentList_multiple() {
- createParser('<E, F, G> +');
- Token following = parser.skipTypeArgumentList(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipTypeArgumentList_single() {
- createParser('<E> +');
- Token following = parser.skipTypeArgumentList(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipTypeName_invalid() {
- createParser('+');
- Token following = parser.skipTypeName(parser.currentToken);
- expect(following, isNull);
- }
-
- void test_skipTypeName_parameterized() {
- createParser('C<E<F<G>>> +');
- Token following = parser.skipTypeName(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- void test_skipTypeName_simple() {
- createParser('C +');
- Token following = parser.skipTypeName(parser.currentToken);
- expect(following, isNotNull);
- expect(following.type, TokenType.PLUS);
- }
-
- /**
- * Invoke the method [Parser.computeStringValue] with the given argument.
- *
- * @param lexeme the argument to the method
- * @param first `true` if this is the first token in a string literal
- * @param last `true` if this is the last token in a string literal
- * @return the result of invoking the method
- * @throws Exception if the method could not be invoked or throws an exception
- */
- String _computeStringValue(String lexeme, bool first, bool last) {
- createParser('');
- String value = parser.computeStringValue(lexeme, first, last);
- listener.assertNoErrors();
- return value;
- }
-
- /**
- * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the token
- * stream produced by scanning the given source.
- *
- * @param source the source to be scanned to produce the token stream being tested
- * @return the result of invoking the method
- * @throws Exception if the method could not be invoked or throws an exception
- */
- bool _isFunctionDeclaration(String source) {
- createParser(source);
- bool result = parser.isFunctionDeclaration();
- expectNotNullIfNoErrors(result);
- return result;
- }
-
- /**
- * Invoke the method [Parser.isFunctionExpression] with the parser set to the token stream
- * produced by scanning the given source.
- *
- * @param source the source to be scanned to produce the token stream being tested
- * @return the result of invoking the method
- * @throws Exception if the method could not be invoked or throws an exception
- */
- bool _isFunctionExpression(String source) {
- createParser(source);
- return parser.isFunctionExpression(parser.currentToken);
- }
-
- /**
- * Invoke the method [Parser.isInitializedVariableDeclaration] with the parser set to the
- * token stream produced by scanning the given source.
- *
- * @param source the source to be scanned to produce the token stream being tested
- * @return the result of invoking the method
- * @throws Exception if the method could not be invoked or throws an exception
- */
- bool _isInitializedVariableDeclaration(String source) {
- createParser(source);
- bool result = parser.isInitializedVariableDeclaration();
- expectNotNullIfNoErrors(result);
- return result;
- }
-
- /**
- * Invoke the method [Parser.isSwitchMember] with the parser set to the token stream
- * produced by scanning the given source.
- *
- * @param source the source to be scanned to produce the token stream being tested
- * @return the result of invoking the method
- * @throws Exception if the method could not be invoked or throws an exception
- */
- bool _isSwitchMember(String source) {
- createParser(source);
- bool result = parser.isSwitchMember();
- expectNotNullIfNoErrors(result);
- return result;
- }
}
@reflectiveTest

Powered by Google App Engine
This is Rietveld 408576698