Skip to content

Commit 501ffad

Browse files
committed
Add tests for relative hrefs in doc comments
1 parent 4113b33 commit 501ffad

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

test/model_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,21 @@ void main() {
11821182
expect(docsAsHtml,
11831183
contains('<code>ThisIsNotHereNoWay&lt;MyType&gt;</code>'));
11841184
});
1185+
1186+
test('leaves relative href resulting in a broken link', () {
1187+
// Dartdoc does emit a brokenLink warning for this.
1188+
expect(docsAsHtml,
1189+
contains('<a href="SubForDocComments/localMethod.html">link</a>'));
1190+
});
1191+
1192+
test('leaves relative href resulting in a working link', () {
1193+
// Ideally doc comments should not make assumptions about Dartdoc output
1194+
// files, but unfortunately some do...
1195+
expect(
1196+
docsAsHtml,
1197+
contains(
1198+
'<a href="../SubForDocComments/localMethod.html">link</a>'));
1199+
});
11851200
});
11861201

11871202
test('multi-underscore names in brackets do not become italicized', () {

testing/test_package/lib/fake.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,10 @@ class BaseForDocComments {
887887
/// Reference containing a type parameter [ExtraSpecialList<Object>]
888888
///
889889
/// Reference to something that doesn't exist containing a type parameter [ThisIsNotHereNoWay<MyType>]
890+
///
891+
/// Link to a nonexistent file (erroneously expects base href): [link](SubForDocComments/localMethod.html)
892+
///
893+
/// Link to an existing file: [link](../SubForDocComments/localMethod.html)
890894
String doAwesomeStuff(int value) => null;
891895

892896
void anotherMethod() {}

0 commit comments

Comments
 (0)