Implement parser & formater for 'TraceIfFalse'

Interestingly enough, chumsky seems to fail when given a 'choice' with
  more than 25 elements. That's why this commit groups together some of
  the choices as another nested 'choice'.
This commit is contained in:
KtorZ
2023-02-16 13:51:37 +01:00
committed by Lucas
parent 60390fe4f0
commit 6a50bde666
5 changed files with 80 additions and 7 deletions

View File

@@ -255,3 +255,46 @@ fn trace_non_strings() {
Err((_, Error::CouldNotUnify { .. }))
))
}
#[test]
fn trace_if_false_ok() {
let source_code = r#"
fn or(a: Bool, b: Bool) {
(a || b)?
}
test foo() {
or(True, False)?
}
test bar() {
let must_be_signed = True
must_be_signed?
}
"#;
assert!(check(parse(source_code)).is_ok())
}
#[test]
fn trace_if_false_ko() {
let source_code = r#"
fn add(a: Int, b: Int) {
(a + b)?
}
test foo() {
add(14, 42) == 12
}
test bar() {
let must_be_signed = #"FF00"
must_be_signed? == #"FF00"
}
"#;
assert!(matches!(
check(parse(source_code)),
Err((_, Error::CouldNotUnify { .. }))
))
}

View File

@@ -400,3 +400,18 @@ fn format_trace_todo_error() {
assert_fmt(src, src);
}
#[test]
fn test_trace_if_false() {
let src = indoc! {r#"
fn foo() {
my_expression?
}
fn bar() {
(True && False)? || foo()?
}
"#};
assert_fmt(src, src);
}