Skip to content

Commit cec6ec1

Browse files
Update rustdoc tests
1 parent 0395fc2 commit cec6ec1

9 files changed

+66
-149
lines changed

tests/rustdoc-gui/basic-code.goml

-6
This file was deleted.

tests/rustdoc-gui/docblock-code-block-line-number.goml

+17-49
Original file line numberDiff line numberDiff line change
@@ -111,28 +111,6 @@ wait-for: "pre.example-line-numbers"
111111
// Same check with scraped examples line numbers.
112112
go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
113113

114-
assert-css: (
115-
".scraped-example .src-line-numbers > pre",
116-
{
117-
// There should not be a radius on the right of the line numbers.
118-
"border-top-left-radius": "6px",
119-
"border-bottom-left-radius": "6px",
120-
"border-top-right-radius": "0px",
121-
"border-bottom-right-radius": "0px",
122-
},
123-
ALL,
124-
)
125-
assert-css: (
126-
".scraped-example .src-line-numbers",
127-
{
128-
// There should not be a radius on the right of the line numbers.
129-
"border-top-left-radius": "6px",
130-
"border-bottom-left-radius": "6px",
131-
"border-top-right-radius": "0px",
132-
"border-bottom-right-radius": "0px",
133-
},
134-
ALL,
135-
)
136114
assert-css: (
137115
".scraped-example .rust",
138116
{
@@ -149,23 +127,15 @@ define-function: (
149127
"check-padding",
150128
[path, padding_bottom],
151129
block {
152-
assert-css: (|path| + " .src-line-numbers", {
130+
assert-css: (|path| + " span[data-nosnippet]", {
153131
"padding-top": "0px",
154132
"padding-bottom": "0px",
155-
"padding-left": "0px",
156-
"padding-right": "0px",
157-
}, ALL)
158-
assert-css: (|path| + " .src-line-numbers > pre", {
159-
"padding-top": "14px",
160-
"padding-bottom": |padding_bottom|,
161-
"padding-left": "0px",
162-
"padding-right": "0px",
163-
}, ALL)
164-
assert-css: (|path| + " .src-line-numbers > pre > span", {
165-
"padding-top": "0px",
166-
"padding-bottom": "0px",
167-
"padding-left": "8px",
168-
"padding-right": "8px",
133+
"padding-left": "4px",
134+
"padding-right": "4px",
135+
"margin-right": "20px",
136+
"margin-left": "0px",
137+
"margin-top": "0px",
138+
"margin-bottom": "0px",
169139
}, ALL)
170140
},
171141
)
@@ -196,13 +166,13 @@ define-function: ("check-line-numbers-existence", [], block {
196166
wait-for-local-storage-false: {"rustdoc-line-numbers": "true" }
197167
assert-false: ".example-line-numbers"
198168
// Line numbers should still be there.
199-
assert: ".src-line-numbers"
169+
assert-css: ("[data-nosnippet]", { "display": "inline-block"})
200170
// Now disabling the setting.
201171
click: "input#line-numbers"
202172
wait-for-local-storage: {"rustdoc-line-numbers": "true" }
203173
assert-false: ".example-line-numbers"
204174
// Line numbers should still be there.
205-
assert: ".src-line-numbers"
175+
assert-css: ("[data-nosnippet]", { "display": "inline-block"})
206176
// Closing settings menu.
207177
click: "#settings-menu"
208178
wait-for-css: ("#settings", {"display": "none"})
@@ -214,18 +184,16 @@ call-function: ("check-line-numbers-existence", {})
214184

215185
// Now checking the line numbers in the source code page.
216186
click: ".src"
217-
assert-css: (".src-line-numbers", {
218-
"padding-top": "20px",
219-
"padding-bottom": "20px",
220-
"padding-left": "4px",
221-
"padding-right": "0px",
222-
})
223-
assert-css: (".src-line-numbers > a", {
187+
assert-css: ("a[data-nosnippet]", {
224188
"padding-top": "0px",
225189
"padding-bottom": "0px",
226-
"padding-left": "8px",
227-
"padding-right": "8px",
228-
})
190+
"padding-left": "4px",
191+
"padding-right": "4px",
192+
"margin-top": "0px",
193+
"margin-bottom": "0px",
194+
"margin-left": "0px",
195+
"margin-right": "20px",
196+
}, ALL)
229197
// Checking that turning off the line numbers setting won't remove line numbers.
230198
call-function: ("check-line-numbers-existence", {})
231199

tests/rustdoc-gui/jump-to-def-background.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define-function: (
88
block {
99
call-function: ("switch-theme", {"theme": |theme|})
1010
assert-css: (
11-
"body.src .example-wrap pre.rust a",
11+
"body.src .example-wrap pre.rust a:not([data-nosnippet])",
1212
{"background-color": |background_color|},
1313
ALL,
1414
)

tests/rustdoc-gui/scrape-examples-button-focus.goml

+2-35
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,19 @@ go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html"
44

55
// The next/prev buttons vertically scroll the code viewport between examples
66
move-cursor-to: ".scraped-example-list > .scraped-example"
7-
store-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
8-
"scrollTop": initialScrollTop,
9-
})
7+
wait-for: ".scraped-example-list > .scraped-example .next"
8+
store-value: (initialScrollTop, 250)
109
assert-property: (".scraped-example-list > .scraped-example .rust", {
1110
"scrollTop": |initialScrollTop|,
1211
})
1312
focus: ".scraped-example-list > .scraped-example .next"
1413
press-key: "Enter"
15-
assert-property-false: (".scraped-example-list > .scraped-example .src-line-numbers", {
16-
"scrollTop": |initialScrollTop|
17-
}, NEAR)
1814
assert-property-false: (".scraped-example-list > .scraped-example .rust", {
1915
"scrollTop": |initialScrollTop|
2016
}, NEAR)
2117
focus: ".scraped-example-list > .scraped-example .prev"
2218
press-key: "Enter"
23-
assert-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
24-
"scrollTop": |initialScrollTop|
25-
}, NEAR)
2619
assert-property: (".scraped-example-list > .scraped-example .rust", {
2720
"scrollTop": |initialScrollTop|
2821
}, NEAR)
2922

30-
// The expand button increases the scrollHeight of the minimized code viewport
31-
store-property: (".scraped-example-list > .scraped-example pre", {"offsetHeight": smallOffsetHeight})
32-
assert-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
33-
"scrollHeight": |smallOffsetHeight|
34-
}, NEAR)
35-
assert-property: (".scraped-example-list > .scraped-example .rust", {
36-
"scrollHeight": |smallOffsetHeight|
37-
}, NEAR)
38-
focus: ".scraped-example-list > .scraped-example .expand"
39-
press-key: "Enter"
40-
assert-property-false: (".scraped-example-list > .scraped-example .src-line-numbers", {
41-
"offsetHeight": |smallOffsetHeight|
42-
}, NEAR)
43-
assert-property-false: (".scraped-example-list > .scraped-example .rust", {
44-
"offsetHeight": |smallOffsetHeight|
45-
}, NEAR)
46-
store-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
47-
"offsetHeight": fullOffsetHeight,
48-
})
49-
assert-property: (".scraped-example-list > .scraped-example .rust", {
50-
"offsetHeight": |fullOffsetHeight|,
51-
"scrollHeight": |fullOffsetHeight|,
52-
})
53-
assert-property: (".scraped-example-list > .scraped-example .src-line-numbers", {
54-
"scrollHeight": |fullOffsetHeight|
55-
}, NEAR)

