Enable patterns in server tests

Change-Id: I1d256b4c1c0cc20cb3e46087cd896d0920f82690
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/274084
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2022-12-08 02:12:14 +00:00 committed by Commit Queue
parent 44b877b55a
commit de36e1cfb7
9 changed files with 367 additions and 8 deletions

View file

@ -49,11 +49,9 @@ class AbstractContextTest with ResourceProviderMixin {
/// Return a list of the experiments that are to be enabled for tests in this
/// class, an empty list if there are no experiments that should be enabled.
List<String> get experiments => [
EnableString.enhanced_enums,
EnableString.macros,
EnableString.named_arguments_anywhere,
EnableString.patterns,
EnableString.records,
EnableString.super_parameters,
];
String get latestLanguageVersion =>

View file

@ -2400,14 +2400,40 @@ f() => [...^];
assertSuggestKeywords([Keyword.CASE, Keyword.DEFAULT]);
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_switch_statement_case_break_insideClass() async {
addTestSource('class A{foo() {switch(1) {case 1: b^}}}');
addTestSource('''
class A{foo() {switch(1) {case 1: b^}}}
''');
await computeSuggestions();
assertSuggestKeywords(statementStartInSwitchCaseInClass);
}
Future<void>
test_switch_statement_case_break_insideClass_language219() async {
addTestSource('''
// @dart=2.19
class A{foo() {switch(1) {case 1: b^}}}
''');
await computeSuggestions();
assertSuggestKeywords(statementStartInSwitchCaseInClass);
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_switch_statement_case_break_outsideClass() async {
addTestSource('foo() {switch(1) {case 1: b^}}');
addTestSource('''
foo() {switch(1) {case 1: b^}}
''');
await computeSuggestions();
assertSuggestKeywords(statementStartInSwitchCaseOutsideClass);
}
Future<void>
test_switch_statement_case_break_outsideClass_language219() async {
addTestSource('''
// @dart=2.19
foo() {switch(1) {case 1: b^}}
''');
await computeSuggestions();
assertSuggestKeywords(statementStartInSwitchCaseOutsideClass);
}

View file

@ -2394,11 +2394,35 @@ void f(E e) {
assertSuggestEnumConst('F.four');
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_enum_filter_switchCase() async {
addTestSource('''
enum E { one, two }
enum F { three, four }
void f(E e) {
switch (e) {
case ^
}
}
''');
await computeSuggestions();
assertSuggestEnum('E');
assertSuggestEnumConst('E.one');
assertSuggestEnumConst('E.two');
assertSuggestEnum('F');
assertNotSuggested('F.three');
assertNotSuggested('F.four');
}
Future<void> test_enum_filter_switchCase_language219() async {
addTestSource('''
// @dart=2.19
enum E { one, two }
enum F { three, four }
void f(E e) {
switch (e) {
case ^
@ -5825,9 +5849,27 @@ class C<T> {
assertNotSuggested('String');
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_SwitchStatement_case_var() async {
// SwitchStatement Block BlockFunctionBody MethodDeclaration
addTestSource('g(int x) {var t; switch(x) {case 0: var bar; b^}}');
addTestSource('''
g(int x) {var t; switch(x) {case 0: var bar; b^}}
''');
await computeSuggestions();
assertSuggestFunction('g', 'dynamic');
assertSuggestLocalVariable('t', 'dynamic');
assertSuggestParameter('x', 'int');
assertSuggestLocalVariable('bar', 'dynamic');
assertNotSuggested('String');
}
Future<void> test_SwitchStatement_case_var_language219() async {
// SwitchStatement Block BlockFunctionBody MethodDeclaration
addTestSource('''
// @dart=2.19
g(int x) {var t; switch(x) {case 0: var bar; b^}}
''');
await computeSuggestions();
assertSuggestFunction('g', 'dynamic');

View file

@ -1373,7 +1373,7 @@ class Thing extends Object {
_assertHasChange('Add a semicolon and newline', '''
class Thing extends Object {
int foo() => 1;
////
}
''');
}
@ -1455,7 +1455,7 @@ void f() {
'''
void f() {
int g();
////
}
''',
(s) => _afterLast(s, '();\n '));
@ -1557,6 +1557,7 @@ void f() {
@reflectiveTest
class _SwitchCompletionTest extends StatementCompletionTest {
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_caseNoColon() async {
await _prepareCompletion(
'label',
@ -1580,6 +1581,31 @@ void f(x) {
(s) => _after(s, 'label: '));
}
Future<void> test_caseNoColon_language219() async {
await _prepareCompletion(
'label',
'''
// @dart=2.19
void f(x) {
switch (x) {
case label
}
}
''',
atEnd: true);
_assertHasChange(
'Complete switch-statement',
'''
// @dart=2.19
void f(x) {
switch (x) {
case label: ////
}
}
''',
(s) => _after(s, 'label: '));
}
Future<void> test_defaultNoColon() async {
await _prepareCompletion(
'default',

View file

@ -154,6 +154,7 @@ void f() {
''');
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_OK_inSwitchCase() async {
await indexTestUnit('''
void f(int p) {
@ -178,6 +179,32 @@ void f(int p) {
''');
}
Future<void> test_OK_inSwitchCase_language219() async {
await indexTestUnit('''
// @dart=2.19
void f(int p) {
switch (p) {
case 0:
int test = 42;
print(test);
break;
}
}
''');
_createRefactoring('test =');
// validate change
return assertSuccessfulRefactoring('''
// @dart=2.19
void f(int p) {
switch (p) {
case 0:
print(42);
break;
}
}
''');
}
Future<void> test_OK_intoStringInterpolation_binaryExpression() async {
await indexTestUnit(r'''
void f() {

View file

@ -256,6 +256,7 @@ void f(E e) {
await assertNoFix(errorFilter: _filter);
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_notEmpty() async {
await resolveTestCode('''
enum E {a, b, c}
@ -283,6 +284,35 @@ void f(E e) {
''');
}
Future<void> test_notEmpty_language219() async {
await resolveTestCode('''
// @dart=2.19
enum E {a, b, c}
void f(E e) {
switch (e) {
case E.a:
break;
}
}
''');
await assertHasFixWithFilter('''
// @dart=2.19
enum E {a, b, c}
void f(E e) {
switch (e) {
case E.a:
break;
case E.b:
// TODO: Handle this case.
break;
case E.c:
// TODO: Handle this case.
break;
}
}
''');
}
Future<void> test_static() async {
await resolveTestCode('''
enum E {

View file

@ -116,6 +116,7 @@ class E {
''');
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_notEmpty() async {
await resolveTestCode('''
void f(E e) {
@ -153,6 +154,48 @@ class E {
final int x;
const E._(this.x);
}
''');
}
Future<void> test_notEmpty_language219() async {
await resolveTestCode('''
// @dart=2.19
void f(E e) {
switch (e) {
case E.a:
break;
case E.b:
break;
}
}
class E {
static const E a = E._(0);
static const E b = E._(1);
static const E c = E._(2);
final int x;
const E._(this.x);
}
''');
await assertHasFix('''
// @dart=2.19
void f(E e) {
switch (e) {
case E.a:
break;
case E.b:
break;
case E.c:
// TODO: Handle this case.
break;
}
}
class E {
static const E a = E._(0);
static const E b = E._(1);
static const E c = E._(2);
final int x;
const E._(this.x);
}
''');
}
}

View file

@ -21,6 +21,7 @@ class AddSwitchCaseBreakMultiTest extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.ADD_SWITCH_CASE_BREAK_MULTI;
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_singleFile() async {
await resolveTestCode('''
void f(int i) {
@ -48,6 +49,38 @@ void f(int i) {
i++;
}
}
''');
}
Future<void> test_singleFile_language219() async {
await resolveTestCode('''
// @dart=2.19
void f(int i) {
switch(i) {
case 0:
i++;
case 1:
i++;
case 2:
i++;
}
}
''');
await assertHasFixAllFix(
CompileTimeErrorCode.SWITCH_CASE_COMPLETES_NORMALLY, '''
// @dart=2.19
void f(int i) {
switch(i) {
case 0:
i++;
break;
case 1:
i++;
break;
case 2:
i++;
}
}
''');
}
}
@ -57,6 +90,7 @@ class AddSwitchCaseBreakTest extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.ADD_SWITCH_CASE_BREAK;
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_indentation() async {
await resolveTestCode('''
void f(int i) {
@ -78,6 +112,32 @@ void f(int i) {
i++;
}
}
''');
}
Future<void> test_indentation_language219() async {
await resolveTestCode('''
// @dart=2.19
void f(int i) {
switch(i) {
case 0:
i++;
case 1:
i++;
}
}
''');
await assertHasFix('''
// @dart=2.19
void f(int i) {
switch(i) {
case 0:
i++;
break;
case 1:
i++;
}
}
''');
}
}

View file

@ -61,6 +61,7 @@ class RemoveDuplicateCaseTest extends FixProcessorLintTest {
@override
String get lintCode => LintNames.no_duplicate_case_values;
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_fallThroughFromPrevious() async {
await resolveTestCode('''
void switchInt() {
@ -95,6 +96,43 @@ void switchInt() {
''');
}
Future<void> test_fallThroughFromPrevious_language219() async {
await resolveTestCode('''
// @dart=2.19
void switchInt() {
switch (2) {
case 1:
print('a');
break;
case 2:
case 3:
case 2:
print('b');
break;
default:
print('?');
}
}
''');
await assertHasFix('''
// @dart=2.19
void switchInt() {
switch (2) {
case 1:
print('a');
break;
case 2:
case 3:
print('b');
break;
default:
print('?');
}
}
''');
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_removeIntCase() async {
await resolveTestCode('''
void switchInt() {
@ -123,6 +161,37 @@ void switchInt() {
''');
}
Future<void> test_removeIntCase_language219() async {
await resolveTestCode('''
// @dart=2.19
void switchInt() {
switch (2) {
case 1:
print('a');
break;
case 2:
case 2:
default:
print('?');
}
}
''');
await assertHasFix('''
// @dart=2.19
void switchInt() {
switch (2) {
case 1:
print('a');
break;
case 2:
default:
print('?');
}
}
''');
}
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49759')
Future<void> test_removeStringCase() async {
await resolveTestCode('''
void switchString() {
@ -156,6 +225,44 @@ void switchString() {
print('?');
}
}
''');
}
Future<void> test_removeStringCase_language219() async {
await resolveTestCode('''
// @dart=2.19
void switchString() {
String v = 'a';
switch (v) {
case 'a':
print('a');
break;
case 'b':
print('b');
break;
case 'a':
print('a');
break;
default:
print('?');
}
}
''');
await assertHasFix('''
// @dart=2.19
void switchString() {
String v = 'a';
switch (v) {
case 'a':
print('a');
break;
case 'b':
print('b');
break;
default:
print('?');
}
}
''');
}
}