Skip to content

Commit 162d0d1

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Remove EngineTestCase.assertInstanceOf and extract ast/element TypeMatcher(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]>
1 parent fa181d9 commit 162d0d1

14 files changed

+733
-882
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/dart/ast/ast.dart';
6+
import 'package:test/test.dart';
7+
8+
const isAsExpression = const TypeMatcher<AsExpression>();
9+
10+
const isAssertInitializer = const TypeMatcher<AssertInitializer>();
11+
12+
const isAssignmentExpression = const TypeMatcher<AssignmentExpression>();
13+
14+
const isAwaitExpression = const TypeMatcher<AwaitExpression>();
15+
16+
const isBinaryExpression = const TypeMatcher<BinaryExpression>();
17+
18+
const isBlock = const TypeMatcher<Block>();
19+
20+
const isBlockFunctionBody = const TypeMatcher<BlockFunctionBody>();
21+
22+
const isClassDeclaration = const TypeMatcher<ClassDeclaration>();
23+
24+
const isClassTypeAlias = const TypeMatcher<ClassTypeAlias>();
25+
26+
const isCompilationUnit = const TypeMatcher<CompilationUnit>();
27+
28+
const isConditionalExpression = const TypeMatcher<ConditionalExpression>();
29+
30+
const isConstructorDeclaration = const TypeMatcher<ConstructorDeclaration>();
31+
32+
const isConstructorFieldInitializer =
33+
const TypeMatcher<ConstructorFieldInitializer>();
34+
35+
const isDefaultFormalParameter = const TypeMatcher<DefaultFormalParameter>();
36+
37+
const isEmptyFunctionBody = const TypeMatcher<EmptyFunctionBody>();
38+
39+
const isEmptyStatement = const TypeMatcher<EmptyStatement>();
40+
41+
const isExpressionFunctionBody = const TypeMatcher<ExpressionFunctionBody>();
42+
43+
const isExpressionStatement = const TypeMatcher<ExpressionStatement>();
44+
45+
const isFieldDeclaration = const TypeMatcher<FieldDeclaration>();
46+
47+
const isFieldFormalParameter = const TypeMatcher<FieldFormalParameter>();
48+
49+
const isForStatement = const TypeMatcher<ForStatement>();
50+
51+
const isFunctionDeclaration = const TypeMatcher<FunctionDeclaration>();
52+
53+
const isFunctionDeclarationStatement =
54+
const TypeMatcher<FunctionDeclarationStatement>();
55+
56+
const isFunctionExpression = const TypeMatcher<FunctionExpression>();
57+
58+
const isFunctionTypeAlias = const TypeMatcher<FunctionTypeAlias>();
59+
60+
const isFunctionTypedFormalParameter =
61+
const TypeMatcher<FunctionTypedFormalParameter>();
62+
63+
const isGenericFunctionType = const TypeMatcher<GenericFunctionType>();
64+
65+
const isIndexExpression = const TypeMatcher<IndexExpression>();
66+
67+
const isInstanceCreationExpression =
68+
const TypeMatcher<InstanceCreationExpression>();
69+
70+
const isIntegerLiteral = const TypeMatcher<IntegerLiteral>();
71+
72+
const isInterpolationExpression = const TypeMatcher<InterpolationExpression>();
73+
74+
const isInterpolationString = const TypeMatcher<InterpolationString>();
75+
76+
const isIsExpression = const TypeMatcher<IsExpression>();
77+
78+
const isLibraryDirective = const TypeMatcher<LibraryDirective>();
79+
80+
const isMethodDeclaration = const TypeMatcher<MethodDeclaration>();
81+
82+
const isMethodInvocation = const TypeMatcher<MethodInvocation>();
83+
84+
const isNullLiteral = const TypeMatcher<NullLiteral>();
85+
86+
const isParenthesizedExpression = const TypeMatcher<ParenthesizedExpression>();
87+
88+
const isPrefixedIdentifier = const TypeMatcher<PrefixedIdentifier>();
89+
90+
const isPrefixExpression = const TypeMatcher<PrefixExpression>();
91+
92+
const isPropertyAccess = const TypeMatcher<PropertyAccess>();
93+
94+
const isReturnStatement = const TypeMatcher<ReturnStatement>();
95+
96+
const isSimpleFormalParameter = const TypeMatcher<SimpleFormalParameter>();
97+
98+
const isSimpleIdentifier = const TypeMatcher<SimpleIdentifier>();
99+
100+
const isStringInterpolation = const TypeMatcher<StringInterpolation>();
101+
102+
const isSuperExpression = const TypeMatcher<SuperExpression>();
103+
104+
const isTopLevelVariableDeclaration =
105+
const TypeMatcher<TopLevelVariableDeclaration>();
106+
107+
const isTypeName = const TypeMatcher<TypeName>();
108+
109+
const isVariableDeclarationStatement =
110+
const TypeMatcher<VariableDeclarationStatement>();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/dart/element/element.dart';
6+
import 'package:test/test.dart';
7+
8+
const isClassElement = const TypeMatcher<ClassElement>();
9+
10+
const isCompilationUnitElement = const TypeMatcher<CompilationUnitElement>();
11+
12+
const isConstructorElement = const TypeMatcher<ConstructorElement>();
13+
14+
const isExportElement = const TypeMatcher<ExportElement>();
15+
16+
const isFieldElement = const TypeMatcher<FieldElement>();
17+
18+
const isFunctionElement = const TypeMatcher<FunctionElement>();
19+
20+
const isImportElement = const TypeMatcher<ImportElement>();
21+
22+
const isLibraryElement = const TypeMatcher<LibraryElement>();
23+
24+
const isMethodElement = const TypeMatcher<MethodElement>();
25+
26+
const isPropertyAccessorElement = const TypeMatcher<PropertyAccessorElement>();
27+
28+
const isPropertyInducingElement = const TypeMatcher<PropertyInducingElement>();
29+
30+
const isTopLevelVariableElement = const TypeMatcher<TopLevelVariableElement>();

