mirror of
https://github.com/dart-lang/sdk
synced 2024-10-03 21:21:32 +00:00
Add tests to test InstanceCreationExpressionImpl.canBeConst
Change-Id: Id678d054d7b54e5eb33e5f406efa7b51a7aa4361 Reviewed-on: https://dart-review.googlesource.com/55902 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
def6f6c86c
commit
802c25aff9
|
@ -470,7 +470,18 @@ class InstanceCreationExpressionImplTest extends ResolverTestCase {
|
|||
|
||||
bool get enableNewAnalysisDriver => true;
|
||||
|
||||
void assertIsConst(String snippet, bool isConst) {
|
||||
void assertCanBeConst(String snippet, bool expectedResult) {
|
||||
int index = testSource.indexOf(snippet);
|
||||
expect(index >= 0, isTrue);
|
||||
NodeLocator visitor = new NodeLocator(index);
|
||||
AstNodeImpl node = visitor.searchWithin(testUnit);
|
||||
node = node.getAncestor((node) => node is InstanceCreationExpressionImpl);
|
||||
expect(node, isNotNull);
|
||||
expect((node as InstanceCreationExpressionImpl).canBeConst(),
|
||||
expectedResult ? isTrue : isFalse);
|
||||
}
|
||||
|
||||
void assertIsConst(String snippet, bool expectedResult) {
|
||||
int index = testSource.indexOf(snippet);
|
||||
expect(index >= 0, isTrue);
|
||||
NodeLocator visitor = new NodeLocator(index);
|
||||
|
@ -478,7 +489,7 @@ class InstanceCreationExpressionImplTest extends ResolverTestCase {
|
|||
node = node.getAncestor((node) => node is InstanceCreationExpressionImpl);
|
||||
expect(node, isNotNull);
|
||||
expect((node as InstanceCreationExpressionImpl).isConst,
|
||||
isConst ? isTrue : isFalse);
|
||||
expectedResult ? isTrue : isFalse);
|
||||
}
|
||||
|
||||
void enablePreviewDart2() {
|
||||
|
@ -490,6 +501,68 @@ class InstanceCreationExpressionImplTest extends ResolverTestCase {
|
|||
testUnit = await resolveSource2('/test.dart', source);
|
||||
}
|
||||
|
||||
void test_canBeConst_false_argument_invocation() async {
|
||||
enablePreviewDart2();
|
||||
await resolve('''
|
||||
class A {}
|
||||
class B {
|
||||
const B(A a);
|
||||
}
|
||||
A f() => A();
|
||||
B g() => B(f());
|
||||
''');
|
||||
assertCanBeConst("B(f", false);
|
||||
}
|
||||
|
||||
void test_canBeConst_false_argument_invocationInList() async {
|
||||
enablePreviewDart2();
|
||||
await resolve('''
|
||||
class A {}
|
||||
class B {
|
||||
const B(a);
|
||||
}
|
||||
A f() => A();
|
||||
B g() => B([f()]);
|
||||
''');
|
||||
assertCanBeConst("B([", false);
|
||||
}
|
||||
|
||||
void test_canBeConst_false_argument_nonConstConstructor() async {
|
||||
enablePreviewDart2();
|
||||
await resolve('''
|
||||
class A {}
|
||||
class B {
|
||||
const B(A a);
|
||||
}
|
||||
B f() => B(A());
|
||||
''');
|
||||
assertCanBeConst("B(A(", false);
|
||||
}
|
||||
|
||||
void test_canBeConst_false_nonConstConstructor() async {
|
||||
enablePreviewDart2();
|
||||
await resolve('''
|
||||
class A {}
|
||||
A f() => A();
|
||||
''');
|
||||
assertCanBeConst("A(", false);
|
||||
}
|
||||
|
||||
@failingTest
|
||||
void test_canBeConst_true_argument_constConstructor() async {
|
||||
enablePreviewDart2();
|
||||
await resolve('''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
class B {
|
||||
const B(A a);
|
||||
}
|
||||
B f() => B(A());
|
||||
''');
|
||||
assertCanBeConst("B(A(", true);
|
||||
}
|
||||
|
||||
void
|
||||
test_isConst_notInContext_constructor_const_constParam_identifier() async {
|
||||
enablePreviewDart2();
|
||||
|
|
Loading…
Reference in a new issue