mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
Initial tests for the implicit new and const constructor support in the analyzer
Change-Id: Ieef3294810520aaa03f6782971ccaaeff6ddb875 Reviewed-on: https://dart-review.googlesource.com/37422 Commit-Queue: Jaime Wren <jwren@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
991753313f
commit
25d0bac724
|
@ -323,6 +323,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
|
|||
}
|
||||
this._options.strongMode = options.strongMode;
|
||||
this._options.useFastaParser = options.useFastaParser;
|
||||
this._options.previewDart2 = options.previewDart2;
|
||||
this._options.trackCacheDependencies = options.trackCacheDependencies;
|
||||
this._options.disableCacheFlushing = options.disableCacheFlushing;
|
||||
this._options.patchPaths = options.patchPaths;
|
||||
|
|
|
@ -32,6 +32,7 @@ import 'test_support.dart';
|
|||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ElementResolverCodeTest);
|
||||
defineReflectiveTests(PreviewDart2Test);
|
||||
defineReflectiveTests(ElementResolverTest);
|
||||
});
|
||||
}
|
||||
|
@ -298,6 +299,88 @@ class C {}
|
|||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class PreviewDart2Test extends ResolverTestCase {
|
||||
@override
|
||||
void setUp() {
|
||||
AnalysisOptionsImpl options = new AnalysisOptionsImpl()
|
||||
..previewDart2 = true;
|
||||
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() {}
|
||||
A.named() {}
|
||||
}
|
||||
main() {
|
||||
var v = new A(); // marker
|
||||
}
|
||||
''';
|
||||
CompilationUnit unit = await resolveSource(code);
|
||||
AstNode constructorName = findMarkedIdentifier(code, unit, "(); // marker");
|
||||
InstanceCreationExpression instanceCreationExpression =
|
||||
constructorName.parent.parent.parent;
|
||||
expect(instanceCreationExpression, isNotNull);
|
||||
expect(instanceCreationExpression.constructorName.type.type, isNotNull);
|
||||
expect(instanceCreationExpression.constructorName.staticElement, isNotNull);
|
||||
expect(instanceCreationExpression.staticElement, isNotNull);
|
||||
expect(instanceCreationExpression.staticType, isNotNull);
|
||||
}
|
||||
|
||||
// Test that the call to a constructor with an implicit unnamed constructor is
|
||||
// re-written as an InstanceCreationExpression AST node from a
|
||||
// MethodInvocation.
|
||||
test_visitMethodInvocations_implicit() async {
|
||||
String code = '''
|
||||
class A {
|
||||
A() {}
|
||||
}
|
||||
main() {
|
||||
var v = A(); // marker
|
||||
}
|
||||
''';
|
||||
CompilationUnit unit = await resolveSource(code);
|
||||
AstNode constructorName = findMarkedIdentifier(code, unit, "(); // marker");
|
||||
InstanceCreationExpression instanceCreationExpression =
|
||||
constructorName.parent.parent.parent;
|
||||
expect(instanceCreationExpression, isNotNull);
|
||||
expect(instanceCreationExpression, isNotNull);
|
||||
expect(instanceCreationExpression.constructorName.type.type, isNotNull);
|
||||
expect(instanceCreationExpression.constructorName.staticElement, isNotNull);
|
||||
expect(instanceCreationExpression.staticElement, isNotNull);
|
||||
expect(instanceCreationExpression.staticType, isNotNull);
|
||||
}
|
||||
|
||||
// Test that the call to a constructor with an implicit named constructor is
|
||||
// re-written as an InstanceCreationExpression AST node from a
|
||||
// MethodInvocation.
|
||||
test_visitMethodInvocations_implicit_named() async {
|
||||
String code = '''
|
||||
class A {
|
||||
A.named() {}
|
||||
}
|
||||
main() {
|
||||
var v = A.named(); // marker
|
||||
}
|
||||
''';
|
||||
CompilationUnit unit = await resolveSource(code);
|
||||
AstNode constructorName = findMarkedIdentifier(code, unit, "(); // marker");
|
||||
InstanceCreationExpression instanceCreationExpression =
|
||||
constructorName.parent.parent;
|
||||
expect(instanceCreationExpression, isNotNull);
|
||||
expect(instanceCreationExpression, isNotNull);
|
||||
expect(instanceCreationExpression.constructorName.type.type, isNotNull);
|
||||
expect(instanceCreationExpression.constructorName.staticElement, isNotNull);
|
||||
expect(instanceCreationExpression.staticElement, isNotNull);
|
||||
expect(instanceCreationExpression.staticType, isNotNull);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ElementResolverTest extends EngineTestCase {
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue