- {# https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag#data-nosnippet-attr
- Do not show "1 2 3 4 5 ..." in web search results. #}
-
{# #}
{# #}
{{code_html|safe}}
diff --git a/tests/rustdoc-gui/basic-code.goml b/tests/rustdoc-gui/basic-code.goml
deleted file mode 100644
index 22ac531618423..0000000000000
--- a/tests/rustdoc-gui/basic-code.goml
+++ /dev/null
@@ -1,6 +0,0 @@
-// Small test to ensure the "src-line-numbers" element is only present once on
-// the page.
-go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
-click: "a.src"
-wait-for: ".src-line-numbers"
-assert-count: (".src-line-numbers", 1)
diff --git a/tests/rustdoc-gui/docblock-code-block-line-number.goml b/tests/rustdoc-gui/docblock-code-block-line-number.goml
index 3c16626336ea6..032746a6bdf44 100644
--- a/tests/rustdoc-gui/docblock-code-block-line-number.goml
+++ b/tests/rustdoc-gui/docblock-code-block-line-number.goml
@@ -111,28 +111,6 @@ wait-for: "pre.example-line-numbers"
// Same check with scraped examples line numbers.
go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
-assert-css: (
- ".scraped-example .src-line-numbers > pre",
- {
- // There should not be a radius on the right of the line numbers.
- "border-top-left-radius": "6px",
- "border-bottom-left-radius": "6px",
- "border-top-right-radius": "0px",
- "border-bottom-right-radius": "0px",
- },
- ALL,
-)
-assert-css: (
- ".scraped-example .src-line-numbers",
- {
- // There should not be a radius on the right of the line numbers.
- "border-top-left-radius": "6px",
- "border-bottom-left-radius": "6px",
- "border-top-right-radius": "0px",
- "border-bottom-right-radius": "0px",
- },
- ALL,
-)
assert-css: (
".scraped-example .rust",
{
@@ -149,23 +127,15 @@ define-function: (
"check-padding",
[path, padding_bottom],
block {
- assert-css: (|path| + " .src-line-numbers", {
+ assert-css: (|path| + " span[data-nosnippet]", {
"padding-top": "0px",
"padding-bottom": "0px",
- "padding-left": "0px",
- "padding-right": "0px",
- }, ALL)
- assert-css: (|path| + " .src-line-numbers > pre", {
- "padding-top": "14px",
- "padding-bottom": |padding_bottom|,
- "padding-left": "0px",
- "padding-right": "0px",
- }, ALL)
- assert-css: (|path| + " .src-line-numbers > pre > span", {
- "padding-top": "0px",
- "padding-bottom": "0px",
- "padding-left": "8px",
- "padding-right": "8px",
+ "padding-left": "4px",
+ "padding-right": "4px",
+ "margin-right": "20px",
+ "margin-left": "0px",
+ "margin-top": "0px",
+ "margin-bottom": "0px",
}, ALL)
},
)
@@ -196,13 +166,13 @@ define-function: ("check-line-numbers-existence", [], block {
wait-for-local-storage-false: {"rustdoc-line-numbers": "true" }
assert-false: ".example-line-numbers"
// Line numbers should still be there.
- assert: ".src-line-numbers"
+ assert-css: ("[data-nosnippet]", { "display": "inline-block"})
// Now disabling the setting.
click: "input#line-numbers"
wait-for-local-storage: {"rustdoc-line-numbers": "true" }
assert-false: ".example-line-numbers"
// Line numbers should still be there.
- assert: ".src-line-numbers"
+ assert-css: ("[data-nosnippet]", { "display": "inline-block"})
// Closing settings menu.
click: "#settings-menu"
wait-for-css: ("#settings", {"display": "none"})
@@ -214,18 +184,16 @@ call-function: ("check-line-numbers-existence", {})
// Now checking the line numbers in the source code page.
click: ".src"
-assert-css: (".src-line-numbers", {
- "padding-top": "20px",
- "padding-bottom": "20px",
- "padding-left": "4px",
- "padding-right": "0px",
-})
-assert-css: (".src-line-numbers > a", {
+assert-css: ("a[data-nosnippet]", {
"padding-top": "0px",
"padding-bottom": "0px",
- "padding-left": "8px",
- "padding-right": "8px",
-})
+ "padding-left": "4px",
+ "padding-right": "4px",
+ "margin-top": "0px",
+ "margin-bottom": "0px",
+ "margin-left": "0px",
+ "margin-right": "20px",
+}, ALL)
// Checking that turning off the line numbers setting won't remove line numbers.
call-function: ("check-line-numbers-existence", {})
diff --git a/tests/rustdoc-gui/jump-to-def-background.goml b/tests/rustdoc-gui/jump-to-def-background.goml
index 71320360740c4..de5ea6c9b0b08 100644
--- a/tests/rustdoc-gui/jump-to-def-background.goml
+++ b/tests/rustdoc-gui/jump-to-def-background.goml
@@ -8,7 +8,7 @@ define-function: (
block {
call-function: ("switch-theme", {"theme": |theme|})
assert-css: (
- "body.src .example-wrap pre.rust a",
+ "body.src .example-wrap pre.rust a:not([data-nosnippet])",
{"background-color": |background_color|},
ALL,
)
diff --git a/tests/rustdoc-gui/scrape-examples-button-focus.goml b/tests/rustdoc-gui/scrape-examples-button-focus.goml
index 83ed6a219b25a..d53993ac08bae 100644
--- a/tests/rustdoc-gui/scrape-examples-button-focus.goml
+++ b/tests/rustdoc-gui/scrape-examples-button-focus.goml
@@ -4,52 +4,18 @@ go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html"
// The next/prev buttons vertically scroll the code viewport between examples
move-cursor-to: ".scraped-example-list > .scraped-example"
-store-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
- "scrollTop": initialScrollTop,
-})
+wait-for: ".scraped-example-list > .scraped-example .next"
+store-value: (initialScrollTop, 250)
assert-property: (".scraped-example-list > .scraped-example .rust", {
"scrollTop": |initialScrollTop|,
-})
+}, NEAR)
focus: ".scraped-example-list > .scraped-example .next"
press-key: "Enter"
-assert-property-false: (".scraped-example-list > .scraped-example .src-line-numbers", {
- "scrollTop": |initialScrollTop|
-}, NEAR)
assert-property-false: (".scraped-example-list > .scraped-example .rust", {
"scrollTop": |initialScrollTop|
}, NEAR)
focus: ".scraped-example-list > .scraped-example .prev"
press-key: "Enter"
-assert-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
- "scrollTop": |initialScrollTop|
-}, NEAR)
assert-property: (".scraped-example-list > .scraped-example .rust", {
"scrollTop": |initialScrollTop|
}, NEAR)
-
-// The expand button increases the scrollHeight of the minimized code viewport
-store-property: (".scraped-example-list > .scraped-example pre", {"offsetHeight": smallOffsetHeight})
-assert-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
- "scrollHeight": |smallOffsetHeight|
-}, NEAR)
-assert-property: (".scraped-example-list > .scraped-example .rust", {
- "scrollHeight": |smallOffsetHeight|
-}, NEAR)
-focus: ".scraped-example-list > .scraped-example .expand"
-press-key: "Enter"
-assert-property-false: (".scraped-example-list > .scraped-example .src-line-numbers", {
- "offsetHeight": |smallOffsetHeight|
-}, NEAR)
-assert-property-false: (".scraped-example-list > .scraped-example .rust", {
- "offsetHeight": |smallOffsetHeight|
-}, NEAR)
-store-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
- "offsetHeight": fullOffsetHeight,
-})
-assert-property: (".scraped-example-list > .scraped-example .rust", {
- "offsetHeight": |fullOffsetHeight|,
- "scrollHeight": |fullOffsetHeight|,
-})
-assert-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
- "scrollHeight": |fullOffsetHeight|
-}, NEAR)
diff --git a/tests/rustdoc-gui/scrape-examples-layout.goml b/tests/rustdoc-gui/scrape-examples-layout.goml
index 5187ac486b088..85a3b2a628734 100644
--- a/tests/rustdoc-gui/scrape-examples-layout.goml
+++ b/tests/rustdoc-gui/scrape-examples-layout.goml
@@ -3,35 +3,38 @@ go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
set-window-size: (1000, 1000)
+// We move the mouse over the scraped example for the prev button to be generated.
+move-cursor-to: ".scraped-example"
+
// Check that it's not zero.
assert-property-false: (
- ".more-scraped-examples .scraped-example .src-line-numbers",
+ ".more-scraped-examples .scraped-example span[data-nosnippet]",
{"clientWidth": "0"}
)
// Check that examples with very long lines have the same width as ones that don't.
store-property: (
- ".more-scraped-examples .scraped-example:nth-child(2) .src-line-numbers",
+ ".more-scraped-examples .scraped-example:nth-child(2) span[data-nosnippet]",
{"clientWidth": clientWidth},
)
assert-property: (
- ".more-scraped-examples .scraped-example:nth-child(3) .src-line-numbers",
+ ".more-scraped-examples .scraped-example:nth-child(3) span[data-nosnippet]",
{"clientWidth": |clientWidth|}
)
assert-property: (
- ".more-scraped-examples .scraped-example:nth-child(4) .src-line-numbers",
+ ".more-scraped-examples .scraped-example:nth-child(4) span[data-nosnippet]",
{"clientWidth": |clientWidth|}
)
assert-property: (
- ".more-scraped-examples .scraped-example:nth-child(5) .src-line-numbers",
+ ".more-scraped-examples .scraped-example:nth-child(5) span[data-nosnippet]",
{"clientWidth": |clientWidth|}
)
assert-property: (
- ".more-scraped-examples .scraped-example:nth-child(6) .src-line-numbers",
+ ".more-scraped-examples .scraped-example:nth-child(6) span[data-nosnippet]",
{"clientWidth": |clientWidth|}
)
@@ -55,25 +58,6 @@ assert-size: (".more-scraped-examples .scraped-example .example-wrap", {
"width": |width|,
})
-// Check that the expand button works and also that line number aligns with code.
-move-cursor-to: ".scraped-example .rust"
-click: ".scraped-example .button-holder .expand"
-wait-for: ".scraped-example.expanded"
-// They should have the same y position.
-compare-elements-position: (
- ".scraped-example.expanded .src-line-numbers pre span",
- ".scraped-example.expanded .rust code",
- ["y"],
-)
-// And they should have the same height.
-compare-elements-size: (
- ".scraped-example.expanded .src-line-numbers",
- ".scraped-example.expanded .rust",
- ["height"],
-)
-// Collapse code again.
-click: ".scraped-example .button-holder .expand"
-
// Check that for both mobile and desktop sizes, the buttons in scraped examples are displayed
// correctly.
@@ -98,7 +82,7 @@ define-function: (
[],
block {
// Title should be above the code.
- store-position: (".scraped-example .example-wrap .src-line-numbers", {"x": x, "y": y})
+ store-position: (".scraped-example .example-wrap", {"x": x, "y": y})
store-size: (".scraped-example .scraped-example-title", { "height": title_height })
assert-position: (".scraped-example .scraped-example-title", {
@@ -107,10 +91,13 @@ define-function: (
})
// Line numbers should be right beside the code.
- compare-elements-position: (
- ".scraped-example .example-wrap .src-line-numbers",
- ".scraped-example .example-wrap .rust",
- ["y"],
+ compare-elements-position-near: (
+ ".scraped-example .example-wrap span[data-nosnippet]",
+ // On the first line, the code starts with `fn main` so we have a keyword.
+ ".scraped-example .example-wrap .rust span.kw",
+ // They're not exactly the same size but since they're on the same line,
+ // it's kinda the same.
+ {"y": 2},
)
}
)
diff --git a/tests/rustdoc-gui/source-anchor-scroll.goml b/tests/rustdoc-gui/source-anchor-scroll.goml
index 4ad65bbbd61ac..c005af1e7a1c6 100644
--- a/tests/rustdoc-gui/source-anchor-scroll.goml
+++ b/tests/rustdoc-gui/source-anchor-scroll.goml
@@ -8,13 +8,13 @@ set-window-size: (600, 800)
assert-property: ("html", {"scrollTop": "0"})
click: '//a[text() = "barbar" and @href="#5-7"]'
-assert-property: ("html", {"scrollTop": "208"})
+assert-property: ("html", {"scrollTop": "206"})
click: '//a[text() = "bar" and @href="#28-36"]'
assert-property: ("html", {"scrollTop": "239"})
click: '//a[normalize-space() = "sub_fn" and @href="#2-4"]'
-assert-property: ("html", {"scrollTop": "136"})
+assert-property: ("html", {"scrollTop": "134"})
// We now check that clicking on lines doesn't change the scroll
// Extra information: the "sub_fn" function header is on line 1.
click: '//*[@id="6"]'
-assert-property: ("html", {"scrollTop": "136"})
+assert-property: ("html", {"scrollTop": "134"})
diff --git a/tests/rustdoc-gui/source-code-page-code-scroll.goml b/tests/rustdoc-gui/source-code-page-code-scroll.goml
index 60012db6c8c8b..c15a9ae7983c6 100644
--- a/tests/rustdoc-gui/source-code-page-code-scroll.goml
+++ b/tests/rustdoc-gui/source-code-page-code-scroll.goml
@@ -2,7 +2,7 @@
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
set-window-size: (800, 1000)
// "scrollWidth" should be superior than "clientWidth".
-assert-property: ("body", {"scrollWidth": 1776, "clientWidth": 800})
+assert-property: ("body", {"scrollWidth": 1780, "clientWidth": 800})
// Both properties should be equal (ie, no scroll on the code block).
-assert-property: (".example-wrap .rust", {"scrollWidth": 1662, "clientWidth": 1662})
+assert-property: (".example-wrap .rust", {"scrollWidth": 1715, "clientWidth": 1715})
diff --git a/tests/rustdoc-gui/source-code-page.goml b/tests/rustdoc-gui/source-code-page.goml
index afb194625210c..aa5a16aac7048 100644
--- a/tests/rustdoc-gui/source-code-page.goml
+++ b/tests/rustdoc-gui/source-code-page.goml
@@ -3,7 +3,7 @@ include: "utils.goml"
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
show-text: true
// Check that we can click on the line number.
-click: ".src-line-numbers > a:nth-child(4)" // This is the anchor for line 4.
+click: "//a[@data-nosnippet and text()='4']" // This is the anchor for line 4.
// Ensure that the page URL was updated.
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
@@ -14,11 +14,11 @@ assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
assert-css: ("//*[@id='4']", {"border-right-width": "0px"})
// We now check that the good anchors are highlighted
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6"
-assert-attribute-false: (".src-line-numbers > a:nth-child(3)", {"class": "line-highlighted"})
-assert-attribute: (".src-line-numbers > a:nth-child(4)", {"class": "line-highlighted"})
-assert-attribute: (".src-line-numbers > a:nth-child(5)", {"class": "line-highlighted"})
-assert-attribute: (".src-line-numbers > a:nth-child(6)", {"class": "line-highlighted"})
-assert-attribute-false: (".src-line-numbers > a:nth-child(7)", {"class": "line-highlighted"})
+assert-attribute-false: ("//a[@data-nosnippet and text()='3']", {"class": "line-highlighted"})
+assert-attribute: ("//a[@data-nosnippet and text()='4']", {"class": "line-highlighted"})
+assert-attribute: ("//a[@data-nosnippet and text()='5']", {"class": "line-highlighted"})
+assert-attribute: ("//a[@data-nosnippet and text()='6']", {"class": "line-highlighted"})
+assert-attribute-false: ("//a[@data-nosnippet and text()='7']", {"class": "line-highlighted"})
define-function: (
"check-colors",
@@ -26,12 +26,12 @@ define-function: (
block {
call-function: ("switch-theme", {"theme": |theme|})
assert-css: (
- ".src-line-numbers > a:not(.line-highlighted)",
+ "a[data-nosnippet]:not(.line-highlighted)",
{"color": |color|, "background-color": |background_color|},
ALL,
)
assert-css: (
- ".src-line-numbers > a.line-highlighted",
+ "a[data-nosnippet].line-highlighted",
{"color": |highlight_color|, "background-color": |highlight_background_color|},
ALL,
)
@@ -61,37 +61,37 @@ call-function: ("check-colors", {
})
// This is to ensure that the content is correctly align with the line numbers.
-compare-elements-position: ("//*[@id='1']", ".rust > code > span", ["y"])
+compare-elements-position-near: ("//*[@id='1']", ".rust > code > span", {"y": 2})
// Check the `href` property so that users can treat anchors as links.
-assert-property: (".src-line-numbers > a:nth-child(1)", {
+assert-property: ("//a[@data-nosnippet and text()='1']", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#1"
}, ENDS_WITH)
-assert-property: (".src-line-numbers > a:nth-child(2)", {
+assert-property: ("//a[@data-nosnippet and text()='2']", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#2"
}, ENDS_WITH)
-assert-property: (".src-line-numbers > a:nth-child(3)", {
+assert-property: ("//a[@data-nosnippet and text()='3']", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#3"
}, ENDS_WITH)
-assert-property: (".src-line-numbers > a:nth-child(4)", {
+assert-property: ("//a[@data-nosnippet and text()='4']", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#4"
}, ENDS_WITH)
-assert-property: (".src-line-numbers > a:nth-child(5)", {
+assert-property: ("//a[@data-nosnippet and text()='5']", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#5"
}, ENDS_WITH)
-assert-property: (".src-line-numbers > a:nth-child(6)", {
+assert-property: ("//a[@data-nosnippet and text()='6']", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#6"
}, ENDS_WITH)
// Assert that the line numbers text is aligned to the right.
-assert-css: (".src-line-numbers", {"text-align": "right"})
+assert-css: ("a[data-nosnippet]", {"text-align": "right"}, ALL)
// Now let's check that clicking on something else than the line number doesn't
// do anything (and certainly not add a `#NaN` to the URL!).
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
// We use this assert-position to know where we will click.
-assert-position: ("//*[@id='1']", {"x": 88, "y": 171})
-// We click on the left of the "1" anchor but still in the "src-line-number" ``.
-click: (163, 77)
+assert-position: ("//*[@id='1']", {"x": 81, "y": 169})
+// We click on the left of the "1" anchor but still in the `a[data-nosnippet]`.
+click: (77, 163)
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
// Checking the source code sidebar.
diff --git a/tests/rustdoc/check-source-code-urls-to-def.rs b/tests/rustdoc/check-source-code-urls-to-def.rs
index 8703287abc553..d701b88bf9fd0 100644
--- a/tests/rustdoc/check-source-code-urls-to-def.rs
+++ b/tests/rustdoc/check-source-code-urls-to-def.rs
@@ -31,7 +31,8 @@ fn babar() {}
//@ has - '//pre[@class="rust"]//a/@href' '/struct.String.html'
//@ has - '//pre[@class="rust"]//a/@href' '/primitive.u32.html'
//@ has - '//pre[@class="rust"]//a/@href' '/primitive.str.html'
-//@ count - '//pre[@class="rust"]//a[@href="#23"]' 5
+// The 5 links to line 23 and the line 23 itself.
+//@ count - '//pre[@class="rust"]//a[@href="#23"]' 6
//@ has - '//pre[@class="rust"]//a[@href="../../source_code/struct.SourceCode.html"]' \
// 'source_code::SourceCode'
pub fn foo(a: u32, b: &str, c: String, d: Foo, e: bar::Bar, f: source_code::SourceCode) {
@@ -50,8 +51,8 @@ pub fn foo2(t: &T, v: &V, b: bool) {}
pub trait AnotherTrait {}
pub trait WhyNot {}
-//@ has - '//pre[@class="rust"]//a[@href="#50"]' 'AnotherTrait'
-//@ has - '//pre[@class="rust"]//a[@href="#51"]' 'WhyNot'
+//@ has - '//pre[@class="rust"]//a[@href="#51"]' 'AnotherTrait'
+//@ has - '//pre[@class="rust"]//a[@href="#52"]' 'WhyNot'
pub fn foo3(t: &T, v: &V)
where
T: AnotherTrait,
@@ -60,7 +61,7 @@ where
pub trait AnotherTrait2 {}
-//@ has - '//pre[@class="rust"]//a[@href="#61"]' 'AnotherTrait2'
+//@ has - '//pre[@class="rust"]//a[@href="#62"]' 'AnotherTrait2'
pub fn foo4() {
let x: Vec<&dyn AnotherTrait2> = Vec::new();
}
diff --git a/tests/rustdoc/source-line-numbers.rs b/tests/rustdoc/source-line-numbers.rs
new file mode 100644
index 0000000000000..0b654b1a00476
--- /dev/null
+++ b/tests/rustdoc/source-line-numbers.rs
@@ -0,0 +1,35 @@
+// This test ensures that we have the expected number of line generated.
+
+#![crate_name = "foo"]
+
+//@ has 'src/foo/source-line-numbers.rs.html'
+//@ count - '//a[@data-nosnippet]' 35
+//@ has - '//a[@id="35"]' '35'
+
+#[
+macro_export
+]
+macro_rules! bar {
+ ($x:ident) => {{
+ $x += 2;
+ $x *= 2;
+ }}
+}
+
+/*
+multi line
+comment
+*/
+fn x(_: u8, _: u8) {}
+
+fn foo() {
+ let mut y = 0;
+ bar!(y);
+ println!("
+ {y}
+ ");
+ x(
+ 1,
+ 2,
+ );
+}