test(napi): add tests for bytes in struct
This commit is contained in:
parent
bbd495a795
commit
f4ae035c84
5 changed files with 35 additions and 1 deletions
|
@ -236,7 +236,7 @@ test('is promise', (t) => {
|
|||
t.true(bindings.testIsPromise(Promise.reject().catch(() => {})))
|
||||
t.true(
|
||||
bindings.testIsPromise(
|
||||
new Promise((resolve) => {
|
||||
new Promise<void>((resolve) => {
|
||||
resolve()
|
||||
}),
|
||||
),
|
||||
|
|
|
@ -12,6 +12,7 @@ const testFunc = [
|
|||
'make_buff',
|
||||
'make_obj',
|
||||
'make_map',
|
||||
'make_bytes_struct',
|
||||
]
|
||||
|
||||
if (napiVersion >= 6) {
|
||||
|
@ -24,3 +25,10 @@ for (const func of testFunc) {
|
|||
t.snapshot(bindings[func]())
|
||||
})
|
||||
}
|
||||
|
||||
test('serialize make_bytes_struct', (t) => {
|
||||
t.deepEqual(bindings.make_bytes_struct(), {
|
||||
code: Buffer.from([0, 1, 2, 3]),
|
||||
map: 'source map',
|
||||
})
|
||||
})
|
||||
|
|
|
@ -72,6 +72,17 @@ Generated by [AVA](https://avajs.dev).
|
|||
c: 3,
|
||||
}
|
||||
|
||||
## serialize make_bytes_struct from bindings
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
{
|
||||
code: Buffer @Uint8Array [
|
||||
00010203
|
||||
],
|
||||
map: 'source map',
|
||||
}
|
||||
|
||||
## serialize make_object from bindings
|
||||
|
||||
> Snapshot 1
|
||||
|
|
Binary file not shown.
|
@ -44,6 +44,13 @@ struct AnObjectTwo {
|
|||
r: i128,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Deserialize)]
|
||||
struct BytesObject<'a> {
|
||||
#[serde(with = "serde_bytes")]
|
||||
code: &'a [u8],
|
||||
map: String,
|
||||
}
|
||||
|
||||
macro_rules! make_test {
|
||||
($name:ident, $val:expr) => {
|
||||
#[js_function]
|
||||
|
@ -104,6 +111,13 @@ const NUMBER_BYTES: &[u8] = &[255u8, 254, 253];
|
|||
|
||||
make_test!(make_buff, { serde_bytes::Bytes::new(NUMBER_BYTES) });
|
||||
|
||||
make_test!(make_bytes_struct, {
|
||||
BytesObject {
|
||||
code: &[0, 1, 2, 3],
|
||||
map: "source map".to_owned(),
|
||||
}
|
||||
});
|
||||
|
||||
macro_rules! make_expect {
|
||||
($name:ident, $val:expr, $val_type:ty) => {
|
||||
#[js_function(1)]
|
||||
|
@ -189,6 +203,7 @@ pub fn register_js(exports: &mut JsObject) -> Result<()> {
|
|||
exports.create_named_method("make_obj", make_obj)?;
|
||||
exports.create_named_method("make_object", make_object)?;
|
||||
exports.create_named_method("make_map", make_map)?;
|
||||
exports.create_named_method("make_bytes_struct", make_bytes_struct)?;
|
||||
|
||||
exports.create_named_method("expect_hello_world", expect_hello_world)?;
|
||||
exports.create_named_method("expect_obj", expect_obj)?;
|
||||
|
|
Loading…
Reference in a new issue