From 3ed8fe332f348444ee6b6ca306031f22361e2584 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Fri, 24 Aug 2018 19:20:23 -0500 Subject: [PATCH] FEATURE: Support boolean and EMPTY as a format string variable. Also add format string regression tests. --- integration_tests/format_test.ucg | 4 ++++ src/build/compile_test.rs | 5 +++++ src/build/mod.rs | 2 ++ 3 files changed, 11 insertions(+) create mode 100644 integration_tests/format_test.ucg diff --git a/integration_tests/format_test.ucg b/integration_tests/format_test.ucg new file mode 100644 index 0000000..e2d825f --- /dev/null +++ b/integration_tests/format_test.ucg @@ -0,0 +1,4 @@ +assert |"hello @" % ("world") == "hello world"|; +assert |"1 @ @" % (2, 3) == "1 2 3"|; +assert |"@ or @" % (true, false) == "true or false"|; +assert |"@" % (NULL) == "NULL"|; \ No newline at end of file diff --git a/src/build/compile_test.rs b/src/build/compile_test.rs index f893ac1..00495c0 100644 --- a/src/build/compile_test.rs +++ b/src/build/compile_test.rs @@ -73,3 +73,8 @@ fn test_concatenation() { "../../integration_tests/concatenation_test.ucg" )); } + +#[test] +fn test_format() { + assert_build(include_str!("../../integration_tests/format_test.ucg")); +} diff --git a/src/build/mod.rs b/src/build/mod.rs index 0e19110..32152a9 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -276,6 +276,8 @@ impl From for String { Val::Int(ref i) => format!("{}", i), Val::Float(ref f) => format!("{}", f), Val::Str(ref s) => s.to_string(), + Val::Boolean(ref b) => format!("{}", b), + Val::Empty => "NULL".to_string(), val => format!("<{}>", val), } }