Unquote empty string is null

This commit is contained in:
ConnorSkees 2020-02-16 18:45:14 -05:00
parent 3962c4410a
commit c68a55327b
2 changed files with 6 additions and 1 deletions

View File

@ -45,7 +45,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
decl!(f "unquote", |args, _| {
max_args!(args, 1);
match arg!(args, 0, "string").eval() {
Value::Ident(i, QuoteKind::None) if i.is_empty() => Ok(Value::Null),
Value::Ident(i, _) if i.is_empty() => Ok(Value::Null),
i @ Value::Ident(..) => Ok(i.unquote()),
v => Err(format!("$string: {} is not a string.", v).into()),
}

View File

@ -93,6 +93,11 @@ test!(
"a {\n color: str-length(cde);\n}\n",
"a {\n color: 3;\n}\n"
);
test!(
unquote_empty_string_is_null,
"a {\n color: unquote('');\n}\n",
""
);
// blocked on refactoring how function-call args are parsed
// right now, whitespace is eaten between idents with no
// regard for quotes