From 3904a92c402adbfaa964552922ef890dc999301d Mon Sep 17 00:00:00 2001 From: Keerti Parthasarathy Date: Tue, 13 Feb 2024 20:00:13 +0000 Subject: [PATCH] Add call hierarchy tests for augmentations Change-Id: I5078dc604f1c5368fde708cd95033d3b134874d2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352401 Reviewed-by: Brian Wilkerson Commit-Queue: Keerti Parthasarathy --- .../call_hierarchy_computer_test.dart | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/pkg/analysis_server/test/src/computer/call_hierarchy_computer_test.dart b/pkg/analysis_server/test/src/computer/call_hierarchy_computer_test.dart index 8efbe02e66f..374a8f9bbd0 100644 --- a/pkg/analysis_server/test/src/computer/call_hierarchy_computer_test.dart +++ b/pkg/analysis_server/test/src/computer/call_hierarchy_computer_test.dart @@ -7,6 +7,7 @@ import 'package:analysis_server/src/services/search/search_engine.dart'; import 'package:analysis_server/src/services/search/search_engine_internal.dart'; import 'package:analyzer/source/source_range.dart'; import 'package:analyzer/src/test_utilities/test_code_format.dart'; +import 'package:matcher/expect.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -172,6 +173,37 @@ class Foo { )); } + Future test_constructorCall_to_augmentation() async { + final code = TestCode.parse(''' +import augment 'other.dart'; + +class Foo {} + +void f() { + Foo.na^med(); +} +'''); + + final otherCode = TestCode.parse(''' +library augment 'test.dart'; +augment class Foo { + [!Foo.named(){}!] +} +'''); + + newFile(otherFile, otherCode.code); + await expectTarget( + code, + _isItem( + CallHierarchyKind.constructor, + 'Foo.named', + otherFile, + containerName: 'Foo', + nameRange: rangeAtSearch('named', otherCode), + codeRange: otherCode.range.sourceRange, + )); + } + Future test_extension_method() async { final code = TestCode.parse(''' extension StringExtension on String { @@ -455,6 +487,38 @@ class Foo { )); } + Future test_methodCall_to_augmentation() async { + final code = TestCode.parse(''' +import augment 'other.dart'; + +class Foo {} + +void f() { + Foo().myMet^hod(); +} +'''); + + final otherCode = TestCode.parse(''' +library augment 'test.dart'; + +augment class Foo { + [!void myMethod() {}!] +} +'''); + + newFile(otherFile, otherCode.code); + await expectTarget( + code, + _isItem( + CallHierarchyKind.method, + 'myMethod', + otherFile, + containerName: 'Foo', + nameRange: rangeAtSearch('myMethod', otherCode), + codeRange: otherCode.range.sourceRange, + )); + } + Future test_mixin_method() async { final code = TestCode.parse(''' mixin Bar { @@ -1015,6 +1079,39 @@ import 'test.dart'; ); } + Future test_method_from_augmentation() async { + final code = TestCode.parse(''' +import augment 'other.dart'; + +class Foo { + void myMet^hod() {} +} +'''); + + final otherCode = TestCode.parse(''' +library augment 'test.dart'; + +augment class Foo { + [!void f() { + myMethod(); + }!] +} +'''); + + newFile(otherFile, otherCode.code); + final calls = await findIncomingCalls(code); + expect(calls, [ + _isResult( + CallHierarchyKind.method, + 'f', + otherFile, + containerName: 'Foo', + nameRange: rangeAtSearch('f() {', otherCode, 'f'), + codeRange: otherCode.range.sourceRange, + ), + ]); + } + Future test_mixin_method() async { final code = TestCode.parse(''' mixin Bar { @@ -1209,6 +1306,40 @@ class A { ); } + Future test_constructor_from_augmentation() async { + final code = TestCode.parse(''' +import augment 'other.dart'; + +class Foo {} + +void ba^r() { + Foo.named(); +} +'''); + + final otherCode = TestCode.parse(''' +library augment 'test.dart'; + +augment class Foo { + [!Foo.named() { + }!] +} +'''); + + newFile(otherFile, otherCode.code); + final calls = await findOutgoingCalls(code); + expect(calls, [ + _isResult( + CallHierarchyKind.constructor, + 'Foo.named', + otherFile, + containerName: 'Foo', + nameRange: rangeAtSearch('named() {', otherCode, 'named'), + codeRange: otherCode.range.sourceRange, + ), + ]); + } + Future test_extension_method() async { final code = TestCode.parse(''' // ignore_for_file: unused_local_variable @@ -1428,6 +1559,43 @@ class Foo { ); } + Future test_method_from_augmentation() async { + final code = TestCode.parse(''' +import augment 'other.dart'; + +class Foo {} + +void ba^r() { + Foo().myMethod(); +} +'''); + + final otherCode = TestCode.parse(''' +library augment 'test.dart'; + +augment class Foo { + [!void myMethod() { + }!] +} +'''); + + newFile(otherFile, otherCode.code); + final calls = await findOutgoingCalls(code); + expect( + calls, + contains( + _isResult( + CallHierarchyKind.method, + 'myMethod', + otherFile, + containerName: 'Foo', + nameRange: rangeAtSearch('myMethod() {', otherCode, 'myMethod'), + codeRange: otherCode.range.sourceRange, + ), + ), + ); + } + Future test_mixin_method() async { final code = TestCode.parse(''' // ignore_for_file: unused_local_variable