2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(unused_mut)]
|
2018-01-29 16:26:11 -06:00
|
|
|
// The logic for parsing Kleene operators in macros has a special case to disambiguate `?`.
|
|
|
|
// Specifically, `$(pat)?` is the ZeroOrOne operator whereas `$(pat)?+` or `$(pat)?*` are the
|
|
|
|
// ZeroOrMore and OneOrMore operators using `?` as a separator. These tests are intended to
|
|
|
|
// exercise that logic in the macro parser.
|
|
|
|
//
|
|
|
|
// Moreover, we also throw in some tests for using a separator with `?`, which is meaningless but
|
|
|
|
// included for consistency with `+` and `*`.
|
|
|
|
//
|
|
|
|
// This test focuses on non-error cases and making sure the correct number of repetitions happen.
|
|
|
|
|
2018-08-16 02:36:11 -05:00
|
|
|
// edition:2018
|
2018-06-15 21:49:00 -05:00
|
|
|
|
2018-01-18 21:17:27 -06:00
|
|
|
macro_rules! foo {
|
2018-01-29 16:26:11 -06:00
|
|
|
($($a:ident)? ; $num:expr) => { {
|
|
|
|
let mut x = 0;
|
|
|
|
|
|
|
|
$(
|
|
|
|
x += $a;
|
|
|
|
)?
|
|
|
|
|
|
|
|
assert_eq!(x, $num);
|
|
|
|
} }
|
2018-01-18 21:17:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2018-01-29 16:26:11 -06:00
|
|
|
let a = 1;
|
|
|
|
|
|
|
|
// accept 0 or 1 repetitions
|
|
|
|
foo!( ; 0);
|
|
|
|
foo!(a ; 1);
|
2018-01-18 21:17:27 -06:00
|
|
|
}
|