/* Entry point pulled in by <script type="module" src>.
 *
 * Two importers of modmath (this file and modutil) must share one instance:
 * if the loader instantiated it twice, `counter` below would go out of step
 * with the copy modutil.bump() increments.
 */

import * as math from "./modmath.mjs";
import { bump, counter, hypotSquared, awaited, TAU } from "./modutil.mjs";

import { report } from "./modreport.mjs";

report("named import", math.add(2, 3) === 5);
report("default export", math.default(4) === 16);
report("namespace import", typeof math === "object" && math.TAU === TAU);
report("re-export", TAU > 6.28 && TAU < 6.29);
report("import.meta.url", /modmath\.mjs$/.test(math.whoami));
report("top-level await", awaited === "tla-ok");

/* Live bindings: `counter` is a binding into modutil, not a copy taken at
 * import time, so bumping there is visible here. */
bump();
bump();
report("live binding", counter === 2);

report("shared instance", hypotSquared(3, 4) === 25);

/* Dynamic import returns a promise, so this only ever resolves if the
 * microtask queue is drained. */
import("./modlazy.mjs").then(function (m) {
	report("dynamic import", m.lazy === "lazy-ok");
}).catch(function (e) {
	report("dynamic import", false, String(e));
});
