Skip to content

Commit e71b239

Browse files
committed
fix generated tests
1 parent 0088f84 commit e71b239

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

crates/ide_assists/src/handlers/sort_items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ use crate::{utils::get_methods, AssistContext, AssistId, AssistKind, Assists};
6262
// ->
6363
// ```
6464
// enum Animal {
65-
// // variants sorted
6665
// Cat { weight: f64, name: String },
6766
// Dog(String, f64),
6867
// }
@@ -79,7 +78,7 @@ use crate::{utils::get_methods, AssistContext, AssistId, AssistKind, Assists};
7978
// ```
8079
// enum Animal {
8180
// Dog(String, f64),
82-
// Cat { name: String, weight: f64 }, // Cat fields sorted
81+
// Cat { name: String, weight: f64 },
8382
// }
8483
// ```
8584
pub(crate) fn sort_items(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {

crates/ide_assists/src/tests/generated.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ struct Foo { first: String, second: u32 }
15391539
#[test]
15401540
fn doctest_sort_items_1() {
15411541
check_doc_test(
1542-
"sort_items_1",
1542+
"sort_items",
15431543
r#####"
15441544
trait $0Bar {
15451545
fn second(&self) -> u32;
@@ -1558,7 +1558,7 @@ trait Bar {
15581558
#[test]
15591559
fn doctest_sort_items_2() {
15601560
check_doc_test(
1561-
"sort_items_2",
1561+
"sort_items",
15621562
r#####"
15631563
struct Baz;
15641564
impl $0Baz {
@@ -1579,7 +1579,7 @@ impl Baz {
15791579
#[test]
15801580
fn doctest_sort_items_3() {
15811581
check_doc_test(
1582-
"sort_items_3",
1582+
"sort_items",
15831583
r#####"
15841584
en$0um Animal {
15851585
Dog(String, f64),
@@ -1588,7 +1588,6 @@ en$0um Animal {
15881588
"#####,
15891589
r#####"
15901590
enum Animal {
1591-
// variants sorted
15921591
Cat { weight: f64, name: String },
15931592
Dog(String, f64),
15941593
}
@@ -1599,7 +1598,7 @@ enum Animal {
15991598
#[test]
16001599
fn doctest_sort_items_4() {
16011600
check_doc_test(
1602-
"sort_items_4",
1601+
"sort_items",
16031602
r#####"
16041603
enum Animal {
16051604
Dog(String, f64),
@@ -1609,7 +1608,7 @@ enum Animal {
16091608
r#####"
16101609
enum Animal {
16111610
Dog(String, f64),
1612-
Cat { name: String, weight: f64 }, // Cat fields sorted
1611+
Cat { name: String, weight: f64 },
16131612
}
16141613
"#####,
16151614
)

crates/ide_assists/src/tests/sourcegen.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ use super::check_doc_test;
1717
.to_string();
1818
for assist in assists.iter() {
1919
for (idx, section) in assist.sections.iter().enumerate() {
20-
let id = if idx == 0 { assist.id.clone() } else { format!("{}_{}", &assist.id, idx)};
20+
let test_id =
21+
if idx == 0 { assist.id.clone() } else { format!("{}_{}", &assist.id, idx) };
2122
let test = format!(
22-
r######"
23+
r######"
2324
#[test]
2425
fn doctest_{}() {{
2526
check_doc_test(
@@ -29,13 +30,13 @@ r#####"
2930
{}"#####)
3031
}}
3132
"######,
32-
&id,
33-
&id,
33+
&test_id,
34+
&assist.id,
3435
reveal_hash_comments(&section.before),
3536
reveal_hash_comments(&section.after)
3637
);
37-
38-
buf.push_str(&test)
38+
39+
buf.push_str(&test)
3940
}
4041
}
4142
let buf = sourcegen::add_preamble("sourcegen_assists_docs", sourcegen::reformat(buf));
@@ -58,7 +59,8 @@ r#####"
5859
fs::write(dst, contents).unwrap();
5960
}
6061
}
61-
#[derive(Debug)]struct Section {
62+
#[derive(Debug)]
63+
struct Section {
6264
doc: String,
6365
before: String,
6466
after: String,
@@ -68,7 +70,7 @@ r#####"
6870
struct Assist {
6971
id: String,
7072
___location: sourcegen::Location,
71-
sections: Vec<Section>
73+
sections: Vec<Section>,
7274
}
7375

7476
impl Assist {
@@ -106,14 +108,14 @@ impl Assist {
106108
"\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n",
107109
&assist.id, doc,
108110
);
109-
111+
110112
let before = take_until(lines.by_ref(), "```");
111-
113+
112114
assert_eq!(lines.next().unwrap().as_str(), "->");
113115
assert_eq!(lines.next().unwrap().as_str(), "```");
114116
let after = take_until(lines.by_ref(), "```");
115117

116-
assist.sections.push(Section{doc, before, after});
118+
assist.sections.push(Section { doc, before, after });
117119
}
118120

119121
acc.push(assist)
@@ -139,16 +141,15 @@ impl fmt::Display for Assist {
139141
f,
140142
"[discrete]\n=== `{}`
141143
**Source:** {}",
142-
self.id,
143-
self.___location,
144-
);
144+
self.id, self.___location,
145+
);
145146

146147
for section in &self.sections {
147148
let before = section.before.replace("$0", "┃"); // Unicode pseudo-graphics bar
148149
let after = section.after.replace("$0", "┃");
149-
let _= writeln!(
150+
let _ = writeln!(
150151
f,
151-
"
152+
"
152153
{}
153154
154155
.Before
@@ -161,7 +162,7 @@ impl fmt::Display for Assist {
161162
section.doc,
162163
hide_hash_comments(&before),
163164
hide_hash_comments(&after)
164-
);
165+
);
165166
}
166167

167168
Ok(())

0 commit comments

Comments
 (0)