]> git.lizzy.rs Git - rust.git/blob - crates/hir_def/src/macro_expansion_tests/mbe/matching.rs
Merge #10491
[rust.git] / crates / hir_def / src / macro_expansion_tests / mbe / matching.rs
1 //! Test that `$var:expr` captures function correctly.
2
3 use expect_test::expect;
4
5 use crate::macro_expansion_tests::check;
6
7 #[test]
8 fn unary_minus_is_a_literal() {
9     check(
10         r#"
11 macro_rules! m { ($x:literal) => (literal!();); ($x:tt) => (not_a_literal!();); }
12 m!(92);
13 m!(-92);
14 m!(-9.2);
15 m!(--92);
16 "#,
17         expect![[r#"
18 macro_rules! m { ($x:literal) => (literal!();); ($x:tt) => (not_a_literal!();); }
19 literal!();
20 literal!();
21 literal!();
22 /* error: leftover tokens */not_a_literal!();
23 "#]],
24     )
25 }
26
27 #[test]
28 fn test_expand_bad_literal() {
29     check(
30         r#"
31 macro_rules! m { ($i:literal) => {}; }
32 m!(&k");
33 "#,
34         expect![[r#"
35 macro_rules! m { ($i:literal) => {}; }
36 /* error: Failed to lower macro args to token tree */"#]],
37     );
38 }
39
40 #[test]
41 fn test_empty_comments() {
42     check(
43         r#"
44 macro_rules! m{ ($fmt:expr) => (); }
45 m!(/**/);
46 "#,
47         expect![[r#"
48 macro_rules! m{ ($fmt:expr) => (); }
49 /* error: expected Expr */
50 "#]],
51     );
52 }