From 4356240fa42eebbd17fdb63b2d0e6f86387ca21c Mon Sep 17 00:00:00 2001 From: darksv Date: Thu, 13 Sep 2018 23:25:05 +0200 Subject: Incremental reparsing for single tokens (WHITESPACE, COMMENT, DOC_COMMENT, IDENT, STRING, RAW_STRING) --- crates/libsyntax2/tests/test/main.rs | 56 +++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'crates/libsyntax2/tests/test') diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index 644df9f3c..ce7e075f8 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs @@ -33,7 +33,7 @@ fn reparse_test() { let incrementally_reparsed = { let f = File::parse(&before); let edit = AtomEdit { delete: range, insert: replace_with.to_string() }; - f.incremental_reparse(&edit).unwrap() + f.incremental_reparse(&edit).expect("cannot incrementally reparse") }; assert_eq_text!( &dump_tree(fully_reparsed.syntax()), @@ -45,6 +45,11 @@ fn reparse_test() { fn foo() { let x = foo + <|>bar<|> } +", "baz"); + do_check(r" +fn foo() { + let x = foo<|> + bar<|> +} ", "baz"); do_check(r" struct Foo { @@ -67,6 +72,11 @@ mod foo { trait Foo { type <|>Foo<|>; } +", "Output"); + do_check(r" +trait Foo { + type<|> Foo<|>; +} ", "Output"); do_check(r" impl IntoIterator for Foo { @@ -94,6 +104,50 @@ extern { fn<|>;<|> } ", " exit(code: c_int)"); +do_check(r"<|><|> +fn foo() -> i32 { + 1 +} +", "\n\n\n \n"); + do_check(r" +fn foo() -> <|><|> {} +", " \n"); + do_check(r" +fn <|>foo<|>() -> i32 { + 1 +} +", "bar"); +do_check(r" +fn aa<|><|>bb() { + +} +", "foofoo"); + do_check(r" +fn aabb /* <|><|> */ () { + +} +", "some comment"); + do_check(r" +fn aabb <|><|> () { + +} +", " \t\t\n\n"); + do_check(r" +trait foo { +// comment <|><|> +} +", "\n"); + do_check(r" +/// good <|><|>omment +mod { +} +", "c"); + do_check(r#" +fn -> &str { "Hello<|><|>" } +"#, ", world"); + do_check(r#" +fn -> &str { // "Hello<|><|>" +"#, ", world"); } #[test] -- cgit v1.2.3 From 16ad5384f0c0427922b2d2d05025412fc8e4addf Mon Sep 17 00:00:00 2001 From: darksv Date: Sat, 15 Sep 2018 13:42:10 +0200 Subject: commit missing file --- crates/libsyntax2/tests/test/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/libsyntax2/tests/test') diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index ce7e075f8..2b68673c6 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs @@ -27,7 +27,7 @@ fn lexer_tests() { fn reparse_test() { fn do_check(before: &str, replace_with: &str) { let (range, before) = extract_range(before); - let after = libsyntax2::replace_range(before.clone(), range, replace_with); + let after = libsyntax2::text_utils::replace_range(before.clone(), range, replace_with); let fully_reparsed = File::parse(&after); let incrementally_reparsed = { -- cgit v1.2.3 From 46cee0415c957f3262ad68cbe617b642f29f347e Mon Sep 17 00:00:00 2001 From: darksv Date: Sat, 15 Sep 2018 14:35:30 +0200 Subject: move reparsing tests --- crates/libsyntax2/tests/test/main.rs | 130 +---------------------------------- 1 file changed, 1 insertion(+), 129 deletions(-) (limited to 'crates/libsyntax2/tests/test') 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::{ fmt::Write, }; -use test_utils::extract_range; use libsyntax2::{ - File, AtomEdit, + File, utils::{dump_tree, check_fuzz_invariants}, }; @@ -23,133 +22,6 @@ fn lexer_tests() { }) } -#[test] -fn reparse_test() { - fn do_check(before: &str, replace_with: &str) { - let (range, before) = extract_range(before); - let after = libsyntax2::text_utils::replace_range(before.clone(), range, replace_with); - - let fully_reparsed = File::parse(&after); - let incrementally_reparsed = { - let f = File::parse(&before); - let edit = AtomEdit { delete: range, insert: replace_with.to_string() }; - f.incremental_reparse(&edit).expect("cannot incrementally reparse") - }; - assert_eq_text!( - &dump_tree(fully_reparsed.syntax()), - &dump_tree(incrementally_reparsed.syntax()), - ) - } - - do_check(r" -fn foo() { - let x = foo + <|>bar<|> -} -", "baz"); - do_check(r" -fn foo() { - let x = foo<|> + bar<|> -} -", "baz"); - do_check(r" -struct Foo { - f: foo<|><|> -} -", ",\n g: (),"); - do_check(r" -fn foo { - let; - 1 + 1; - <|>92<|>; -} -", "62"); - do_check(r" -mod foo { - fn <|><|> -} -", "bar"); - do_check(r" -trait Foo { - type <|>Foo<|>; -} -", "Output"); - do_check(r" -trait Foo { - type<|> Foo<|>; -} -", "Output"); - do_check(r" -impl IntoIterator for Foo { - f<|><|> -} -", "n next("); - do_check(r" -use a::b::{foo,<|>,bar<|>}; - ", "baz"); - do_check(r" -pub enum A { - Foo<|><|> -} -", "\nBar;\n"); - do_check(r" -foo!{a, b<|><|> d} -", ", c[3]"); - do_check(r" -fn foo() { - vec![<|><|>] -} -", "123"); - do_check(r" -extern { - fn<|>;<|> -} -", " exit(code: c_int)"); -do_check(r"<|><|> -fn foo() -> i32 { - 1 -} -", "\n\n\n \n"); - do_check(r" -fn foo() -> <|><|> {} -", " \n"); - do_check(r" -fn <|>foo<|>() -> i32 { - 1 -} -", "bar"); -do_check(r" -fn aa<|><|>bb() { - -} -", "foofoo"); - do_check(r" -fn aabb /* <|><|> */ () { - -} -", "some comment"); - do_check(r" -fn aabb <|><|> () { - -} -", " \t\t\n\n"); - do_check(r" -trait foo { -// comment <|><|> -} -", "\n"); - do_check(r" -/// good <|><|>omment -mod { -} -", "c"); - do_check(r#" -fn -> &str { "Hello<|><|>" } -"#, ", world"); - do_check(r#" -fn -> &str { // "Hello<|><|>" -"#, ", world"); -} - #[test] fn parser_tests() { dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { -- cgit v1.2.3