@@ -130,3 +130,43 @@ fn feature_disabled(function: &str) -> RegorusResult {
130130 format ! ( "{function} unavailable: regorus built without allocator-memory-limits feature" ) ,
131131 )
132132}
133+
134+ #[ cfg( test) ]
135+ mod tests {
136+ use super :: { optional_u64_to_result, regorus_get_global_memory_limit, regorus_set_global_memory_limit} ;
137+ use crate :: common:: { regorus_result_drop, RegorusDataType , RegorusStatus } ;
138+
139+ #[ test]
140+ fn optional_some_returns_integer ( ) {
141+ let result = optional_u64_to_result ( Some ( 123 ) ) ;
142+ assert ! ( result. bool_value) ;
143+ assert ! ( matches!( result. data_type, RegorusDataType :: Integer ) ) ;
144+ assert_eq ! ( result. int_value, 123 ) ;
145+ }
146+
147+ #[ test]
148+ fn optional_none_returns_void ( ) {
149+ let result = optional_u64_to_result ( None ) ;
150+ assert ! ( !result. bool_value) ;
151+ assert ! ( matches!( result. data_type, RegorusDataType :: None ) ) ;
152+ assert_eq ! ( result. int_value, 0 ) ;
153+ }
154+
155+ #[ test]
156+ fn ffi_roundtrips_global_limit ( ) {
157+ let limit = 456_u64 ;
158+ let result = regorus_set_global_memory_limit ( limit, true ) ;
159+ assert ! ( matches!( result. status, RegorusStatus :: Ok ) ) ;
160+ regorus_result_drop ( result) ;
161+
162+ let result = regorus_get_global_memory_limit ( ) ;
163+ assert ! ( matches!( result. status, RegorusStatus :: Ok ) ) ;
164+ assert ! ( result. bool_value) ;
165+ assert ! ( matches!( result. data_type, RegorusDataType :: Integer ) ) ;
166+ assert_eq ! ( result. int_value, 456 ) ;
167+ regorus_result_drop ( result) ;
168+
169+ let result = regorus_set_global_memory_limit ( 0 , false ) ;
170+ regorus_result_drop ( result) ;
171+ }
172+ }
0 commit comments