Skip to content

Commit

Permalink
[enhanced-parts] test “Organize Imports”
Browse files Browse the repository at this point in the history
Fixes: #56683

Change-Id: I6b6aae385d4313e551f7c110e1e2544cc418a5a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384308
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Phil Quitslund <pquitslund@google.com>
  • Loading branch information
pq authored and Commit Queue committed Sep 10, 2024
1 parent 63c1306 commit 1bdb366
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:analyzer/src/services/available_declarations.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart'
hide AnalysisError;
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:analyzer_utilities/test/experiments/experiments.dart';
import 'package:meta/meta.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -89,7 +90,7 @@ abstract class BulkFixProcessorTest extends AbstractSingleUnitTest {
late BulkFixProcessor processor;

@override
List<String> get experiments => const [];
List<String> get experiments => experimentsForTests;

/// The name of the lint code being tested.
String? get lintCode => null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,79 @@ import 'fix_processor.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(OrganizeImportsBulkTest);
defineReflectiveTests(OrganizeImportsTest);
defineReflectiveTests(OrganizeImportsDirectivesOrderingTest);
});
}

@reflectiveTest
class OrganizeImportsBulkTest extends BulkFixProcessorTest {
Future<void> test_partFile() async {
newFile('$testPackageLibPath/a.dart', r'''
part 'test.dart';
''');

await resolveTestCode('''
part of 'a.dart';
import 'dart:io';
import 'dart:async';
Future? a;
''');

await assertOrganize('''
part of 'a.dart';
import 'dart:async';
import 'dart:io';
Future? a;
''');
}

Future<void> test_single_file() async {
await parseTestCode('''
import 'dart:io';
import 'dart:async';
Future a;
Future? a;
''');

await assertOrganize('''
import 'dart:async';
import 'dart:io';
Future a;
Future? a;
''');
}

Future<void> test_withParts() async {
newFile('$testPackageLibPath/a.dart', r'''
part of 'test.dart';
''');

await parseTestCode('''
import 'dart:io';
import 'dart:async';
part 'a.dart';
Future? a;
''');

await assertOrganize('''
import 'dart:async';
import 'dart:io';
part 'a.dart';
Future? a;
''');
}
}

@reflectiveTest
class OrganizeImportsTest extends FixProcessorLintTest {
class OrganizeImportsDirectivesOrderingTest extends FixProcessorLintTest {
@override
FixKind get kind => DartFixKind.ORGANIZE_IMPORTS;

Expand Down

0 comments on commit 1bdb366

Please sign in to comment.