aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
authordarksv <[email protected]>2018-09-15 13:35:30 +0100
committerdarksv <[email protected]>2018-09-15 13:35:30 +0100
commit46cee0415c957f3262ad68cbe617b642f29f347e (patch)
treed87e17ab13142a1a2d60b1d8012c3b09cc7f2815 /crates/libsyntax2/src
parent16ad5384f0c0427922b2d2d05025412fc8e4addf (diff)
move reparsing tests
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/lib.rs4
-rw-r--r--crates/libsyntax2/src/reparsing.rs135
2 files changed, 139 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs
index 014cdafee..886195660 100644
--- a/crates/libsyntax2/src/lib.rs
+++ b/crates/libsyntax2/src/lib.rs
@@ -27,6 +27,10 @@ extern crate parking_lot;
27extern crate smol_str; 27extern crate smol_str;
28extern crate text_unit; 28extern crate text_unit;
29 29
30#[cfg(test)]
31#[macro_use]
32extern crate test_utils;
33
30pub mod algo; 34pub mod algo;
31pub mod ast; 35pub mod ast;
32mod lexer; 36mod lexer;
diff --git a/crates/libsyntax2/src/reparsing.rs b/crates/libsyntax2/src/reparsing.rs
index 723ea2b8b..1df2ca094 100644
--- a/crates/libsyntax2/src/reparsing.rs
+++ b/crates/libsyntax2/src/reparsing.rs
@@ -186,3 +186,138 @@ fn merge_errors(
186 } 186 }
187 res 187 res
188} 188}
189
190#[cfg(test)]
191use super::{File, text_utils, test_utils, utils};
192
193#[cfg(test)]
194mod tests {
195 use super::{*, utils::dump_tree};
196
197 #[test]
198 fn reparse_test() {
199 fn do_check(before: &str, replace_with: &str) {
200 let (range, before) = test_utils::extract_range(before);
201 let after = text_utils::replace_range(before.clone(), range, replace_with);
202
203 let fully_reparsed = File::parse(&after);
204 let incrementally_reparsed = {
205 let f = File::parse(&before);
206 let edit = AtomEdit { delete: range, insert: replace_with.to_string() };
207 f.incremental_reparse(&edit).expect("cannot incrementally reparse")
208 };
209 assert_eq_text!(
210 &dump_tree(fully_reparsed.syntax()),
211 &dump_tree(incrementally_reparsed.syntax()),
212 )
213 }
214
215 do_check(r"
216fn foo() {
217 let x = foo + <|>bar<|>
218}
219", "baz");
220 do_check(r"
221fn foo() {
222 let x = foo<|> + bar<|>
223}
224", "baz");
225 do_check(r"
226struct Foo {
227 f: foo<|><|>
228}
229", ",\n g: (),");
230 do_check(r"
231fn foo {
232 let;
233 1 + 1;
234 <|>92<|>;
235}
236", "62");
237 do_check(r"
238mod foo {
239 fn <|><|>
240}
241", "bar");
242 do_check(r"
243trait Foo {
244 type <|>Foo<|>;
245}
246", "Output");
247 do_check(r"
248trait Foo {
249 type<|> Foo<|>;
250}
251", "Output");
252 do_check(r"
253impl IntoIterator<Item=i32> for Foo {
254 f<|><|>
255}
256", "n next(");
257 do_check(r"
258use a::b::{foo,<|>,bar<|>};
259 ", "baz");
260 do_check(r"
261pub enum A {
262 Foo<|><|>
263}
264", "\nBar;\n");
265 do_check(r"
266foo!{a, b<|><|> d}
267", ", c[3]");
268 do_check(r"
269fn foo() {
270 vec![<|><|>]
271}
272", "123");
273 do_check(r"
274extern {
275 fn<|>;<|>
276}
277", " exit(code: c_int)");
278 do_check(r"<|><|>
279fn foo() -> i32 {
280 1
281}
282", "\n\n\n \n");
283 do_check(r"
284fn foo() -> <|><|> {}
285", " \n");
286 do_check(r"
287fn <|>foo<|>() -> i32 {
288 1
289}
290", "bar");
291 do_check(r"
292fn aa<|><|>bb() {
293
294}
295", "foofoo");
296 do_check(r"
297fn aabb /* <|><|> */ () {
298
299}
300", "some comment");
301 do_check(r"
302fn aabb <|><|> () {
303
304}
305", " \t\t\n\n");
306 do_check(r"
307trait foo {
308// comment <|><|>
309}
310", "\n");
311 do_check(r"
312/// good <|><|>omment
313mod {
314}
315", "c");
316 do_check(r#"
317fn -> &str { "Hello<|><|>" }
318"#, ", world");
319 do_check(r#"
320fn -> &str { // "Hello<|><|>"
321"#, ", world");
322 }
323} \ No newline at end of file