Symbol definition and tests

This commit is contained in:
Marten/Qqwy 2022-07-07 22:51:17 +02:00 committed by Folkert
parent 5632d07179
commit 699ab5c646
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 53 additions and 0 deletions

View file

@ -1297,6 +1297,7 @@ define_builtins! {
6 RESULT_AFTER: "after"
7 RESULT_IS_OK: "isOk"
8 RESULT_IS_ERR: "isErr"
9 RESULT_AFTER_ERR: "afterErr"
}
7 DICT: "Dict" => {
0 DICT_DICT: "Dict" imported // the Dict.Dict type alias

View file

@ -268,3 +268,55 @@ fn issue_2583_specialize_errors_behind_unified_branches() {
RocResult<i64, bool>
)
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn roc_result_after() {
assert_evals_to!(indoc!(
r#"
result : Result I64 I64
result = (Ok "1234") |> after (\numStr -> Num.toNat)
result
"#),
RocResult::ok(1234),
RocResult<i64, RocStr>
);
assert_evals_to!(indoc!(
r#"
result : Result I64 Str
result = (Err "1234") |> after (\numStr -> Num.toNat)
result
"#),
RocResult::err(RocStr::from("1234")),
RocResult<i64, RocStr>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn roc_result_after_err() {
assert_evals_to!(indoc!(
r#"
result : Result I64 Str
result = (Err "1234") |> afterErr (\numStr -> Num.toNat)
result
"#),
RocResult::err(1234),
RocResult<i64, RocStr>
);
assert_evals_to!(indoc!(
r#"
result : Result Str I64
result = (Ok "1234") |> afterErr (\numStr -> Num.toNat)
result
"#),
RocResult::ok(RocStr::from("1234")),
RocResult<RocStr, i64>
);
}