Add more tests for selection with augmentations.
Change-Id: I55acf9bb37bcaaa39fa75898631b4cfd83d23021
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355301
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
diff --git a/pkg/analysis_server/test/src/computer/selection_range_computer_test.dart b/pkg/analysis_server/test/src/computer/selection_range_computer_test.dart
index 790f686..cfd6715 100644
--- a/pkg/analysis_server/test/src/computer/selection_range_computer_test.dart
+++ b/pkg/analysis_server/test/src/computer/selection_range_computer_test.dart
@@ -110,6 +110,60 @@
);
}
+ Future<void> test_class_fields_augmentation() async {
+ newFile('$testPackageLibPath/a.dart', '''
+import augment 'test.dart';
+class Foo {
+ String a = 'test';
+}
+''');
+
+ final content = TestCode.parse('''
+library augment 'a.dart';
+augment class Foo {
+ augment ^String get a => 'test2';
+}
+''');
+
+ final regions = await _computeSelectionRanges(content);
+ _expectRegions(
+ regions,
+ content,
+ [
+ 'String',
+ "augment String get a => 'test2';",
+ "augment class Foo {\n augment String get a => 'test2';\n}",
+ ],
+ );
+ }
+
+ Future<void> test_constructor_augmentation() async {
+ newFile('$testPackageLibPath/a.dart', '''
+import augment 'test.dart';
+class Foo {
+ Foo();
+}
+''');
+
+ final content = TestCode.parse('''
+library augment 'a.dart';
+augment class Foo {
+ augment Foo(^);
+}
+''');
+
+ final regions = await _computeSelectionRanges(content);
+ _expectRegions(
+ regions,
+ content,
+ [
+ '()',
+ 'augment Foo();',
+ 'augment class Foo {\n augment Foo();\n}',
+ ],
+ );
+ }
+
Future<void> test_constructorCall() async {
final content = TestCode.parse('''
class Foo {
@@ -214,6 +268,42 @@
);
}
+ Future<void> test_method_augmentation() async {
+ newFile('$testPackageLibPath/a.dart', '''
+import augment 'test.dart';
+class Foo {
+ void f() {}
+}
+''');
+
+ final content = TestCode.parse('''
+library augment a.dart;
+
+augment class Foo {
+ augment void f() {
+ print((1 ^+ 2) * 3);
+ }
+}
+''');
+
+ final regions = await _computeSelectionRanges(content);
+ _expectRegions(
+ regions,
+ content,
+ [
+ '1 + 2',
+ '(1 + 2)',
+ '(1 + 2) * 3',
+ '((1 + 2) * 3)',
+ 'print((1 + 2) * 3)',
+ 'print((1 + 2) * 3);',
+ '{\n print((1 + 2) * 3);\n }',
+ 'augment void f() {\n print((1 + 2) * 3);\n }',
+ 'augment class Foo {\n augment void f() {\n print((1 + 2) * 3);\n }\n}',
+ ],
+ );
+ }
+
Future<void> test_methodLambda() async {
final content = TestCode.parse('''
class Foo<T> {
@@ -238,6 +328,42 @@
);
}
+ Future<void> test_mixin_augmentation() async {
+ newFile('$testPackageLibPath/a.dart', '''
+import augment 'test.dart';
+mixin Foo {
+ void a(String b){}
+}
+''');
+
+ final content = TestCode.parse('''
+library augment a.dart;
+
+augment mixin Foo {
+ augment void a(String b) {
+ print((1 ^+ 2) * 3);
+ }
+}
+''');
+
+ final regions = await _computeSelectionRanges(content);
+ _expectRegions(
+ regions,
+ content,
+ [
+ '1 + 2',
+ '(1 + 2)',
+ '(1 + 2) * 3',
+ '((1 + 2) * 3)',
+ 'print((1 + 2) * 3)',
+ 'print((1 + 2) * 3);',
+ '{\n print((1 + 2) * 3);\n }',
+ 'augment void a(String b) {\n print((1 + 2) * 3);\n }',
+ 'augment mixin Foo {\n augment void a(String b) {\n print((1 + 2) * 3);\n }\n}',
+ ],
+ );
+ }
+
Future<void> test_pattern_relational() async {
final content = TestCode.parse('''
final a = switch(123) {
@@ -338,6 +464,37 @@
);
}
+ Future<void> test_topLevelFunction_augmentation() async {
+ newFile('$testPackageLibPath/a.dart', '''
+import augment 'test.dart';
+void a(String b) {}
+''');
+
+ final content = TestCode.parse('''
+library augment 'a.dart';
+augment void a(String b) {
+ print((1 ^+ 2) * 3);
+}
+''');
+
+ final regions = await _computeSelectionRanges(content);
+ _expectRegions(
+ regions,
+ content,
+ [
+ '1 + 2',
+ '(1 + 2)',
+ '(1 + 2) * 3',
+ '((1 + 2) * 3)',
+ 'print((1 + 2) * 3)',
+ 'print((1 + 2) * 3);',
+ '{\n print((1 + 2) * 3);\n}',
+ '(String b) {\n print((1 + 2) * 3);\n}',
+ 'augment void a(String b) {\n print((1 + 2) * 3);\n}',
+ ],
+ );
+ }
+
Future<void> test_topLevelFunction_record() async {
final content = TestCode.parse('''
void f() {
diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart
index b01f415..9317c72 100644
--- a/pkg/analyzer/lib/src/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/src/dart/ast/ast.dart
@@ -4339,7 +4339,7 @@
@override
Token get firstTokenAfterCommentAndMetadata {
return Token.lexicallyFirst(
- externalKeyword, constKeyword, factoryKeyword) ??
+ externalKeyword, constKeyword, factoryKeyword, augmentKeyword) ??
_returnType.beginToken;
}