Skip to content

Commit

Permalink
Remove previewDart2 related code in some tests.
Browse files Browse the repository at this point in the history
PreviewDart2Test in element_resolver_test.dart was replaced with
AstRewriteMethodInvocationTest recently.

R=brianwilkerson@google.com

Change-Id: I8d8d9a6889f13f3ae5deb8d062d520338a50b43e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115903
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Sep 6, 2019
1 parent 836039e commit 0a49dde
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 354 deletions.
343 changes: 0 additions & 343 deletions pkg/analyzer/test/generated/element_resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../src/dart/resolution/driver_resolution.dart';
import '../util/element_type_matchers.dart';
import '../utils.dart';
import 'analysis_context_factory.dart';
import 'resolver_test_case.dart';
import 'test_support.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(AnnotationElementResolverTest);
defineReflectiveTests(ElementResolverTest);
defineReflectiveTests(PreviewDart2Test);
});
}

Expand Down Expand Up @@ -1248,343 +1245,3 @@ class ElementResolverTest extends EngineTestCase with ResourceProviderMixin {
}
}
}

@reflectiveTest
class PreviewDart2Test extends ResolverTestCase {
@override
void setUp() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
resetWith(options: options);
}

/**
* Tests and verifies that even with a explicit 'new' keyword, the
* construction of the InstanceCreationExpression node with types and elements
* is all correct.
*/
test_visitMethodInvocations_explicit() async {
String code = '''
class A {
A() {}
}
main() {
new A();
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;

expect(creation.staticElement, isConstructorElement);
expect(creation.staticType, isNotNull);

expect(creation.constructorName.staticElement, isConstructorElement);

expect(creation.constructorName.type.type, isNotNull);
expect(creation.constructorName.type.name.staticElement, isClassElement);

expect(creation.constructorName.name, isNull);
}

/**
* Test that the call to a constructor with an implicit unnamed constructor is
* re-written as an InstanceCreationExpression AST node from a
* MethodInvocation.
*
* C()
*/
test_visitMethodInvocations_implicit() async {
String code = '''
class A {
A(a, {b}) {}
}
main() {
A(0, b: 1);
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
ConstructorElement constructor = creation.staticElement;

expect(constructor, isConstructorElement);
expect(creation.staticType, isNotNull);

expect(creation.constructorName.staticElement, constructor);

expect(creation.constructorName.type.type, isNotNull);
expect(creation.constructorName.type.name.staticElement, isClassElement);

expect(creation.constructorName.name, isNull);

List<Expression> arguments = creation.argumentList.arguments;
Expression argumentA = arguments[0];
expect(argumentA.staticParameterElement, constructor.parameters[0]);
NamedExpression argumentB = arguments[1];
expect(argumentB.name.label.staticElement, constructor.parameters[1]);
}

/**
* Test that the call to a constructor with an implicit unnamed constructor is
* re-written as an InstanceCreationExpression AST node from a
* MethodInvocation.
*
* C(), where class C has no constructors
*/
test_visitMethodInvocations_implicit_implicit() async {
String code = '''
class A {}
main() {
A();
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
ConstructorElement constructor = creation.staticElement;

expect(constructor, isConstructorElement);
expect(creation.staticType, isNotNull);

expect(creation.constructorName.staticElement, constructor);

expect(creation.constructorName.type.type, isNotNull);
expect(creation.constructorName.type.name.staticElement, isClassElement);

expect(creation.constructorName.name, isNull);

expect(creation.argumentList.arguments, isEmpty);
}

/**
* Test that the call to a constructor with an implicit named constructor is
* re-written as an InstanceCreationExpression AST node from a
* MethodInvocation.
*
* C.n()
*/
test_visitMethodInvocations_implicit_named() async {
String code = '''
class A {
A.named() {}
}
main() {
A.named();
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
ConstructorElement constructor = creation.staticElement;

expect(constructor, isConstructorElement);
expect(creation.staticType, isNotNull);

expect(creation.constructorName.staticElement, constructor);

expect(creation.constructorName.type.type, isNotNull);
expect(creation.constructorName.type.name.staticElement, isClassElement);

expect(creation.constructorName.name.staticElement, constructor);
}

/**
* Test that the call to a constructor with a prefixed implicit constructor is
* re-written as an InstanceCreationExpression AST node from a
* MethodInvocation.
*
* p.C()
*/
test_visitMethodInvocations_implicit_prefixed() async {
addNamedSource("/fileOne.dart", r'''
class A {
A() {}
}
''');
String code = '''
import 'fileOne.dart' as one;
main() {
one.A();
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
ConstructorElement constructor = creation.staticElement;

expect(constructor, isConstructorElement);
expect(creation.staticType, isNotNull);

expect(creation.constructorName.staticElement, constructor);

expect(creation.constructorName.type.type, isNotNull);
expect(creation.constructorName.type.name.staticElement, isClassElement);

expect(creation.constructorName.name, isNull);
}

/**
* Test that the call to a constructor with a prefixed implicit named constructor is
* re-written as an InstanceCreationExpression AST node from a
* MethodInvocation.
*
* p.C.n()
*/
test_visitMethodInvocations_implicit_prefixed_named() async {
addNamedSource("/fileOne.dart", r'''
class A {
A.named(a, {b}) {}
}
''');
String code = '''
import 'fileOne.dart' as one;
main() {
one.A.named(0, b: 1);
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
ConstructorElement constructor = creation.staticElement;

expect(constructor, isConstructorElement);
expect(creation.staticType, isNotNull);

expect(creation.constructorName.staticElement, constructor);

expect(creation.constructorName.type.type, isNotNull);
expect(creation.constructorName.type.name.staticElement, isClassElement);

expect(creation.constructorName.name.staticElement, constructor);

List<Expression> arguments = creation.argumentList.arguments;
Expression argumentA = arguments[0];
expect(argumentA.staticParameterElement, constructor.parameters[0]);
NamedExpression argumentB = arguments[1];
expect(argumentB.name.label.staticElement, constructor.parameters[1]);
}

/**
* Test that the call to a constructor with a prefixed implicit constructor is
* re-written as an InstanceCreationExpression AST node from a
* MethodInvocation.
*
* p.C<>()
*/
test_visitMethodInvocations_implicit_prefixed_typeArgs() async {
addNamedSource("/fileOne.dart", r'''
class A<T> {
final T x;
A(this.x) {}
}
''');
String code = '''
import 'fileOne.dart' as one;
main() {
one.A<int>(42);
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
ConstructorElement constructor = creation.staticElement;

expect(constructor, isConstructorElement);
expect(creation.staticType, isNotNull);

expect(creation.constructorName.staticElement, constructor);

expect(creation.constructorName.type.type, isNotNull);
expect(creation.constructorName.type.name.staticElement, isClassElement);

expect(creation.constructorName.name, isNull);
}

/**
* Test that the call to a constructor with an implicit unnamed constructor is
* re-written as an InstanceCreationExpression AST node from a
* MethodInvocation.
*
* C<>()
*/
test_visitMethodInvocations_implicit_typeArgs() async {
String code = '''
class A<T> {
final T x;
A(this.x) {}
}
main() {
A<int>(42);
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
ConstructorElement constructor = creation.staticElement;

expect(constructor, isConstructorElement);
expect(creation.staticType, isNotNull);

expect(creation.constructorName.staticElement, constructor);

expect(creation.constructorName.type.type, isNotNull);
expect(creation.constructorName.type.name.staticElement, isClassElement);

expect(creation.constructorName.name, isNull);
}

test_visitMethodInvocations_importPrefix_function() async {
String code = '''
import 'dart:math' as ma;
main() {
ma.max(1, 2); // marker
}
''';
CompilationUnit unit = await resolveSource(code);
var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');

ExpressionStatement statement = statements[0];
MethodInvocation invocation = statement.expression;

SimpleIdentifier prefix = invocation.target;
expect(prefix.staticElement, isPrefixElement);

expect(invocation.methodName.name, 'max');
}

/**
* Test that the call to a static method will not be re-written as a
* InstanceCreationExpression AST node.
*/
test_visitMethodInvocations_not_implicit_constructor() async {
String code = '''
class A {
static staticMethod() {}
}
main() {
A.staticMethod(); // marker
}
''';
CompilationUnit unit = await resolveSource(code);
AstNode node = findMarkedIdentifier(code, unit, "(); // marker");
assert(node.parent is MethodInvocation);
}
}
11 changes: 0 additions & 11 deletions pkg/analyzer/test/src/dart/analysis/driver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,8 @@ class B {}
}
}

/// TODO(paulberry): migrate this test away from the task model.
/// See dartbug.com/35734.
@reflectiveTest
class AnalysisDriverTest extends BaseAnalysisDriverTest {
void configurePreviewDart2() {
driver.configure(
analysisOptions: new AnalysisOptionsImpl.from(driver.analysisOptions));
}

test_addedFiles() async {
var a = convertPath('/test/lib/a.dart');
var b = convertPath('/test/lib/b.dart');
Expand Down Expand Up @@ -1277,8 +1270,6 @@ class B {}
}

test_const_implicitCreation() async {
configurePreviewDart2();

var a = convertPath('/test/bin/a.dart');
var b = convertPath('/test/bin/b.dart');
newFile(a, content: r'''
Expand All @@ -1303,8 +1294,6 @@ const d = D.WARNING;
}

test_const_implicitCreation_rewrite() async {
configurePreviewDart2();

var a = convertPath('/test/bin/a.dart');
var b = convertPath('/test/bin/b.dart');
newFile(a, content: r'''
Expand Down

0 comments on commit 0a49dde

Please sign in to comment.