Files
sdk/pkg/linter/test/rules/comment_references_test.dart
T
Parker Lougheed 80ad96837c [linter] Add field and super parameter tests for comment_references lint
The core issue was solved in https://github.com/dart-lang/sdk/commit/c8b18439d48a3acd7a8c73b6539265708f4417dc.
This CL adds tests to verify the linter correctly finds the associated static elements and doesn't report a comment_references lint.

Closes https://github.com/dart-lang/linter/issues/3563

Bug: https://github.com/dart-lang/linter/issues/3563
Change-Id: Icf281faf1934b135b51e98271be461b527b83a14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339061
Auto-Submit: Parker Lougheed <parlough@gmail.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-12-02 22:43:35 +00:00

155 lines
2.6 KiB
Dart

// 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(CommentReferencesTest);
});
}
@reflectiveTest
class CommentReferencesTest extends LintRuleTest {
@override
String get lintRule => 'comment_references';
test_false() async {
await assertDiagnostics(r'''
/// [false]
class C {}
''', [
lint(5, 5),
]);
}
test_field() async {
await assertNoDiagnostics(r'''
class A {
int x = 0;
/// Assigns to [x].
void m() {}
}
''');
}
test_importedElement() async {
await assertNoDiagnostics(r'''
/// [String] is OK.
class C {}
''');
}
test_markdown_inlineLink() async {
await assertNoDiagnostics(r'''
/// A link to [Sha256](http://tools.ietf.org/html/rfc6234) hash function.
class C {}
''');
}
test_markdown_inlineLink_withTitle() async {
await assertNoDiagnostics(r'''
/// A link to [Sha256](http://tools.ietf.org/html/rfc6234 "Some") hash function.
class C {}
''');
}
test_markdown_referenceLink() async {
await assertNoDiagnostics(r'''
/// A link to [Sha256][rfc] hash function.
///
/// [rfc]: http://tools.ietf.org/html/rfc6234
class C {}
''');
}
test_markdown_referenceLink_shortcut() async {
await assertNoDiagnostics(r'''
/// A link to [rfc][] hash function.
///
/// [rfc]: http://tools.ietf.org/html/rfc6234
class C {}
''');
}
test_null() async {
await assertDiagnostics(r'''
/// [null]
class C {}
''', [
lint(5, 4),
]);
}
test_parameter() async {
await assertNoDiagnostics(r'''
class A {
/// Reads [x].
void m(int x) {}
}
''');
}
test_parameter_constructor_field() async {
await assertNoDiagnostics(r'''
class A {
final int x;
/// [x]
A(this.x);
}
''');
}
test_parameter_constructor_super() async {
await assertNoDiagnostics(r'''
class A {
A(int x);
}
class B extends A {
/// [x]
B(super.x);
}
''');
}
test_this() async {
await assertDiagnostics(r'''
/// [this]
class C {}
''', [
lint(5, 4),
]);
}
test_true() async {
await assertDiagnostics(r'''
/// [true]
class C {}
''', [
lint(5, 4),
]);
}
test_unclosedSquareBracket() async {
await assertNoDiagnostics(r'''
/// [
/// ^--- Should not crash (#819).
class C {}
''');
}
test_unknownElement() async {
await assertDiagnostics(r'''
/// Parameter [y].
void f(int x) {}
''', [
lint(15, 1),
]);
}
}