test(napi): add tests for hashmap <-> object
This commit is contained in:
parent
b7b405a49b
commit
7a04176cf9
6 changed files with 26 additions and 0 deletions
|
@ -68,6 +68,8 @@ Generated by [AVA](https://avajs.dev).
|
|||
export function mutateExternal(external: ExternalObject<number>, newVal: number): void␊
|
||||
export function tsRename(a: { foo: number }): string[]␊
|
||||
export function xxh64Alias(input: Buffer): BigInt␊
|
||||
export function getMapping(): Record<string, number>␊
|
||||
export function sumMapping(nums: Record<string, number>): number␊
|
||||
export function mapOption(val?: number | undefined | null): number | undefined | null␊
|
||||
export function returnNull(): null␊
|
||||
export function returnUndefined(): void␊
|
||||
|
|
Binary file not shown.
|
@ -14,6 +14,8 @@ import {
|
|||
getNums,
|
||||
getWords,
|
||||
sumNums,
|
||||
getMapping,
|
||||
sumMapping,
|
||||
getCwd,
|
||||
Animal,
|
||||
Kind,
|
||||
|
@ -104,6 +106,11 @@ test('array', (t) => {
|
|||
t.is(sumNums([1, 2, 3, 4, 5]), 15)
|
||||
})
|
||||
|
||||
test('map', (t) => {
|
||||
t.deepEqual(getMapping(), { a: 101, b: 102 })
|
||||
t.is(sumMapping({ a: 101, b: 102 }), 203)
|
||||
})
|
||||
|
||||
test('enum', (t) => {
|
||||
t.deepEqual([Kind.Dog, Kind.Cat, Kind.Duck], [0, 1, 2])
|
||||
t.is(enumToI32(CustomNumEnum.Eight), 8)
|
||||
|
|
2
examples/napi/index.d.ts
vendored
2
examples/napi/index.d.ts
vendored
|
@ -58,6 +58,8 @@ export function getExternal(external: ExternalObject<number>): number
|
|||
export function mutateExternal(external: ExternalObject<number>, newVal: number): void
|
||||
export function tsRename(a: { foo: number }): string[]
|
||||
export function xxh64Alias(input: Buffer): BigInt
|
||||
export function getMapping(): Record<string, number>
|
||||
export function sumMapping(nums: Record<string, number>): number
|
||||
export function mapOption(val?: number | undefined | null): number | undefined | null
|
||||
export function returnNull(): null
|
||||
export function returnUndefined(): void
|
||||
|
|
|
@ -22,6 +22,7 @@ mod error;
|
|||
mod external;
|
||||
mod fn_ts_override;
|
||||
mod js_mod;
|
||||
mod map;
|
||||
mod nullable;
|
||||
mod number;
|
||||
mod object;
|
||||
|
|
14
examples/napi/src/map.rs
Normal file
14
examples/napi/src/map.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
#[napi]
|
||||
fn get_mapping() -> HashMap<String, u32> {
|
||||
let mut map = HashMap::new();
|
||||
map.insert("a".to_string(), 101);
|
||||
map.insert("b".to_string(), 102);
|
||||
map
|
||||
}
|
||||
|
||||
#[napi]
|
||||
fn sum_mapping(nums: HashMap<String, u32>) -> u32 {
|
||||
nums.into_values().sum()
|
||||
}
|
Loading…
Reference in a new issue