Merge remote-tracking branch 'remote/main' into upgrade-llvm-zig

This commit is contained in:
Luke Boswell 2024-08-15 07:11:29 +10:00
commit 57b277da5c
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
212 changed files with 9379 additions and 7534 deletions

View file

@ -354,3 +354,85 @@ fn roc_result_after_err() {
RocResult<RocStr, i64>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn roc_result_map_both() {
assert_evals_to!(
indoc!(
r#"
result : Result I64 I64
result = Ok 42
result |> Result.mapBoth Num.toStr Num.toStr
"#
),
RocResult::ok(RocStr::from("42")),
RocResult<RocStr, RocStr>
);
assert_evals_to!(
indoc!(
r#"
result : Result I64 I64
result = Err 24
result |> Result.mapBoth Num.toStr Num.toStr
"#
),
RocResult::err(RocStr::from("24")),
RocResult<RocStr, RocStr>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn roc_result_map_two() {
assert_evals_to!(
indoc!(
r#"
first : Result I64 Str
first = Ok 24
second : Result I64 Str
second = Ok -10
Result.map2 first second \a, b -> a + b
"#
),
RocResult::ok(14i64),
RocResult<i64, RocStr>
);
assert_evals_to!(
indoc!(
r#"
first : Result I64 Str
first = Err "foo"
second : Result I64 Str
second = Err "bar"
Result.map2 first second \a, b -> a + b
"#
),
RocResult::err(RocStr::from("foo")),
RocResult<i64, RocStr>
);
assert_evals_to!(
indoc!(
r#"
first : Result I64 Str
first = Ok 42
second : Result I64 Str
second = Err "bar"
Result.map2 first second \a, b -> a + b
"#
),
RocResult::err(RocStr::from("bar")),
RocResult<i64, RocStr>
);
}