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 {
|
impl Display for Val {
|
||||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
&Val::Boolean(b) => write!(f, "Boolean({})", b),
|
&Val::Boolean(b) => write!(f, "{}", b),
|
||||||
&Val::Empty => write!(f, "EmptyValue"),
|
&Val::Empty => write!(f, "NULL"),
|
||||||
&Val::Float(ref ff) => write!(f, "Float({})", ff),
|
&Val::Float(ref ff) => write!(f, "{}", ff),
|
||||||
&Val::Int(ref i) => write!(f, "Int({})", i),
|
&Val::Int(ref i) => write!(f, "{}", i),
|
||||||
&Val::Str(ref s) => write!(f, "String({})", s),
|
// TODO(jwall): Escape quotes in the string.
|
||||||
|
&Val::Str(ref s) => write!(f, "\"{}\"", s),
|
||||||
&Val::List(ref def) => {
|
&Val::List(ref def) => {
|
||||||
write!(f, "[\n")?;
|
write!(f, "[")?;
|
||||||
for v in def.iter() {
|
for v in def.iter() {
|
||||||
write!(f, "\t{},\n", v)?;
|
write!(f, "{}, ", v)?;
|
||||||
}
|
}
|
||||||
write!(f, "]")
|
write!(f, "]")
|
||||||
}
|
}
|
||||||
&Val::Macro(_) => write!(f, "Macro(..)"),
|
&Val::Macro(_) => write!(f, "Macro(..)"),
|
||||||
&Val::Module(_) => write!(f, "Module{{..}}"),
|
&Val::Module(_) => write!(f, "Module{{..}}"),
|
||||||
&Val::Tuple(ref def) => {
|
&Val::Tuple(ref def) => {
|
||||||
write!(f, "Tuple(\n")?;
|
write!(f, "{{\n")?;
|
||||||
for v in def.iter() {
|
for v in def.iter() {
|
||||||
write!(f, "\t{} = {},\n", v.0.val, v.1)?;
|
write!(f, "\t{} = {},\n", v.0.val, v.1)?;
|
||||||
}
|
}
|
||||||
write!(f, ")")
|
write!(f, "}}")
|
||||||
}
|
}
|
||||||
&Val::Env(ref def) => {
|
&Val::Env(ref def) => {
|
||||||
write!(f, "Env(\n")?;
|
write!(f, "{{\n")?;
|
||||||
for v in def.iter() {
|
for v in def.iter() {
|
||||||
write!(f, "\t{}=\"{}\"\n", v.0, v.1)?;
|
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::Str(ref s) => s.to_string(),
|
||||||
Val::Boolean(ref b) => format!("{}", b),
|
Val::Boolean(ref b) => format!("{}", b),
|
||||||
Val::Empty => "NULL".to_string(),
|
Val::Empty => "NULL".to_string(),
|
||||||
val => format!("<{}>", val),
|
val => format!("{}", val),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ fn test_expr_copy_no_such_tuple() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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() {
|
fn test_expr_copy_not_a_tuple() {
|
||||||
let i_paths = Vec::new();
|
let i_paths = Vec::new();
|
||||||
let cache = Rc::new(RefCell::new(MemoryCache::new()));
|
let cache = Rc::new(RefCell::new(MemoryCache::new()));
|
||||||
|
@ -42,11 +42,11 @@ let asserts = module{
|
|||||||
left=NULL,
|
left=NULL,
|
||||||
// right value for deep equal comparison.
|
// right value for deep equal comparison.
|
||||||
right=NULL,
|
right=NULL,
|
||||||
desc=NULL,
|
desc="",
|
||||||
} => {
|
} => {
|
||||||
let ok = mod.left == mod.right;
|
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,
|
false = mod.desc,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -57,11 +57,11 @@ let asserts = module{
|
|||||||
left=NULL,
|
left=NULL,
|
||||||
// right value for deep equal comparison.
|
// right value for deep equal comparison.
|
||||||
right=NULL,
|
right=NULL,
|
||||||
desc=NULL,
|
desc="",
|
||||||
} => {
|
} => {
|
||||||
let ok = mod.left != mod.right;
|
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,
|
false = mod.desc,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user