aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/tests
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-09-15 21:57:06 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-09-15 21:57:06 +0100
commit2a56b5c4f096736d6795eecb835cc2dc14b00107 (patch)
treea57d09a900dcd0aec2357c7368bbc2dfe6a1b423 /crates/libsyntax2/tests
parent6ee4c287f9c95738f0482bf635ccc3801fc2fea2 (diff)
parentab00639032981f8b959e06c4015dd72201df651d (diff)
Merge #69
69: Incremental reparsing for single tokens r=matklad a=darksv Implement incremental reparsing for `WHITESPACE`, `COMMENT`, `DOC_COMMENT`, `IDENT`, `STRING` and `RAW_STRING`. This allows to avoid reparsing whole blocks when a change was made only within these tokens. Co-authored-by: darksv <[email protected]>
Diffstat (limited to 'crates/libsyntax2/tests')
-rw-r--r--crates/libsyntax2/tests/test/main.rs76
1 files changed, 1 insertions, 75 deletions
diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs
index 644df9f3c..5a8879fce 100644
--- a/crates/libsyntax2/tests/test/main.rs
+++ b/crates/libsyntax2/tests/test/main.rs
@@ -9,9 +9,8 @@ use std::{
9 fmt::Write, 9 fmt::Write,
10}; 10};
11 11
12use test_utils::extract_range;
13use libsyntax2::{ 12use libsyntax2::{
14 File, AtomEdit, 13 File,
15 utils::{dump_tree, check_fuzz_invariants}, 14 utils::{dump_tree, check_fuzz_invariants},
16}; 15};
17 16
@@ -24,79 +23,6 @@ fn lexer_tests() {
24} 23}
25 24
26#[test] 25#[test]
27fn reparse_test() {
28 fn do_check(before: &str, replace_with: &str) {
29 let (range, before) = extract_range(before);
30 let after = libsyntax2::replace_range(before.clone(), range, replace_with);
31
32 let fully_reparsed = File::parse(&after);
33 let incrementally_reparsed = {
34 let f = File::parse(&before);
35 let edit = AtomEdit { delete: range, insert: replace_with.to_string() };
36 f.incremental_reparse(&edit).unwrap()
37 };
38 assert_eq_text!(
39 &dump_tree(fully_reparsed.syntax()),
40 &dump_tree(incrementally_reparsed.syntax()),
41 )
42 }
43
44 do_check(r"
45fn foo() {
46 let x = foo + <|>bar<|>
47}
48", "baz");
49 do_check(r"
50struct Foo {
51 f: foo<|><|>
52}
53", ",\n g: (),");
54 do_check(r"
55fn foo {
56 let;
57 1 + 1;
58 <|>92<|>;
59}
60", "62");
61 do_check(r"
62mod foo {
63 fn <|><|>
64}
65", "bar");
66 do_check(r"
67trait Foo {
68 type <|>Foo<|>;
69}
70", "Output");
71 do_check(r"
72impl IntoIterator<Item=i32> for Foo {
73 f<|><|>
74}
75", "n next(");
76 do_check(r"
77use a::b::{foo,<|>,bar<|>};
78 ", "baz");
79 do_check(r"
80pub enum A {
81 Foo<|><|>
82}
83", "\nBar;\n");
84 do_check(r"
85foo!{a, b<|><|> d}
86", ", c[3]");
87 do_check(r"
88fn foo() {
89 vec![<|><|>]
90}
91", "123");
92 do_check(r"
93extern {
94 fn<|>;<|>
95}
96", " exit(code: c_int)");
97}
98
99#[test]
100fn parser_tests() { 26fn parser_tests() {
101 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { 27 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
102 let file = File::parse(text); 28 let file = File::parse(text);