From 0ff64e3bac9120aa3c4a45847b86fa38d3fe3b7b Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 14 Aug 2023 22:05:48 -0400 Subject: [PATCH] test: check and format tests for logical op chain --- crates/aiken-lang/src/tests/check.rs | 21 +++++++++++++++++++ crates/aiken-lang/src/tests/format.rs | 9 ++++++++ .../snapshots/format_logical_op_chain.snap | 15 +++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 crates/aiken-lang/src/tests/snapshots/format_logical_op_chain.snap diff --git a/crates/aiken-lang/src/tests/check.rs b/crates/aiken-lang/src/tests/check.rs index c45df4c3..8b13fe33 100644 --- a/crates/aiken-lang/src/tests/check.rs +++ b/crates/aiken-lang/src/tests/check.rs @@ -661,6 +661,27 @@ fn expect_sugar_incorrect_type() { )) } +#[test] +fn logical_op_chain_expressions_should_be_bool() { + let source_code = r#" + fn foo() { + and { + 1 == 1, + False, + or { + 2 == 3, + 1 + } + } + } + "#; + + assert!(matches!( + check(parse(source_code)), + Err((_, Error::CouldNotUnify { .. })) + )) +} + #[test] fn anonymous_function_scoping() { let source_code = r#" diff --git a/crates/aiken-lang/src/tests/format.rs b/crates/aiken-lang/src/tests/format.rs index 79cc289f..3f57a3e1 100644 --- a/crates/aiken-lang/src/tests/format.rs +++ b/crates/aiken-lang/src/tests/format.rs @@ -20,6 +20,15 @@ fn format_simple_module() { ); } +#[test] +fn format_logical_op_chain() { + assert_format!( + r#" + fn smth() { and { foo, bar, or { bar, foo }} } + "# + ); +} + #[test] fn format_if() { assert_format!( diff --git a/crates/aiken-lang/src/tests/snapshots/format_logical_op_chain.snap b/crates/aiken-lang/src/tests/snapshots/format_logical_op_chain.snap new file mode 100644 index 00000000..c1eb5d94 --- /dev/null +++ b/crates/aiken-lang/src/tests/snapshots/format_logical_op_chain.snap @@ -0,0 +1,15 @@ +--- +source: crates/aiken-lang/src/tests/format.rs +description: "Code:\n\nfn smth() { and { foo, bar, or { bar, foo }} }\n" +--- +fn smth() { + and { + foo, + bar, + or { + bar, + foo, + }, + } +} +