Skip to content

Commit b8a6321

Browse files
bors[bot]matklad
andauthored
Merge #11152
11152: internal: add more tests for entry points r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 3d63abf + 7c4276b commit b8a6321

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

crates/hir_def/src/macro_expansion_tests/mbe/matching.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,22 @@ stringify!(;
103103
"#]],
104104
);
105105
}
106+
107+
#[test]
108+
fn range_patterns() {
109+
// FIXME: rustc thinks there are three patterns here, not one.
110+
check(
111+
r#"
112+
macro_rules! m {
113+
($($p:pat)*) => (stringify!($($p |)*);)
114+
}
115+
m!(.. .. ..);
116+
"#,
117+
expect![[r#"
118+
macro_rules! m {
119+
($($p:pat)*) => (stringify!($($p |)*);)
120+
}
121+
stringify!(.. .. ..|);
122+
"#]],
123+
);
124+
}

crates/parser/src/tests/entries.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,48 @@ fn stmt() {
2121
check_prefix(PrefixEntryPoint::Stmt, "92; fn", "92");
2222
check_prefix(PrefixEntryPoint::Stmt, "let _ = 92; 1", "let _ = 92");
2323
check_prefix(PrefixEntryPoint::Stmt, "pub fn f() {} = 92", "pub fn f() {}");
24+
check_prefix(PrefixEntryPoint::Stmt, "struct S;;", "struct S;");
25+
check_prefix(PrefixEntryPoint::Stmt, "fn f() {};", "fn f() {}");
2426
check_prefix(PrefixEntryPoint::Stmt, ";;;", ";");
2527
check_prefix(PrefixEntryPoint::Stmt, "+", "+");
2628
check_prefix(PrefixEntryPoint::Stmt, "@", "@");
2729
check_prefix(PrefixEntryPoint::Stmt, "loop {} - 1", "loop {}");
2830
}
2931

32+
#[test]
33+
fn pat() {
34+
check_prefix(PrefixEntryPoint::Pat, "x y", "x");
35+
check_prefix(PrefixEntryPoint::Pat, "fn f() {}", "fn");
36+
// FIXME: This one is wrong, we should consume only one pattern.
37+
check_prefix(PrefixEntryPoint::Pat, ".. ..", ".. ..");
38+
}
39+
40+
#[test]
41+
fn ty() {
42+
check_prefix(PrefixEntryPoint::Ty, "fn() foo", "fn()");
43+
check_prefix(PrefixEntryPoint::Ty, "Clone + Copy + fn", "Clone + Copy +");
44+
check_prefix(PrefixEntryPoint::Ty, "struct f", "struct");
45+
}
46+
47+
#[test]
48+
fn expr() {
49+
check_prefix(PrefixEntryPoint::Expr, "92 92", "92");
50+
check_prefix(PrefixEntryPoint::Expr, "+1", "+");
51+
check_prefix(PrefixEntryPoint::Expr, "-1", "-1");
52+
check_prefix(PrefixEntryPoint::Expr, "fn foo() {}", "fn");
53+
check_prefix(PrefixEntryPoint::Expr, "#[attr] ()", "#[attr] ()");
54+
}
55+
56+
#[test]
57+
fn path() {
58+
check_prefix(PrefixEntryPoint::Path, "foo::bar baz", "foo::bar");
59+
check_prefix(PrefixEntryPoint::Path, "foo::<> baz", "foo::<>");
60+
check_prefix(PrefixEntryPoint::Path, "foo<> baz", "foo<>");
61+
check_prefix(PrefixEntryPoint::Path, "Fn() -> i32?", "Fn() -> i32");
62+
// FIXME: this shouldn't be accepted as path actually.
63+
check_prefix(PrefixEntryPoint::Path, "<_>::foo", "<_>::foo");
64+
}
65+
3066
fn check_prefix(entry: PrefixEntryPoint, input: &str, prefix: &str) {
3167
let lexed = LexedStr::new(input);
3268
let input = lexed.to_input();

0 commit comments

Comments
 (0)