2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(unused_mut)]
|
2018-01-29 22:26:11 +00: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 07:36:11 +00:00
|
|
|
// edition:2018
|
2018-06-16 02:49:00 +00:00
|
|
|
|
2018-01-19 03:17:27 +00:00
|
|
|
macro_rules! foo {
|
2018-01-29 22:26:11 +00:00
|
|
|
($($a:ident)? ; $num:expr) => { {
|
|
|
|
let mut x = 0;
|
|
|
|
|
|
|
|
$(
|
|
|
|
x += $a;
|
|
|
|
)?
|
|
|
|
|
|
|
|
assert_eq!(x, $num);
|
|
|
|
} }
|
2018-01-19 03:17:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2018-01-29 22:26:11 +00:00
|
|
|
let a = 1;
|
|
|
|
|
|
|
|
// accept 0 or 1 repetitions
|
|
|
|
foo!( ; 0);
|
|
|
|
foo!(a ; 1);
|
2018-01-19 03:17:27 +00:00
|
|
|
}
|