|
1 | 1 | import fs from "fs-extra";
|
2 | 2 | import { join } from "node:path";
|
| 3 | +import { Imports as ASImports } from "@assemblyscript/loader"; |
3 | 4 | import { fileURLToPath, URL } from "node:url";
|
4 | 5 | import { DebugInfo, CovDebugInfo } from "../../../../src/interface.js";
|
5 |
| -import { isIncluded, json2map, checkFunctionName, checkGenerics } from "../../../../src/utils/index.js"; |
| 6 | +import { |
| 7 | + isIncluded, |
| 8 | + json2map, |
| 9 | + checkFunctionName, |
| 10 | + checkGenerics, |
| 11 | + supplyDefaultFunction, |
| 12 | +} from "../../../../src/utils/index.js"; |
6 | 13 |
|
7 | 14 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
8 | 15 |
|
@@ -65,3 +72,30 @@ test("checkGenerics", () => {
|
65 | 72 | expect(checkGenerics("func<")).toEqual(undefined);
|
66 | 73 | expect(checkGenerics("fun>a")).toEqual(undefined);
|
67 | 74 | });
|
| 75 | + |
| 76 | +describe("supplyDefaultFunction", () => { |
| 77 | + test("supplyTest", () => { |
| 78 | + const mockImportList: WebAssembly.ModuleImportDescriptor[] = [ |
| 79 | + { kind: "function", module: "myenv", name: "processEvent" }, |
| 80 | + { kind: "function", module: "externalMath", name: "add" }, |
| 81 | + { kind: "function", module: "system", name: "getStatus" }, |
| 82 | + { kind: "function", module: "logger", name: "logWarning" }, |
| 83 | + { kind: "function", module: "customOps", name: "combineValues" }, |
| 84 | + ]; |
| 85 | + |
| 86 | + const mockImportObject: ASImports = { |
| 87 | + myenv: {}, |
| 88 | + externalMath: {}, |
| 89 | + system: {}, |
| 90 | + logger: {}, |
| 91 | + customOps: {}, |
| 92 | + }; |
| 93 | + |
| 94 | + supplyDefaultFunction(mockImportList, mockImportObject); |
| 95 | + |
| 96 | + expect(typeof mockImportObject["myenv"]?.["processEvent"]).toBe("function"); |
| 97 | + expect(typeof mockImportObject["system"]?.["getStatus"]).toBe("function"); |
| 98 | + expect(typeof mockImportObject["logger"]?.["logWarning"]).toBe("function"); |
| 99 | + expect(typeof mockImportObject["customOps"]?.["combineValues"]).toBe("function"); |
| 100 | + }); |
| 101 | +}); |
0 commit comments