diff options
Diffstat (limited to 'crates/libsyntax2/tests/test')
-rw-r--r-- | crates/libsyntax2/tests/test/main.rs | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index cb8a52c98..e7ae4d601 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs | |||
@@ -9,7 +9,11 @@ use std::{ | |||
9 | fmt::Write, | 9 | fmt::Write, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use libsyntax2::File; | 12 | use test_utils::extract_range; |
13 | use libsyntax2::{ | ||
14 | File, AtomEdit, | ||
15 | utils::dump_tree, | ||
16 | }; | ||
13 | 17 | ||
14 | #[test] | 18 | #[test] |
15 | fn lexer_tests() { | 19 | fn lexer_tests() { |
@@ -23,10 +27,40 @@ fn lexer_tests() { | |||
23 | fn parser_tests() { | 27 | fn parser_tests() { |
24 | dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { | 28 | dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { |
25 | let file = File::parse(text); | 29 | let file = File::parse(text); |
26 | libsyntax2::utils::dump_tree(file.syntax()) | 30 | dump_tree(file.syntax()) |
27 | }) | 31 | }) |
28 | } | 32 | } |
29 | 33 | ||
34 | #[test] | ||
35 | fn reparse_test() { | ||
36 | fn do_check(before: &str, replace_with: &str) { | ||
37 | let (range, before) = extract_range(before); | ||
38 | let after = libsyntax2::replace_range(before.clone(), range, replace_with); | ||
39 | |||
40 | let fully_reparsed = File::parse(&after); | ||
41 | let incrementally_reparsed = { | ||
42 | let f = File::parse(&before); | ||
43 | let edit = AtomEdit { delete: range, insert: replace_with.to_string() }; | ||
44 | f.incremental_reparse(&edit).unwrap() | ||
45 | }; | ||
46 | assert_eq_text!( | ||
47 | &dump_tree(fully_reparsed.syntax()), | ||
48 | &dump_tree(incrementally_reparsed.syntax()), | ||
49 | ) | ||
50 | } | ||
51 | |||
52 | do_check(r" | ||
53 | fn foo() { | ||
54 | let x = foo + <|>bar<|> | ||
55 | } | ||
56 | ", "baz"); | ||
57 | do_check(r" | ||
58 | struct Foo { | ||
59 | f: foo<|><|> | ||
60 | } | ||
61 | ", ",\n g: (),"); | ||
62 | } | ||
63 | |||
30 | 64 | ||
31 | /// Read file and normalize newlines. | 65 | /// Read file and normalize newlines. |
32 | /// | 66 | /// |