From 592c76cc29b76c61600c9934dcc8ec2e2a205db1 Mon Sep 17 00:00:00 2001 From: Colin Benner Date: Fri, 28 Sep 2018 00:16:04 +0200 Subject: [PATCH] Test Expr::fmt --- src/ast.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index b23b0d2..ec2a837 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -312,3 +312,26 @@ impl fmt::Display for DateToken { } } } + +#[cfg(test)] +mod test { + use super::Expr::{self, *}; + + fn check(e: T, expected: &str) { + assert_eq!(format!("{}", e), expected); + } + + impl From 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)"); + } +}