diff --git a/packages/bugc-react/src/examples.test.ts b/packages/bugc-react/src/examples.test.ts new file mode 100644 index 000000000..97ae456af --- /dev/null +++ b/packages/bugc-react/src/examples.test.ts @@ -0,0 +1,44 @@ +/** + * The curated example set must stay small, clean, and — above all — + * compilable: these strings are shipped verbatim into the docs + * playground editor, so a typo would surface as a broken example. + */ +import { describe, it, expect } from "vitest"; +import { compile } from "@ethdebug/bugc"; +import { bugExamples } from "./examples.js"; + +describe("bugExamples", () => { + it("is the curated trio (counter, functions, arrays)", () => { + expect(bugExamples.map((e) => e.name)).toEqual([ + "counter", + "functions", + "arrays", + ]); + }); + + it("gives every example a display name and non-empty source", () => { + for (const ex of bugExamples) { + expect(ex.displayName.trim().length).toBeGreaterThan(0); + expect(ex.code.trim().length).toBeGreaterThan(0); + } + }); + + it("carries no leftover @test annotation blocks", () => { + for (const ex of bugExamples) { + expect(ex.code).not.toContain("@test"); + } + }); + + // Each curated source must compile cleanly to bytecode — this is + // the guard that matters, since these ship straight to the editor. + for (const ex of bugExamples) { + it(`compiles ${ex.name} to bytecode without errors`, async () => { + const result = await compile({ + to: "bytecode", + source: ex.code, + optimizer: { level: 0 }, + }); + expect(result.success).toBe(true); + }); + } +}); diff --git a/packages/bugc-react/src/examples.ts b/packages/bugc-react/src/examples.ts new file mode 100644 index 000000000..99c1dcbd9 --- /dev/null +++ b/packages/bugc-react/src/examples.ts @@ -0,0 +1,102 @@ +/** + * A small, curated set of BUG programs for the docs playground's + * example selector. Kept intentionally short and clean — these + * strings are shown verbatim in the editor, so they carry no + * `/*@test*\/`-style behavioral annotations (unlike the raw + * `packages/bugc/examples` sources they're distilled from). + * + * The set is validated by examples.test.ts: every entry must + * compile to bytecode without errors. + */ + +/** A named, display-labelled BUG source for the example selector. */ +export interface BugExample { + /** Stable identifier (used as the