From 28ca645ec767bcada38fcecd9d83d8945272b283 Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Thu, 21 Aug 2025 14:02:11 +0000 Subject: [PATCH 1/3] Add test for dot shorthands --- test/dot_shorthands_test.dart | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/dot_shorthands_test.dart diff --git a/test/dot_shorthands_test.dart b/test/dot_shorthands_test.dart new file mode 100644 index 0000000000..a27d06aed4 --- /dev/null +++ b/test/dot_shorthands_test.dart @@ -0,0 +1,60 @@ +// Copyright (c) 2025, 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:test/test.dart'; +import 'package:test_reflective_loader/test_reflective_loader.dart'; + +import 'dartdoc_test_base.dart'; +import 'src/utils.dart'; + +void main() { + defineReflectiveSuite(() { + defineReflectiveTests(DotShorthandsTest); + }); +} + +@reflectiveTest +class DotShorthandsTest extends DartdocTestBase { + @override + String get libraryName => 'dot_shorthands'; + + void test_doc_dot_shorthand_property_access_success() async { + var library = await bootPackageWithLibrary(''' +enum Color { + red, green +} + +class C { + /// [Color] can be referenced but [.red] cannot. + void m(Color p) {} + +} +'''); + var m = library.classes.named('C').instanceMethods.named('m'); + + expect(m.hasDocumentationComment, true); + expect( + m.documentationAsHtml, + '

Color can be referenced but ' + '.red cannot.

', + ); + } + + void test_doc_dot_shorthand_method_invocation_success() async { + var library = await bootPackageWithLibrary(''' +class C { + /// Cannot link [.c()] + void m(String p) {} + + C.c(); +} +'''); + var m = library.classes.named('C').instanceMethods.named('m'); + + expect(m.hasDocumentationComment, true); + expect( + m.documentationAsHtml, + '

Cannot link .c()

', + ); + } +} From 8a9585a978b2e5eef19fc2dae36ce716fc021e42 Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Fri, 22 Aug 2025 09:00:08 +0000 Subject: [PATCH 2/3] add test for static method dot shorthand --- test/dot_shorthands_test.dart | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/dot_shorthands_test.dart b/test/dot_shorthands_test.dart index a27d06aed4..7b8fbc6bd2 100644 --- a/test/dot_shorthands_test.dart +++ b/test/dot_shorthands_test.dart @@ -1,6 +1,7 @@ // Copyright (c) 2025, 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/dart/ast/ast.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -40,7 +41,7 @@ class C { ); } - void test_doc_dot_shorthand_method_invocation_success() async { + void test_doc_dot_shorthand_constructor_invocation_success() async { var library = await bootPackageWithLibrary(''' class C { /// Cannot link [.c()] @@ -57,4 +58,23 @@ class C { '

Cannot link .c()

', ); } + + void test_doc_dot_shorthand_method_invocation_success() async { + var library = await bootPackageWithLibrary(''' +class C { + /// Cannot link [.f()] + void m(String p) {} + + + static C f() => C(); +} +'''); + var m = library.classes.named('C').instanceMethods.named('m'); + + expect(m.hasDocumentationComment, true); + expect( + m.documentationAsHtml, + '

Cannot link .f()

', + ); + } } From 76a83ad4ef8a259c26439a8390eb96888a1a79bd Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Mon, 25 Aug 2025 09:07:23 +0000 Subject: [PATCH 3/3] Remove unused import --- test/dot_shorthands_test.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/test/dot_shorthands_test.dart b/test/dot_shorthands_test.dart index 7b8fbc6bd2..0a92dd91c5 100644 --- a/test/dot_shorthands_test.dart +++ b/test/dot_shorthands_test.dart @@ -1,7 +1,6 @@ // Copyright (c) 2025, 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/dart/ast/ast.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart';