diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index e82f0718dc..d6fc773326 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -986,6 +986,77 @@ mod cli_run { ); } + #[test] + #[cfg_attr(windows, ignore)] + fn effectful_hello() { + test_roc_app( + "crates/cli/tests/effectful", + "hello.roc", + &[], + &[], + &[], + indoc!( + r#" + I'm an effect 👻 + "# + ), + UseValgrind::No, + TestCliCommands::Dev, + ); + } + + #[test] + #[cfg_attr(windows, ignore)] + fn effectful_form() { + test_roc_app( + "crates/cli/tests/effectful", + "form.roc", + &["Agus\n", "Zubiaga\n", "27\n"], + &[], + &[], + indoc!( + r#" + What's your first name? + What's your last name? + + Hi, Agus Zubiaga! + + How old are you? + + Nice! You can vote! + + Bye! 👋 + "# + ), + UseValgrind::No, + TestCliCommands::Dev, + ); + } + + #[test] + #[cfg_attr(windows, ignore)] + fn effectful_loops() { + test_roc_app( + "crates/cli/tests/effectful", + "loops.roc", + &[], + &[], + &[], + indoc!( + r#" + Lu + Marce + Joaquin + Chloé + Mati + Pedro + "# + ), + UseValgrind::No, + TestCliCommands::Dev, + ); + } + #[test] #[cfg_attr(windows, ignore)] fn effectful_untyped_passed_fx() { @@ -1007,6 +1078,25 @@ mod cli_run { ); } + #[test] + #[cfg_attr(windows, ignore)] + fn effectful_ignore_result() { + test_roc_app( + "crates/cli/tests/effectful", + "ignore_result.roc", + &[], + &[], + &[], + indoc!( + r#" + I asked for input and I ignored it. Deal with it! 😎 + "# + ), + UseValgrind::No, + TestCliCommands::Dev, + ); + } + #[test] #[cfg_attr(windows, ignore)] fn transitive_expects() { diff --git a/crates/cli/tests/effectful/form.roc b/crates/cli/tests/effectful/form.roc new file mode 100644 index 0000000000..6882f2178f --- /dev/null +++ b/crates/cli/tests/effectful/form.roc @@ -0,0 +1,27 @@ +app [main!] { pf: platform "../../../../examples/cli/effects-platform/main.roc" } + +import pf.Effect + +main! : {} => {} +main! = \{} -> + first = ask! "What's your first name?" + last = ask! "What's your last name?" + + Effect.putLine! "\nHi, $(first) $(last)!\n" + + when Str.toU8 (ask! "How old are you?") is + Err InvalidNumStr -> + Effect.putLine! "Enter a valid number" + + Ok age if age >= 18 -> + Effect.putLine! "\nNice! You can vote!" + + Ok age -> + Effect.putLine! "\nYou'll be able to vote in $(Num.toStr (18 - age)) years" + + Effect.putLine! "\nBye! 👋" + +ask! : Str => Str +ask! = \question -> + Effect.putLine! question + Effect.getLine! {} diff --git a/crates/cli/tests/effectful/hello.roc b/crates/cli/tests/effectful/hello.roc new file mode 100644 index 0000000000..8e56a52dc6 --- /dev/null +++ b/crates/cli/tests/effectful/hello.roc @@ -0,0 +1,7 @@ +app [main!] { pf: platform "../../../../examples/cli/effects-platform/main.roc" } + +import pf.Effect + +main! : {} => {} +main! = \{} -> + Effect.putLine! "I'm an effect 👻" diff --git a/crates/cli/tests/effectful/loops.roc b/crates/cli/tests/effectful/loops.roc new file mode 100644 index 0000000000..bde0599d97 --- /dev/null +++ b/crates/cli/tests/effectful/loops.roc @@ -0,0 +1,16 @@ +app [main!] { pf: platform "../../../../examples/cli/effects-platform/main.roc" } + +import pf.Effect + +main! : {} => {} +main! = \{} -> + friends = ["Lu", "Marce", "Joaquin", "Chloé", "Mati", "Pedro"] + printAll! friends + +printAll! : List Str => {} +printAll! = \friends -> + when friends is + [] -> {} + [first, .. as remaining] -> + Effect.putLine! first + printAll! remaining diff --git a/crates/cli/tests/effectful/untyped_passed_fx.roc b/crates/cli/tests/effectful/untyped_passed_fx.roc index d0021f41a6..28f567176a 100644 --- a/crates/cli/tests/effectful/untyped_passed_fx.roc +++ b/crates/cli/tests/effectful/untyped_passed_fx.roc @@ -6,7 +6,6 @@ main! : {} => {} main! = \{} -> logged! "hello" (\{} -> Effect.putLine! "Hello, World!") - logged! = \name, fx! -> Effect.putLine! "Before $(name)" fx! {}