Test Expr::fmt

This commit is contained in:
Colin Benner 2018-09-28 00:16:04 +02:00
parent eb48aecf84
commit 592c76cc29

View file

@ -312,3 +312,26 @@ impl fmt::Display for DateToken {
}
}
}
#[cfg(test)]
mod test {
use super::Expr::{self, *};
fn check<T: ::std::fmt::Display>(e: T, expected: &str) {
assert_eq!(format!("{}", e), expected);
}
impl From<i64> for Expr {
fn from(x: i64) -> Self {
Const(x.into())
}
}
#[test]
fn test_display_call() {
check(Call("f".into(), vec![]), "f()");
check(Call("f".into(), vec![1.into()]), "f(1)");
check(Call("f".into(), vec![1.into(), 2.into()]), "f(1, 2)");
check(Call("f".into(), vec![1.into(), 2.into(), 3.into()]), "f(1, 2, 3)");
}
}