aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/ffi.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-02 04:37:24 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-02 04:37:24 -0700
commitd70e92e79f3940f80bee186a6c7c3c8ef23aed00 (patch)
tree87262bc08985233bf43a77ac5f22dae928a76b0e /integration/bunjs-only-snippets/ffi.test.js
parent15466865e07b623dceeb51f54aa6b47eb4881b43 (diff)
downloadbun-d70e92e79f3940f80bee186a6c7c3c8ef23aed00.tar.gz
bun-d70e92e79f3940f80bee186a6c7c3c8ef23aed00.tar.zst
bun-d70e92e79f3940f80bee186a6c7c3c8ef23aed00.zip
[bun:ffi] Support `double` and `float`
Diffstat (limited to 'integration/bunjs-only-snippets/ffi.test.js')
-rw-r--r--integration/bunjs-only-snippets/ffi.test.js54
1 files changed, 28 insertions, 26 deletions
diff --git a/integration/bunjs-only-snippets/ffi.test.js b/integration/bunjs-only-snippets/ffi.test.js
index 14a38d6b2..597c0ef1f 100644
--- a/integration/bunjs-only-snippets/ffi.test.js
+++ b/integration/bunjs-only-snippets/ffi.test.js
@@ -27,9 +27,9 @@ it("ffi print", async () => {
import.meta.dir + "/ffi.test.fixture.receiver.c",
viewSource(
{
- callback: {
- return_type: 13,
- args: ["ptr"],
+ not_a_callback: {
+ return_type: "float",
+ args: [],
},
},
false
@@ -71,14 +71,14 @@ it("ffi run", () => {
return_type: "char",
args: [],
},
- // returns_42_float: {
- // return_type: "float",
- // args: [],
- // },
- // returns_42_double: {
- // return_type: "double",
- // args: [],
- // },
+ returns_42_float: {
+ return_type: "float",
+ args: [],
+ },
+ returns_42_double: {
+ return_type: "double",
+ args: [],
+ },
returns_42_uint8_t: {
return_type: "uint8_t",
args: [],
@@ -116,18 +116,18 @@ it("ffi run", () => {
return_type: "char",
args: ["char"],
},
- // identity_float: {
- // return_type: "float",
- // args: ["float"],
- // },
+ identity_float: {
+ return_type: "float",
+ args: ["float"],
+ },
identity_bool: {
return_type: "bool",
args: ["bool"],
},
- // identity_double: {
- // return_type: "double",
- // args: ["double"],
- // },
+ identity_double: {
+ return_type: "double",
+ args: ["double"],
+ },
identity_int8_t: {
return_type: "int8_t",
args: ["int8_t"],
@@ -340,8 +340,10 @@ it("ffi run", () => {
expect(returns_true()).toBe(true);
expect(returns_false()).toBe(false);
expect(returns_42_char()).toBe(42);
- // expect(returns_42_float()).toBe(42);
- // expect(returns_42_double()).toBe(42);
+
+ expect(Math.fround(returns_42_float())).toBe(Math.fround(42.41999804973602));
+
+ expect(returns_42_double()).toBe(42.42);
expect(returns_42_uint8_t()).toBe(42);
expect(returns_neg_42_int8_t()).toBe(-42);
expect(returns_42_uint16_t()).toBe(42);
@@ -352,20 +354,20 @@ it("ffi run", () => {
expect(identity_int32_t(10)).toBe(10);
// expect(returns_neg_42_int64_t()).toBe(-42);
expect(identity_char(10)).toBe(10);
- // expect(identity_float(10.1)).toBe(10.1);
+ expect(identity_float(10.199999809265137)).toBe(10.199999809265137);
expect(identity_bool(true)).toBe(true);
expect(identity_bool(false)).toBe(false);
- // expect(identity_double(10.1)).toBe(10.1);
+ expect(identity_double(10.100000000000364)).toBe(10.100000000000364);
expect(identity_int8_t(10)).toBe(10);
expect(identity_int16_t(10)).toBe(10);
-
+ console.log("here");
// expect(identity_int64_t(10)).toBe(10);
expect(identity_uint8_t(10)).toBe(10);
expect(identity_uint16_t(10)).toBe(10);
expect(identity_uint32_t(10)).toBe(10);
expect(add_char(1, 1)).toBe(2);
- // expect(add_float(1.1, 1.1)).toBe(2.2);
- // expect(add_double(1.1, 1.1)).toBe(2.2);
+ expect(add_float(2.4, 2.8)).toBe(Math.fround(5.2));
+ expect(add_double(4.2, 0.1)).toBe(4.3);
expect(add_int8_t(1, 1)).toBe(2);
expect(add_int16_t(1, 1)).toBe(2);
expect(add_int32_t(1, 1)).toBe(2);