diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-07-10 20:01:18 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-07-10 23:10:17 +0200 |
| commit | 6a4823461f491aef63451f097ddfe5602e0b2157 (patch) | |
| tree | ad11b0ad169d030942d950573c729d50f7b3291b /src/pretty.rs | |
| parent | 36b3067c19c8743032a44f888ee48702b88d135b (diff) | |
Reference-count complex values
Rename some nodes types
Diffstat (limited to 'src/pretty.rs')
| -rw-r--r-- | src/pretty.rs | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/src/pretty.rs b/src/pretty.rs index 83c207b5..2a825b14 100644 --- a/src/pretty.rs +++ b/src/pretty.rs @@ -86,7 +86,7 @@ impl Pretty for SyntaxTree { } } -impl Pretty for Node { +impl Pretty for SyntaxNode { fn pretty(&self, p: &mut Printer) { match self { // TODO: Handle escaping. @@ -493,7 +493,7 @@ impl Pretty for Value { } } -impl Pretty for ArrayValue { +impl Pretty for Array { fn pretty(&self, p: &mut Printer) { p.push('('); p.join(self, ", ", |item, p| item.pretty(p)); @@ -504,7 +504,7 @@ impl Pretty for ArrayValue { } } -impl Pretty for DictValue { +impl Pretty for Dict { fn pretty(&self, p: &mut Printer) { p.push('('); if self.is_empty() { @@ -520,13 +520,13 @@ impl Pretty for DictValue { } } -impl Pretty for TemplateValue { +impl Pretty for Template { fn pretty(&self, p: &mut Printer) { p.push_str("<template>"); } } -impl Pretty for FuncValue { +impl Pretty for Function { fn pretty(&self, p: &mut Printer) { p.push_str("<function"); if let Some(name) = self.name() { @@ -608,20 +608,9 @@ pretty_display! { #[cfg(test)] mod tests { - use std::collections::BTreeMap; - use super::*; use crate::parse::parse; - macro_rules! map { - ($($k:ident: $v:expr),* $(,)?) => {{ - #[allow(unused_mut)] - let mut m = BTreeMap::new(); - $(m.insert(stringify!($k).into(), $v);)* - m - }}; - } - #[track_caller] fn roundtrip(src: &str) { test_parse(src, src); @@ -757,18 +746,15 @@ mod tests { test_value("\n", r#""\n""#); test_value("\\", r#""\\""#); test_value("\"", r#""\"""#); - test_value(Value::Array(vec![]), "()"); - test_value(vec![Value::None], "(none,)"); - test_value(vec![Value::Int(1), Value::Int(2)], "(1, 2)"); - test_value(map![], "(:)"); - test_value(map![one: Value::Int(1)], "(one: 1)"); - test_value( - map![two: Value::Bool(false), one: Value::Int(1)], - "(one: 1, two: false)", - ); - test_value(FuncValue::new(None, |_, _| Value::None), "<function>"); + test_value(array![], "()"); + test_value(array![Value::None], "(none,)"); + test_value(array![1, 2], "(1, 2)"); + test_value(dict![], "(:)"); + test_value(dict!["one" => 1], "(one: 1)"); + test_value(dict!["two" => false, "one" => 1], "(one: 1, two: false)"); + test_value(Function::new(None, |_, _| Value::None), "<function>"); test_value( - FuncValue::new(Some("nil".into()), |_, _| Value::None), + Function::new(Some("nil".into()), |_, _| Value::None), "<function nil>", ); test_value(AnyValue::new(1), "1"); |