pkg/analyzer/test/dart/ast/visitor_test.dart

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
7+
import 'package:analyzer/src/test_utilities/ast_type_matchers.dart';
78
import 'package:test/test.dart';
89
import 'package:test_reflective_loader/test_reflective_loader.dart';
910

1011
import '../../generated/parser_test.dart' show ParserTestCase;
11-
import '../../generated/test_support.dart';
1212

1313
main() {
1414
defineReflectiveSuite(() {
@@ -44,19 +44,11 @@ A f(var p) {
4444
new _BreadthFirstVisitorTestHelper(nodes);
4545
visitor.visitAllNodes(unit);
4646
expect(nodes, hasLength(59));
47-
EngineTestCase.assertInstanceOf(
48-
(obj) => obj is CompilationUnit, CompilationUnit, nodes[0]);
49-
EngineTestCase.assertInstanceOf(
50-
(obj) => obj is ClassDeclaration, ClassDeclaration, nodes[2]);
51-
EngineTestCase.assertInstanceOf(
52-
(obj) => obj is FunctionDeclaration, FunctionDeclaration, nodes[3]);
53-
EngineTestCase.assertInstanceOf(
54-
(obj) => obj is FunctionDeclarationStatement,
55-
FunctionDeclarationStatement,
56-
nodes[27]);
57-
EngineTestCase.assertInstanceOf(
58-
(obj) => obj is IntegerLiteral, IntegerLiteral, nodes[58]);
59-
//3
47+
expect(nodes[0], isCompilationUnit);
48+
expect(nodes[2], isClassDeclaration);
49+
expect(nodes[3], isFunctionDeclaration);
50+
expect(nodes[27], isFunctionDeclarationStatement);
51+
expect(nodes[58], isIntegerLiteral); // 3
6052
}
6153
}
6254

pkg/analyzer/test/dart/element/builder_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,9 +1948,7 @@ class C {
19481948
expect(accessor.isSetter, isFalse);
19491949
expect(accessor.isSynthetic, isFalse);
19501950
expect(accessor.typeParameters, hasLength(0));
1951-
PropertyInducingElement variable = accessor.variable;
1952-
EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
1953-
TopLevelVariableElement, variable);
1951+
TopLevelVariableElement variable = accessor.variable;
19541952
expect(variable.isSynthetic, isTrue);
19551953
}
19561954

@@ -2012,9 +2010,7 @@ class C {
20122010
expect(accessor.isSetter, isTrue);
20132011
expect(accessor.isSynthetic, isFalse);
20142012
expect(accessor.typeParameters, hasLength(0));
2015-
PropertyInducingElement variable = accessor.variable;
2016-
EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement,
2017-
TopLevelVariableElement, variable);
2013+
TopLevelVariableElement variable = accessor.variable;
20182014
expect(variable.isSynthetic, isTrue);
20192015
}
20202016

0 commit comments

Comments
 (0)