From 9e1eb484cda5e1a882f0a888a9b705a2c5bfe9e9 Mon Sep 17 00:00:00 2001 From: Esteve Soler Arderiu Date: Fri, 4 Oct 2024 14:41:34 +0200 Subject: [PATCH] Add a test. --- src/libfuncs/array.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libfuncs/array.rs b/src/libfuncs/array.rs index be48705eb..fe87547af 100644 --- a/src/libfuncs/array.rs +++ b/src/libfuncs/array.rs @@ -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 { + let mut x: Array> = 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())))); + } }