2021-10-19 09:42:59 +00:00
|
|
|
// Checks that the setting "line numbers" is working as expected.
|
2024-04-05 19:38:55 +00:00
|
|
|
include: "utils.goml"
|
2023-04-11 17:11:34 +00:00
|
|
|
go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
|
2021-10-19 09:42:59 +00:00
|
|
|
|
|
|
|
// We check that without this setting, there is no line number displayed.
|
2022-09-26 17:50:51 +00:00
|
|
|
assert-false: "pre.example-line-numbers"
|
2021-10-19 09:42:59 +00:00
|
|
|
|
2024-08-31 20:28:56 +00:00
|
|
|
// All corners should be rounded.
|
|
|
|
assert-css: (
|
|
|
|
".example-wrap .rust",
|
|
|
|
{
|
|
|
|
"border-top-left-radius": "6px",
|
|
|
|
"border-bottom-left-radius": "6px",
|
|
|
|
"border-top-right-radius": "6px",
|
|
|
|
"border-bottom-right-radius": "6px",
|
|
|
|
},
|
|
|
|
ALL,
|
|
|
|
)
|
|
|
|
|
2024-04-08 10:14:41 +00:00
|
|
|
// We set the setting to show the line numbers on code examples.
|
|
|
|
set-local-storage: {"rustdoc-line-numbers": "true"}
|
|
|
|
reload:
|
|
|
|
// We wait for the line numbers to be added into the DOM by the JS...
|
|
|
|
wait-for: "pre.example-line-numbers"
|
|
|
|
|
|
|
|
// Otherwise, we can't check text color
|
|
|
|
show-text: true
|
|
|
|
|
2021-10-19 09:42:59 +00:00
|
|
|
// Let's now check some CSS properties...
|
2022-12-24 05:55:04 +00:00
|
|
|
define-function: (
|
|
|
|
"check-colors",
|
2024-04-01 19:11:22 +00:00
|
|
|
[theme, color],
|
2023-01-06 14:18:51 +00:00
|
|
|
block {
|
2024-04-05 19:38:55 +00:00
|
|
|
// Page will be reloaded in "switch-theme".
|
|
|
|
call-function: ("switch-theme", {"theme": |theme|})
|
2022-12-24 05:55:04 +00:00
|
|
|
// If the test didn't fail, it means that it was found!
|
2023-01-06 14:18:51 +00:00
|
|
|
assert-css: (
|
2022-12-24 05:55:04 +00:00
|
|
|
"pre.example-line-numbers",
|
|
|
|
{
|
|
|
|
"color": |color|,
|
|
|
|
"margin": "0px",
|
2024-09-20 13:59:50 +00:00
|
|
|
"padding-top": "14px",
|
|
|
|
"padding-bottom": "14px",
|
|
|
|
"padding-left": "8px",
|
|
|
|
"padding-right": "2px",
|
2022-12-24 05:55:04 +00:00
|
|
|
"text-align": "right",
|
2024-08-31 20:28:56 +00:00
|
|
|
// 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",
|
2022-12-24 05:55:04 +00:00
|
|
|
},
|
|
|
|
ALL,
|
2023-01-06 14:18:51 +00:00
|
|
|
)
|
2024-08-31 20:28:56 +00:00
|
|
|
// There should not be a radius on the left of the line numbers.
|
|
|
|
assert-css: ("pre.example-line-numbers + .rust", {
|
|
|
|
"border-top-left-radius": "0px",
|
|
|
|
"border-bottom-left-radius": "0px",
|
|
|
|
"border-top-right-radius": "6px",
|
|
|
|
"border-bottom-right-radius": "6px",
|
|
|
|
})
|
2023-01-06 14:18:51 +00:00
|
|
|
},
|
2022-12-24 05:55:04 +00:00
|
|
|
)
|
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "ayu",
|
2023-06-25 08:49:28 +00:00
|
|
|
"color": "#5c6773",
|
2021-10-19 09:42:59 +00:00
|
|
|
})
|
2022-12-24 05:55:04 +00:00
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "dark",
|
2023-06-25 08:49:28 +00:00
|
|
|
"color": "#3b91e2",
|
2022-12-24 05:55:04 +00:00
|
|
|
})
|
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "light",
|
2023-06-25 08:49:28 +00:00
|
|
|
"color": "#c67e2d",
|
2022-12-24 05:55:04 +00:00
|
|
|
})
|
|
|
|
|
2021-10-19 09:42:59 +00:00
|
|
|
// The first code block has two lines so let's check its `<pre>` elements lists both of them.
|
2022-09-26 17:50:51 +00:00
|
|
|
assert-text: ("pre.example-line-numbers", "1\n2")
|
2022-09-21 22:43:38 +00:00
|
|
|
|
|
|
|
// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
|
|
|
|
// and make sure it goes away.
|
|
|
|
|
|
|
|
// First, open the settings menu.
|
|
|
|
click: "#settings-menu"
|
|
|
|
wait-for: "#settings"
|
|
|
|
assert-css: ("#settings", {"display": "block"})
|
|
|
|
|
|
|
|
// Then, click the toggle button.
|
2022-11-10 23:51:14 +00:00
|
|
|
click: "input#line-numbers"
|
2024-09-28 16:04:00 +00:00
|
|
|
wait-for-false: "pre.example-line-numbers"
|
2022-12-12 21:49:19 +00:00
|
|
|
assert-local-storage: {"rustdoc-line-numbers": "false" }
|
2022-09-21 22:43:38 +00:00
|
|
|
|
2024-08-31 20:28:56 +00:00
|
|
|
// Check that the rounded corners are back.
|
|
|
|
assert-css: (
|
|
|
|
".example-wrap .rust",
|
|
|
|
{
|
|
|
|
"border-top-left-radius": "6px",
|
|
|
|
"border-bottom-left-radius": "6px",
|
|
|
|
"border-top-right-radius": "6px",
|
|
|
|
"border-bottom-right-radius": "6px",
|
|
|
|
},
|
|
|
|
ALL,
|
|
|
|
)
|
|
|
|
|
2022-09-21 22:43:38 +00:00
|
|
|
// Finally, turn it on again.
|
2022-11-10 23:51:14 +00:00
|
|
|
click: "input#line-numbers"
|
2022-09-26 17:50:51 +00:00
|
|
|
wait-for: "pre.example-line-numbers"
|
2022-12-12 21:49:19 +00:00
|
|
|
assert-local-storage: {"rustdoc-line-numbers": "true" }
|
2024-09-28 16:04:00 +00:00
|
|
|
wait-for: "pre.example-line-numbers"
|
2024-08-31 20:28:56 +00:00
|
|
|
|
|
|
|
// Same check with scraped examples line numbers.
|
|
|
|
go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
|
|
|
|
|
2024-09-03 20:17:04 +00:00
|
|
|
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,
|
|
|
|
)
|
2024-08-31 20:28:56 +00:00
|
|
|
assert-css: (
|
2024-09-02 13:59:00 +00:00
|
|
|
".scraped-example .src-line-numbers",
|
2024-08-31 20:28:56 +00:00
|
|
|
{
|
|
|
|
// 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",
|
|
|
|
{
|
|
|
|
// There should not be a radius on the left of the code.
|
|
|
|
"border-top-left-radius": "0px",
|
|
|
|
"border-bottom-left-radius": "0px",
|
|
|
|
"border-top-right-radius": "6px",
|
|
|
|
"border-bottom-right-radius": "6px",
|
|
|
|
},
|
|
|
|
ALL,
|
|
|
|
)
|
2024-09-20 13:59:50 +00:00
|
|
|
|
|
|
|
define-function: (
|
|
|
|
"check-padding",
|
|
|
|
[path, padding_bottom],
|
|
|
|
block {
|
|
|
|
assert-css: (|path| + " .src-line-numbers", {
|
|
|
|
"padding-top": "0px",
|
|
|
|
"padding-bottom": "0px",
|
|
|
|
"padding-left": "0px",
|
|
|
|
"padding-right": "0px",
|
2024-09-21 15:00:42 +00:00
|
|
|
}, ALL)
|
2024-09-20 13:59:50 +00:00
|
|
|
assert-css: (|path| + " .src-line-numbers > pre", {
|
|
|
|
"padding-top": "14px",
|
|
|
|
"padding-bottom": |padding_bottom|,
|
|
|
|
"padding-left": "0px",
|
|
|
|
"padding-right": "0px",
|
2024-09-21 15:00:42 +00:00
|
|
|
}, ALL)
|
2024-09-20 13:59:50 +00:00
|
|
|
assert-css: (|path| + " .src-line-numbers > pre > span", {
|
|
|
|
"padding-top": "0px",
|
|
|
|
"padding-bottom": "0px",
|
|
|
|
"padding-left": "8px",
|
|
|
|
"padding-right": "8px",
|
2024-09-21 15:00:42 +00:00
|
|
|
}, ALL)
|
2024-09-20 13:59:50 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
call-function: ("check-padding", {
|
|
|
|
"path": ".scraped-example .example-wrap",
|
|
|
|
"padding_bottom": "0px",
|
|
|
|
})
|
|
|
|
|
|
|
|
move-cursor-to: ".scraped-example .example-wrap .rust"
|
|
|
|
wait-for: ".scraped-example .example-wrap .button-holder .expand"
|
|
|
|
click: ".scraped-example .example-wrap .button-holder .expand"
|
|
|
|
wait-for: ".scraped-example.expanded"
|
|
|
|
|
|
|
|
call-function: ("check-padding", {
|
|
|
|
"path": ".scraped-example.expanded .example-wrap",
|
|
|
|
"padding_bottom": "14px",
|
|
|
|
})
|
|
|
|
|
2024-09-21 15:00:42 +00:00
|
|
|
define-function: ("check-line-numbers-existence", [], block {
|
|
|
|
assert-local-storage: {"rustdoc-line-numbers": "true" }
|
|
|
|
assert-false: ".example-line-numbers"
|
|
|
|
click: "#settings-menu"
|
|
|
|
wait-for: "#settings"
|
|
|
|
|
|
|
|
// Then, click the toggle button.
|
|
|
|
click: "input#line-numbers"
|
2024-09-28 16:04:00 +00:00
|
|
|
wait-for-local-storage-false: {"rustdoc-line-numbers": "true" }
|
2024-09-21 15:00:42 +00:00
|
|
|
assert-false: ".example-line-numbers"
|
|
|
|
// Line numbers should still be there.
|
|
|
|
assert: ".src-line-numbers"
|
|
|
|
// Now disabling the setting.
|
|
|
|
click: "input#line-numbers"
|
2024-09-28 16:04:00 +00:00
|
|
|
wait-for-local-storage: {"rustdoc-line-numbers": "true" }
|
2024-09-21 15:00:42 +00:00
|
|
|
assert-false: ".example-line-numbers"
|
|
|
|
// Line numbers should still be there.
|
|
|
|
assert: ".src-line-numbers"
|
|
|
|
// Closing settings menu.
|
|
|
|
click: "#settings-menu"
|
|
|
|
wait-for-css: ("#settings", {"display": "none"})
|
|
|
|
})
|
|
|
|
|
|
|
|
// Checking that turning off the line numbers setting won't remove line numbers from scraped
|
|
|
|
// examples.
|
|
|
|
call-function: ("check-line-numbers-existence", {})
|
|
|
|
|
2024-09-20 13:59:50 +00:00
|
|
|
// 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", {
|
|
|
|
"padding-top": "0px",
|
|
|
|
"padding-bottom": "0px",
|
|
|
|
"padding-left": "8px",
|
|
|
|
"padding-right": "8px",
|
|
|
|
})
|
2024-09-21 15:00:42 +00:00
|
|
|
// Checking that turning off the line numbers setting won't remove line numbers.
|
|
|
|
call-function: ("check-line-numbers-existence", {})
|
|
|
|
|
|
|
|
// Now checking that even non-rust code blocks have line numbers generated.
|
|
|
|
go-to: "file://" + |DOC_PATH| + "/lib2/sub_mod/struct.Foo.html"
|
|
|
|
assert-local-storage: {"rustdoc-line-numbers": "true" }
|
|
|
|
assert: ".example-wrap > pre.language-txt"
|
|
|
|
assert: ".example-wrap > pre.rust"
|
|
|
|
assert-count: (".example-wrap", 2)
|
|
|
|
assert-count: (".example-wrap > pre.example-line-numbers", 2)
|
|
|
|
|
|
|
|
click: "#settings-menu"
|
|
|
|
wait-for: "#settings"
|
|
|
|
|
|
|
|
// Then, click the toggle button.
|
|
|
|
click: "input#line-numbers"
|
2024-09-28 16:04:00 +00:00
|
|
|
wait-for-count: (".example-wrap > pre.example-line-numbers", 0)
|
2024-09-21 15:00:42 +00:00
|
|
|
assert-local-storage-false: {"rustdoc-line-numbers": "true" }
|
|
|
|
|
|
|
|
// Now turning off the setting.
|
|
|
|
click: "input#line-numbers"
|
2024-09-28 16:04:00 +00:00
|
|
|
wait-for-count: (".example-wrap > pre.example-line-numbers", 2)
|
2024-09-21 15:00:42 +00:00
|
|
|
assert-local-storage: {"rustdoc-line-numbers": "true" }
|