mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 15:59:20 +03:00
Add base gen tests for list matching compilation
This commit is contained in:
parent
45f7cd5ad7
commit
b0edcc9af4
@ -3578,3 +3578,102 @@ fn list_walk_from_even_prefix_sum() {
|
||||
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…
Reference in New Issue
Block a user