index.js 829 B

123456789101112131415161718192021222324252627282930313233
  1. const { assert } = require("chai");
  2. const { parse } = require("@webassemblyjs/wast-parser");
  3. const { moduleContextFromModuleAST } = require("../lib");
  4. const contextFromWast = wast => moduleContextFromModuleAST(parse(wast).body[0]);
  5. describe("module context", () => {
  6. describe("start segment", () => {
  7. it("should return the start function offset", () => {
  8. const context = contextFromWast(`
  9. (module
  10. (func)
  11. (func)
  12. (start 1)
  13. )
  14. `);
  15. assert.isOk(context.getStart());
  16. assert.typeOf(context.getStart(), "number");
  17. assert.equal(context.getStart(), 1);
  18. });
  19. it("should return null if no start function", () => {
  20. const context = contextFromWast(`
  21. (module (func))
  22. `);
  23. assert.isNull(context.getStart());
  24. });
  25. });
  26. });