[analysis_server] Dot shorthands: Selection range tests.

Testing that selection range still works with the new dot shorthands ASTs.

Bug: https://github.com/dart-lang/sdk/issues/59836
Change-Id: I2f444998943b50c4976f3e905f21a50140ebba74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433420
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
diff --git a/pkg/analysis_server/test/lsp/selection_range_test.dart b/pkg/analysis_server/test/lsp/selection_range_test.dart
index 104a07b..7511b8b 100644
--- a/pkg/analysis_server/test/lsp/selection_range_test.dart
+++ b/pkg/analysis_server/test/lsp/selection_range_test.dart
@@ -22,6 +22,107 @@
 /// test/src/computer/selection_range_computer_test.dart
 @reflectiveTest
 class SelectionRangeTest extends AbstractLspAnalysisServerTest {
+  Future<void> test_dotShorthand_constructorInvocation() async {
+    var code = TestCode.parse('''
+class A {}
+void f() {
+  A a = .^new();
+}
+''');
+
+    await initialize();
+    await openFile(mainFileUri, code.code);
+    var lineInfo = LineInfo.fromContent(code.code);
+    var regions = await getSelectionRanges(mainFileUri, [
+      code.position.position,
+    ]);
+    expect(regions!.length, equals(1));
+    var regionTexts =
+        _getSelectionRangeText(lineInfo, code.code, regions.first).toList();
+
+    expect(
+      regionTexts,
+      equals([
+        'new',
+        '.new()',
+        'a = .new()',
+        'A a = .new()',
+        'A a = .new();',
+        '{\n  A a = .new();\n}',
+        '() {\n  A a = .new();\n}',
+        'void f() {\n  A a = .new();\n}',
+      ]),
+    );
+  }
+
+  Future<void> test_dotShorthand_methodInvocation() async {
+    var code = TestCode.parse('''
+class A {
+  static A method() => A();
+}
+void f() {
+  A a = .me^thod();
+}
+''');
+
+    await initialize();
+    await openFile(mainFileUri, code.code);
+    var lineInfo = LineInfo.fromContent(code.code);
+    var regions = await getSelectionRanges(mainFileUri, [
+      code.position.position,
+    ]);
+    expect(regions!.length, equals(1));
+    var regionTexts =
+        _getSelectionRangeText(lineInfo, code.code, regions.first).toList();
+
+    expect(
+      regionTexts,
+      equals([
+        'method',
+        '.method()',
+        'a = .method()',
+        'A a = .method()',
+        'A a = .method();',
+        '{\n  A a = .method();\n}',
+        '() {\n  A a = .method();\n}',
+        'void f() {\n  A a = .method();\n}',
+      ]),
+    );
+  }
+
+  Future<void> test_dotShorthand_propertyAccess() async {
+    var code = TestCode.parse('''
+enum A { a }
+void f() {
+  A a = .^a;
+}
+''');
+
+    await initialize();
+    await openFile(mainFileUri, code.code);
+    var lineInfo = LineInfo.fromContent(code.code);
+    var regions = await getSelectionRanges(mainFileUri, [
+      code.position.position,
+    ]);
+    expect(regions!.length, equals(1));
+    var regionTexts =
+        _getSelectionRangeText(lineInfo, code.code, regions.first).toList();
+
+    expect(
+      regionTexts,
+      equals([
+        'a',
+        '.a',
+        'a = .a',
+        'A a = .a',
+        'A a = .a;',
+        '{\n  A a = .a;\n}',
+        '() {\n  A a = .a;\n}',
+        'void f() {\n  A a = .a;\n}',
+      ]),
+    );
+  }
+
   Future<void> test_multiple() async {
     var content = '''
 class Foo {
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 efed8aa..839eaec 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
@@ -164,6 +164,27 @@
     ]);
   }
 
+  Future<void> test_constructorCall_dotShorthand() async {
+    var content = '''
+class A {}
+void f() {
+  A a = .^new();
+}
+''';
+
+    var regions = await _computeSelectionRanges(content);
+    _expectRegions(regions, [
+      'new',
+      '.new()',
+      'a = .new()',
+      'A a = .new()',
+      'A a = .new();',
+      '{\n  A a = .new();\n}',
+      '() {\n  A a = .new();\n}',
+      'void f() {\n  A a = .new();\n}',
+    ]);
+  }
+
   Future<void> test_extensionType() async {
     var content = '''
 extension type E<T>(int it) {
@@ -265,6 +286,29 @@
     ]);
   }
 
+  Future<void> test_method_dotShorthand() async {
+    var content = '''
+class A {
+  static A method() => A();
+}
+void f() {
+  A a = .me^thod();
+}
+''';
+
+    var regions = await _computeSelectionRanges(content);
+    _expectRegions(regions, [
+      'method',
+      '.method()',
+      'a = .method()',
+      'A a = .method()',
+      'A a = .method();',
+      '{\n  A a = .method();\n}',
+      '() {\n  A a = .method();\n}',
+      'void f() {\n  A a = .method();\n}',
+    ]);
+  }
+
   Future<void> test_method_withNullAwareElements_inList() async {
     var content = '''
 class Foo<T> {
@@ -484,6 +528,27 @@
     ]);
   }
 
+  Future<void> test_propertyAccess_dotShorthand() async {
+    var content = '''
+enum A { a }
+void f() {
+  A a = .^a;
+}
+''';
+
+    var regions = await _computeSelectionRanges(content);
+    _expectRegions(regions, [
+      'a',
+      '.a',
+      'a = .a',
+      'A a = .a',
+      'A a = .a;',
+      '{\n  A a = .a;\n}',
+      '() {\n  A a = .a;\n}',
+      'void f() {\n  A a = .a;\n}',
+    ]);
+  }
+
   Future<void> test_topLevelFunction() async {
     var content = '''
 void a(String b) {