about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-01 16:03:24 +0000
committerGitHub <noreply@github.com>2022-01-01 16:03:24 +0000
commitb8a632121b051f65061fc78ba6bbd3ad006a9e69 (patch)
treebdd51a66ed9ff21fdd2c5e42e952a738642b2b38
parent3d63abf1d868218613f33dc59968d3671f7f14a8 (diff)
parent7c4276b3e15a04c9f20d0ad56555a89ac8da2c74 (diff)
downloadrust-b8a632121b051f65061fc78ba6bbd3ad006a9e69.tar.gz
rust-b8a632121b051f65061fc78ba6bbd3ad006a9e69.zip
Merge #11152
11152: internal: add more tests for entry points r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
-rw-r--r--crates/hir_def/src/macro_expansion_tests/mbe/matching.rs19
-rw-r--r--crates/parser/src/tests/entries.rs36
2 files changed, 55 insertions, 0 deletions
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 b93072d4466..517dfb15b6a 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 947922d8b32..1174e33f5f8 100644
--- a/crates/parser/src/tests/entries.rs
+++ b/crates/parser/src/tests/entries.rs
@@ -21,12 +21,48 @@ fn stmt() {
     check_prefix(PrefixEntryPoint::Stmt, "92; fn", "92");
     check_prefix(PrefixEntryPoint::Stmt, "let _ = 92; 1", "let _ = 92");
     check_prefix(PrefixEntryPoint::Stmt, "pub fn f() {} = 92", "pub fn f() {}");
+    check_prefix(PrefixEntryPoint::Stmt, "struct S;;", "struct S;");
+    check_prefix(PrefixEntryPoint::Stmt, "fn f() {};", "fn f() {}");
     check_prefix(PrefixEntryPoint::Stmt, ";;;", ";");
     check_prefix(PrefixEntryPoint::Stmt, "+", "+");
     check_prefix(PrefixEntryPoint::Stmt, "@", "@");
     check_prefix(PrefixEntryPoint::Stmt, "loop {} - 1", "loop {}");
 }
 
+#[test]
+fn pat() {
+    check_prefix(PrefixEntryPoint::Pat, "x y", "x");
+    check_prefix(PrefixEntryPoint::Pat, "fn f() {}", "fn");
+    // FIXME: This one is wrong, we should consume only one pattern.
+    check_prefix(PrefixEntryPoint::Pat, ".. ..", ".. ..");
+}
+
+#[test]
+fn ty() {
+    check_prefix(PrefixEntryPoint::Ty, "fn() foo", "fn()");
+    check_prefix(PrefixEntryPoint::Ty, "Clone + Copy + fn", "Clone + Copy +");
+    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] ()");
+}
+
+#[test]
+fn path() {
+    check_prefix(PrefixEntryPoint::Path, "foo::bar baz", "foo::bar");
+    check_prefix(PrefixEntryPoint::Path, "foo::<> baz", "foo::<>");
+    check_prefix(PrefixEntryPoint::Path, "foo<> baz", "foo<>");
+    check_prefix(PrefixEntryPoint::Path, "Fn() -> i32?", "Fn() -> i32");
+    // FIXME: this shouldn't be accepted as path actually.
+    check_prefix(PrefixEntryPoint::Path, "<_>::foo", "<_>::foo");
+}
+
 fn check_prefix(entry: PrefixEntryPoint, input: &str, prefix: &str) {
     let lexed = LexedStr::new(input);
     let input = lexed.to_input();