Skip to content

Commit

Permalink
Move noop_primitive_operations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Jul 26, 2023
1 parent bd49571 commit e326dfe
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 53 deletions.
2 changes: 2 additions & 0 deletions test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import 'no_self_assignments_test.dart' as no_self_assignments;
import 'no_wildcard_variable_uses_test.dart' as no_wildcard_variable_uses;
import 'non_constant_identifier_names_test.dart'
as non_constant_identifier_names;
import 'noop_primitive_operations_test.dart' as noop_primitive_operations;
import 'null_check_on_nullable_type_parameter_test.dart'
as null_check_on_nullable_type_parameter;
import 'null_closures_test.dart' as null_closures;
Expand Down Expand Up @@ -262,6 +263,7 @@ void main() {
no_self_assignments.main();
no_wildcard_variable_uses.main();
non_constant_identifier_names.main();
noop_primitive_operations.main();
null_check_on_nullable_type_parameter.main();
null_closures.main();
omit_local_variable_types.main();
Expand Down
175 changes: 175 additions & 0 deletions test/rules/noop_primitive_operations_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Copyright (c) 2023, 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 '../rule_test_support.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(NoopPrimitiveOperationsTest);
});
}

@reflectiveTest
class NoopPrimitiveOperationsTest extends LintRuleTest {
@override
String get lintRule => 'noop_primitive_operations';

test_double_toDouble() async {
await assertDiagnostics(r'''
void f(double x) {
x.toDouble();
}
''', [
lint(23, 8),
]);
}

test_int_ceil() async {
await assertDiagnostics(r'''
void f(int x) {
x.ceil();
}
''', [
lint(20, 4),
]);
}

test_int_floor() async {
await assertDiagnostics(r'''
void f(int x) {
x.floor();
}
''', [
lint(20, 5),
]);
}

test_int_round() async {
await assertDiagnostics(r'''
void f(int x) {
x.round();
}
''', [
lint(20, 5),
]);
}

test_int_toInt() async {
await assertDiagnostics(r'''
void f(int x) {
x.toInt();
}
''', [
lint(20, 5),
]);
}

test_int_truncate() async {
await assertDiagnostics(r'''
void f(int x) {
x.truncate();
}
''', [
lint(20, 8),
]);
}

test_interpolation_object_toString() async {
await assertDiagnostics(r'''
void f() {
'${1.toString()}';
}
''', [
lint(18, 8),
]);
}

test_interpolation_super_toString() async {
await assertNoDiagnostics(r'''
class C {
void m() {
'${super.toString()}';
}
}
''');
}

test_print_null_toString() async {
await assertDiagnostics(r'''
void f() {
print(null.toString());
}
''', [
lint(24, 8),
]);
}

test_print_object_toString() async {
await assertDiagnostics(r'''
void f() {
print(1.toString());
}
''', [
lint(21, 8),
]);
}

test_print_stringLiteral() async {
await assertNoDiagnostics(r'''
onPrint() {
print(''); // OK
}
''');
}

test_string_adjacentBlankString() async {
await assertDiagnostics(r'''
void f(String x) {
x = 'hello\n' 'world\n' '';
}
''', [
lint(45, 2),
]);
}

test_string_nullable_toString() async {
await assertNoDiagnostics(r'''
void f(String? x) {
x.toString();
}
''');
}

test_string_toString() async {
await assertDiagnostics(r'''
void f(String x) {
x.toString();
}
''', [
lint(23, 8),
]);
}

test_super_toString() async {
await assertNoDiagnostics(r'''
class C {
void m() {
super.toString();
}
}
''');
}

test_unrelatedToStringFunction() async {
await assertNoDiagnostics(r'''
void f() {
print(toString());
}
String toString() => '';
''');
}
}
53 changes: 0 additions & 53 deletions test_data/rules/noop_primitive_operations.dart

This file was deleted.

0 comments on commit e326dfe

Please sign in to comment.