Add simple effectful cli run tests

This commit is contained in:
Agus Zubiaga 2024-10-24 12:48:47 -03:00
parent ca7697db91
commit de2260e67a
No known key found for this signature in database
5 changed files with 140 additions and 1 deletions

View file

@ -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] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
fn effectful_untyped_passed_fx() { 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] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
fn transitive_expects() { fn transitive_expects() {

View file

@ -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! {}

View file

@ -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 👻"

View file

@ -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

View file

@ -6,7 +6,6 @@ main! : {} => {}
main! = \{} -> main! = \{} ->
logged! "hello" (\{} -> Effect.putLine! "Hello, World!") logged! "hello" (\{} -> Effect.putLine! "Hello, World!")
logged! = \name, fx! -> logged! = \name, fx! ->
Effect.putLine! "Before $(name)" Effect.putLine! "Before $(name)"
fx! {} fx! {}