a16de199d7
This is a rediculously large CL, and if you want me to split it up I'm willing to do so. However, the changes were all made by running a script I wrote and then running the formatter over the code, so hopefully a spot-check will be sufficient. Change-Id: Ifc59b2cc3bf9e4edf0229a130cd587dc73f95615 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505042 Reviewed-by: Samuel Rawlins <srawlins@google.com> SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
230 lines
6.0 KiB
Dart
230 lines
6.0 KiB
Dart
// Copyright (c) 2026, 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:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
import '../rule_test_support.dart';
|
|
|
|
void main() {
|
|
defineReflectiveSuite(() {
|
|
defineReflectiveTests(SimpleDirectivePathsTest);
|
|
});
|
|
}
|
|
|
|
@reflectiveTest
|
|
class SimpleDirectivePathsTest extends LintRuleTest {
|
|
@override
|
|
String get lintRule => 'simple_directive_paths';
|
|
|
|
Future<void> test_export_authority() async {
|
|
await assertDiagnostics(
|
|
r'''
|
|
export '//localhost/a.dart';
|
|
''',
|
|
[error(diag.uriDoesNotExist, 7, 20)],
|
|
);
|
|
}
|
|
|
|
Future<void> test_export_package_minimal() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
await assertNoDiagnostics(r'''
|
|
export 'package:test/a.dart';
|
|
''');
|
|
}
|
|
|
|
Future<void> test_export_package_nonMinimal() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
export [!'package:test/./a.dart'!];
|
|
''');
|
|
}
|
|
|
|
Future<void> test_export_relative_minimal() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
await assertNoDiagnostics(r'''
|
|
export 'a.dart';
|
|
''');
|
|
}
|
|
|
|
Future<void> test_export_relative_nonMinimal() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
export [!'./a.dart'!];
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_absolute_backtracking() async {
|
|
await assertDiagnostics(
|
|
r'''
|
|
export '/src/../a.dart';
|
|
''',
|
|
[error(diag.uriDoesNotExist, 7, 16), lint(7, 16)],
|
|
);
|
|
}
|
|
|
|
Future<void> test_import_absolute_backtracking_root() async {
|
|
await assertDiagnostics(
|
|
r'''
|
|
export '/../a.dart';
|
|
''',
|
|
[error(diag.uriDoesNotExist, 7, 12), lint(7, 12)],
|
|
);
|
|
}
|
|
|
|
Future<void> test_import_absolute_normalized() async {
|
|
await assertDiagnostics(
|
|
r'''
|
|
export '/a.dart';
|
|
''',
|
|
[error(diag.uriDoesNotExist, 7, 9)],
|
|
);
|
|
}
|
|
|
|
Future<void> test_import_absolute_unnormalized() async {
|
|
await assertDiagnostics(
|
|
r'''
|
|
export '/./a.dart';
|
|
''',
|
|
[error(diag.uriDoesNotExist, 7, 11), lint(7, 11)],
|
|
);
|
|
}
|
|
|
|
Future<void> test_import_conditional() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
newFile('$testPackageLibPath/b.dart', '');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
export 'a.dart' if (dart.library.io) [!'./b.dart'!];
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_escape() async {
|
|
newFile('$testPackageLibPath/A.dart', '');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
export [!'%41.dart'!];
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_fragment() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
await assertDiagnostics(
|
|
r'''
|
|
export 'a.dart#frag';
|
|
''',
|
|
[error(diag.uriDoesNotExist, 7, 13), lint(7, 13)],
|
|
);
|
|
}
|
|
|
|
Future<void> test_import_in_part_relative_nonMinimal() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
newFile('$testPackageLibPath/src/lib.dart', "part 'part.dart';");
|
|
var part = newFile('$testPackageLibPath/src/part.dart', r'''
|
|
part of 'lib.dart';
|
|
export './../a.dart';
|
|
''');
|
|
await assertDiagnosticsInFile(part.path, [lint(27, 13)]);
|
|
}
|
|
|
|
Future<void> test_import_inTest_package_nonMinimal() async {
|
|
newFile('$testPackageLibPath/a.dart', 'class A {}');
|
|
var b = newFile('$testPackageRootPath/test/b.dart', r'''
|
|
import 'package:test/./a.dart';
|
|
A? a;
|
|
''');
|
|
await assertDiagnosticsInFile(b.path, [lint(7, 23)]);
|
|
}
|
|
|
|
Future<void> test_import_inTest_relative_nonMinimal() async {
|
|
newFile('$testPackageRootPath/test/a.dart', 'class A {}');
|
|
var b = newFile('$testPackageRootPath/test/b.dart', r'''
|
|
import './a.dart';
|
|
A? a;
|
|
''');
|
|
await assertDiagnosticsInFile(b.path, [lint(7, 10)]);
|
|
}
|
|
|
|
Future<void> test_import_package_minimal() async {
|
|
newFile('$testPackageLibPath/a.dart', 'class A {}');
|
|
await assertNoDiagnostics(r'''
|
|
import 'package:test/a.dart';
|
|
A? a;
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_package_nonMinimal() async {
|
|
newFile('$testPackageLibPath/a.dart', 'class A {}');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import [!'package:test/./a.dart'!];
|
|
A? a;
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_package_nonMinimal_backtracking() async {
|
|
newFile('$testPackageLibPath/a.dart', 'class A {}');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import [!'package:test/src/../a.dart'!];
|
|
A? a;
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_query() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
export [!'a.dart?key=val'!];
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_relative_minimal() async {
|
|
newFile('$testPackageLibPath/a.dart', 'class A {}');
|
|
await assertNoDiagnostics(r'''
|
|
import 'a.dart';
|
|
A? a;
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_relative_nonMinimal() async {
|
|
newFile('$testPackageLibPath/a.dart', 'class A {}');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
import [!'./a.dart'!];
|
|
A? a;
|
|
''');
|
|
}
|
|
|
|
Future<void> test_import_relative_nonMinimal_backtracking() async {
|
|
newFile('$testPackageLibPath/a.dart', 'class A {}');
|
|
var b = newFile('$testPackageLibPath/src/b.dart', r'''
|
|
import '../src/../a.dart';
|
|
A? a;
|
|
''');
|
|
await assertDiagnosticsInFile(b.path, [lint(7, 18)]);
|
|
}
|
|
|
|
Future<void> test_part() async {
|
|
newFile('$testPackageLibPath/a.dart', 'part of "test.dart";');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
part [!'./a.dart'!];
|
|
''');
|
|
}
|
|
|
|
Future<void> test_partOf() async {
|
|
newFile('$testPackageLibPath/test.dart', 'part "a.dart";');
|
|
var a = newFile('$testPackageLibPath/a.dart', r'''
|
|
part of './test.dart';
|
|
''');
|
|
await assertDiagnosticsInFile(a.path, [lint(8, 13)]);
|
|
}
|
|
|
|
Future<void> test_raw_string() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
await assertDiagnosticsFromMarkdown(r'''
|
|
export [!r'./a.dart'!];
|
|
''');
|
|
}
|
|
|
|
Future<void> test_triple_quotes() async {
|
|
newFile('$testPackageLibPath/a.dart', '');
|
|
await assertDiagnosticsFromMarkdown("export [!'''./a.dart'''!];");
|
|
}
|
|
}
|