Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rustdoc] Allows links in headings #117662

Merged
merged 7 commits into from
Jan 20, 2024
Merged
Prev Previous commit
Next Next commit
Add tests for headings anchor and links in headings
  • Loading branch information
GuillaumeGomez committed Dec 5, 2023
commit 42fcba7a6731ec2a0fc6e75383fbd35dd75db41d
8 changes: 4 additions & 4 deletions tests/rustdoc-gui/headers-color.goml
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
// This test check for headers text and background colors for the different themes.
// This test check for headings text and background colors for the different themes.

define-function: (
"check-colors",
Expand Down Expand Up @@ -45,7 45,7 @@ call-function: (
"color": "#c5c5c5",
"code_header_color": "#e6e1cf",
"focus_background_color": "rgba(255, 236, 164, 0.06)",
"headings_color": "#39afd7",
"headings_color": "#c5c5c5",
},
)
call-function: (
Expand All @@ -55,7 55,7 @@ call-function: (
"color": "#ddd",
"code_header_color": "#ddd",
"focus_background_color": "#494a3d",
"headings_color": "#d2991d",
"headings_color": "#ddd",
},
)
call-function: (
Expand All @@ -65,6 65,6 @@ call-function: (
"color": "black",
"code_header_color": "black",
"focus_background_color": "#fdffd3",
"headings_color": "#3873ad",
"headings_color": "black",
},
)
32 changes: 32 additions & 0 deletions tests/rustdoc-gui/headings-anchor.goml
Original file line number Diff line number Diff line change
@@ -0,0 1,32 @@
// Test to ensure that the headings anchor behave as expected.
go-to: "file://" |DOC_PATH| "/test_docs/struct.HeavilyDocumentedStruct.html"
show-text: true

define-function: (
"check-heading-anchor",
(heading_id),
block {
// The anchor should not be displayed by default.
assert-css: ("#" |heading_id| " .doc-anchor", { "display": "none" })
// We ensure that hovering the heading makes the anchor visible.
move-cursor-to: "#" |heading_id|
assert-css: ("#" |heading_id| ":hover .doc-anchor", { "display": "block" })
// We then ensure that moving from the heading to the anchor doesn't make the anchor
// disappear.
move-cursor-to: "#" |heading_id| " .doc-anchor"
assert-css: ("#" |heading_id| " .doc-anchor:hover", {
"display": "block",
// We also ensure that there is no underline decoration.
"text-decoration-line": "none",
})
}
)

move-cursor-to: "#top-doc-prose-title"
// If the top documentation block first element is a heading, we should never display its anchor
// to prevent it from overlapping with the `[-]` element.
assert-css: ("#top-doc-prose-title:hover .doc-anchor", { "display": "none" })

call-function: ("check-heading-anchor", ("top-doc-prose-sub-heading"))
call-function: ("check-heading-anchor", ("top-doc-prose-sub-sub-heading"))
call-function: ("check-heading-anchor", ("you-know-the-drill"))
14 changes: 14 additions & 0 deletions tests/rustdoc/links-in-headings.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,14 @@
#![crate_name = "foo"]

//! # Heading with [a link](https://a.com) inside
//!
//! And even with
//!
//! ## [multiple](https://b.com) [links](https://c.com)
//!
//! !

// @has 'foo/index.html'
// @has - '//h2/a[@href="https://a.com"]' 'a link'
// @has - '//h3/a[@href="https://b.com"]' 'multiple'
// @has - '//h3/a[@href="https://c.com"]' 'links'