inspect([]) => []

This commit is contained in:
ConnorSkees 2020-04-03 16:53:45 -04:00
parent faa8951ee4
commit 60c16de830
2 changed files with 10 additions and 2 deletions

View File

@ -1,7 +1,7 @@
use std::collections::HashMap;
use super::{Builtin, GLOBAL_FUNCTIONS};
use crate::common::QuoteKind;
use crate::common::{Brackets, QuoteKind};
use crate::scope::global_var_exists;
use crate::unit::Unit;
use crate::value::Value;
@ -81,7 +81,10 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
max_args!(args, 1);
Ok(Value::Ident(
match arg!(args, 0, "value") {
Value::List(v, ..) if v.is_empty() => "()".to_string(),
Value::List(v, _, brackets) if v.is_empty() => match brackets {
Brackets::None => "()".to_string(),
Brackets::Bracketed => "[]".to_string(),
},
v => v.to_string(),
},
QuoteKind::None,

View File

@ -239,6 +239,11 @@ test!(
"a {\n color: inspect(null)\n}\n",
"a {\n color: null;\n}\n"
);
test!(
inspect_empty_brackets,
"a {\n color: inspect([]);\n}\n",
"a {\n color: [];\n}\n"
);
test!(
variable_does_exist,
"$a: red; a {\n color: variable-exists(a)\n}\n",