diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-06-09 04:43:57 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-06-30 09:02:46 +0100 |
commit | 2023af53f09ed9466c6d7442d6830276eba19b45 (patch) | |
tree | 84924a0e47a70b0255b1811f127147e9a9d92682 /crates/ra_syntax/src/ast/traits.rs | |
parent | 2bd717139918e15e537dcd833bb003e85d24b3d1 (diff) |
Hover doc link rewriting
Diffstat (limited to 'crates/ra_syntax/src/ast/traits.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/traits.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index a8f2454fd..323d78bbc 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs | |||
@@ -146,3 +146,39 @@ impl Iterator for CommentIter { | |||
146 | self.iter.by_ref().find_map(|el| el.into_token().and_then(ast::Comment::cast)) | 146 | self.iter.by_ref().find_map(|el| el.into_token().and_then(ast::Comment::cast)) |
147 | } | 147 | } |
148 | } | 148 | } |
149 | |||
150 | #[cfg(test)] | ||
151 | mod tests { | ||
152 | use comrak::{parse_document,format_commonmark, ComrakOptions, Arena}; | ||
153 | use comrak::nodes::{AstNode, NodeValue}; | ||
154 | |||
155 | fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F) | ||
156 | where F : Fn(&'a AstNode<'a>) { | ||
157 | f(node); | ||
158 | for c in node.children() { | ||
159 | iter_nodes(c, f); | ||
160 | } | ||
161 | } | ||
162 | |||
163 | #[allow(non_snake_case)] | ||
164 | #[test] | ||
165 | fn test_link_rewrite() { | ||
166 | let src = include_str!("./test.txt"); | ||
167 | |||
168 | let arena = Arena::new(); | ||
169 | let doc = parse_document(&arena, src, &ComrakOptions::default()); | ||
170 | |||
171 | iter_nodes(doc, &|node| { | ||
172 | match &mut node.data.borrow_mut().value { | ||
173 | &mut NodeValue::Link(ref mut link) => { | ||
174 | link.url = "https://www.google.com".as_bytes().to_vec(); | ||
175 | }, | ||
176 | _ => () | ||
177 | } | ||
178 | }); | ||
179 | |||
180 | let mut out = Vec::new(); | ||
181 | format_commonmark(doc, &ComrakOptions::default(), &mut out); | ||
182 | panic!("{}", String::from_utf8(out).unwrap()); | ||
183 | } | ||
184 | } | ||