aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/tests/test
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/tests/test')
-rw-r--r--crates/libsyntax2/tests/test/main.rs130
1 files changed, 1 insertions, 129 deletions
diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs
index 2b68673c6..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,133 +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::text_utils::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).expect("cannot incrementally reparse")
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"
50fn foo() {
51 let x = foo<|> + bar<|>
52}
53", "baz");
54 do_check(r"
55struct Foo {
56 f: foo<|><|>
57}
58", ",\n g: (),");
59 do_check(r"
60fn foo {
61 let;
62 1 + 1;
63 <|>92<|>;
64}
65", "62");
66 do_check(r"
67mod foo {
68 fn <|><|>
69}
70", "bar");
71 do_check(r"
72trait Foo {
73 type <|>Foo<|>;
74}
75", "Output");
76 do_check(r"
77trait Foo {
78 type<|> Foo<|>;
79}
80", "Output");
81 do_check(r"
82impl IntoIterator<Item=i32> for Foo {
83 f<|><|>
84}
85", "n next(");
86 do_check(r"
87use a::b::{foo,<|>,bar<|>};
88 ", "baz");
89 do_check(r"
90pub enum A {
91 Foo<|><|>
92}
93", "\nBar;\n");
94 do_check(r"
95foo!{a, b<|><|> d}
96", ", c[3]");
97 do_check(r"
98fn foo() {
99 vec![<|><|>]
100}
101", "123");
102 do_check(r"
103extern {
104 fn<|>;<|>
105}
106", " exit(code: c_int)");
107do_check(r"<|><|>
108fn foo() -> i32 {
109 1
110}
111", "\n\n\n \n");
112 do_check(r"
113fn foo() -> <|><|> {}
114", " \n");
115 do_check(r"
116fn <|>foo<|>() -> i32 {
117 1
118}
119", "bar");
120do_check(r"
121fn aa<|><|>bb() {
122
123}
124", "foofoo");
125 do_check(r"
126fn aabb /* <|><|> */ () {
127
128}
129", "some comment");
130 do_check(r"
131fn aabb <|><|> () {
132
133}
134", " \t\t\n\n");
135 do_check(r"
136trait foo {
137// comment <|><|>
138}
139", "\n");
140 do_check(r"
141/// good <|><|>omment
142mod {
143}
144", "c");
145 do_check(r#"
146fn -> &str { "Hello<|><|>" }
147"#, ", world");
148 do_check(r#"
149fn -> &str { // "Hello<|><|>"
150"#, ", world");
151}
152
153#[test]
154fn parser_tests() { 26fn parser_tests() {
155 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { 27 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
156 let file = File::parse(text); 28 let file = File::parse(text);