diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-01-11 15:47:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-11 15:47:26 +0100 |
commit | d0a53c3ce509d8a012315d8008a33c03802fc70c (patch) | |
tree | 01dc7aca1d36056c807723bbb78a88d235ab5f9d /test_napi/src/typedarray.rs | |
parent | e26fc195ef97d27dae0ca34b2bf592ae839ca218 (diff) |
refactor(napi): Cleanup tests (#17347)
Diffstat (limited to 'test_napi/src/typedarray.rs')
-rw-r--r-- | test_napi/src/typedarray.rs | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/test_napi/src/typedarray.rs b/test_napi/src/typedarray.rs index f8b5fd674..034757dd0 100644 --- a/test_napi/src/typedarray.rs +++ b/test_napi/src/typedarray.rs @@ -1,7 +1,8 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use crate::assert_napi_ok; +use crate::napi_new_property; use core::ffi::c_void; -use napi_sys::Status::napi_ok; use napi_sys::TypedarrayType::uint8_array; use napi_sys::*; use std::ptr; @@ -12,42 +13,36 @@ extern "C" fn test_external( ) -> napi_value { let mut arraybuffer: napi_value = ptr::null_mut(); let mut external: Box<[u8; 4]> = Box::new([0, 1, 2, 3]); - assert!( - unsafe { - napi_create_external_arraybuffer( - env, - external.as_mut_ptr() as *mut c_void, - external.len(), - None, - ptr::null_mut(), - &mut arraybuffer, - ) - } == napi_ok - ); + assert_napi_ok!(napi_create_external_arraybuffer( + env, + external.as_mut_ptr() as *mut c_void, + external.len(), + None, + ptr::null_mut(), + &mut arraybuffer, + )); let mut typedarray: napi_value = ptr::null_mut(); - assert!( - unsafe { - napi_create_typedarray( - env, - uint8_array, - external.len(), - arraybuffer, - 0, - &mut typedarray, - ) - } == napi_ok - ); + assert_napi_ok!(napi_create_typedarray( + env, + uint8_array, + external.len(), + arraybuffer, + 0, + &mut typedarray, + )); std::mem::forget(external); // Leak into JS land typedarray } pub fn init(env: napi_env, exports: napi_value) { - let properties = - &[crate::new_property!(env, "test_external\0", test_external)]; + let properties = &[napi_new_property!(env, "test_external", test_external)]; - unsafe { - napi_define_properties(env, exports, properties.len(), properties.as_ptr()) - }; + assert_napi_ok!(napi_define_properties( + env, + exports, + properties.len(), + properties.as_ptr() + )); } |