blob: a1d77a3b36d7e5c2adbe04b01b04f248020c55e8 [file]
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'context_collection_resolution.dart';
import 'node_text_expectations.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NullAssertPatternResolutionTest);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
@reflectiveTest
class NullAssertPatternResolutionTest extends PubPackageResolutionTest {
test_ifCase() async {
var result = await resolveTestCodeWithDiagnostics(r'''
void f(int? x) {
if (x case var y!) {}
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
}
''');
var node = result.findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
NullAssertPattern
pattern: DeclaredVariablePattern
keyword: var
name: y
declaredFragment: isPublic y@34
element: hasImplicitType isPublic
type: int
matchedValueType: int
operator: !
matchedValueType: int?
''');
}
test_switchCase() async {
var result = await resolveTestCodeWithDiagnostics(r'''
void f(int? x) {
switch (x) {
case var y!:
// ^
// [diag.unusedLocalVariable] The value of the local variable 'y' isn't used.
break;
}
}
''');
var node = result.findNode.singleGuardedPattern.pattern;
assertResolvedNodeText(node, r'''
NullAssertPattern
pattern: DeclaredVariablePattern
keyword: var
name: y
declaredFragment: isPublic y@45
element: hasImplicitType isPublic
type: int
matchedValueType: int
operator: !
matchedValueType: int?
''');
}
test_variableDeclaration() async {
var result = await resolveTestCodeWithDiagnostics(r'''
void f(int? x) {
var (a!) = x;
// ^
// [diag.unusedLocalVariable] The value of the local variable 'a' isn't used.
}
''');
var node = result.findNode.singlePatternVariableDeclaration;
assertResolvedNodeText(node, r'''
PatternVariableDeclaration
keyword: var
pattern: ParenthesizedPattern
leftParenthesis: (
pattern: NullAssertPattern
pattern: DeclaredVariablePattern
name: a
declaredFragment: isPublic a@24
element: hasImplicitType isPublic
type: int
matchedValueType: int
operator: !
matchedValueType: int?
rightParenthesis: )
matchedValueType: int?
equals: =
expression2: SimpleIdentifier
token: x
element: <testLibrary>::@function::f::@formalParameter::x
staticType: int?
patternTypeSchema: _
''');
}
}