Add GUI test for --generate-macro-expansion option
This commit is contained in:
parent
b7a415017c
commit
e6f9e2e623
5 changed files with 140 additions and 1 deletions
74
tests/rustdoc-gui/macro-expansion.goml
Normal file
74
tests/rustdoc-gui/macro-expansion.goml
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
// This test ensures that the macro expansion is generated and working as expected.
|
||||
go-to: "file://" + |DOC_PATH| + "/src/macro_expansion/lib.rs.html"
|
||||
|
||||
define-function: (
|
||||
"check-expansion",
|
||||
[line, original_content],
|
||||
block {
|
||||
assert-text: ("a[id='" + |line| + "'] + .expansion .original", |original_content|)
|
||||
// The "original" content should be expanded.
|
||||
assert-css: ("a[id='" + |line| + "'] + .expansion .original", {"display": "inline"})
|
||||
// The expanded macro should be hidden.
|
||||
assert-css: ("a[id='" + |line| + "'] + .expansion .expanded", {"display": "none"})
|
||||
|
||||
// We "expand" the macro.
|
||||
click: "a[id='" + |line| + "'] + .expansion label"
|
||||
// The "original" content is hidden.
|
||||
assert-css: ("a[id='" + |line| + "'] + .expansion .original", {"display": "none"})
|
||||
// The expanded macro is visible.
|
||||
assert-css: ("a[id='" + |line| + "'] + .expansion .expanded", {"display": "inline"})
|
||||
|
||||
// We collapse the macro.
|
||||
click: "a[id='" + |line| + "'] + .expansion label"
|
||||
// The "original" content is expanded.
|
||||
assert-css: ("a[id='" + |line| + "'] + .expansion .original", {"display": "inline"})
|
||||
// The expanded macro is hidden.
|
||||
assert-css: ("a[id='" + |line| + "'] + .expansion .expanded", {"display": "none"})
|
||||
}
|
||||
)
|
||||
|
||||
// First we check the derive macro expansion at line 12.
|
||||
call-function: ("check-expansion", {"line": 12, "original_content": "Debug"})
|
||||
// Then we check the `bar` macro expansion at line 22.
|
||||
call-function: ("check-expansion", {"line": 22, "original_content": "bar!(y)"})
|
||||
// Then we check the `println` macro expansion at line 23-25.
|
||||
call-function: ("check-expansion", {"line": 23, "original_content": 'println!("
|
||||
24 {y}
|
||||
25 ")'})
|
||||
|
||||
// Then finally we check when there are two macro calls on a same line.
|
||||
assert-count: ("#expand-27 ~ .original", 2)
|
||||
assert-count: ("#expand-27 ~ .expanded", 2)
|
||||
|
||||
store-value: (repeat_o, '/following-sibling::*[@class="original"]')
|
||||
store-value: (repeat_e, '/following-sibling::*[@class="expanded"]')
|
||||
assert-text: ('//*[@id="expand-27"]' + |repeat_o|, "stringify!(foo)")
|
||||
assert-text: ('//*[@id="expand-27"]' + |repeat_o| + |repeat_o|, "stringify!(bar)")
|
||||
assert-text: ('//*[@id="expand-27"]' + |repeat_e|, '"foo"')
|
||||
assert-text: ('//*[@id="expand-27"]' + |repeat_e| + |repeat_e|, '"bar"')
|
||||
|
||||
// The "original" content should be expanded.
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_o|, {"display": "inline"})
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_o| + |repeat_o|, {"display": "inline"})
|
||||
// The expanded macro should be hidden.
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_e|, {"display": "none"})
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_e| + |repeat_e|, {"display": "none"})
|
||||
|
||||
// We "expand" the macro (because the line starts with a string, the label is not at the "top
|
||||
// level" of the `<code>`, so we need to use a different selector).
|
||||
click: ".expansion label[for='expand-27']"
|
||||
// The "original" content is hidden.
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_o|, {"display": "none"})
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_o| + |repeat_o|, {"display": "none"})
|
||||
// The expanded macro is visible.
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_e|, {"display": "inline"})
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_e| + |repeat_e|, {"display": "inline"})
|
||||
|
||||
// We collapse the macro.
|
||||
click: ".expansion label[for='expand-27']"
|
||||
// The "original" content is expanded.
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_o|, {"display": "inline"})
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_o| + |repeat_o|, {"display": "inline"})
|
||||
// The expanded macro is hidden.
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_e|, {"display": "none"})
|
||||
assert-css: ('//*[@id="expand-27"]' + |repeat_e| + |repeat_e|, {"display": "none"})
|
||||
|
|
@ -71,7 +71,7 @@ assert: "//*[@class='dir-entry' and @open]/*[normalize-space()='sub_mod']"
|
|||
// Only "another_folder" should be "open" in "lib2".
|
||||
assert: "//*[@class='dir-entry' and not(@open)]/*[normalize-space()='another_mod']"
|
||||
// All other trees should be collapsed.
|
||||
assert-count: ("//*[@id='src-sidebar']/details[not(normalize-space()='lib2') and not(@open)]", 11)
|
||||
assert-count: ("//*[@id='src-sidebar']/details[not(normalize-space()='lib2') and not(@open)]", 12)
|
||||
|
||||
// We now switch to mobile mode.
|
||||
set-window-size: (600, 600)
|
||||
|
|
|
|||
7
tests/rustdoc-gui/src/macro_expansion/Cargo.lock
Normal file
7
tests/rustdoc-gui/src/macro_expansion/Cargo.lock
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "macro_expansion"
|
||||
version = "0.1.0"
|
||||
7
tests/rustdoc-gui/src/macro_expansion/Cargo.toml
Normal file
7
tests/rustdoc-gui/src/macro_expansion/Cargo.toml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "macro_expansion"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
51
tests/rustdoc-gui/src/macro_expansion/lib.rs
Normal file
51
tests/rustdoc-gui/src/macro_expansion/lib.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// Test crate used to check the `--generate-macro-expansion` option.
|
||||
//@ compile-flags: -Zunstable-options --generate-macro-expansion --generate-link-to-definition
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! bar {
|
||||
($x:ident) => {{
|
||||
$x += 2;
|
||||
$x *= 2;
|
||||
}}
|
||||
}
|
||||
|
||||
macro_rules! bar2 {
|
||||
() => {
|
||||
fn foo2() -> impl std::fmt::Display {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! bar3 {
|
||||
() => {
|
||||
fn foo3() {}
|
||||
fn foo4() -> String { String::new() }
|
||||
}
|
||||
}
|
||||
|
||||
bar2!();
|
||||
bar3!();
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Bar;
|
||||
|
||||
#[derive(Debug
|
||||
)]
|
||||
pub struct Bar2;
|
||||
|
||||
fn y_f(_: &str, _: &str, _: &str) {}
|
||||
|
||||
fn foo() {
|
||||
let mut y = 0;
|
||||
bar!(y);
|
||||
println!("
|
||||
{y}
|
||||
");
|
||||
// comment
|
||||
println!("
|
||||
{y}
|
||||
");
|
||||
let s = y_f("\
|
||||
bla", stringify!(foo), stringify!(bar));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue