Add builtin List.split

This commit is contained in:
satotake 2021-11-15 13:50:11 +00:00 committed by GitHub
parent cac718638d
commit 73dda714de
6 changed files with 154 additions and 13 deletions

View file

@ -248,6 +248,47 @@ fn list_sublist() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_split() {
assert_evals_to!(
r#"
list = List.split [1, 2, 3] 0
list.before
"#,
RocList::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
r#"
list = List.split [1, 2, 3] 0
list.others
"#,
RocList::from_slice(&[1, 2, 3]),
RocList<i64>
);
assert_evals_to!(
"List.split [1, 2, 3] 1",
(RocList::from_slice(&[1]), RocList::from_slice(&[2, 3]),),
(RocList<i64>, RocList<i64>,)
);
assert_evals_to!(
"List.split [1, 2, 3] 3",
(RocList::from_slice(&[1, 2, 3]), RocList::from_slice(&[]),),
(RocList<i64>, RocList<i64>,)
);
assert_evals_to!(
"List.split [1, 2, 3] 4",
(RocList::from_slice(&[1, 2, 3]), RocList::from_slice(&[]),),
(RocList<i64>, RocList<i64>,)
);
assert_evals_to!(
"List.split [] 1",
(RocList::from_slice(&[]), RocList::from_slice(&[]),),
(RocList<i64>, RocList<i64>,)
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_drop() {