summaryrefslogtreecommitdiff
path: root/test_ffi/tests
diff options
context:
space:
mode:
Diffstat (limited to 'test_ffi/tests')
-rw-r--r--test_ffi/tests/ffi_types.ts15
-rw-r--r--test_ffi/tests/test.js17
2 files changed, 32 insertions, 0 deletions
diff --git a/test_ffi/tests/ffi_types.ts b/test_ffi/tests/ffi_types.ts
index c04c13d79..ff2a4fd5d 100644
--- a/test_ffi/tests/ffi_types.ts
+++ b/test_ffi/tests/ffi_types.ts
@@ -46,6 +46,11 @@ const remote = Deno.dlopen(
parameters: ["bool"],
result: "bool",
},
+ method25: {
+ parameters: [],
+ result: "void",
+ optional: true,
+ },
static1: { type: "usize" },
static2: { type: "pointer" },
static3: { type: "usize" },
@@ -61,6 +66,10 @@ const remote = Deno.dlopen(
static13: { type: "f32" },
static14: { type: "f64" },
static15: { type: "bool" },
+ static16: {
+ type: "bool",
+ optional: true,
+ },
},
);
@@ -277,6 +286,9 @@ let r24_0: true = remote.symbols.method24(true);
let r42_1: number = remote.symbols.method24(true);
<boolean> remote.symbols.method24(Math.random() > 0.5);
+// @ts-expect-error: Optional symbol; can be null.
+remote.symbols.method25();
+
// @ts-expect-error: Invalid member type
const static1_wrong: null = remote.symbols.static1;
const static1_right: number | bigint = remote.symbols.static1;
@@ -322,6 +334,9 @@ const static14_right: number = remote.symbols.static14;
// @ts-expect-error: Invalid member type
const static15_wrong: number = remote.symbols.static15;
const static15_right: boolean = remote.symbols.static15;
+// @ts-expect-error: Invalid member type
+const static16_wrong: boolean = remote.symbols.static16;
+const static16_right: boolean | null = remote.symbols.static16;
// Adapted from https://stackoverflow.com/a/53808212/10873797
type Equal<T, U> = (<G>() => G extends T ? 1 : 2) extends
diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js
index 5e193e99f..f4fc96a1b 100644
--- a/test_ffi/tests/test.js
+++ b/test_ffi/tests/test.js
@@ -252,6 +252,7 @@ const dylib = Deno.dlopen(libPath, {
*/
"static_char": {
type: "pointer",
+ optional: true,
},
"hash": { parameters: ["buffer", "u32"], result: "u32" },
make_rect: {
@@ -281,6 +282,22 @@ const dylib = Deno.dlopen(libPath, {
print_mixed: {
parameters: [{ struct: Mixed }],
result: "void",
+ optional: true,
+ },
+ non_existent_symbol: {
+ parameters: [],
+ result: "void",
+ optional: true,
+ },
+ non_existent_nonblocking_symbol: {
+ parameters: [],
+ result: "void",
+ nonblocking: true,
+ optional: true,
+ },
+ non_existent_static: {
+ type: "u32",
+ optional: true,
},
});
const { symbols } = dylib;