From 276c155264d6b389f3c14950f7c5a513e6161479 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sun, 3 Feb 2019 20:56:21 -0600 Subject: [PATCH] FIX: More error reporting improvements. --- src/build/compile_test.rs | 22 ++++++++++++++++++++++ src/parse/mod.rs | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/build/compile_test.rs b/src/build/compile_test.rs index 763f43d..37ac9ce 100644 --- a/src/build/compile_test.rs +++ b/src/build/compile_test.rs @@ -396,3 +396,25 @@ fn test_incomplete_tuple_key_value_missing_value_compile_failure() { ], ) } + +#[test] +fn test_format_expr_missing_expr_compile_error() { + assert_build_failure( + "\"foo\" %", + vec![ + Regex::new(r"Expected format arguments").unwrap(), + Regex::new(r"at line: 1, column: 8").unwrap(), + ], + ) +} + +#[test] +fn test_format_expr_unclosed_parens_compile_failure() { + assert_build_failure( + "\"foo\" % (1", + vec![ + Regex::new(r"Expected \(\)\) but got \(\)").unwrap(), + Regex::new(r"at line: 1, column: 9").unwrap(), + ], + ) +} diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 4b874c8..62ed697 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -503,7 +503,8 @@ make_fn!( do_each!( tmpl => match_type!(STR), _ => punct!("%"), - args => either!(simple_format_args, expression_format_args), + args => wrap_err!(must!(either!(simple_format_args, expression_format_args)), + "Expected format arguments"), (Expression::Format(FormatDef { template: tmpl.fragment.to_string(), args: args,