tests/rustdoc-gui/scrape-examples-layout.goml

+17-30
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,38 @@ go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
33

44
set-window-size: (1000, 1000)
55

6+
// We move the mouse over the scraped example for the prev button to be generated.
7+
move-cursor-to: ".scraped-example"
8+
69
// Check that it's not zero.
710
assert-property-false: (
8-
".more-scraped-examples .scraped-example .src-line-numbers",
11+
".more-scraped-examples .scraped-example span[data-nosnippet]",
912
{"clientWidth": "0"}
1013
)
1114

1215
// Check that examples with very long lines have the same width as ones that don't.
1316
store-property: (
14-
".more-scraped-examples .scraped-example:nth-child(2) .src-line-numbers",
17+
".more-scraped-examples .scraped-example:nth-child(2) span[data-nosnippet]",
1518
{"clientWidth": clientWidth},
1619
)
1720

1821
assert-property: (
19-
".more-scraped-examples .scraped-example:nth-child(3) .src-line-numbers",
22+
".more-scraped-examples .scraped-example:nth-child(3) span[data-nosnippet]",
2023
{"clientWidth": |clientWidth|}
2124
)
2225

2326
assert-property: (
24-
".more-scraped-examples .scraped-example:nth-child(4) .src-line-numbers",
27+
".more-scraped-examples .scraped-example:nth-child(4) span[data-nosnippet]",
2528
{"clientWidth": |clientWidth|}
2629
)
2730

2831
assert-property: (
29-
".more-scraped-examples .scraped-example:nth-child(5) .src-line-numbers",
32+
".more-scraped-examples .scraped-example:nth-child(5) span[data-nosnippet]",
3033
{"clientWidth": |clientWidth|}
3134
)
3235

