diff options
author | 2022-04-29 23:21:14 -0700 | |
---|---|---|
committer | 2022-04-29 23:21:14 -0700 | |
commit | 516b54578dec5506fed1d88fb6b9e2d8dc89d2ea (patch) | |
tree | c639bae8fb3951b1b619e132c63e77868a289fcb /integration/bunjs-only-snippets | |
parent | d49ba5028949f726e68b31093921c2187759ab4b (diff) | |
download | bun-516b54578dec5506fed1d88fb6b9e2d8dc89d2ea.tar.gz bun-516b54578dec5506fed1d88fb6b9e2d8dc89d2ea.tar.zst bun-516b54578dec5506fed1d88fb6b9e2d8dc89d2ea.zip |
[bun:ffi] it works
Diffstat (limited to 'integration/bunjs-only-snippets')
-rw-r--r-- | integration/bunjs-only-snippets/buffer.test.js | 4 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/ffi.test.js | 35 |
2 files changed, 23 insertions, 16 deletions
diff --git a/integration/bunjs-only-snippets/buffer.test.js b/integration/bunjs-only-snippets/buffer.test.js index 0d5821fdc..d1a5c7ff3 100644 --- a/integration/bunjs-only-snippets/buffer.test.js +++ b/integration/bunjs-only-snippets/buffer.test.js @@ -31,10 +31,6 @@ it("Buffer", () => { expect(new Buffer(input).toString("utf8")).toBe(inputs[i]); expect(Array.from(new Buffer(input)).join(",")).toBe(good[i].join(",")); } - for (let i = 0; i < inputs.length; i++) { - var input = inputs[i]; - expect(new Buffer(input, "ucs2").toString("utf8")).toBe(inputs[i]); - } }); it("Buffer.toBuffer throws", () => { diff --git a/integration/bunjs-only-snippets/ffi.test.js b/integration/bunjs-only-snippets/ffi.test.js index 16967fe51..2337a44c8 100644 --- a/integration/bunjs-only-snippets/ffi.test.js +++ b/integration/bunjs-only-snippets/ffi.test.js @@ -1,10 +1,20 @@ import { describe, it, expect } from "bun:test"; import { unsafe } from "bun"; +// +import { + viewSource, + dlopen, + CString, + ptr, + toBuffer, + toArrayBuffer, + FFIType, +} from "bun:ffi"; it("ffi print", () => { - Bun.dlprint({ + viewSource({ add: { - params: ["int32_t", "int32_t"], + args: [FFIType.int], return_type: "int32_t", }, })[0]; @@ -211,7 +221,7 @@ it("ffi run", () => { ptr_should_point_to_42_as_int32_t, }, close, - } = Bun.dlopen("/tmp/bun-ffi-test.dylib", types); + } = dlopen("/tmp/bun-ffi-test.dylib", types); expect(returns_true()).toBe(true); expect(returns_false()).toBe(false); @@ -249,16 +259,17 @@ it("ffi run", () => { expect(add_uint16_t(1, 1)).toBe(2); expect(add_uint32_t(1, 1)).toBe(2); - const ptr = ptr_should_point_to_42_as_int32_t(); - expect(ptr != 0).toBe(true); - expect(typeof ptr === "number").toBe(true); - expect(does_pointer_equal_42_as_int32_t(ptr)).toBe(true); - const buffer = unsafe.bufferFromPtr(ptr, 4); + const cptr = ptr_should_point_to_42_as_int32_t(); + expect(cptr != 0).toBe(true); + expect(typeof cptr === "number").toBe(true); + expect(does_pointer_equal_42_as_int32_t(cptr)).toBe(true); + const buffer = toBuffer(cptr, 0, 4); expect(buffer.readInt32(0)).toBe(42); - expect( - new DataView(unsafe.arrayBufferFromPtr(ptr, 4), 0, 4).getInt32(0, true) - ).toBe(42); - expect(unsafe.arrayBufferToPtr(buffer)).toBe(ptr); + expect(new DataView(toArrayBuffer(cptr, 0, 4), 0, 4).getInt32(0, true)).toBe( + 42 + ); + expect(ptr(buffer)).toBe(cptr); + expect(new CString(cptr, 0, 1)).toBe("*"); close(); }); ``; |