summaryrefslogtreecommitdiff
path: root/test_napi/src
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-05-21 21:14:48 +0200
committerGitHub <noreply@github.com>2023-05-21 13:14:48 -0600
commit6255cf4642f97478fbf05f7b2cff1a1934364983 (patch)
tree14b05a8ed2856ef608909d4aeb747f7f1bf5f45b /test_napi/src
parent3e03865d89e3abf0755e6d3b8305632a5319fdfe (diff)
chore: add tests for N-API symbol (#19205)
Diffstat (limited to 'test_napi/src')
-rw-r--r--test_napi/src/lib.rs2
-rw-r--r--test_napi/src/symbol.rs39
2 files changed, 41 insertions, 0 deletions
diff --git a/test_napi/src/lib.rs b/test_napi/src/lib.rs
index 8c467d307..8fa7d9ef6 100644
--- a/test_napi/src/lib.rs
+++ b/test_napi/src/lib.rs
@@ -23,6 +23,7 @@ pub mod primitives;
pub mod promise;
pub mod properties;
pub mod strings;
+pub mod symbol;
pub mod tsfn;
pub mod typedarray;
@@ -160,6 +161,7 @@ unsafe extern "C" fn napi_register_module_v1(
tsfn::init(env, exports);
mem::init(env, exports);
bigint::init(env, exports);
+ symbol::init(env, exports);
init_cleanup_hook(env, exports);
diff --git a/test_napi/src/symbol.rs b/test_napi/src/symbol.rs
new file mode 100644
index 000000000..5f404d590
--- /dev/null
+++ b/test_napi/src/symbol.rs
@@ -0,0 +1,39 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+use crate::assert_napi_ok;
+use crate::napi_get_callback_info;
+use crate::napi_new_property;
+use napi_sys::ValueType::napi_string;
+use napi_sys::*;
+
+extern "C" fn symbol_new(
+ env: napi_env,
+ info: napi_callback_info,
+) -> napi_value {
+ let (args, argc, _) = napi_get_callback_info!(env, info, 1);
+
+ let mut description: napi_value = std::ptr::null_mut();
+
+ if argc >= 1 {
+ let mut ty = -1;
+ assert_napi_ok!(napi_typeof(env, args[0], &mut ty));
+ assert_eq!(ty, napi_string);
+ description = args[0];
+ }
+
+ let mut symbol: napi_value = std::ptr::null_mut();
+ assert_napi_ok!(napi_create_symbol(env, description, &mut symbol));
+
+ symbol
+}
+
+pub fn init(env: napi_env, exports: napi_value) {
+ let properties = &[napi_new_property!(env, "symbolNew", symbol_new)];
+
+ assert_napi_ok!(napi_define_properties(
+ env,
+ exports,
+ properties.len(),
+ properties.as_ptr()
+ ));
+}