-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.vscode/ | ||
|
||
deno.json | ||
deno.jsonc | ||
deno.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"tasks": { | ||
"test": "deno test --unstable --allow-ffi test/unit/base_utils/convert.ts" | ||
"test": "deno test --unstable --allow-ffi --allow-read test/unit/base_utils/*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
assert, | ||
assertEquals, | ||
} from "https://deno.land/[email protected]/assert/mod.ts"; | ||
import * as mod from "../../../src/base_utils/ffipp.js"; | ||
|
||
Deno.test("createType", () => { | ||
const symbol = "test"; | ||
const size = 1; | ||
const serilize = (arg_0: unknown) => arg_0; | ||
const deserilize = (arg_0: unknown) => arg_0; | ||
|
||
const result = mod.createType({ | ||
symbol, | ||
size, | ||
serilize, | ||
deserilize, | ||
}); | ||
|
||
assert(result, "result is null"); | ||
assertEquals( | ||
typeof result, | ||
"function", | ||
"result is not a function", | ||
); | ||
|
||
const parameters = [1, 2, 3] as any; | ||
const instance = result(parameters); | ||
|
||
assert(instance, "instance is null"); | ||
assertEquals(typeof instance, "object", "instance is not an object"); | ||
assert(Object.hasOwn(instance, "result"), "instance has no result property"); | ||
assert( | ||
Object.hasOwn(instance, "parameters"), | ||
"instance has no parameters property", | ||
); | ||
assertEquals( | ||
instance.parameters, | ||
[parameters], | ||
"instance.parameters is not the same as the original parameters", | ||
); | ||
assertEquals( | ||
instance.result, | ||
result, | ||
"instance.result is not the same as the original result", | ||
); | ||
// @ts-ignore symbol is a private property | ||
assertEquals(result.symbol, symbol, "result.symbol is not the same"); | ||
// @ts-ignore symbol is a private property | ||
assertEquals(result.size, size, "result.size is not the same"); | ||
// @ts-ignore symbol is a private property | ||
assertEquals( | ||
// @ts-ignore symbol is a private property | ||
result.serilize, | ||
serilize, | ||
"result.serilize is not the same", | ||
); | ||
assertEquals( | ||
// @ts-ignore symbol is a private property | ||
result.deserilize, | ||
deserilize, | ||
"result.deserilize is not the same", | ||
); | ||
}); | ||
|
||
// TODO: test openLib | ||
|
||
Deno.test("libName", () => { | ||
const name = "test"; | ||
const version = 1; | ||
const result = mod.libName(name, version); | ||
|
||
// TODO: fake check every OS | ||
switch (Deno.build.os) { | ||
case "darwin": | ||
assertEquals(result, `lib${name}.${version}.dylib`); | ||
break; | ||
case "linux": | ||
assertEquals(result, `lib${name}.so.${version}`); | ||
break; | ||
case "windows": | ||
assertEquals(result, `lib${name}-${version}.dll`); | ||
break; | ||
default: | ||
throw new Error("Unsupported OS"); | ||
} | ||
}); |