fix: "when bool is" was not properly assigning term to body when not a complex clause
Add some end to end tests to test uplc
This commit is contained in:
parent
9bb1a88f23
commit
ff87a4c60f
|
@ -4402,7 +4402,7 @@ impl<'a> CodeGenerator<'a> {
|
||||||
let other_clauses = if complex_clause {
|
let other_clauses = if complex_clause {
|
||||||
Term::var("__other_clauses_delayed")
|
Term::var("__other_clauses_delayed")
|
||||||
} else {
|
} else {
|
||||||
term.clone()
|
term.clone().delay()
|
||||||
};
|
};
|
||||||
|
|
||||||
if matches!(clause, Term::Constant(boolean) if matches!(boolean.as_ref(), UplcConstant::Bool(true)))
|
if matches!(clause, Term::Constant(boolean) if matches!(boolean.as_ref(), UplcConstant::Bool(true)))
|
||||||
|
@ -4418,6 +4418,8 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
if complex_clause {
|
if complex_clause {
|
||||||
term = body.lambda("__other_clauses_delayed").apply(term.delay());
|
term = body.lambda("__other_clauses_delayed").apply(term.delay());
|
||||||
|
} else {
|
||||||
|
term = body;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let condition = if tipo.is_int() {
|
let condition = if tipo.is_int() {
|
||||||
|
|
|
@ -1060,3 +1060,72 @@ fn expect_empty_list_on_new_list() {
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn when_bool_is_true() {
|
||||||
|
let src = r#"
|
||||||
|
test it() {
|
||||||
|
when True is {
|
||||||
|
True ->
|
||||||
|
True
|
||||||
|
False ->
|
||||||
|
error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
assert_uplc(
|
||||||
|
src,
|
||||||
|
Term::var("subject")
|
||||||
|
.delayed_if_else(Term::bool(true), Term::Error)
|
||||||
|
.lambda("subject")
|
||||||
|
.apply(Term::bool(true)),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn when_bool_is_true_switched_cases() {
|
||||||
|
let src = r#"
|
||||||
|
test it() {
|
||||||
|
when True is {
|
||||||
|
False ->
|
||||||
|
error
|
||||||
|
True ->
|
||||||
|
True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
assert_uplc(
|
||||||
|
src,
|
||||||
|
Term::var("subject")
|
||||||
|
.delayed_if_else(Term::bool(true), Term::Error)
|
||||||
|
.lambda("subject")
|
||||||
|
.apply(Term::bool(true)),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn when_bool_is_false() {
|
||||||
|
let src = r#"
|
||||||
|
test it() {
|
||||||
|
when False is {
|
||||||
|
False ->
|
||||||
|
error
|
||||||
|
True ->
|
||||||
|
True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
assert_uplc(
|
||||||
|
src,
|
||||||
|
Term::var("subject")
|
||||||
|
.delayed_if_else(Term::bool(true), Term::Error)
|
||||||
|
.lambda("subject")
|
||||||
|
.apply(Term::bool(false)),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue