Skip to content

Commit 34a18fa

Browse files
Update rustdoc tests
1 parent 0395fc2 commit 34a18fa

10 files changed

+71
-155
lines changed

src/librustdoc/html/highlight/tests.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn test_html_highlighting() {
2323
let src = include_str!("fixtures/sample.rs");
2424
let html = {
2525
let mut out = Buffer::new();
26-
write_code(&mut out, src, None, None);
26+
write_code(&mut out, src, None, None, None);
2727
format!("{STYLE}<pre><code>{}</code></pre>\n", out.into_inner())
2828
};
2929
expect_file!["fixtures/sample.html"].assert_eq(&html);
@@ -37,7 +37,7 @@ fn test_dos_backline() {
3737
println!(\"foo\");\r\n\
3838
}\r\n";
3939
let mut html = Buffer::new();
40-
write_code(&mut html, src, None, None);
40+
write_code(&mut html, src, None, None, None);
4141
expect_file!["fixtures/dos_line.html"].assert_eq(&html.into_inner());
4242
});
4343
}
@@ -51,7 +51,7 @@ let x = super::b::foo;
5151
let y = Self::whatever;";
5252

5353
let mut html = Buffer::new();
54-
write_code(&mut html, src, None, None);
54+
write_code(&mut html, src, None, None, None);
5555
expect_file!["fixtures/highlight.html"].assert_eq(&html.into_inner());
5656
});
5757
}
@@ -61,7 +61,7 @@ fn test_union_highlighting() {
6161
create_default_session_globals_then(|| {
6262
let src = include_str!("fixtures/union.rs");
6363
let mut html = Buffer::new();
64-
write_code(&mut html, src, None, None);
64+
write_code(&mut html, src, None, None, None);
6565
expect_file!["fixtures/union.html"].assert_eq(&html.into_inner());
6666
});
6767
}
@@ -78,7 +78,7 @@ let a = 4;";
7878
decorations.insert("example2", vec![(22, 32)]);
7979

8080
let mut html = Buffer::new();
81-
write_code(&mut html, src, None, Some(&DecorationInfo(decorations)));
81+
write_code(&mut html, src, None, Some(&DecorationInfo(decorations)), None);
8282
expect_file!["fixtures/decorations.html"].assert_eq(&html.into_inner());
8383
});
8484
}

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-36
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,18 @@ 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)
29-
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})

0 commit comments

Comments
 (0)