mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
FEATURE: Better rendering of Val's to text.
This commit is contained in:
parent
924dcb40ff
commit
207a08d112
@ -186,33 +186,34 @@ impl Val {
|
||||
impl Display for Val {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Val::Boolean(b) => write!(f, "Boolean({})", b),
|
||||
&Val::Empty => write!(f, "EmptyValue"),
|
||||
&Val::Float(ref ff) => write!(f, "Float({})", ff),
|
||||
&Val::Int(ref i) => write!(f, "Int({})", i),
|
||||
&Val::Str(ref s) => write!(f, "String({})", s),
|
||||
&Val::Boolean(b) => write!(f, "{}", b),
|
||||
&Val::Empty => write!(f, "NULL"),
|
||||
&Val::Float(ref ff) => write!(f, "{}", ff),
|
||||
&Val::Int(ref i) => write!(f, "{}", i),
|
||||
// TODO(jwall): Escape quotes in the string.
|
||||
&Val::Str(ref s) => write!(f, "\"{}\"", s),
|
||||
&Val::List(ref def) => {
|
||||
write!(f, "[\n")?;
|
||||
write!(f, "[")?;
|
||||
for v in def.iter() {
|
||||
write!(f, "\t{},\n", v)?;
|
||||
write!(f, "{}, ", v)?;
|
||||
}
|
||||
write!(f, "]")
|
||||
}
|
||||
&Val::Macro(_) => write!(f, "Macro(..)"),
|
||||
&Val::Module(_) => write!(f, "Module{{..}}"),
|
||||
&Val::Tuple(ref def) => {
|
||||
write!(f, "Tuple(\n")?;
|
||||
write!(f, "{{\n")?;
|
||||
for v in def.iter() {
|
||||
write!(f, "\t{} = {},\n", v.0.val, v.1)?;
|
||||
}
|
||||
write!(f, ")")
|
||||
write!(f, "}}")
|
||||
}
|
||||
&Val::Env(ref def) => {
|
||||
write!(f, "Env(\n")?;
|
||||
write!(f, "{{\n")?;
|
||||
for v in def.iter() {
|
||||
write!(f, "\t{}=\"{}\"\n", v.0, v.1)?;
|
||||
}
|
||||
write!(f, ")")
|
||||
write!(f, "}}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,7 +227,7 @@ impl From<Val> for 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ fn test_expr_copy_no_such_tuple() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Expected Tuple or Module got Int(1)")]
|
||||
#[should_panic(expected = "Expected Tuple or Module got 1")]
|
||||
fn test_expr_copy_not_a_tuple() {
|
||||
let i_paths = Vec::new();
|
||||
let cache = Rc::new(RefCell::new(MemoryCache::new()));
|
||||
|
@ -42,11 +42,11 @@ let asserts = module{
|
||||
left=NULL,
|
||||
// right value for deep equal comparison.
|
||||
right=NULL,
|
||||
desc=NULL,
|
||||
desc="",
|
||||
} => {
|
||||
let ok = mod.left == mod.right;
|
||||
|
||||
let desc = select (mod.desc == NULL), "@ == @" % (mod.left, mod.right), {
|
||||
let desc = select (mod.desc == ""), "@ == @" % (mod.left, mod.right), {
|
||||
false = mod.desc,
|
||||
};
|
||||
};
|
||||
@ -57,11 +57,11 @@ let asserts = module{
|
||||
left=NULL,
|
||||
// right value for deep equal comparison.
|
||||
right=NULL,
|
||||
desc=NULL,
|
||||
desc="",
|
||||
} => {
|
||||
let ok = mod.left != mod.right;
|
||||
|
||||
let desc = select (mod.desc == NULL), "@ != @" % (mod.left, mod.right), {
|
||||
let desc = select (mod.desc == ""), "@ != @" % (mod.left, mod.right), {
|
||||
false = mod.desc,
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user