Fix incorrect messages in serialized tokens assertions
Serializer contains expected tokens, called methods provide actual tokens
This commit is contained in:
parent
8084258a3e
commit
920a77ad61
@ -32,18 +32,18 @@ impl<'a> Serializer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_next_token {
|
macro_rules! assert_next_token {
|
||||||
($ser:expr, $expected:ident) => {
|
($ser:expr, $actual:ident) => {
|
||||||
assert_next_token!($ser, stringify!($expected), Token::$expected, true);
|
assert_next_token!($ser, stringify!($actual), Token::$actual, true);
|
||||||
};
|
};
|
||||||
($ser:expr, $expected:ident($v:expr)) => {
|
($ser:expr, $actual:ident($v:expr)) => {
|
||||||
assert_next_token!(
|
assert_next_token!(
|
||||||
$ser,
|
$ser,
|
||||||
format_args!(concat!(stringify!($expected), "({:?})"), $v),
|
format_args!(concat!(stringify!($actual), "({:?})"), $v),
|
||||||
Token::$expected(v),
|
Token::$actual(v),
|
||||||
v == $v
|
v == $v
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
($ser:expr, $expected:ident { $($k:ident),* }) => {
|
($ser:expr, $actual:ident { $($k:ident),* }) => {
|
||||||
let compare = ($($k,)*);
|
let compare = ($($k,)*);
|
||||||
let field_format = || {
|
let field_format = || {
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
@ -55,21 +55,21 @@ macro_rules! assert_next_token {
|
|||||||
};
|
};
|
||||||
assert_next_token!(
|
assert_next_token!(
|
||||||
$ser,
|
$ser,
|
||||||
format_args!(concat!(stringify!($expected), " {{ {}}}"), field_format()),
|
format_args!(concat!(stringify!($actual), " {{ {}}}"), field_format()),
|
||||||
Token::$expected { $($k),* },
|
Token::$actual { $($k),* },
|
||||||
($($k,)*) == compare
|
($($k,)*) == compare
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
($ser:expr, $expected:expr, $pat:pat, $guard:expr) => {
|
($ser:expr, $actual:expr, $pat:pat, $guard:expr) => {
|
||||||
match $ser.next_token() {
|
match $ser.next_token() {
|
||||||
Some($pat) if $guard => {}
|
Some($pat) if $guard => {}
|
||||||
Some(other) => {
|
Some(expected) => {
|
||||||
panic!("expected Token::{} but serialized as {}",
|
panic!("expected Token::{} but serialized as {}",
|
||||||
$expected, other);
|
expected, $actual);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
panic!("expected Token::{} after end of serialized tokens",
|
panic!("expected end of tokens, but {} was serialized",
|
||||||
$expected);
|
$actual);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user