mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Add base gen tests for list matching compilation
This commit is contained in:
parent
45f7cd5ad7
commit
b0edcc9af4
1 changed files with 99 additions and 0 deletions
|
@ -3578,3 +3578,102 @@ fn list_walk_from_even_prefix_sum() {
|
||||||
i64
|
i64
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||||
|
mod pattern_match {
|
||||||
|
#[cfg(feature = "gen-llvm")]
|
||||||
|
use crate::helpers::llvm::assert_evals_to;
|
||||||
|
|
||||||
|
#[cfg(feature = "gen-wasm")]
|
||||||
|
use crate::helpers::wasm::assert_evals_to;
|
||||||
|
|
||||||
|
use super::RocList;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unary_exact_size_match() {
|
||||||
|
assert_evals_to!(
|
||||||
|
r#"
|
||||||
|
helper = \l -> when l is
|
||||||
|
[] -> 1u8
|
||||||
|
_ -> 2u8
|
||||||
|
|
||||||
|
[ helper [], helper [{}] ]
|
||||||
|
"#,
|
||||||
|
RocList::from_slice(&[1, 2]),
|
||||||
|
RocList<u8>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn many_exact_size_match() {
|
||||||
|
assert_evals_to!(
|
||||||
|
r#"
|
||||||
|
helper = \l -> when l is
|
||||||
|
[] -> 1u8
|
||||||
|
[_] -> 2u8
|
||||||
|
[_, _] -> 3u8
|
||||||
|
[_, _, _] -> 4u8
|
||||||
|
_ -> 5u8
|
||||||
|
|
||||||
|
[ helper [], helper [{}], helper [{}, {}], helper [{}, {}, {}], helper [{}, {}, {}, {}] ]
|
||||||
|
"#,
|
||||||
|
RocList::from_slice(&[1, 2, 3, 4, 5]),
|
||||||
|
RocList<u8>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ranged_matches_head() {
|
||||||
|
assert_evals_to!(
|
||||||
|
r#"
|
||||||
|
helper = \l -> when l is
|
||||||
|
[] -> 1u8
|
||||||
|
[A] -> 2u8
|
||||||
|
[A, A, ..] -> 3u8
|
||||||
|
[A, B, ..] -> 4u8
|
||||||
|
[B, ..] -> 5u8
|
||||||
|
|
||||||
|
[
|
||||||
|
helper [],
|
||||||
|
helper [A],
|
||||||
|
helper [A, A], helper [A, A, A], helper [A, A, B], helper [A, A, B, A],
|
||||||
|
helper [A, B], helper [A, B, A], helper [A, B, B], helper [A, B, A, B],
|
||||||
|
helper [B], helper [B, A], helper [B, B], helper [B, A, B, B],
|
||||||
|
]
|
||||||
|
"#,
|
||||||
|
RocList::from_slice(&[
|
||||||
|
1, //
|
||||||
|
2, //
|
||||||
|
3, 3, 3, 3, //
|
||||||
|
4, 4, 4, 4, //
|
||||||
|
5, 5, 5, 5, //
|
||||||
|
]),
|
||||||
|
RocList<u8>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bind_variables() {
|
||||||
|
assert_evals_to!(
|
||||||
|
r#"
|
||||||
|
helper : List U8 -> U8
|
||||||
|
helper = \l -> when l is
|
||||||
|
[] -> 1u8
|
||||||
|
[x] -> x
|
||||||
|
[x, y, ..] -> x * y
|
||||||
|
|
||||||
|
[
|
||||||
|
helper [],
|
||||||
|
helper [5],
|
||||||
|
helper [3, 5], helper [3, 5, 7], helper [3, 5, 7, 11],
|
||||||
|
]
|
||||||
|
"#,
|
||||||
|
RocList::from_slice(&[
|
||||||
|
1, //
|
||||||
|
5, //
|
||||||
|
15, 15, 15 //
|
||||||
|
]),
|
||||||
|
RocList<u8>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue