diff --git a/integration_tests/select_expressions_test.ucg b/integration_tests/select_expressions_test.ucg new file mode 100644 index 0000000..0be2573 --- /dev/null +++ b/integration_tests/select_expressions_test.ucg @@ -0,0 +1,30 @@ +let goodwant = "door1"; +let badwant = "door4"; + +let got = select goodwant, "OOPS", { + door1 = "grand prize", + door2 = "you lose", +}; + +let defaultgot = select badwant, "OOPS", { + door1 = "grand prize", + door2 = "you lose", +}; + +assert |got == "grand prize"|; +assert |defaultgot == "OOPS"|; + +// select inside a macro + +let condmacro = macro(arg) => { + output = select arg, NULL, { + opt1 = "yay", + opt2 = "boo", + }, +}; + +let result = condmacro("opt1"); + +assert |condmacro("opt1") == {output = "yay"}|; +assert |condmacro("opt2") == {output = "boo"}|; +assert |condmacro("invalid") == {output = NULL}|; \ No newline at end of file diff --git a/src/build/compile_test.rs b/src/build/compile_test.rs index 5ffaf68..75dde34 100644 --- a/src/build/compile_test.rs +++ b/src/build/compile_test.rs @@ -48,6 +48,13 @@ fn test_empty_value() { assert_build(include_str!("../../integration_tests/empty_test.ucg")); } +#[test] +fn test_select_expressions() { + assert_build(include_str!( + "../../integration_tests/select_expressions_test.ucg" + )); +} + #[test] fn test_binary_operator_precedence() { assert_build(include_str!(