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