3336
assert-property: (
34-
".more-scraped-examples .scraped-example:nth-child(6) .src-line-numbers",
37+
".more-scraped-examples .scraped-example:nth-child(6) span[data-nosnippet]",
3538
{"clientWidth": |clientWidth|}
3639
)
3740

@@ -55,25 +58,6 @@ assert-size: (".more-scraped-examples .scraped-example .example-wrap", {
5558
"width": |width|,
5659
})
5760

58-
// Check that the expand button works and also that line number aligns with code.
59-
move-cursor-to: ".scraped-example .rust"
60-
click: ".scraped-example .button-holder .expand"
61-
wait-for: ".scraped-example.expanded"
62-
// They should have the same y position.
63-
compare-elements-position: (
64-
".scraped-example.expanded .src-line-numbers pre span",
65-
".scraped-example.expanded .rust code",
66-
["y"],
67-
)
68-
// And they should have the same height.
69-
compare-elements-size: (
70-
".scraped-example.expanded .src-line-numbers",
71-
".scraped-example.expanded .rust",
72-
["height"],
73-
)
74-
// Collapse code again.
75-
click: ".scraped-example .button-holder .expand"
76-
7761
// Check that for both mobile and desktop sizes, the buttons in scraped examples are displayed
7862
// correctly.
7963

