mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Merge attempt
This commit is contained in:
parent
7c15c16ae0
commit
12df3a04de
236 changed files with 9053 additions and 6428 deletions
|
@ -2479,39 +2479,6 @@ fn expanded_result() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn backpassing_result() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
a : Result I64 Str
|
||||
a = Ok 1
|
||||
|
||||
f = \x -> Ok (x + 1)
|
||||
g = \y -> Ok (y * 2)
|
||||
|
||||
main : I64
|
||||
main =
|
||||
helper =
|
||||
x <- Result.try a
|
||||
y <- Result.try (f x)
|
||||
z <- Result.try (g y)
|
||||
|
||||
Ok z
|
||||
|
||||
helper
|
||||
|> Result.withDefault 0
|
||||
|
||||
"#
|
||||
),
|
||||
4,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
#[should_panic(expected = "Shadowing { original_region: @55-56, shadow: @72-73 Ident")]
|
||||
|
|
|
@ -885,6 +885,38 @@ fn update_single_element_record() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn update_record_shorthand() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
rec = { foo: 42, bar: 2.46f64 }
|
||||
|
||||
rec |> &foo (rec.foo + 1)
|
||||
"
|
||||
),
|
||||
(2.46, 43),
|
||||
(f64, i64)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
|
||||
fn update_single_element_record_shorthand() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
rec = { foo: 42}
|
||||
|
||||
&foo rec (rec.foo + 1)
|
||||
"
|
||||
),
|
||||
43,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn booleans_in_record() {
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue