mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Add simple effectful cli run tests
This commit is contained in:
parent
ca7697db91
commit
de2260e67a
5 changed files with 140 additions and 1 deletions
|
@ -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() {
|
||||
|
|
27
crates/cli/tests/effectful/form.roc
Normal file
27
crates/cli/tests/effectful/form.roc
Normal 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! {}
|
7
crates/cli/tests/effectful/hello.roc
Normal file
7
crates/cli/tests/effectful/hello.roc
Normal 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 👻"
|
16
crates/cli/tests/effectful/loops.roc
Normal file
16
crates/cli/tests/effectful/loops.roc
Normal 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
|
|
@ -6,7 +6,6 @@ main! : {} => {}
|
|||
main! = \{} ->
|
||||
logged! "hello" (\{} -> Effect.putLine! "Hello, World!")
|
||||
|
||||
|
||||
logged! = \name, fx! ->
|
||||
Effect.putLine! "Before $(name)"
|
||||
fx! {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue