aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/tests
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-25 12:45:17 +0100
committerAleksey Kladov <[email protected]>2018-08-25 12:45:17 +0100
commitc3e5987c433cdd0ea95a6b1057b442f4f0fe1ffc (patch)
tree1ef2814a3ddc800ef6976aa0459c6b5cf0c3b621 /crates/libsyntax2/tests
parent5211e7d97771aa7f8d7cc99e5131fb3cc71a1627 (diff)
incremental reparse
Diffstat (limited to 'crates/libsyntax2/tests')
-rw-r--r--crates/libsyntax2/tests/test/main.rs38
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
12use libsyntax2::File; 12use test_utils::extract_range;
13use libsyntax2::{
14 File, AtomEdit,
15 utils::dump_tree,
16};
13 17
14#[test] 18#[test]
15fn lexer_tests() { 19fn lexer_tests() {
@@ -23,10 +27,40 @@ fn lexer_tests() {
23fn parser_tests() { 27fn 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]
35fn 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"
53fn foo() {
54 let x = foo + <|>bar<|>
55}
56", "baz");
57 do_check(r"
58struct 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///