| // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| // 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. |
| |
| import 'package:analyzer/dart/ast/ast.dart'; |
| import 'package:analyzer/dart/element/element.dart'; |
| import 'package:analyzer/error/error.dart'; |
| import 'package:front_end/src/fasta/analyzer/ast_builder.dart'; |
| import 'package:front_end/src/fasta/analyzer/element_store.dart'; |
| import 'package:front_end/src/fasta/builder/scope.dart'; |
| import 'package:front_end/src/fasta/kernel/kernel_builder.dart'; |
| import 'package:front_end/src/fasta/kernel/kernel_library_builder.dart'; |
| import 'package:front_end/src/fasta/parser/parser.dart'; |
| import 'package:front_end/src/fasta/scanner/string_scanner.dart'; |
| import 'package:front_end/src/fasta/scanner/token.dart'; |
| import 'package:test/test.dart'; |
| import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| |
| import 'parser_test.dart'; |
| |
| main() { |
| defineReflectiveSuite(() { |
| defineReflectiveTests(ComplexParserTest_Fasta); |
| }); |
| } |
| |
| /** |
| * Type of the "parse..." methods defined in the Fasta parser. |
| */ |
| typedef Token ParseFunction(Token token); |
| |
| /** |
| * Proxy implementation of [Builder] used by Fasta parser tests. |
| * |
| * All undeclared identifiers are presumed to resolve via an instance of this |
| * class. |
| */ |
| class BuilderProxy implements Builder { |
| noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| } |
| |
| /** |
| * Tests of the fasta parser based on [ComplexParserTestMixin]. |
| */ |
| @reflectiveTest |
| class ComplexParserTest_Fasta extends FastaParserTestCase |
| with ComplexParserTestMixin { |
| @override |
| @failingTest |
| void test_additiveExpression_precedence_multiplicative_left_withSuper() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_additiveExpression_precedence_multiplicative_left_withSuper(); |
| } |
| |
| @override |
| @failingTest |
| void test_additiveExpression_super() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_additiveExpression_super(); |
| } |
| |
| @override |
| @failingTest |
| void test_assignableExpression_arguments_normal_chain() { |
| // TODO(paulberry,ahe): AstBuilder.doInvocation doesn't handle receiver |
| // other than SimpleIdentifier. |
| super.test_assignableExpression_arguments_normal_chain(); |
| } |
| |
| @override |
| @failingTest |
| void test_assignableExpression_arguments_normal_chain_typeArgumentComments() { |
| // TODO(paulberry,ahe): Fasta doesn't support generic method comment syntax. |
| super |
| .test_assignableExpression_arguments_normal_chain_typeArgumentComments(); |
| } |
| |
| @override |
| @failingTest |
| void test_assignableExpression_arguments_normal_chain_typeArguments() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // endTypeArguments(). |
| super.test_assignableExpression_arguments_normal_chain_typeArguments(); |
| } |
| |
| @override |
| @failingTest |
| void test_assignmentExpression_prefixedIdentifier() { |
| // TODO(paulberry,ahe): Analyzer expects "x.y" to be parsed as a |
| // PrefixedIdentifier, even if x is not a prefix. |
| super.test_assignmentExpression_prefixedIdentifier(); |
| } |
| |
| @override |
| @failingTest |
| void test_assignmentExpression_propertyAccess() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_assignmentExpression_propertyAccess(); |
| } |
| |
| @override |
| @failingTest |
| void test_bitwiseAndExpression_super() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_bitwiseAndExpression_super(); |
| } |
| |
| @override |
| @failingTest |
| void test_bitwiseOrExpression_super() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_bitwiseOrExpression_super(); |
| } |
| |
| @override |
| @failingTest |
| void test_bitwiseXorExpression_super() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_bitwiseXorExpression_super(); |
| } |
| |
| @override |
| @failingTest |
| void test_cascade_withAssignment() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // endConstructorReference(). |
| super.test_cascade_withAssignment(); |
| } |
| |
| @override |
| @failingTest |
| void test_conditionalExpression_precedence_nullableType_as() { |
| // TODO(paulberry,ahe): Fasta doesn't support NNBD syntax yet. |
| super.test_conditionalExpression_precedence_nullableType_as(); |
| } |
| |
| @override |
| @failingTest |
| void test_conditionalExpression_precedence_nullableType_is() { |
| // TODO(paulberry,ahe): Fasta doesn't support NNBD syntax yet. |
| super.test_conditionalExpression_precedence_nullableType_is(); |
| } |
| |
| @override |
| @failingTest |
| void test_constructor_initializer_withParenthesizedExpression() { |
| // TODO(paulberry): Implement parseCompilationUnitWithOptions |
| super.test_constructor_initializer_withParenthesizedExpression(); |
| } |
| |
| @override |
| @failingTest |
| void test_equalityExpression_normal() { |
| // TODO(paulberry,ahe): bad error recovery |
| super.test_equalityExpression_normal(); |
| } |
| |
| @override |
| @failingTest |
| void test_equalityExpression_super() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_equalityExpression_super(); |
| } |
| |
| @override |
| @failingTest |
| void test_logicalAndExpression_precedence_nullableType() { |
| // TODO(paulberry,ahe): Fasta doesn't support NNBD syntax yet. |
| super.test_logicalAndExpression_precedence_nullableType(); |
| } |
| |
| @override |
| @failingTest |
| void test_logicalOrExpression_precedence_nullableType() { |
| // TODO(paulberry,ahe): Fasta doesn't support NNBD syntax yet. |
| super.test_logicalOrExpression_precedence_nullableType(); |
| } |
| |
| @override |
| @failingTest |
| void test_multipleLabels_statement() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement handleLabel(). |
| super.test_multipleLabels_statement(); |
| } |
| |
| @override |
| @failingTest |
| void test_multiplicativeExpression_super() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_multiplicativeExpression_super(); |
| } |
| |
| @override |
| @failingTest |
| void test_shiftExpression_super() { |
| // TODO(paulberry,ahe): AstBuilder doesn't implement |
| // handleSuperExpression(). |
| super.test_shiftExpression_super(); |
| } |
| |
| @override |
| @failingTest |
| void test_topLevelFunction_nestedGenericFunction() { |
| // TODO(paulberry): Implement parseCompilationUnitWithOptions |
| super.test_topLevelFunction_nestedGenericFunction(); |
| } |
| } |
| |
| /** |
| * Proxy implementation of [KernelClassElement] used by Fasta parser tests. |
| * |
| * All undeclared identifiers are presumed to resolve to an instance of this |
| * class. |
| */ |
| class ElementProxy implements KernelClassElement { |
| @override |
| final KernelInterfaceType rawType = new InterfaceTypeProxy(); |
| |
| noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| } |
| |
| /** |
| * Proxy implementation of [KernelClassElement] used by Fasta parser tests. |
| * |
| * Any request for an element is satisfied by creating an instance of |
| * [ElementProxy]. |
| */ |
| class ElementStoreProxy implements ElementStore { |
| final _elements = <Builder, Element>{}; |
| |
| @override |
| Element operator [](Builder builder) => |
| _elements.putIfAbsent(builder, () => new ElementProxy()); |
| |
| noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| } |
| |
| /** |
| * Implementation of [AbstractParserTestCase] specialized for testing the |
| * Fasta parser. |
| */ |
| class FastaParserTestCase implements AbstractParserTestCase { |
| @override |
| set enableGenericMethodComments(bool value) { |
| if (value == true) { |
| // TODO(paulberry,ahe): generic method comment syntax is not supported by |
| // Fasta. |
| throw new UnimplementedError(); |
| } |
| } |
| |
| @override |
| set enableNnbd(bool value) { |
| if (value == true) { |
| // TODO(paulberry,ahe): non-null-by-default syntax is not supported by |
| // Fasta. |
| throw new UnimplementedError(); |
| } |
| } |
| |
| @override |
| CompilationUnit parseCompilationUnit(String source, |
| [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| // TODO(paulberry): implement parseCompilationUnit |
| throw new UnimplementedError(); |
| } |
| |
| @override |
| CompilationUnit parseCompilationUnitWithOptions(String source, |
| [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| // TODO(paulberry): implement parseCompilationUnitWithOptions |
| throw new UnimplementedError(); |
| } |
| |
| @override |
| Expression parseExpression(String source, |
| [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| return _runParser(source, (parser) => parser.parseExpression, errorCodes); |
| } |
| |
| @override |
| Statement parseStatement(String source, |
| [List<ErrorCode> errorCodes = const <ErrorCode>[], |
| bool enableLazyAssignmentOperators]) { |
| return _runParser(source, (parser) => parser.parseStatement, errorCodes); |
| } |
| |
| Object _runParser(String source, ParseFunction getParseFuction(Parser parser), |
| [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| if (errorCodes.isNotEmpty) { |
| // TODO(paulberry): Check that the parser generates the proper errors. |
| throw new UnimplementedError(); |
| } |
| var scanner = new StringScanner(source); |
| var token = scanner.tokenize(); |
| var library = new KernelLibraryBuilderProxy(); |
| var member = new BuilderProxy(); |
| var elementStore = new ElementStoreProxy(); |
| var scope = new ScopeProxy(); |
| var astBuilder = new AstBuilder(library, member, elementStore, scope); |
| var parser = new Parser(astBuilder); |
| var parseFunction = getParseFuction(parser); |
| var endToken = parseFunction(token); |
| expect(endToken.isEof, isTrue); |
| expect(astBuilder.stack, hasLength(1)); |
| return astBuilder.pop(); |
| } |
| } |
| |
| /** |
| * Proxy implementation of [KernelClassElement] used by Fasta parser tests. |
| * |
| * Any element used as a type name is presumed to refer to an instance of this |
| * class. |
| */ |
| class InterfaceTypeProxy implements KernelInterfaceType { |
| noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| } |
| |
| /** |
| * Proxy implementation of [KernelLibraryBuilderProxy] used by Fasta parser |
| * tests. |
| */ |
| class KernelLibraryBuilderProxy implements KernelLibraryBuilder { |
| @override |
| final uri = Uri.parse('file:///test.dart'); |
| |
| @override |
| Uri get fileUri => uri; |
| |
| noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| } |
| |
| /** |
| * Proxy implementation of [Scope] used by Fasta parser tests. |
| * |
| * Any name lookup request is satisfied by creating an instance of |
| * [BuilderProxy]. |
| */ |
| class ScopeProxy implements Scope { |
| final _locals = <String, Builder>{}; |
| |
| @override |
| Builder lookup(String name, int charOffset, Uri fileUri) => |
| _locals.putIfAbsent(name, () => new BuilderProxy()); |
| |
| noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| } |