Skip to content

Commit

Permalink
Add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
azteca1998 committed Oct 4, 2024
1 parent c6c4fcd commit 9e1eb48
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libfuncs/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2437,4 +2437,22 @@ mod test {
)
);
}

/// Test to ensure that the returned element in `array_get` does NOT get dropped.
#[test]
fn array_get_avoid_dropping_element() {
let program = load_cairo! {
use core::{array::{array_append, array_at, array_new}, box::{into_box, unbox}};

fn run_test() -> @Box<felt252> {
let mut x: Array<Box<felt252>> = array_new();
array_append(ref x, into_box(42));

unbox(array_at(@x, 0))
}
};
let result = run_program(&program, "run_test", &[]).return_value;

assert_eq!(result, jit_enum!(0, jit_struct!(Value::Felt252(42.into()))));
}
}

0 comments on commit 9e1eb48

Please sign in to comment.