Skip to content

Commit

Permalink
lint rules: move tests for hash_and_equals
Browse files Browse the repository at this point in the history
Change-Id: Ib196e5ada71d5a822965e9bd1c01527d9cb10587
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387523
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
srawlins authored and Commit Queue committed Sep 30, 2024
1 parent 7b502b1 commit 3d27988
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 48 deletions.
63 changes: 63 additions & 0 deletions pkg/linter/test/rules/hash_and_equals_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,41 @@ enum A {
]);
}

test_equalsEquals_andHashCode() async {
await assertNoDiagnostics(r'''
class C {
@override
bool operator ==(Object other) => false;
@override
int get hashCode => 7;
}
''');
}

test_equalsEquals_andHashCodeField() async {
await assertNoDiagnostics(r'''
class C {
@override
bool operator ==(Object other) => false;
@override
int hashCode = 7;
}
''');
}

test_equalsEquals_noHashCode() async {
await assertDiagnostics(r'''
class C {
@override
bool operator ==(Object other) => false;
}
''', [
lint(38, 2),
]);
}

test_extensionType_missingHash() async {
await assertDiagnostics(r'''
extension type E(Object o) {
Expand All @@ -78,4 +113,32 @@ extension type E(Object o) {
CompileTimeErrorCode.EXTENSION_TYPE_DECLARES_MEMBER_OF_OBJECT, 45, 2),
]);
}

test_hashCode_noEqualsEquals() async {
await assertDiagnostics(r'''
class C {
@override
int get hashCode => 7;
}
''', [
lint(32, 8),
]);
}

test_hashCodeField_missingEqualsEquals() async {
await assertDiagnostics(r'''
class C {
@override
final int hashCode = 7;
}
''', [
lint(34, 8),
]);
}

test_neither() async {
await assertNoDiagnostics(r'''
class C {}
''');
}
}
48 changes: 0 additions & 48 deletions pkg/linter/test_data/rules/hash_and_equals.dart

This file was deleted.

0 comments on commit 3d27988

Please sign in to comment.