Merge branch 'main' into str-withprefix

This commit is contained in:
Prajwal S N 2022-10-09 15:53:16 +05:30
commit aef15ac1e8
No known key found for this signature in database
GPG key ID: D0FECEE245BC2695
57 changed files with 1388 additions and 631 deletions

View file

@ -3395,3 +3395,59 @@ fn list_let_generalization() {
usize
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_walk_backwards_until_sum() {
assert_evals_to!(
r#"List.walkBackwardsUntil [1, 2] 0 \a,b -> Continue (a + b)"#,
3,
i64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_walk_backwards_implements_position() {
assert_evals_to!(
r#"
Option a : [Some a, None]
find : List a, a -> Option Nat
find = \list, needle ->
findHelp list needle
|> .v
findHelp = \list, needle ->
List.walkBackwardsUntil list { n: 0, v: None } \{ n, v }, element ->
if element == needle then
Break { n, v: Some n }
else
Continue { n: n + 1, v }
when find [1, 2, 3] 3 is
None -> 0
Some v -> v
"#,
0,
usize
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_walk_backwards_until_even_prefix_sum() {
assert_evals_to!(
r#"
helper = \a, b ->
if Num.isEven b then
Continue (a + b)
else
Break a
List.walkBackwardsUntil [9, 8, 4, 2] 0 helper"#,
2 + 4 + 8,
i64
);
}

View file

@ -1931,6 +1931,34 @@ fn when_on_strings() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn with_capacity() {
assert_evals_to!(
indoc!(
r#"
Str.withCapacity 10
"#
),
RocStr::from(""),
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn with_capacity_concat() {
assert_evals_to!(
indoc!(
r#"
Str.withCapacity 10 |> Str.concat "Forty-two"
"#
),
RocStr::from("Forty-two"),
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn str_with_prefix() {

View file

@ -2004,3 +2004,21 @@ fn match_on_result_with_uninhabited_error_branch() {
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn dispatch_tag_union_function_inferred() {
assert_evals_to!(
indoc!(
r#"
g = \b -> if b then H else J
when P ((g Bool.true) "") ((g Bool.false) "") is
P (H _) (J _) -> "okay"
_ -> "FAIL"
"#
),
RocStr::from("okay"),
RocStr
);
}