Skip to content

Commit b467e9d

Browse files
Add GUI test for code wrapping
1 parent 0cd6fed commit b467e9d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Checks that the interactions with the source code pages are working as expected.
2+
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
3+
show-text: true
4+
5+
define-function: (
6+
"click-code-wrapping",
7+
[expected],
8+
block {
9+
click: "#wrap-source-code"
10+
wait-for-local-storage: {"rustdoc-wrap-source-code": |expected|}
11+
},
12+
)
13+
14+
store-size: (".rust code", {"width": width, "height": height})
15+
click: "#settings-menu"
16+
wait-for: "#settings"
17+
call-function: ("click-code-wrapping", {"expected": "true"})
18+
store-size: (".rust code", {"width": new_width, "height": new_height})
19+
// The width should now be smaller than the window's and the height
20+
// should have increased.
21+
assert: |width| > |new_width| && |height| < |new_height|
22+
23+
// Switching back to the original setting.
24+
call-function: ("click-code-wrapping", {"expected": "false"})
25+
assert-size: (".rust code", {"width": |width|, "height": |height|})
26+
27+
// Now let's check in docs code examples.
28+
go-to: "file://" + |DOC_PATH| + "/test_docs/trait_bounds/index.html"
29+
click: "#settings-menu"
30+
wait-for: "#settings"
31+
32+
store-size: (".example-wrap .rust code", {"width": rust_width, "height": rust_height})
33+
store-size: (".example-wrap .language-text code", {"width": txt_width, "height": txt_height})
34+
call-function: ("click-code-wrapping", {"expected": "true"})
35+
36+
store-size: (".example-wrap .rust code", {"width": new_rust_width, "height": new_rust_height})
37+
store-size: (".example-wrap .language-text code", {"width": new_txt_width, "height": new_txt_height})
38+
39+
assert: |rust_width| > |new_rust_width| && |rust_height| < |new_rust_height|
40+
assert: |txt_width| > |new_txt_width| && |txt_height| < |new_txt_height|
41+
42+
call-function: ("click-code-wrapping", {"expected": "false"})
43+
assert-size: (".example-wrap .rust code", {"width": |rust_width|, "height": |rust_height|})
44+
assert-size: (".example-wrap .language-text code", {"width": |txt_width|, "height": |txt_height|})

tests/rustdoc-gui/src/test_docs/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,15 @@ pub mod private {
615615
}
616616
}
617617

618+
/// ```
619+
/// fn super_long_function_name_because_i_need_to_hit_the_limit_and_break_beyond_it() {
620+
/// }
621+
/// ```
622+
///
623+
/// ```text
624+
/// fn super_long_function_name_because_i_need_to_hit_the_limit_and_break_beyond_it_v2() {
625+
/// }
626+
/// ```
618627
pub mod trait_bounds {
619628
pub trait OneBound: Sized {}
620629
pub trait TwoBounds: Sized + Copy {}

0 commit comments

Comments
 (0)