11// Checks that the setting "line numbers" is working as expected.
22include: "utils.goml"
3+
34go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html"
45
6+ // Otherwise, we can't check text color
7+ show-text: true
8+
9+ store-value: (line_numbers_selector, ".example-wrap pre.rust code [data-nosnippet]")
510// We check that without this setting, there is no line number displayed.
6- assert-false: "pre.example-line-numbers"
11+ assert-count: (|line_numbers_selector|, 0)
712
813// All corners should be rounded.
914assert-css: (
@@ -17,14 +22,16 @@ assert-css: (
1722 ALL,
1823)
1924
20- // We set the setting to show the line numbers on code examples.
21- set-local-storage: {"rustdoc-line-numbers": "true"}
22- reload:
23- // We wait for the line numbers to be added into the DOM by the JS...
24- wait-for: ".digits-1 pre"
25+ // Before we add line numbers, we get the X position of a span in a code example that we will
26+ // use later on to ensure that when we disable the line numbers, it goes back to its original
27+ // position.
28+ store-position: (".example-wrap code .macro", {"x": span_x_pos})
2529
26- // Otherwise, we can't check text color
27- show-text: true
30+ // We enable the setting to show the line numbers on code examples.
31+ call-function: ("switch-line-numbers-setting", {"expected_status": "true"})
32+ // We ensure that there are actually line numbers generated in the DOM.
33+ assert-text: (".example-wrap pre.rust code span[data-nosnippet]", "1")
34+ assert-position-false: (".example-wrap code .macro", {"x": |span_x_pos|})
2835
2936// Let's now check some CSS properties...
3037define-function: (
@@ -68,20 +75,18 @@ call-function: ("check-colors", {
6875// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
6976// and make sure it goes away.
7077
71- // First, open the settings menu.
72- click: "rustdoc-toolbar .settings-menu"
73- wait-for: "#settings"
74- assert-css: ("#settings", {"display": "block"})
78+ call-function: ("switch-line-numbers-setting", {"expected_status": "false"})
79+ assert: ".digits-1.hide-lines"
7580
76- // Then, click the toggle button.
77- click: "input#line-numbers"
78- wait-for: ".digits-1.hide-lines"
79- assert-local-storage: {"rustdoc-line-numbers": "false" }
81+ // The line numbers not being displayed, their "space" should have disappear as well.
82+ assert-position: (".example-wrap code .macro", {"x": |span_x_pos|})
8083
8184// Finally, turn it on again.
82- click: "input# line-numbers"
85+ call-function: ("switch- line-numbers-setting", {"expected_status": "true"})
8386wait-for: ".digits-1:not(.hide-lines)"
84- assert-local-storage: {"rustdoc-line-numbers": "true" }
87+
88+ // The line numbers are being displayed, their "space" should be back.
89+ assert-position-false: (".example-wrap code .macro", {"x": |span_x_pos|})
8590
8691// Same check with scraped examples line numbers.
8792go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
@@ -119,26 +124,14 @@ call-function: ("check-padding", {
119124})
120125
121126define-function: ("check-line-numbers-existence", [], block {
122- assert-local-storage: {"rustdoc-line-numbers": "true" }
123- assert-false: ".example-line-numbers"
124- click: "rustdoc-toolbar .settings-menu"
125- wait-for: "#settings"
126-
127- // Then, click the toggle button.
128- click: "input#line-numbers"
129- wait-for-local-storage-false: {"rustdoc-line-numbers": "true" }
130- assert-false: ".example-line-numbers"
131- // Line numbers should still be there.
132- assert-css: ("[data-nosnippet]", { "display": "block"})
133- // Now disabling the setting.
134- click: "input#line-numbers"
135- wait-for-local-storage: {"rustdoc-line-numbers": "true" }
136- assert-false: ".example-line-numbers"
127+ assert-local-storage: {"rustdoc-line-numbers": "true"}
128+ assert-count-false: (|line_numbers_selector|, 0)
129+ call-function: ("switch-line-numbers-setting", {"expected_status": "false"})
137130 // Line numbers should still be there.
138- assert-css : ("[data-nosnippet]", { "display": "block"} )
139- // Closing settings menu.
140- click: "rustdoc-toolbar .settings-menu"
141- wait-for-css : ("#settings ", {"display ": "none "})
131+ assert-count-false : (|line_numbers_selector|, 0 )
132+ assert-css: (|line_numbers_selector|, {"display": "block"})
133+ // Now re-enabling the setting.
134+ call-function : ("switch-line-numbers-setting ", {"expected_status ": "true "})
142135})
143136
144137// Checking that turning off the line numbers setting won't remove line numbers from scraped
@@ -168,16 +161,11 @@ assert: ".example-wrap > pre.rust"
168161assert-count: (".example-wrap", 2)
169162assert-count: (".example-wrap.digits-1", 2)
170163
171- click: "rustdoc-toolbar .settings-menu"
172- wait-for: "#settings"
173-
174- // Then, click the toggle button.
175- click: "input#line-numbers"
164+ // Disabling the line numbers setting.
165+ call-function: ("switch-line-numbers-setting", {"expected_status": "false"})
176166wait-for-count: (".example-wrap.digits-1.hide-lines", 2)
177- assert-local-storage-false: {"rustdoc-line-numbers": "true" }
178167
179- // Now turning off the setting.
180- click: "input# line-numbers"
168+ // Now re-enabling the setting.
169+ call-function: ("switch- line-numbers-setting", {"expected_status": "true"})
181170wait-for-count: (".example-wrap.digits-1", 2)
182171wait-for-count: (".example-wrap.digits-1.hide-lines", 0)
183- assert-local-storage: {"rustdoc-line-numbers": "true" }
0 commit comments