From e71b239d377135bf940c574865f409e40200333c Mon Sep 17 00:00:00 2001 From: vsrs Date: Sat, 31 Jul 2021 10:18:38 +0300 Subject: [PATCH] fix generated tests --- crates/ide_assists/src/handlers/sort_items.rs | 3 +- crates/ide_assists/src/tests/generated.rs | 11 +++--- crates/ide_assists/src/tests/sourcegen.rs | 35 ++++++++++--------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/crates/ide_assists/src/handlers/sort_items.rs b/crates/ide_assists/src/handlers/sort_items.rs index 75e501d3dd..3a3afa7e07 100644 --- a/crates/ide_assists/src/handlers/sort_items.rs +++ b/crates/ide_assists/src/handlers/sort_items.rs @@ -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<()> { diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs index 7ed89ce88a..1d9d14d941 100644 --- a/crates/ide_assists/src/tests/generated.rs +++ b/crates/ide_assists/src/tests/generated.rs @@ -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 }, } "#####, ) diff --git a/crates/ide_assists/src/tests/sourcegen.rs b/crates/ide_assists/src/tests/sourcegen.rs index 46c71048dd..2af1de66fa 100644 --- a/crates/ide_assists/src/tests/sourcegen.rs +++ b/crates/ide_assists/src/tests/sourcegen.rs @@ -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
+ sections: Vec
, } 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(())