|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | +import 'package:test/test.dart'; |
| 5 | +import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 6 | + |
| 7 | +import 'dartdoc_test_base.dart'; |
| 8 | +import 'src/utils.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + defineReflectiveSuite(() { |
| 12 | + defineReflectiveTests(DotShorthandsTest); |
| 13 | + }); |
| 14 | +} |
| 15 | + |
| 16 | +@reflectiveTest |
| 17 | +class DotShorthandsTest extends DartdocTestBase { |
| 18 | + @override |
| 19 | + String get libraryName => 'dot_shorthands'; |
| 20 | + |
| 21 | + void test_doc_dot_shorthand_property_access_success() async { |
| 22 | + var library = await bootPackageWithLibrary(''' |
| 23 | +enum Color { |
| 24 | + red, green |
| 25 | +} |
| 26 | +
|
| 27 | +class C { |
| 28 | + /// [Color] can be referenced but [.red] cannot. |
| 29 | + void m(Color p) {} |
| 30 | +
|
| 31 | +} |
| 32 | +'''); |
| 33 | + var m = library.classes.named('C').instanceMethods.named('m'); |
| 34 | + |
| 35 | + expect(m.hasDocumentationComment, true); |
| 36 | + expect( |
| 37 | + m.documentationAsHtml, |
| 38 | + '<p><a href="$linkPrefix/Color.html">Color</a> can be referenced but ' |
| 39 | + '<code>.red</code> cannot.</p>', |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + void test_doc_dot_shorthand_constructor_invocation_success() async { |
| 44 | + var library = await bootPackageWithLibrary(''' |
| 45 | +class C { |
| 46 | + /// Cannot link [.c()] |
| 47 | + void m(String p) {} |
| 48 | +
|
| 49 | + C.c(); |
| 50 | +} |
| 51 | +'''); |
| 52 | + var m = library.classes.named('C').instanceMethods.named('m'); |
| 53 | + |
| 54 | + expect(m.hasDocumentationComment, true); |
| 55 | + expect( |
| 56 | + m.documentationAsHtml, |
| 57 | + '<p>Cannot link <code>.c()</code></p>', |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + void test_doc_dot_shorthand_method_invocation_success() async { |
| 62 | + var library = await bootPackageWithLibrary(''' |
| 63 | +class C { |
| 64 | + /// Cannot link [.f()] |
| 65 | + void m(String p) {} |
| 66 | +
|
| 67 | +
|
| 68 | + static C f() => C(); |
| 69 | +} |
| 70 | +'''); |
| 71 | + var m = library.classes.named('C').instanceMethods.named('m'); |
| 72 | + |
| 73 | + expect(m.hasDocumentationComment, true); |
| 74 | + expect( |
| 75 | + m.documentationAsHtml, |
| 76 | + '<p>Cannot link <code>.f()</code></p>', |
| 77 | + ); |
| 78 | + } |
| 79 | +} |
0 commit comments