Skip to content

Commit 5c9ce7b

Browse files
committed
test: add tests for keeping attrs in assist 'generate_delegate_trait'
1 parent faea7fc commit 5c9ce7b

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

crates/ide-assists/src/handlers/generate_delegate_trait.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,4 +1716,65 @@ impl some_module::SomeTrait for B {
17161716
}"#,
17171717
)
17181718
}
1719+
1720+
#[test]
1721+
fn test_fn_with_attrs() {
1722+
check_assist(
1723+
generate_delegate_trait,
1724+
r#"
1725+
struct A;
1726+
1727+
trait T {
1728+
#[cfg(test)]
1729+
fn f(&self, a: u32);
1730+
#[cfg(not(test))]
1731+
fn f(&self, a: bool);
1732+
}
1733+
1734+
impl T for A {
1735+
#[cfg(test)]
1736+
fn f(&self, a: u32) {}
1737+
#[cfg(not(test))]
1738+
fn f(&self, a: bool) {}
1739+
}
1740+
1741+
struct B {
1742+
a$0: A,
1743+
}
1744+
"#,
1745+
r#"
1746+
struct A;
1747+
1748+
trait T {
1749+
#[cfg(test)]
1750+
fn f(&self, a: u32);
1751+
#[cfg(not(test))]
1752+
fn f(&self, a: bool);
1753+
}
1754+
1755+
impl T for A {
1756+
#[cfg(test)]
1757+
fn f(&self, a: u32) {}
1758+
#[cfg(not(test))]
1759+
fn f(&self, a: bool) {}
1760+
}
1761+
1762+
struct B {
1763+
a: A,
1764+
}
1765+
1766+
impl T for B {
1767+
#[cfg(test)]
1768+
fn f(&self, a: u32) {
1769+
<A as T>::f(&self.a, a)
1770+
}
1771+
1772+
#[cfg(not(test))]
1773+
fn f(&self, a: bool) {
1774+
<A as T>::f(&self.a, a)
1775+
}
1776+
}
1777+
"#,
1778+
);
1779+
}
17191780
}

0 commit comments

Comments
 (0)