mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
add tests for List.dropAt
This commit is contained in:
parent
3baff93a97
commit
700ab20a8c
3 changed files with 29 additions and 8 deletions
|
@ -833,8 +833,6 @@ pub fn listDrop(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GIESCH add type inference test
|
|
||||||
// GIESCH add unit tests
|
|
||||||
// GIESCH do a uniqueness check, and reuse the same array if possible
|
// GIESCH do a uniqueness check, and reuse the same array if possible
|
||||||
// GIESCH figure out where to specify uniqueness of output, update builtins readme
|
// GIESCH figure out where to specify uniqueness of output, update builtins readme
|
||||||
pub fn listDropAt(
|
pub fn listDropAt(
|
||||||
|
@ -848,7 +846,8 @@ pub fn listDropAt(
|
||||||
const size = list.len();
|
const size = list.len();
|
||||||
|
|
||||||
if (drop_index >= size) {
|
if (drop_index >= size) {
|
||||||
return RocList.empty();
|
// GIESCH should this still copy/reallocate if non-unique?
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drop_index < size) {
|
if (drop_index < size) {
|
||||||
|
@ -856,11 +855,6 @@ pub fn listDropAt(
|
||||||
dec(element);
|
dec(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GIESCH is this necessary?
|
|
||||||
if (size < 2 and drop_index == 0) {
|
|
||||||
return RocList.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = RocList.allocate(alignment, (size - 1), element_width);
|
const output = RocList.allocate(alignment, (size - 1), element_width);
|
||||||
const target_ptr = output.bytes orelse unreachable;
|
const target_ptr = output.bytes orelse unreachable;
|
||||||
|
|
||||||
|
|
|
@ -3709,6 +3709,18 @@ mod solve_expr {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn list_drop_at() {
|
||||||
|
infer_eq_without_problem(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
List.dropAt
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
"List a, Nat -> List a",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_that_captures_nothing_is_not_captured() {
|
fn function_that_captures_nothing_is_not_captured() {
|
||||||
// we should make sure that a function that doesn't capture anything it not itself captured
|
// we should make sure that a function that doesn't capture anything it not itself captured
|
||||||
|
|
|
@ -198,6 +198,21 @@ fn list_drop() {
|
||||||
assert_evals_to!("List.drop [1,2] 5", RocList::from_slice(&[]), RocList<i64>);
|
assert_evals_to!("List.drop [1,2] 5", RocList::from_slice(&[]), RocList<i64>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn list_drop_at() {
|
||||||
|
assert_evals_to!(
|
||||||
|
"List.dropAt [1, 2, 3] 0",
|
||||||
|
RocList::from_slice(&[2, 3]),
|
||||||
|
RocList<i64>
|
||||||
|
);
|
||||||
|
assert_evals_to!(
|
||||||
|
"List.dropAt [0, 0, 0] 3",
|
||||||
|
RocList::from_slice(&[1, 2, 3]),
|
||||||
|
RocList<i64>
|
||||||
|
);
|
||||||
|
assert_evals_to!("List.dropAt [] 1", RocList::from_slice(&[]), RocList<i64>);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_swap() {
|
fn list_swap() {
|
||||||
assert_evals_to!("List.swap [] 0 1", RocList::from_slice(&[]), RocList<i64>);
|
assert_evals_to!("List.swap [] 0 1", RocList::from_slice(&[]), RocList<i64>);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue