Skip to content

Commit b666b7f

Browse files
Add GUI test for --generate-macro-expansion option
1 parent e3ff707 commit b666b7f

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-1
lines changed
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This test ensures that the macro expansion is generated and working as expected.
2+
go-to: "file://" + |DOC_PATH| + "/src/macro_expansion/lib.rs.html"
3+
4+
define-function: (
5+
"check-expansion",
6+
[line, original_content],
7+
block {
8+
assert-text: ("a[id='" + |line| + "'] + .expansion .original", |original_content|)
9+
// The "original" content should be expanded.
10+
assert-css: ("a[id='" + |line| + "'] + .expansion .original", {"display": "inline"})
11+
// The expanded macro should be hidden.
12+
assert-css: ("a[id='" + |line| + "'] + .expansion .expanded", {"display": "none"})
13+
14+
// We "expand" the macro.
15+
click: "a[id='" + |line| + "'] + .expansion label"
16+
// The "original" content is hidden.
17+
assert-css: ("a[id='" + |line| + "'] + .expansion .original", {"display": "none"})
18+
// The expanded macro is visible.
19+
assert-css: ("a[id='" + |line| + "'] + .expansion .expanded", {"display": "inline"})
20+
21+
// We collapse the macro.
22+
click: "a[id='" + |line| + "'] + .expansion label"
23+
// The "original" content is expanded.
24+
assert-css: ("a[id='" + |line| + "'] + .expansion .original", {"display": "inline"})
25+
// The expanded macro is hidden.
26+
assert-css: ("a[id='" + |line| + "'] + .expansion .expanded", {"display": "none"})
27+
}
28+
)
29+
30+
// First we check the derive macro expansion at line 12.
31+
call-function: ("check-expansion", {"line": 12, "original_content": "Debug"})
32+
// Then we check the `bar` macro expansion at line 22.
33+
call-function: ("check-expansion", {"line": 22, "original_content": "bar!(y)"})
34+
// Then we check the `println` macro expansion at line 23-25.
35+
call-function: ("check-expansion", {"line": 23, "original_content": 'println!("
36+
24 {y}
37+
25 ")'})
38+
39+
// Then finally we check when there are two macro calls on a same line.
40+
assert-count: ("#expand-27 ~ .original", 2)
41+
assert-count: ("#expand-27 ~ .expanded", 2)
42+
43+
store-value: (repeat_o, '/following-sibling::*[@class="original"]')
44+
store-value: (repeat_e, '/following-sibling::*[@class="expanded"]')
45+
assert-text: ('//*[@id="expand-27"]' + |repeat_o|, "stringify!(foo)")
46+
assert-text: ('//*[@id="expand-27"]' + |repeat_o| + |repeat_o|, "stringify!(bar)")
47+
assert-text: ('//*[@id="expand-27"]' + |repeat_e|, '"foo"')
48+
assert-text: ('//*[@id="expand-27"]' + |repeat_e| + |repeat_e|, '"bar"')
49+
50+
// The "original" content should be expanded.
51+
assert-css: ('//*[@id="expand-27"]' + |repeat_o|, {"display": "inline"})
52+
assert-css: ('//*[@id="expand-27"]' + |repeat_o| + |repeat_o|, {"display": "inline"})
53+
// The expanded macro should be hidden.
54+
assert-css: ('//*[@id="expand-27"]' + |repeat_e|, {"display": "none"})
55+
assert-css: ('//*[@id="expand-27"]' + |repeat_e| + |repeat_e|, {"display": "none"})
56+
57+
// We "expand" the macro (because the line starts with a string, the label is not at the "top
58+
// level" of the `<code>`, so we need to use a different selector).
59+
click: ".expansion label[for='expand-27']"
60+
// The "original" content is hidden.
61+
assert-css: ('//*[@id="expand-27"]' + |repeat_o|, {"display": "none"})
62+
assert-css: ('//*[@id="expand-27"]' + |repeat_o| + |repeat_o|, {"display": "none"})
63+
// The expanded macro is visible.
64+
assert-css: ('//*[@id="expand-27"]' + |repeat_e|, {"display": "inline"})
65+
assert-css: ('//*[@id="expand-27"]' + |repeat_e| + |repeat_e|, {"display": "inline"})
66+
67+
// We collapse the macro.
68+
click: ".expansion label[for='expand-27']"
69+
// The "original" content is expanded.
70+
assert-css: ('//*[@id="expand-27"]' + |repeat_o|, {"display": "inline"})
71+
assert-css: ('//*[@id="expand-27"]' + |repeat_o| + |repeat_o|, {"display": "inline"})
72+
// The expanded macro is hidden.
73+
assert-css: ('//*[@id="expand-27"]' + |repeat_e|, {"display": "none"})
74+
assert-css: ('//*[@id="expand-27"]' + |repeat_e| + |repeat_e|, {"display": "none"})

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ assert: "//*[@class='dir-entry' and @open]/*[normalize-space()='sub_mod']"
7171
// Only "another_folder" should be "open" in "lib2".
7272
assert: "//*[@class='dir-entry' and not(@open)]/*[normalize-space()='another_mod']"
7373
// All other trees should be collapsed.
74-
assert-count: ("//*[@id='src-sidebar']/details[not(normalize-space()='lib2') and not(@open)]", 11)
74+
assert-count: ("//*[@id='src-sidebar']/details[not(normalize-space()='lib2') and not(@open)]", 12)
7575

7676
// We now switch to mobile mode.
7777
set-window-size: (600, 600)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
3+
version = 4
4+
5+
[[package]]
6+
name = "macro_expansion"
7+
version = "0.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "macro_expansion"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
path = "lib.rs"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test crate used to check the `--generate-macro-expansion` option.
2+
//@ compile-flags: -Zunstable-options --generate-macro-expansion --generate-link-to-definition
3+
4+
#[macro_export]
5+
macro_rules! bar {
6+
($x:ident) => {{
7+
$x += 2;
8+
$x *= 2;
9+
}}
10+
}
11+
12+
#[derive(Debug)]
13+
pub struct Bar {
14+
a: String,
15+
b: u8,
16+
}
17+
18+
fn y_f(_: &str, _: &str, _: &str) {}
19+
20+
fn foo() {
21+
let mut y = 0;
22+
bar!(y);
23+
println!("
24+
{y}
25+
");
26+
let s = y_f("\
27+
bla", stringify!(foo), stringify!(bar));
28+
}

0 commit comments

Comments
 (0)