FEATURE: Support boolean and EMPTY as a format string variable.

Also add format string regression tests.
This commit is contained in:
Jeremy Wall 2018-08-24 19:20:23 -05:00
parent aa88f5a196
commit 3ed8fe332f
3 changed files with 11 additions and 0 deletions

View File

@ -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"|;

View File

@ -73,3 +73,8 @@ fn test_concatenation() {
"../../integration_tests/concatenation_test.ucg" "../../integration_tests/concatenation_test.ucg"
)); ));
} }
#[test]
fn test_format() {
assert_build(include_str!("../../integration_tests/format_test.ucg"));
}

View File

@ -276,6 +276,8 @@ impl From<Val> for String {
Val::Int(ref i) => format!("{}", i), Val::Int(ref i) => format!("{}", i),
Val::Float(ref f) => format!("{}", f), Val::Float(ref f) => format!("{}", f),
Val::Str(ref s) => s.to_string(), Val::Str(ref s) => s.to_string(),
Val::Boolean(ref b) => format!("{}", b),
Val::Empty => "NULL".to_string(),
val => format!("<{}>", val), val => format!("<{}>", val),
} }
} }