From 720e29437e3c25930a2861997d356b69bd62628e Mon Sep 17 00:00:00 2001 From: Christian Lewe Date: Mon, 9 Dec 2024 17:43:49 +0100 Subject: [PATCH 1/2] chore: Update old test case jet_verify -> assert! --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 30fb357..aec80b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -539,7 +539,7 @@ mod tests { } fn main() { - jet_verify(my_true()); + assert!(my_true()); } "#; match SatisfiedProgram::new(prog_text, Arguments::default(), WitnessValues::default()) { From 4a18efe0a88f05a6f4c00cb6cbfaab605f006a9f Mon Sep 17 00:00:00 2001 From: Christian Lewe Date: Mon, 9 Dec 2024 17:44:29 +0100 Subject: [PATCH 2/2] fix: Parse type aliases I forgot to enforce the semicolon at the end of each type alias. This meant that type aliases only parsed without semicolon, which is not the intended behavior. This commit adds a unit test to assert that type aliases can be parsed as expected. Adding semicolons also makes one fuzz regression obsolete. --- src/lib.rs | 19 ++++++++++++++----- src/minimal.pest | 2 +- src/parse.rs | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index aec80b3..a56d13f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -552,11 +552,6 @@ fn main() { } } - #[test] - fn fuzz_regression_1() { - parse::Program::parse_from_str("type f=f").unwrap(); - } - #[test] fn fuzz_regression_2() { parse::Program::parse_from_str("fn dbggscas(h: bool, asyxhaaaa: a) {\nfalse}\n\n").unwrap(); @@ -567,4 +562,18 @@ fn main() { fn fuzz_slow_unit_1() { parse::Program::parse_from_str("fn fnnfn(MMet:(((sssss,((((((sssss,ssssss,ss,((((((sssss,ss,((((((sssss,ssssss,ss,((((((sssss,ssssss,((((((sssss,sssssssss,(((((((sssss,sssssssss,(((((ssss,((((((sssss,sssssssss,(((((((sssss,ssss,((((((sssss,ss,((((((sssss,ssssss,ss,((((((sssss,ssssss,((((((sssss,sssssssss,(((((((sssss,sssssssss,(((((ssss,((((((sssss,sssssssss,(((((((sssss,sssssssssssss,(((((((((((u|(").unwrap_err(); } + + #[test] + fn type_alias() { + let prog_text = r#"type MyAlias = u32; + +fn main() { + let x: MyAlias = 32; + assert!(jet::eq_32(x, 32)); +} +"#; + TestCase::program_text(Cow::Borrowed(prog_text)) + .with_witness_values(WitnessValues::default()) + .assert_run_success(); + } } diff --git a/src/minimal.pest b/src/minimal.pest index 8644aab..4b396f2 100644 --- a/src/minimal.pest +++ b/src/minimal.pest @@ -49,7 +49,7 @@ ty = { alias_name | builtin_alias | sum_type | option_type | boo builtin_alias = @{ "Ctx8" | "Pubkey" | "Message64" | "Message" | "Signature" | "Scalar" | "Fe" | "Gej" | "Ge" | "Point" | "Height" | "Time" | "Distance" | "Duration" | "Lock" | "Outpoint" | "Confidential1" | "ExplicitAsset" | "Asset1" | "ExplicitAmount" | "Amount1" | "ExplicitNonce" | "Nonce" | "TokenAmount1" } alias_name = { !builtin_alias ~ identifier } type_keyword = @{ "type" ~ !ASCII_ALPHANUMERIC } -type_alias = { type_keyword ~ alias_name ~ "=" ~ ty } +type_alias = { type_keyword ~ alias_name ~ "=" ~ ty ~ ";" } left_expr = { "Left(" ~ expression ~ ")" } right_expr = { "Right(" ~ expression ~ ")" } diff --git a/src/parse.rs b/src/parse.rs index 5ac8571..5fb2cbf 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -505,7 +505,7 @@ impl fmt::Display for Item { impl fmt::Display for TypeAlias { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "type {} = {}", self.name(), self.ty()) + write!(f, "type {} = {};", self.name(), self.ty()) } }