Allow but ignore trailing comma in test macros

This commit is contained in:
David Tolnay 2020-05-27 15:05:59 -07:00
parent f38e6b5c16
commit c594eb00fc
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -2,7 +2,7 @@ macro_rules! json_str {
([]) => { ([]) => {
"[]" "[]"
}; };
([ $e0:tt $(, $e:tt)* ]) => { ([ $e0:tt $(, $e:tt)* $(,)? ]) => {
concat!("[", concat!("[",
json_str!($e0), json_str!($e0),
$(",", json_str!($e),)* $(",", json_str!($e),)*
@ -11,7 +11,7 @@ macro_rules! json_str {
({}) => { ({}) => {
"{}" "{}"
}; };
({ $k0:tt : $v0:tt $(, $k:tt : $v:tt)* }) => { ({ $k0:tt : $v0:tt $(, $k:tt : $v:tt)* $(,)? }) => {
concat!("{", concat!("{",
stringify!($k0), ":", json_str!($v0), stringify!($k0), ":", json_str!($v0),
$(",", stringify!($k), ":", json_str!($v),)* $(",", stringify!($k), ":", json_str!($v),)*
@ -35,7 +35,7 @@ macro_rules! pretty_str_impl {
($indent:expr, []) => { ($indent:expr, []) => {
"[]" "[]"
}; };
($indent:expr, [ $e0:tt $(, $e:tt)* ]) => { ($indent:expr, [ $e0:tt $(, $e:tt)* $(,)? ]) => {
concat!("[\n ", concat!("[\n ",
$indent, pretty_str_impl!(concat!(" ", $indent), $e0), $indent, pretty_str_impl!(concat!(" ", $indent), $e0),
$(",\n ", $indent, pretty_str_impl!(concat!(" ", $indent), $e),)* $(",\n ", $indent, pretty_str_impl!(concat!(" ", $indent), $e),)*
@ -44,7 +44,7 @@ macro_rules! pretty_str_impl {
($indent:expr, {}) => { ($indent:expr, {}) => {
"{}" "{}"
}; };
($indent:expr, { $k0:tt : $v0:tt $(, $k:tt : $v:tt)* }) => { ($indent:expr, { $k0:tt : $v0:tt $(, $k:tt : $v:tt)* $(,)? }) => {
concat!("{\n ", concat!("{\n ",
$indent, stringify!($k0), ": ", pretty_str_impl!(concat!(" ", $indent), $v0), $indent, stringify!($k0), ": ", pretty_str_impl!(concat!(" ", $indent), $v0),
$(",\n ", $indent, stringify!($k), ": ", pretty_str_impl!(concat!(" ", $indent), $v),)* $(",\n ", $indent, stringify!($k), ": ", pretty_str_impl!(concat!(" ", $indent), $v),)*