Skip to content

Commit

Permalink
Remove EngineTestCase.assertInstanceOf and extract ast/element TypeMa…
Browse files Browse the repository at this point in the history
…tcher(s).

[email protected]

Change-Id: I9c47b4a7426dccafb8d3ffc1b0652da0106f2184
Reviewed-on: https://dart-review.googlesource.com/c/87302
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
scheglov authored and [email protected] committed Dec 14, 2018
1 parent fa181d9 commit 162d0d1
Show file tree
Hide file tree
Showing 14 changed files with 733 additions and 882 deletions.
110 changes: 110 additions & 0 deletions pkg/analyzer/lib/src/test_utilities/ast_type_matchers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright (c) 2018, 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:test/test.dart';

const isAsExpression = const TypeMatcher<AsExpression>();

const isAssertInitializer = const TypeMatcher<AssertInitializer>();

const isAssignmentExpression = const TypeMatcher<AssignmentExpression>();

const isAwaitExpression = const TypeMatcher<AwaitExpression>();

const isBinaryExpression = const TypeMatcher<BinaryExpression>();

const isBlock = const TypeMatcher<Block>();

const isBlockFunctionBody = const TypeMatcher<BlockFunctionBody>();

const isClassDeclaration = const TypeMatcher<ClassDeclaration>();

const isClassTypeAlias = const TypeMatcher<ClassTypeAlias>();

const isCompilationUnit = const TypeMatcher<CompilationUnit>();

const isConditionalExpression = const TypeMatcher<ConditionalExpression>();

const isConstructorDeclaration = const TypeMatcher<ConstructorDeclaration>();

const isConstructorFieldInitializer =
const TypeMatcher<ConstructorFieldInitializer>();

const isDefaultFormalParameter = const TypeMatcher<DefaultFormalParameter>();

const isEmptyFunctionBody = const TypeMatcher<EmptyFunctionBody>();

const isEmptyStatement = const TypeMatcher<EmptyStatement>();

const isExpressionFunctionBody = const TypeMatcher<ExpressionFunctionBody>();

const isExpressionStatement = const TypeMatcher<ExpressionStatement>();

const isFieldDeclaration = const TypeMatcher<FieldDeclaration>();

const isFieldFormalParameter = const TypeMatcher<FieldFormalParameter>();

const isForStatement = const TypeMatcher<ForStatement>();

const isFunctionDeclaration = const TypeMatcher<FunctionDeclaration>();

const isFunctionDeclarationStatement =
const TypeMatcher<FunctionDeclarationStatement>();

const isFunctionExpression = const TypeMatcher<FunctionExpression>();

const isFunctionTypeAlias = const TypeMatcher<FunctionTypeAlias>();

const isFunctionTypedFormalParameter =
const TypeMatcher<FunctionTypedFormalParameter>();

const isGenericFunctionType = const TypeMatcher<GenericFunctionType>();

const isIndexExpression = const TypeMatcher<IndexExpression>();

const isInstanceCreationExpression =
const TypeMatcher<InstanceCreationExpression>();

const isIntegerLiteral = const TypeMatcher<IntegerLiteral>();

const isInterpolationExpression = const TypeMatcher<InterpolationExpression>();

const isInterpolationString = const TypeMatcher<InterpolationString>();

const isIsExpression = const TypeMatcher<IsExpression>();

const isLibraryDirective = const TypeMatcher<LibraryDirective>();

const isMethodDeclaration = const TypeMatcher<MethodDeclaration>();

const isMethodInvocation = const TypeMatcher<MethodInvocation>();

const isNullLiteral = const TypeMatcher<NullLiteral>();

const isParenthesizedExpression = const TypeMatcher<ParenthesizedExpression>();

const isPrefixedIdentifier = const TypeMatcher<PrefixedIdentifier>();

const isPrefixExpression = const TypeMatcher<PrefixExpression>();

const isPropertyAccess = const TypeMatcher<PropertyAccess>();

const isReturnStatement = const TypeMatcher<ReturnStatement>();

const isSimpleFormalParameter = const TypeMatcher<SimpleFormalParameter>();

const isSimpleIdentifier = const TypeMatcher<SimpleIdentifier>();

const isStringInterpolation = const TypeMatcher<StringInterpolation>();

const isSuperExpression = const TypeMatcher<SuperExpression>();

const isTopLevelVariableDeclaration =
const TypeMatcher<TopLevelVariableDeclaration>();

const isTypeName = const TypeMatcher<TypeName>();

const isVariableDeclarationStatement =
const TypeMatcher<VariableDeclarationStatement>();
30 changes: 30 additions & 0 deletions pkg/analyzer/lib/src/test_utilities/element_type_matchers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2018, 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/element/element.dart';
import 'package:test/test.dart';

const isClassElement = const TypeMatcher<ClassElement>();

const isCompilationUnitElement = const TypeMatcher<CompilationUnitElement>();

const isConstructorElement = const TypeMatcher<ConstructorElement>();

const isExportElement = const TypeMatcher<ExportElement>();

const isFieldElement = const TypeMatcher<FieldElement>();

const isFunctionElement = const TypeMatcher<FunctionElement>();

const isImportElement = const TypeMatcher<ImportElement>();

const isLibraryElement = const TypeMatcher<LibraryElement>();

const isMethodElement = const TypeMatcher<MethodElement>();

const isPropertyAccessorElement = const TypeMatcher<PropertyAccessorElement>();

const isPropertyInducingElement = const TypeMatcher<PropertyInducingElement>();

const isTopLevelVariableElement = const TypeMatcher<TopLevelVariableElement>();
20 changes: 6 additions & 14 deletions pkg/analyzer/test/dart/ast/visitor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/src/test_utilities/ast_type_matchers.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../../generated/parser_test.dart' show ParserTestCase;
import '../../generated/test_support.dart';

main() {
defineReflectiveSuite(() {
Expand Down Expand Up @@ -44,19 +44,11 @@ A f(var p) {
new _BreadthFirstVisitorTestHelper(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
expect(nodes[0], isCompilationUnit);
expect(nodes[2], isClassDeclaration);
expect(nodes[3], isFunctionDeclaration);
expect(nodes[27], isFunctionDeclarationStatement);
expect(nodes[58], isIntegerLiteral); // 3
}
}

Expand Down
8 changes: 2 additions & 6 deletions pkg/analyzer/test/dart/element/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1948,9 +1948,7 @@ class C {
expect(accessor.isSetter, isFalse);
expect(accessor.isSynthetic, isFalse);
expect(accessor.typeParameters, hasLength(0));
PropertyInducingElement variable = accessor.variable;
EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
TopLevelVariableElement, variable);
TopLevelVariableElement variable = accessor.variable;
expect(variable.isSynthetic, isTrue);
}

Expand Down Expand Up @@ -2012,9 +2010,7 @@ class C {
expect(accessor.isSetter, isTrue);
expect(accessor.isSynthetic, isFalse);
expect(accessor.typeParameters, hasLength(0));
PropertyInducingElement variable = accessor.variable;
EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
TopLevelVariableElement, variable);
TopLevelVariableElement variable = accessor.variable;
expect(variable.isSynthetic, isTrue);
}

Expand Down
Loading

0 comments on commit 162d0d1

Please sign in to comment.