add additonal tests

This commit is contained in:
Folkert 2022-03-26 12:46:31 +01:00
parent 4426f5793b
commit de77748dd5
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 59 additions and 11 deletions

View file

@ -202,7 +202,7 @@ fn values() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn from_list_with_fold() { fn from_list_with_fold_simple() {
assert_evals_to!( assert_evals_to!(
indoc!( indoc!(
r#" r#"
@ -217,7 +217,11 @@ fn from_list_with_fold() {
RocList::from_slice(&[2, 3, 1]), RocList::from_slice(&[2, 3, 1]),
RocList<i64> RocList<i64>
); );
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn from_list_with_fold_reallocates() {
assert_evals_to!( assert_evals_to!(
indoc!( indoc!(
r#" r#"
@ -235,11 +239,13 @@ fn from_list_with_fold() {
|> List.walk Dict.empty (\accum, value -> Dict.insert accum value value) |> List.walk Dict.empty (\accum, value -> Dict.insert accum value value)
Dict.values myDict Dict.values myDict
|> List.len
"# "#
), ),
25, RocList::from_slice(&[
i64 4, 5, 20, 0, 7, 3, 1, 21, 10, 6, 13, 9, 14, 19, 2, 15, 12, 17, 16, 18, 22, 8, 11, 24,
23
]),
RocList<i64>
); );
} }

View file

@ -2391,13 +2391,49 @@ fn list_wrap_in_tag() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_contains() { fn list_contains_int() {
assert_evals_to!(indoc!("List.contains [1,2,3] 1"), true, bool); assert_evals_to!(indoc!("List.contains [1,2,3] 1"), true, bool);
assert_evals_to!(indoc!("List.contains [1,2,3] 4"), false, bool); assert_evals_to!(indoc!("List.contains [1,2,3] 4"), false, bool);
assert_evals_to!(indoc!("List.contains [] 4"), false, bool); assert_evals_to!(indoc!("List.contains [] 4"), false, bool);
} }
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_contains_str() {
assert_evals_to!(indoc!(r#"List.contains ["foo", "bar"] "bar""#), true, bool);
assert_evals_to!(
indoc!(r#"List.contains ["foo", "bar"] "spam""#),
false,
bool
);
assert_evals_to!(indoc!(r#"List.contains [] "spam""#), false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_manual_range() {
assert_evals_to!(
indoc!(
r#"
range : I64, I64, List I64-> List I64
range = \low, high, accum ->
if low < high then
range (low + 1) high (List.append accum low)
else
accum
range 0 5 [ 42 ]
"#
),
RocList::from_slice(&[42, 0, 1, 2, 3, 4]),
RocList<i64>
);
}
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_min() { fn list_min() {
@ -2470,12 +2506,23 @@ fn list_product() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_keep_oks() { fn list_keep_void() {
assert_evals_to!( assert_evals_to!(
"List.keepOks [] (\\x -> x)", "List.keepOks [] (\\x -> x)",
RocList::from_slice(&[]), RocList::from_slice(&[]),
RocList<()> RocList<()>
); );
assert_evals_to!(
"List.keepErrs [] (\\x -> x)",
RocList::from_slice(&[]),
RocList<()>
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_keep_oks() {
assert_evals_to!( assert_evals_to!(
"List.keepOks [Ok {}, Ok {}] (\\x -> x)", "List.keepOks [Ok {}, Ok {}] (\\x -> x)",
RocList::from_slice(&[(), ()]), RocList::from_slice(&[(), ()]),
@ -2501,11 +2548,6 @@ fn list_keep_oks() {
#[test] #[test]
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_keep_errs() { fn list_keep_errs() {
assert_evals_to!(
"List.keepErrs [] (\\x -> x)",
RocList::from_slice(&[]),
RocList<()>
);
assert_evals_to!( assert_evals_to!(
"List.keepErrs [Err {}, Err {}] (\\x -> x)", "List.keepErrs [Err {}, Err {}] (\\x -> x)",
RocList::from_slice(&[(), ()]), RocList::from_slice(&[(), ()]),