summaryrefslogtreecommitdiff
path: root/src/syntax/expr.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-26 21:57:56 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-26 21:57:56 +0100
commit010ddc4795123987bdef3b5a60240203e7f11d01 (patch)
treefa27e7def6d229ba1347ab2cb7d2d06462f46613 /src/syntax/expr.rs
parentf006636dd2af065a149e3aa1d67fcbe889c53b87 (diff)
More straightforward pretty printing tests 🧹
Diffstat (limited to 'src/syntax/expr.rs')
-rw-r--r--src/syntax/expr.rs60
1 files changed, 2 insertions, 58 deletions
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs
index 7e636d3d..ea762511 100644
--- a/src/syntax/expr.rs
+++ b/src/syntax/expr.rs
@@ -64,6 +64,8 @@ impl Pretty for Expr {
Self::Angle(v, u) => write!(p, "{}{}", v, u).unwrap(),
Self::Percent(v) => write!(p, "{}%", v).unwrap(),
Self::Color(v) => write!(p, "{}", v).unwrap(),
+ // TODO: Debug escapes a bit more than we want (e.g. apostrophes).
+ // We probably need to do the escaping ourselves.
Self::Str(v) => write!(p, "{:?}", &v).unwrap(),
Self::Array(v) => v.pretty(p),
Self::Dict(v) => v.pretty(p),
@@ -543,61 +545,3 @@ impl Pretty for ExprFor {
self.body.v.pretty(p);
}
}
-#[cfg(test)]
-mod tests {
- use super::super::tests::test_pretty;
-
- #[test]
- fn test_pretty_print_chaining() {
- // All equivalent.
- test_pretty("[v [[f]]]", "[v | f]");
- test_pretty("[v][[f]]", "[v | f]");
- test_pretty("[v | f]", "[v | f]");
- }
-
- #[test]
- fn test_pretty_print_expressions() {
- // Unary and binary operations.
- test_pretty("{}", "{}");
- test_pretty("{1 +}", "{1}");
- test_pretty("{1++1}", "{1 + +1}");
- test_pretty("{+-1}", "{+-1}");
- test_pretty("{1 + func(-2)}", "{1 + func(-2)}");
- test_pretty("{1+2*3}", "{1 + 2 * 3}");
- test_pretty("{(1+2)*3}", "{(1 + 2) * 3}");
-
- // Array.
- test_pretty("(-5,)", "(-5,)");
- test_pretty("(1, 2, 3)", "(1, 2, 3)");
-
- // Dictionary.
- test_pretty("{(:)}", "{(:)}");
- test_pretty("{(percent: 5%)}", "{(percent: 5%)}");
-
- // Content expression.
- test_pretty("[v [[f]], 1]", "[v [[f]], 1]");
-
- // Parens and blocks.
- test_pretty("{(1)}", "{(1)}");
- test_pretty("{{1}}", "{{1}}");
-
- // Control flow.
- test_pretty("#let x = 1+2", "#let x = 1 + 2");
- test_pretty("#if x [y] #else [z]", "#if x [y] #else [z]");
- test_pretty("#for x #in y {z}", "#for x #in y {z}");
- }
-
- #[test]
- fn test_pretty_print_literals() {
- test_pretty("{none}", "{none}");
- test_pretty("{true}", "{true}");
- test_pretty("{25}", "{25}");
- test_pretty("{2.50}", "{2.5}");
- test_pretty("{1e2}", "{100.0}");
- test_pretty("{12pt}", "{12pt}");
- test_pretty("{90.0deg}", "{90deg}");
- test_pretty("{50%}", "{50%}");
- test_pretty("{#fff}", "{#ffffff}");
- test_pretty(r#"{"hi\n"}"#, r#"{"hi\n"}"#);
- }
-}