summaryrefslogtreecommitdiff
path: root/src/pretty.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-30 18:04:08 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-30 18:49:19 +0200
commit1ee1d078e2480ddd08d40915bc7a74a8352acff0 (patch)
tree1e7ff367278a19fead3e404cf06d65bfb80a6cd9 /src/pretty.rs
parent42a27b48df427edf8dbb624c51551a90ecf2e7ea (diff)
Fatal errors
- Makes errors fatal, so that a phase is only reached when all previous phases were error-free - Parsing still recovers and can produce multiple errors - Evaluation fails fast and can thus produce only a single error (except for parse errors due to an import) - The single error that could occur during execution is removed for now - Removes Value::Error variant
Diffstat (limited to 'src/pretty.rs')
-rw-r--r--src/pretty.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/pretty.rs b/src/pretty.rs
index 10e4fbcb..a4e9b334 100644
--- a/src/pretty.rs
+++ b/src/pretty.rs
@@ -488,7 +488,6 @@ impl Pretty for Value {
Self::Template(v) => v.pretty(p),
Self::Func(v) => v.pretty(p),
Self::Dyn(v) => v.pretty(p),
- Self::Error => p.push_str("<error>"),
}
}
}
@@ -609,6 +608,7 @@ pretty_display! {
#[cfg(test)]
mod tests {
use super::*;
+ use crate::loading::FileId;
use crate::parse::parse;
#[track_caller]
@@ -618,7 +618,7 @@ mod tests {
#[track_caller]
fn test_parse(src: &str, exp: &str) {
- let ast = parse(src).output;
+ let ast = parse(FileId::from_raw(0), src).unwrap();
let found = pretty(&ast);
if exp != found {
println!("tree: {:#?}", ast);
@@ -732,6 +732,7 @@ mod tests {
#[test]
fn test_pretty_print_value() {
+ // Primitives.
test_value(Value::None, "none");
test_value(false, "false");
test_value(12i64, "12");
@@ -742,6 +743,8 @@ mod tests {
test_value(Relative::new(0.3) + Length::cm(2.0), "30% + 2cm");
test_value(Fractional::one() * 7.55, "7.55fr");
test_value(Color::Rgba(RgbaColor::new(1, 1, 1, 0xff)), "#010101");
+
+ // Collections.
test_value("hello", r#""hello""#);
test_value("\n", r#""\n""#);
test_value("\\", r#""\\""#);
@@ -752,12 +755,15 @@ mod tests {
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>");
+
+ // Functions.
+ test_value(Function::new(None, |_, _| Ok(Value::None)), "<function>");
test_value(
- Function::new(Some("nil".into()), |_, _| Value::None),
+ Function::new(Some("nil".into()), |_, _| Ok(Value::None)),
"<function nil>",
);
+
+ // Dynamics.
test_value(Dynamic::new(1), "1");
- test_value(Value::Error, "<error>");
}
}