From 8b710e95353d9f840f78645c9593a66adb0636b6 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Wed, 26 Sep 2018 10:01:42 +0800 Subject: generate testsuite for impl_type --- crates/ra_syntax/src/grammar/items/traits.rs | 10 +-- .../tests/data/parser/err/0026_imp_recovery.rs | 3 +- .../tests/data/parser/err/0026_imp_recovery.txt | 11 ++- .../tests/data/parser/inline/0111_impl_type.rs | 4 ++ .../tests/data/parser/inline/0111_impl_type.txt | 79 ++++++++++++++++++++++ 5 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 crates/ra_syntax/tests/data/parser/inline/0111_impl_type.rs create mode 100644 crates/ra_syntax/tests/data/parser/inline/0111_impl_type.txt (limited to 'crates') diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs index 62ab877fc..5dfdb470c 100644 --- a/crates/ra_syntax/src/grammar/items/traits.rs +++ b/crates/ra_syntax/src/grammar/items/traits.rs @@ -57,7 +57,7 @@ pub(super) fn impl_item(p: &mut Parser) { p.eat(EXCL); impl_type(p); if p.eat(FOR_KW) { - types::type_(p); + impl_type(p); } type_params::opt_where_clause(p); if p.at(L_CURLY) { @@ -116,10 +116,11 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) } +// test impl_type // impl Type {} -// ^^^^ -// impl Trait for T {} -// ^^^^^ +// impl Trait1 for T {} +// impl impl NotType {} +// impl Trait2 for impl NotType {} pub(crate) fn impl_type(p: &mut Parser) { if p.at(IMPL_KW) { p.error("expected trait or type"); @@ -128,4 +129,3 @@ pub(crate) fn impl_type(p: &mut Parser) { types::type_(p); } - diff --git a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs index eac922109..829ca1c4b 100644 --- a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs +++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs @@ -1,3 +1,2 @@ impl -impl OnceCell { -} +impl OnceCell {} diff --git a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt index 60337d6de..9e26f58a0 100644 --- a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt +++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt @@ -1,4 +1,4 @@ -ROOT@[0; 39) +ROOT@[0; 38) IMPL_ITEM@[0; 14) IMPL_KW@[0; 4) TYPE_PARAM_LIST@[4; 14) @@ -17,7 +17,7 @@ ROOT@[0; 39) err: `expected trait or type` err: `expected `{`` WHITESPACE@[14; 15) - IMPL_ITEM@[15; 38) + IMPL_ITEM@[15; 37) IMPL_KW@[15; 19) TYPE_PARAM_LIST@[19; 22) L_ANGLE@[19; 20) @@ -41,8 +41,7 @@ ROOT@[0; 39) IDENT@[32; 33) "T" R_ANGLE@[33; 34) WHITESPACE@[34; 35) - ITEM_LIST@[35; 38) + ITEM_LIST@[35; 37) L_CURLY@[35; 36) - WHITESPACE@[36; 37) - R_CURLY@[37; 38) - WHITESPACE@[38; 39) + R_CURLY@[36; 37) + WHITESPACE@[37; 38) diff --git a/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.rs b/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.rs new file mode 100644 index 000000000..b8c7b65e3 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.rs @@ -0,0 +1,4 @@ +impl Type {} +impl Trait1 for T {} +impl impl NotType {} +impl Trait2 for impl NotType {} diff --git a/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.txt b/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.txt new file mode 100644 index 000000000..a2907b060 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/0111_impl_type.txt @@ -0,0 +1,79 @@ +ROOT@[0; 87) + IMPL_ITEM@[0; 12) + IMPL_KW@[0; 4) + WHITESPACE@[4; 5) + PATH_TYPE@[5; 9) + PATH@[5; 9) + PATH_SEGMENT@[5; 9) + NAME_REF@[5; 9) + IDENT@[5; 9) "Type" + WHITESPACE@[9; 10) + ITEM_LIST@[10; 12) + L_CURLY@[10; 11) + R_CURLY@[11; 12) + WHITESPACE@[12; 13) + IMPL_ITEM@[13; 33) + IMPL_KW@[13; 17) + WHITESPACE@[17; 18) + PATH_TYPE@[18; 24) + PATH@[18; 24) + PATH_SEGMENT@[18; 24) + NAME_REF@[18; 24) + IDENT@[18; 24) "Trait1" + WHITESPACE@[24; 25) + FOR_KW@[25; 28) + WHITESPACE@[28; 29) + PATH_TYPE@[29; 30) + PATH@[29; 30) + PATH_SEGMENT@[29; 30) + NAME_REF@[29; 30) + IDENT@[29; 30) "T" + WHITESPACE@[30; 31) + ITEM_LIST@[31; 33) + L_CURLY@[31; 32) + R_CURLY@[32; 33) + WHITESPACE@[33; 34) + IMPL_ITEM@[34; 38) + IMPL_KW@[34; 38) + err: `expected trait or type` + err: `expected `{`` + WHITESPACE@[38; 39) + IMPL_ITEM@[39; 54) + IMPL_KW@[39; 43) + WHITESPACE@[43; 44) + PATH_TYPE@[44; 51) + PATH@[44; 51) + PATH_SEGMENT@[44; 51) + NAME_REF@[44; 51) + IDENT@[44; 51) "NotType" + WHITESPACE@[51; 52) + ITEM_LIST@[52; 54) + L_CURLY@[52; 53) + R_CURLY@[53; 54) + WHITESPACE@[54; 55) + IMPL_ITEM@[55; 70) + IMPL_KW@[55; 59) + WHITESPACE@[59; 60) + PATH_TYPE@[60; 66) + PATH@[60; 66) + PATH_SEGMENT@[60; 66) + NAME_REF@[60; 66) + IDENT@[60; 66) "Trait2" + WHITESPACE@[66; 67) + FOR_KW@[67; 70) + err: `expected trait or type` + err: `expected `{`` + WHITESPACE@[70; 71) + IMPL_ITEM@[71; 86) + IMPL_KW@[71; 75) + WHITESPACE@[75; 76) + PATH_TYPE@[76; 83) + PATH@[76; 83) + PATH_SEGMENT@[76; 83) + NAME_REF@[76; 83) + IDENT@[76; 83) "NotType" + WHITESPACE@[83; 84) + ITEM_LIST@[84; 86) + L_CURLY@[84; 85) + R_CURLY@[85; 86) + WHITESPACE@[86; 87) -- cgit v1.2.3