Skip to content

Commit

Permalink
Update test for anchors and headings position
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 26, 2021
1 parent 20eda22 commit 2342756
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/test/rustdoc-gui/anchors.goml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This test is to ensure that the anchors (`§`) have the expected color.
// This test is to ensure that the anchors (`§`) have the expected color and position.
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
show-text: true

Expand Down Expand Up @@ -28,3 +28,47 @@ assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"})
// Same thing with the impl block title.
move-cursor-to: "#impl"
assert-css: ("#impl a.anchor", {"color": "rgb(0, 0, 0)"})

// Now we check the positions: only the first heading of the top doc comment should
// have a different position.
move-cursor-to: ".top-doc .docblock .section-header:first-child"
assert-css: (
".top-doc .docblock .section-header:first-child > a::before",
{"left": "-10px", "padding-right": "10px"}
)
// We also check that the heading itself has a different indent.
assert-css: (".top-doc .docblock .section-header:first-child", {"margin-left": "15px"})

move-cursor-to: ".top-doc .docblock .section-header:not(:first-child)"
assert-css: (
".top-doc .docblock .section-header:not(:first-child) > a::before",
{"left": "-25px", "padding-right": "10px"}
)
assert-css: (".top-doc .docblock .section-header:not(:first-child)", {"margin-left": "0px"})

// Now let's check some other docblock headings...
// First the impl block docs.
move-cursor-to: "#title-for-struct-impl-doc"
assert-css: (
"#title-for-struct-impl-doc > a::before",
{"left": "-25px", "padding-right": "10px"}
)
assert-css: ("#title-for-struct-impl-doc", {"margin-left": "0px"})
// Now a method docs.
move-cursor-to: "#title-for-struct-impl-item-doc"
assert-css: (
"#title-for-struct-impl-item-doc > a::before",
{"left": "-25px", "padding-right": "10px"}
)
assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})

// Finally, we want to ensure that if the first element of the doc block isn't a heading,
// if there is a heading afterwards, it won't have the indent.
goto: file://|DOC_PATH|/test_docs/enum.WhoLetTheDogOut.html

move-cursor-to: ".top-doc .docblock .section-header"
assert-css: (
".top-doc .docblock .section-header > a::before",
{"left": "-25px", "padding-right": "10px"}
)
assert-css: (".top-doc .docblock .section-header", {"margin-left": "0px"})
2 changes: 2 additions & 0 deletions src/test/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ impl AsRef<str> for Foo {
}

/// Just a normal enum.
///
/// # title!
#[doc(alias = "ThisIsAnAlias")]
pub enum WhoLetTheDogOut {
/// Woof!
Expand Down

0 comments on commit 2342756

Please sign in to comment.