Skip to content

Commit dec0ea1

Browse files
Add tests for headings anchor and links in headings
1 parent 7b5e96f commit dec0ea1

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

tests/rustdoc-gui/headers-color.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This test check for headers text and background colors for the different themes.
1+
// This test check for headings text and background colors for the different themes.
22

33
define-function: (
44
"check-colors",
@@ -45,7 +45,7 @@ call-function: (
4545
"color": "#c5c5c5",
4646
"code_header_color": "#e6e1cf",
4747
"focus_background_color": "rgba(255, 236, 164, 0.06)",
48-
"headings_color": "#39afd7",
48+
"headings_color": "#c5c5c5",
4949
},
5050
)
5151
call-function: (
@@ -55,7 +55,7 @@ call-function: (
5555
"color": "#ddd",
5656
"code_header_color": "#ddd",
5757
"focus_background_color": "#494a3d",
58-
"headings_color": "#d2991d",
58+
"headings_color": "#ddd",
5959
},
6060
)
6161
call-function: (
@@ -65,6 +65,6 @@ call-function: (
6565
"color": "black",
6666
"code_header_color": "black",
6767
"focus_background_color": "#fdffd3",
68-
"headings_color": "#3873ad",
68+
"headings_color": "black",
6969
},
7070
)
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Test to ensure that the headings anchor behave as expected.
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.HeavilyDocumentedStruct.html"
3+
show-text: true
4+
5+
define-function: (
6+
"check-heading-anchor",
7+
(heading_id),
8+
block {
9+
// The anchor should not be displayed by default.
10+
assert-css: ("#" + |heading_id| + " .doc-anchor", { "display": "none" })
11+
// We ensure that hovering the heading makes the anchor visible.
12+
move-cursor-to: "#" + |heading_id|
13+
assert-css: ("#" + |heading_id| + ":hover .doc-anchor", { "display": "block" })
14+
// We then ensure that moving from the heading to the anchor doesn't make the anchor
15+
// disappear.
16+
move-cursor-to: "#" + |heading_id| + " .doc-anchor"
17+
assert-css: ("#" + |heading_id| + " .doc-anchor:hover", {
18+
"display": "block",
19+
// We also ensure that there is no underline decoration.
20+
"text-decoration-line": "none",
21+
})
22+
}
23+
)
24+
25+
move-cursor-to: "#top-doc-prose-title"
26+
// If the top documentation block first element is a heading, we should never display its anchor
27+
// to prevent it from overlapping with the `[-]` element.
28+
assert-css: ("#top-doc-prose-title:hover .doc-anchor", { "display": "none" })
29+
30+
call-function: ("check-heading-anchor", ("top-doc-prose-sub-heading"))
31+
call-function: ("check-heading-anchor", ("top-doc-prose-sub-sub-heading"))
32+
call-function: ("check-heading-anchor", ("you-know-the-drill"))

tests/rustdoc/links-in-headings.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_name = "foo"]
2+
3+
//! # Heading with [a link](https://a.com) inside
4+
//!
5+
//! And even with
6+
//!
7+
//! ## [multiple](https://b.com) [links](https://c.com)
8+
//!
9+
//! !
10+
11+
// @has 'foo/index.html'
12+
// @has - '//h2/a[@href="https://a.com"]' 'a link'
13+
// @has - '//h3/a[@href="https://b.com"]' 'multiple'
14+
// @has - '//h3/a[@href="https://c.com"]' 'links'

0 commit comments

Comments
 (0)