aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/test.txt15
-rw-r--r--crates/ra_syntax/src/ast/traits.rs36
2 files changed, 51 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/test.txt b/crates/ra_syntax/src/ast/test.txt
new file mode 100644
index 000000000..f746bf1e7
--- /dev/null
+++ b/crates/ra_syntax/src/ast/test.txt
@@ -0,0 +1,15 @@
1The context is a general utility struct provided on event dispatches, which
2helps with dealing with the current "context" of the event dispatch.
3The context also acts as a general high-level interface over the associated
4[`Shard`] which received the event, or the low-level [`http`] module.
5
6The context contains "shortcuts", like for interacting with the shard.
7Methods like [`set_activity`] will unlock the shard and perform an update for
8you to save a bit of work.
9
10A context will only live for the event it was dispatched for. After the
11event handler finished, it is destroyed and will not be re-used.
12
13[`Shard`]: ../gateway/struct.Shard.html
14[`http`]: ../http/index.html
15[`set_activity`]: #method.set_activity
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)]
151mod 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}