"use strict";

const assert = require("node:assert");
const { test } = require("node:test");
const Module = require("node:module");

// These extraction helpers are pure, but their module also registers VS Code
// providers at runtime. Supply a minimal host shim for unit tests.
const originalLoad = Module._load;
Module._load = function load(request, parent, isMain) {
  if (request === "vscode") return {};
  return originalLoad.call(this, request, parent, isMain);
};
const { extractRouteParams, extractStates } = require("../src/completion");
Module._load = originalLoad;

test("extracts dynamic route params from filename", () => {
  const document = {
    fileName: "apps/sso/app/pages/organizations/[organization]/members/[member].wrn",
  };

  assert.deepEqual(extractRouteParams(document), ["organization", "member"]);
});

test("extracts WRN states", () => {
  const document = {
    getText() {
      return `
page Test {
    state token = ctx.params.token
    state loading = false
}
`;
    },
  };

  assert.deepEqual(extractStates(document), ["token", "loading"]);
});