@@ -98,7 +82,7 @@ define-function: (
9882
[],
9983
block {
10084
// Title should be above the code.
101-
store-position: (".scraped-example .example-wrap .src-line-numbers", {"x": x, "y": y})
85+
store-position: (".scraped-example .example-wrap", {"x": x, "y": y})
10286
store-size: (".scraped-example .scraped-example-title", { "height": title_height })
10387

10488
assert-position: (".scraped-example .scraped-example-title", {
@@ -107,10 +91,13 @@ define-function: (
10791
})
10892

10993
// Line numbers should be right beside the code.
110-
compare-elements-position: (
111-
".scraped-example .example-wrap .src-line-numbers",
112-
".scraped-example .example-wrap .rust",
113-
["y"],
94+
compare-elements-position-near: (
95+
".scraped-example .example-wrap span[data-nosnippet]",
96+
// On the first line, the code starts with `fn main` so we have a keyword.
97+
".scraped-example .example-wrap .rust span.kw",
98+
// They're not exactly the same size but since they're on the same line,
99+
// it's kinda the same.
100+
{"y": 2},
114101
)
115102
}
116103
)

tests/rustdoc-gui/source-anchor-scroll.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ set-window-size: (600, 800)
88
assert-property: ("html", {"scrollTop": "0"})
99

1010
click: '//a[text() = "barbar" and @href="#5-7"]'
11-
assert-property: ("html", {"scrollTop": "208"})
11+
assert-property: ("html", {"scrollTop": "206"})
1212
click: '//a[text() = "bar" and @href="#28-36"]'
1313
assert-property: ("html", {"scrollTop": "239"})
1414
click: '//a[normalize-space() = "sub_fn" and @href="#2-4"]'
15-
assert-property: ("html", {"scrollTop": "136"})
15+
assert-property: ("html", {"scrollTop": "134"})
1616

1717
// We now check that clicking on lines doesn't change the scroll
1818
// Extra information: the "sub_fn" function header is on line 1.
1919
click: '//*[@id="6"]'
20-
assert-property: ("html", {"scrollTop": "136"})
20+
assert-property: ("html", {"scrollTop": "134"})

tests/rustdoc-gui/source-code-page-code-scroll.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
33
set-window-size: (800, 1000)
44
// "scrollWidth" should be superior than "clientWidth".
5-
assert-property: ("body", {"scrollWidth": 1776, "clientWidth": 800})
5+
assert-property: ("body", {"scrollWidth": 1780, "clientWidth": 800})
66

77
// Both properties should be equal (ie, no scroll on the code block).
8-
assert-property: (".example-wrap .rust", {"scrollWidth": 1662, "clientWidth": 1662})
8+
assert-property: (".example-wrap .rust", {"scrollWidth": 1715, "clientWidth": 1715})

tests/rustdoc-gui/source-code-page.goml

+19-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include: "utils.goml"
33
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
44
show-text: true
55
// Check that we can click on the line number.
6-
click: ".src-line-numbers > a:nth-child(4)" // This is the anchor for line 4.
6+
click: "//a[@data-nosnippet and text()='4']" // This is the anchor for line 4.
77
// Ensure that the page URL was updated.
88
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
99
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
@@ -14,24 +14,24 @@ assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
1414
assert-css: ("//*[@id='4']", {"border-right-width": "0px"})
1515
// We now check that the good anchors are highlighted
1616
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6"
17-
assert-attribute-false: (".src-line-numbers > a:nth-child(3)", {"class": "line-highlighted"})
18-
assert-attribute: (".src-line-numbers > a:nth-child(4)", {"class": "line-highlighted"})
19-
assert-attribute: (".src-line-numbers > a:nth-child(5)", {"class": "line-highlighted"})
20-
assert-attribute: (".src-line-numbers > a:nth-child(6)", {"class": "line-highlighted"})
21-
assert-attribute-false: (".src-line-numbers > a:nth-child(7)", {"class": "line-highlighted"})
17+
assert-attribute-false: ("//a[@data-nosnippet and text()='3']", {"class": "line-highlighted"})
18+
assert-attribute: ("//a[@data-nosnippet and text()='4']", {"class": "line-highlighted"})
19+
assert-attribute: ("//a[@data-nosnippet and text()='5']", {"class": "line-highlighted"})
20+
assert-attribute: ("//a[@data-nosnippet and text()='6']", {"class": "line-highlighted"})
21+
assert-attribute-false: ("//a[@data-nosnippet and text()='7']", {"class": "line-highlighted"})
2222

2323
define-function: (
2424
"check-colors",
2525
[theme, color, background_color, highlight_color, highlight_background_color],
2626
block {
2727
call-function: ("switch-theme", {"theme": |theme|})
2828
assert-css: (
29-
".src-line-numbers > a:not(.line-highlighted)",
29+
"a[data-nosnippet]:not(.line-highlighted)",
3030
{"color": |color|, "background-color": |background_color|},
3131
ALL,
3232
)
3333
assert-css: (
34-
".src-line-numbers > a.line-highlighted",
34+
"a[data-nosnippet].line-highlighted",
3535
{"color": |highlight_color|, "background-color": |highlight_background_color|},
3636
ALL,
3737
)
@@ -61,37 +61,37 @@ call-function: ("check-colors", {
6161
})
6262

6363
// This is to ensure that the content is correctly align with the line numbers.
64-
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ["y"])
64+
compare-elements-position-near: ("//*[@id='1']", ".rust > code > span", {"y": 2})
6565
// Check the `href` property so that users can treat anchors as links.
66-
assert-property: (".src-line-numbers > a:nth-child(1)", {
66+
assert-property: ("//a[@data-nosnippet and text()='1']", {
6767
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#1"
6868
}, ENDS_WITH)
69-
assert-property: (".src-line-numbers > a:nth-child(2)", {
69+
assert-property: ("//a[@data-nosnippet and text()='2']", {
7070
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#2"
7171
}, ENDS_WITH)
72-
assert-property: (".src-line-numbers > a:nth-child(3)", {
72+
assert-property: ("//a[@data-nosnippet and text()='3']", {
7373
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#3"
7474
}, ENDS_WITH)
75-
assert-property: (".src-line-numbers > a:nth-child(4)", {
75+
assert-property: ("//a[@data-nosnippet and text()='4']", {
7676
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#4"
7777
}, ENDS_WITH)
78-
assert-property: (".src-line-numbers > a:nth-child(5)", {
78+
assert-property: ("//a[@data-nosnippet and text()='5']", {
7979
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#5"
8080
}, ENDS_WITH)
81-
assert-property: (".src-line-numbers > a:nth-child(6)", {
81+
assert-property: ("//a[@data-nosnippet and text()='6']", {
8282
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#6"
8383
}, ENDS_WITH)
8484

8585
// Assert that the line numbers text is aligned to the right.
86-
assert-css: (".src-line-numbers", {"text-align": "right"})
86+
assert-css: ("a[data-nosnippet]", {"text-align": "right"}, ALL)
8787

8888
// Now let's check that clicking on something else than the line number doesn't
8989
// do anything (and certainly not add a `#NaN` to the URL!).
9090
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
9191
// We use this assert-position to know where we will click.
92-
assert-position: ("//*[@id='1']", {"x": 88, "y": 171})
93-
// We click on the left of the "1" anchor but still in the "src-line-number" `<pre>`.
94-
click: (163, 77)
92+
assert-position: ("//*[@id='1']", {"x": 81, "y": 169})
93+
// We click on the left of the "1" anchor but still in the `a[data-nosnippet]`.
94+
click: (77, 163)
9595
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
9696

9797
// Checking the source code sidebar.

0 commit comments

Comments
 (0)