diff --git a/test/dot_shorthands_test.dart b/test/dot_shorthands_test.dart new file mode 100644 index 0000000000..0a92dd91c5 --- /dev/null +++ b/test/dot_shorthands_test.dart @@ -0,0 +1,79 @@ +// 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_constructor_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()

', + ); + } + + 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()

', + ); + } +}