mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 00:09:33 +03:00
Revise some tests
This commit is contained in:
parent
39249f3905
commit
db502fe2e7
@ -1234,7 +1234,7 @@ fn clone_list<'a, 'ctx, 'env>(
|
||||
|
||||
// Allocate space for the new array that we'll copy into.
|
||||
let elem_type = basic_type_from_layout(env.arena, ctx, elem_layout, env.ptr_bytes);
|
||||
let ptr_val = builder
|
||||
let clone_ptr = builder
|
||||
.build_array_malloc(elem_type, list_len, "list_ptr")
|
||||
.unwrap();
|
||||
|
||||
@ -1247,7 +1247,7 @@ fn clone_list<'a, 'ctx, 'env>(
|
||||
//
|
||||
// TODO how do we decide when to do the small memcpy vs the normal one?
|
||||
builder
|
||||
.build_memcpy(ptr_val, ptr_bytes, elems_ptr, ptr_bytes, size)
|
||||
.build_memcpy(clone_ptr, ptr_bytes, elems_ptr, ptr_bytes, size)
|
||||
.unwrap_or_else(|err| {
|
||||
panic!("Error while attempting LLVM memcpy: {:?}", err);
|
||||
});
|
||||
@ -1256,14 +1256,14 @@ fn clone_list<'a, 'ctx, 'env>(
|
||||
}
|
||||
|
||||
// Create a fresh wrapper struct for the newly populated array
|
||||
let struct_type = collection_wrapper(ctx, ptr_val.get_type(), env.ptr_bytes);
|
||||
let struct_type = collection_wrapper(ctx, clone_ptr.get_type(), env.ptr_bytes);
|
||||
let mut struct_val;
|
||||
|
||||
// Store the pointer
|
||||
struct_val = builder
|
||||
.build_insert_value(
|
||||
struct_type.get_undef(),
|
||||
ptr_val,
|
||||
clone_ptr,
|
||||
Builtin::WRAPPER_PTR,
|
||||
"insert_ptr",
|
||||
)
|
||||
@ -1274,7 +1274,7 @@ fn clone_list<'a, 'ctx, 'env>(
|
||||
.build_insert_value(struct_val, list_len, Builtin::WRAPPER_LEN, "insert_len")
|
||||
.unwrap();
|
||||
|
||||
(struct_val.into_struct_value(), ptr_val)
|
||||
(struct_val.into_struct_value(), clone_ptr)
|
||||
}
|
||||
|
||||
fn bounds_check_comparison<'ctx>(
|
||||
|
@ -564,7 +564,7 @@ mod test_gen {
|
||||
|
||||
#[test]
|
||||
fn set_unique_int_list() {
|
||||
assert_llvm_evals_to!(
|
||||
assert_opt_evals_to!(
|
||||
"List.set [ 12, 9, 7, 1, 5 ] 2 33",
|
||||
&[12, 9, 33, 1, 5],
|
||||
&'static [i64],
|
||||
@ -574,42 +574,42 @@ mod test_gen {
|
||||
|
||||
#[test]
|
||||
fn set_unique_list_oob() {
|
||||
assert_llvm_evals_to!(
|
||||
"List.set [ 3, 17, 4 ] 1337 42",
|
||||
&[3, 17, 4],
|
||||
&'static [i64],
|
||||
assert_opt_evals_to!(
|
||||
"List.set [ 3, 17, 4.1 ] 1337 9.25",
|
||||
&[3.0, 17.0, 4.1],
|
||||
&'static [f64],
|
||||
|x| x
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_shared_int_list() {
|
||||
assert_llvm_evals_to!(
|
||||
assert_opt_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
shared = [ 2, 4 ]
|
||||
shared = [ 2.1, 4.3 ]
|
||||
|
||||
# This should not mutate the original
|
||||
x = List.getUnsafe (List.set shared 1 77) 1
|
||||
x = List.getUnsafe (List.set shared 1 7.7) 1
|
||||
|
||||
{ x, y: List.getUnsafe shared 1 }
|
||||
"#
|
||||
),
|
||||
(77, 4),
|
||||
(i64, i64),
|
||||
(7.7, 4.3),
|
||||
(f64, f64),
|
||||
|x| x
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_shared_list_oob() {
|
||||
assert_llvm_evals_to!(
|
||||
assert_opt_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
shared = [ 2, 4 ]
|
||||
|
||||
# This should not mutate the original
|
||||
x = List.getUnsafe (List.set shared 9000 77) 1
|
||||
x = List.set shared 1 0
|
||||
|
||||
{ x, y: List.getUnsafe shared 1 }
|
||||
"#
|
||||
|
@ -276,7 +276,7 @@ mod test_opt {
|
||||
shared = [ 2, 4 ]
|
||||
|
||||
# This should not mutate the original
|
||||
x = List.set shared 1 77
|
||||
x = List.set shared 1 0
|
||||
|
||||
{ x, y: List.getUnsafe shared 1 }
|
||||
"#,
|
||||
|
Loading…
Reference in New Issue
Block a user