From 287e748aa914c55ac9704209559386e4f4a0676d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Dec 2021 15:09:37 +0300 Subject: [PATCH] add expr tests --- .../src/macro_expansion_tests/mbe/matching.rs | 19 +++++++++++++++++++ crates/parser/src/tests/entries.rs | 11 ++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs index b93072d446..517dfb15b6 100644 --- a/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs +++ b/crates/hir_def/src/macro_expansion_tests/mbe/matching.rs @@ -103,3 +103,22 @@ stringify!(; "#]], ); } + +#[test] +fn range_patterns() { + // FIXME: rustc thinks there are three patterns here, not one. + check( + r#" +macro_rules! m { + ($($p:pat)*) => (stringify!($($p |)*);) +} +m!(.. .. ..); +"#, + expect![[r#" +macro_rules! m { + ($($p:pat)*) => (stringify!($($p |)*);) +} +stringify!(.. .. ..|); +"#]], + ); +} diff --git a/crates/parser/src/tests/entries.rs b/crates/parser/src/tests/entries.rs index a8abe6daf5..7595c251be 100644 --- a/crates/parser/src/tests/entries.rs +++ b/crates/parser/src/tests/entries.rs @@ -33,7 +33,7 @@ fn stmt() { fn pat() { check_prefix(PrefixEntryPoint::Pat, "x y", "x"); check_prefix(PrefixEntryPoint::Pat, "fn f() {}", "fn"); - // FIXME: this one is wrong + // FIXME: This one is wrong, we should consume only one pattern. check_prefix(PrefixEntryPoint::Pat, ".. ..", ".. .."); } @@ -44,6 +44,15 @@ fn ty() { check_prefix(PrefixEntryPoint::Ty, "struct f", "struct"); } +#[test] +fn expr() { + check_prefix(PrefixEntryPoint::Expr, "92 92", "92"); + check_prefix(PrefixEntryPoint::Expr, "+1", "+"); + check_prefix(PrefixEntryPoint::Expr, "-1", "-1"); + check_prefix(PrefixEntryPoint::Expr, "fn foo() {}", "fn"); + check_prefix(PrefixEntryPoint::Expr, "#[attr] ()", "#[attr] ()"); +} + fn check_prefix(entry: PrefixEntryPoint, input: &str, prefix: &str) { let lexed = LexedStr::new(input); let input = lexed.to_input();