2467b7139b
* napi procedural macro for basic rust/JavaScript types * introduce the `compat-mode` for `napi` and `napi-derive` crates for backward compatible * remove #[inline] and let compiler to decide the inline behavior * cli now can produce the `.d.ts` file for native binding * many tests and example for the new procedural macro Co-authored-by: LongYinan <lynweklm@gmail.com>
40 lines
1,022 B
TypeScript
40 lines
1,022 B
TypeScript
import test from 'ava'
|
|
|
|
const bindings = require('../index.node')
|
|
|
|
test('should get buffer length', (t) => {
|
|
const fixture = Buffer.from('wow, hello')
|
|
t.is(bindings.getBufferLength(fixture), fixture.length)
|
|
})
|
|
|
|
test('should stringify buffer', (t) => {
|
|
const fixture = 'wow, hello'
|
|
t.is(bindings.bufferToString(Buffer.from(fixture)), fixture)
|
|
})
|
|
|
|
test('should copy', (t) => {
|
|
const fixture = Buffer.from('wow, hello')
|
|
const copyBuffer = bindings.copyBuffer(fixture)
|
|
t.deepEqual(copyBuffer, fixture)
|
|
t.not(fixture, copyBuffer)
|
|
})
|
|
|
|
test('should create borrowed buffer with noop finalize', (t) => {
|
|
t.deepEqual(
|
|
bindings.createBorrowedBufferWithNoopFinalize(),
|
|
Buffer.from([1, 2, 3]),
|
|
)
|
|
})
|
|
|
|
test('should create borrowed buffer with finalize', (t) => {
|
|
t.deepEqual(
|
|
bindings.createBorrowedBufferWithFinalize(),
|
|
Buffer.from([1, 2, 3]),
|
|
)
|
|
})
|
|
|
|
test('should be able to mutate buffer', (t) => {
|
|
const fixture = Buffer.from([0, 1])
|
|
bindings.mutateBuffer(fixture)
|
|
t.is(fixture[1], 42)
|
|
})
|