mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
More tests in ConstantPatternResolutionTest.
Change-Id: Id91f9da9cd1c4f36738030fae66e2e6fbbd7d31c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263040 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
fe98a5642e
commit
c8799b3e44
|
@ -14,7 +14,67 @@ main() {
|
|||
|
||||
@reflectiveTest
|
||||
class ConstantPatternResolutionTest extends PatternsResolutionTest {
|
||||
test_ifCase() async {
|
||||
test_expression_class_field() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
class A {
|
||||
static const foo = 0;
|
||||
}
|
||||
|
||||
void f(x) {
|
||||
if (x case A.foo) {}
|
||||
}
|
||||
''');
|
||||
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
expression: PrefixedIdentifier
|
||||
prefix: SimpleIdentifier
|
||||
token: A
|
||||
staticElement: self::@class::A
|
||||
staticType: null
|
||||
period: .
|
||||
identifier: SimpleIdentifier
|
||||
token: foo
|
||||
staticElement: self::@class::A::@getter::foo
|
||||
staticType: int
|
||||
staticElement: self::@class::A::@getter::foo
|
||||
staticType: int
|
||||
''');
|
||||
}
|
||||
|
||||
test_expression_instanceCreation() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
|
||||
void f(x) {
|
||||
if (x case const A()) {}
|
||||
}
|
||||
''');
|
||||
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
const: const
|
||||
expression: InstanceCreationExpression
|
||||
constructorName: ConstructorName
|
||||
type: NamedType
|
||||
name: SimpleIdentifier
|
||||
token: A
|
||||
staticElement: self::@class::A
|
||||
staticType: null
|
||||
type: A
|
||||
staticElement: self::@class::A::@constructor::new
|
||||
argumentList: ArgumentList
|
||||
leftParenthesis: (
|
||||
rightParenthesis: )
|
||||
staticType: A
|
||||
''');
|
||||
}
|
||||
|
||||
test_expression_integerLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f(x) {
|
||||
if (x case 0) {}
|
||||
|
@ -29,7 +89,7 @@ ConstantPattern
|
|||
''');
|
||||
}
|
||||
|
||||
test_integerLiteral_contextType_double() async {
|
||||
test_expression_integerLiteral_contextType_double() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f(double x) {
|
||||
switch (x) {
|
||||
|
@ -47,23 +107,184 @@ ConstantPattern
|
|||
''');
|
||||
}
|
||||
|
||||
test_simpleIdentifier_ifCase() async {
|
||||
test_expression_listLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f(x, int y) {
|
||||
if (x case y) {}
|
||||
void f(x) {
|
||||
if (x case const [0]) {}
|
||||
}
|
||||
''');
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
const: const
|
||||
expression: ListLiteral
|
||||
leftBracket: [
|
||||
elements
|
||||
IntegerLiteral
|
||||
literal: 0
|
||||
staticType: int
|
||||
rightBracket: ]
|
||||
staticType: List<int>
|
||||
''');
|
||||
}
|
||||
|
||||
test_expression_mapLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f(x) {
|
||||
if (x case const {0: 1}) {}
|
||||
}
|
||||
''');
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
const: const
|
||||
expression: SetOrMapLiteral
|
||||
leftBracket: {
|
||||
elements
|
||||
SetOrMapLiteral
|
||||
key: IntegerLiteral
|
||||
literal: 0
|
||||
staticType: int
|
||||
separator: :
|
||||
value: IntegerLiteral
|
||||
literal: 1
|
||||
staticType: int
|
||||
rightBracket: }
|
||||
isMap: true
|
||||
staticType: Map<int, int>
|
||||
''');
|
||||
}
|
||||
|
||||
test_expression_prefix_class_topLevelVariable() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {
|
||||
static const foo = 0;
|
||||
}
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'a.dart' as prefix;
|
||||
|
||||
void f(x) {
|
||||
if (x case prefix.A.foo) {}
|
||||
}
|
||||
''');
|
||||
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
expression: PropertyAccess
|
||||
target: PrefixedIdentifier
|
||||
prefix: SimpleIdentifier
|
||||
token: prefix
|
||||
staticElement: self::@prefix::prefix
|
||||
staticType: null
|
||||
period: .
|
||||
identifier: SimpleIdentifier
|
||||
token: A
|
||||
staticElement: package:test/a.dart::@class::A
|
||||
staticType: null
|
||||
staticElement: package:test/a.dart::@class::A
|
||||
staticType: null
|
||||
operator: .
|
||||
propertyName: SimpleIdentifier
|
||||
token: foo
|
||||
staticElement: package:test/a.dart::@class::A::@getter::foo
|
||||
staticType: int
|
||||
staticType: int
|
||||
''');
|
||||
}
|
||||
|
||||
test_expression_prefix_topLevelVariable() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
const foo = 0;
|
||||
''');
|
||||
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'a.dart' as prefix;
|
||||
|
||||
void f(x) {
|
||||
if (x case prefix.foo) {}
|
||||
}
|
||||
''');
|
||||
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
expression: PrefixedIdentifier
|
||||
prefix: SimpleIdentifier
|
||||
token: prefix
|
||||
staticElement: self::@prefix::prefix
|
||||
staticType: null
|
||||
period: .
|
||||
identifier: SimpleIdentifier
|
||||
token: foo
|
||||
staticElement: package:test/a.dart::@getter::foo
|
||||
staticType: int
|
||||
staticElement: package:test/a.dart::@getter::foo
|
||||
staticType: int
|
||||
''');
|
||||
}
|
||||
|
||||
test_expression_setLiteral() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f(x) {
|
||||
if (x case const {0, 1}) {}
|
||||
}
|
||||
''');
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
const: const
|
||||
expression: SetOrMapLiteral
|
||||
leftBracket: {
|
||||
elements
|
||||
IntegerLiteral
|
||||
literal: 0
|
||||
staticType: int
|
||||
IntegerLiteral
|
||||
literal: 1
|
||||
staticType: int
|
||||
rightBracket: }
|
||||
isMap: false
|
||||
staticType: Set<int>
|
||||
''');
|
||||
}
|
||||
|
||||
test_expression_topLevelVariable() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const foo = 0;
|
||||
|
||||
void f(x) {
|
||||
if (x case foo) {}
|
||||
}
|
||||
''');
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
expression: SimpleIdentifier
|
||||
token: y
|
||||
staticElement: self::@function::f::@parameter::y
|
||||
token: foo
|
||||
staticElement: self::@getter::foo
|
||||
staticType: int
|
||||
''');
|
||||
}
|
||||
|
||||
test_switchCase() async {
|
||||
test_location_ifCase() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f(x) {
|
||||
if (x case 0) {}
|
||||
}
|
||||
''');
|
||||
final node = findNode.caseClause('case').pattern;
|
||||
assertResolvedNodeText(node, r'''
|
||||
ConstantPattern
|
||||
expression: IntegerLiteral
|
||||
literal: 0
|
||||
staticType: int
|
||||
''');
|
||||
}
|
||||
|
||||
test_location_switchCase() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
void f(x) {
|
||||
switch (x) {
|
||||
|
|
Loading…
Reference in a new issue