]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/macros/macro-at-most-once-rep-2015.rs
Update tests since ? macro op is supported on 2015.
[rust.git] / src / test / run-pass / macros / macro-at-most-once-rep-2015.rs
1 // run-pass
2 #![allow(unused_mut)]
3 // The logic for parsing Kleene operators in macros has a special case to disambiguate `?`.
4 // Specifically, `$(pat)?` is the ZeroOrOne operator whereas `$(pat)?+` or `$(pat)?*` are the
5 // ZeroOrMore and OneOrMore operators using `?` as a separator. These tests are intended to
6 // exercise that logic in the macro parser.
7 //
8 // Moreover, we also throw in some tests for using a separator with `?`, which is meaningless but
9 // included for consistency with `+` and `*`.
10 //
11 // This test focuses on non-error cases and making sure the correct number of repetitions happen.
12
13 // edition:2015
14
15 macro_rules! foo {
16     ($($a:ident)? ; $num:expr) => { {
17         let mut x = 0;
18
19         $(
20             x += $a;
21          )?
22
23         assert_eq!(x, $num);
24     } }
25 }
26
27 pub fn main() {
28     let a = 1;
29
30     // accept 0 or 1 repetitions
31     foo!( ; 0);
32     foo!(a ; 1);
33 }