mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 01:38:13 +00:00
fix generated tests
This commit is contained in:
parent
0088f84c88
commit
e71b239d37
3 changed files with 24 additions and 25 deletions
|
@ -62,7 +62,6 @@ use crate::{utils::get_methods, AssistContext, AssistId, AssistKind, Assists};
|
|||
// ->
|
||||
// ```
|
||||
// enum Animal {
|
||||
// // variants sorted
|
||||
// Cat { weight: f64, name: String },
|
||||
// Dog(String, f64),
|
||||
// }
|
||||
|
@ -79,7 +78,7 @@ use crate::{utils::get_methods, AssistContext, AssistId, AssistKind, Assists};
|
|||
// ```
|
||||
// enum Animal {
|
||||
// Dog(String, f64),
|
||||
// Cat { name: String, weight: f64 }, // Cat fields sorted
|
||||
// Cat { name: String, weight: f64 },
|
||||
// }
|
||||
// ```
|
||||
pub(crate) fn sort_items(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
|
|
|
@ -1539,7 +1539,7 @@ struct Foo { first: String, second: u32 }
|
|||
#[test]
|
||||
fn doctest_sort_items_1() {
|
||||
check_doc_test(
|
||||
"sort_items_1",
|
||||
"sort_items",
|
||||
r#####"
|
||||
trait $0Bar {
|
||||
fn second(&self) -> u32;
|
||||
|
@ -1558,7 +1558,7 @@ trait Bar {
|
|||
#[test]
|
||||
fn doctest_sort_items_2() {
|
||||
check_doc_test(
|
||||
"sort_items_2",
|
||||
"sort_items",
|
||||
r#####"
|
||||
struct Baz;
|
||||
impl $0Baz {
|
||||
|
@ -1579,7 +1579,7 @@ impl Baz {
|
|||
#[test]
|
||||
fn doctest_sort_items_3() {
|
||||
check_doc_test(
|
||||
"sort_items_3",
|
||||
"sort_items",
|
||||
r#####"
|
||||
en$0um Animal {
|
||||
Dog(String, f64),
|
||||
|
@ -1588,7 +1588,6 @@ en$0um Animal {
|
|||
"#####,
|
||||
r#####"
|
||||
enum Animal {
|
||||
// variants sorted
|
||||
Cat { weight: f64, name: String },
|
||||
Dog(String, f64),
|
||||
}
|
||||
|
@ -1599,7 +1598,7 @@ enum Animal {
|
|||
#[test]
|
||||
fn doctest_sort_items_4() {
|
||||
check_doc_test(
|
||||
"sort_items_4",
|
||||
"sort_items",
|
||||
r#####"
|
||||
enum Animal {
|
||||
Dog(String, f64),
|
||||
|
@ -1609,7 +1608,7 @@ enum Animal {
|
|||
r#####"
|
||||
enum Animal {
|
||||
Dog(String, f64),
|
||||
Cat { name: String, weight: f64 }, // Cat fields sorted
|
||||
Cat { name: String, weight: f64 },
|
||||
}
|
||||
"#####,
|
||||
)
|
||||
|
|
|
@ -17,9 +17,10 @@ use super::check_doc_test;
|
|||
.to_string();
|
||||
for assist in assists.iter() {
|
||||
for (idx, section) in assist.sections.iter().enumerate() {
|
||||
let id = if idx == 0 { assist.id.clone() } else { format!("{}_{}", &assist.id, idx)};
|
||||
let test_id =
|
||||
if idx == 0 { assist.id.clone() } else { format!("{}_{}", &assist.id, idx) };
|
||||
let test = format!(
|
||||
r######"
|
||||
r######"
|
||||
#[test]
|
||||
fn doctest_{}() {{
|
||||
check_doc_test(
|
||||
|
@ -29,13 +30,13 @@ r#####"
|
|||
{}"#####)
|
||||
}}
|
||||
"######,
|
||||
&id,
|
||||
&id,
|
||||
&test_id,
|
||||
&assist.id,
|
||||
reveal_hash_comments(§ion.before),
|
||||
reveal_hash_comments(§ion.after)
|
||||
);
|
||||
|
||||
buf.push_str(&test)
|
||||
|
||||
buf.push_str(&test)
|
||||
}
|
||||
}
|
||||
let buf = sourcegen::add_preamble("sourcegen_assists_docs", sourcegen::reformat(buf));
|
||||
|
@ -58,7 +59,8 @@ r#####"
|
|||
fs::write(dst, contents).unwrap();
|
||||
}
|
||||
}
|
||||
#[derive(Debug)]struct Section {
|
||||
#[derive(Debug)]
|
||||
struct Section {
|
||||
doc: String,
|
||||
before: String,
|
||||
after: String,
|
||||
|
@ -68,7 +70,7 @@ r#####"
|
|||
struct Assist {
|
||||
id: String,
|
||||
location: sourcegen::Location,
|
||||
sections: Vec<Section>
|
||||
sections: Vec<Section>,
|
||||
}
|
||||
|
||||
impl Assist {
|
||||
|
@ -106,14 +108,14 @@ impl Assist {
|
|||
"\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n",
|
||||
&assist.id, doc,
|
||||
);
|
||||
|
||||
|
||||
let before = take_until(lines.by_ref(), "```");
|
||||
|
||||
|
||||
assert_eq!(lines.next().unwrap().as_str(), "->");
|
||||
assert_eq!(lines.next().unwrap().as_str(), "```");
|
||||
let after = take_until(lines.by_ref(), "```");
|
||||
|
||||
assist.sections.push(Section{doc, before, after});
|
||||
assist.sections.push(Section { doc, before, after });
|
||||
}
|
||||
|
||||
acc.push(assist)
|
||||
|
@ -139,16 +141,15 @@ impl fmt::Display for Assist {
|
|||
f,
|
||||
"[discrete]\n=== `{}`
|
||||
**Source:** {}",
|
||||
self.id,
|
||||
self.location,
|
||||
);
|
||||
self.id, self.location,
|
||||
);
|
||||
|
||||
for section in &self.sections {
|
||||
let before = section.before.replace("$0", "┃"); // Unicode pseudo-graphics bar
|
||||
let after = section.after.replace("$0", "┃");
|
||||
let _= writeln!(
|
||||
let _ = writeln!(
|
||||
f,
|
||||
"
|
||||
"
|
||||
{}
|
||||
|
||||
.Before
|
||||
|
@ -161,7 +162,7 @@ impl fmt::Display for Assist {
|
|||
section.doc,
|
||||
hide_hash_comments(&before),
|
||||
hide_hash_comments(&after)
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue