aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-06 17:10:25 +0000
committerAleksey Kladov <[email protected]>2020-02-06 17:14:44 +0000
commit755077e3720bd97e1e506bf8fbe0a2534389f282 (patch)
tree11eb0c7c1c829228c546cd94c2e48331941c4891 /xtask/src
parentd1e8b8d134da802eecef5cbcd5486bd542ad75b5 (diff)
Doctest autoimport
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/codegen/gen_assists_docs.rs42
1 files changed, 33 insertions, 9 deletions
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs
index 69f9b4872..697e830df 100644
--- a/xtask/src/codegen/gen_assists_docs.rs
+++ b/xtask/src/codegen/gen_assists_docs.rs
@@ -20,6 +20,28 @@ struct Assist {
20 after: String, 20 after: String,
21} 21}
22 22
23fn hide_hash_comments(text: &str) -> String {
24 text.split('\n') // want final newline
25 .filter(|&it| !(it.starts_with("# ") || it == "#"))
26 .map(|it| format!("{}\n", it))
27 .collect()
28}
29
30fn reveal_hash_comments(text: &str) -> String {
31 text.split('\n') // want final newline
32 .map(|it| {
33 if it.starts_with("# ") {
34 &it[2..]
35 } else if it == "#" {
36 ""
37 } else {
38 it
39 }
40 })
41 .map(|it| format!("{}\n", it))
42 .collect()
43}
44
23fn collect_assists() -> Result<Vec<Assist>> { 45fn collect_assists() -> Result<Vec<Assist>> {
24 let mut res = Vec::new(); 46 let mut res = Vec::new();
25 for entry in fs::read_dir(project_root().join(codegen::ASSISTS_DIR))? { 47 for entry in fs::read_dir(project_root().join(codegen::ASSISTS_DIR))? {
@@ -91,13 +113,14 @@ fn doctest_{}() {{
91 check( 113 check(
92 "{}", 114 "{}",
93r#####" 115r#####"
94{} 116{}"#####, r#####"
95"#####, r#####" 117{}"#####)
96{}
97"#####)
98}} 118}}
99"######, 119"######,
100 assist.id, assist.id, assist.before, assist.after 120 assist.id,
121 assist.id,
122 reveal_hash_comments(&assist.before),
123 reveal_hash_comments(&assist.after)
101 ); 124 );
102 125
103 buf.push_str(&test) 126 buf.push_str(&test)
@@ -123,12 +146,13 @@ fn generate_docs(assists: &[Assist], mode: Mode) -> Result<()> {
123```rust 146```rust
124// BEFORE 147// BEFORE
125{} 148{}
126
127// AFTER 149// AFTER
128{} 150{}```
129```
130", 151",
131 assist.id, assist.doc, before, after 152 assist.id,
153 assist.doc,
154 hide_hash_comments(&before),
155 hide_hash_comments(&after)
132 ); 156 );
133 buf.push_str(&docs); 157 buf.push_str(&docs);
134 } 158 }