blob: e39942ceed5f70bcffc3f63d26a3d1bee1c58de1 [file] [log] [blame]
// Copyright (c) 2019, 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:analysis_server/src/services/correction/assist.dart';
import 'package:analyzer_plugin/utilities/assist/assist.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'assist_processor.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AddNotNullAssert);
});
}
@reflectiveTest
class AddNotNullAssert extends AssistProcessorTest {
@override
AssistKind get kind => DartAssistKind.ADD_NOT_NULL_ASSERT;
test_function_expressionBody_noAssert() async {
await resolveTestUnit('''
int double(int x) => x * 2;
''');
// todo (pq): support expression bodies.
await assertNoAssistAt('x');
}
test_function_noAssert() async {
await resolveTestUnit('''
foo(int x) {
}
''');
await assertHasAssistAt('x', '''
foo(int x) {
assert(x != null);
}
''');
}
test_function_withAssert() async {
await resolveTestUnit('''
foo(int x) {
assert(x != null);
}
''');
await assertNoAssistAt('x');
}
test_function_withAssert2() async {
await resolveTestUnit('''
foo(int x) {
print('foo');
assert(x != null);
}
''');
await assertNoAssistAt('x');
}
test_method_noAssert() async {
await resolveTestUnit('''
class A {
foo(int x) {
}
}''');
await assertHasAssistAt('x', '''
class A {
foo(int x) {
assert(x != null);
}
}''');
}
}