From d8e97c0f20966ffb765f7359d27e22c9d8086ab8 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sun, 5 Oct 2025 22:24:46 -0700 Subject: [PATCH] test examples --- tests/examples.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/examples.test.ts diff --git a/tests/examples.test.ts b/tests/examples.test.ts new file mode 100644 index 0000000..29a0bb7 --- /dev/null +++ b/tests/examples.test.ts @@ -0,0 +1,31 @@ +import { test, expect } from "bun:test" +import { readdirSync } from "fs" +import { join } from "path" +import { toBytecode } from "#bytecode" +import { VM } from "#vm" + +// Get all .reef files from examples directory +const examplesDir = join(import.meta.dir, "..", "examples") +const exampleFiles = readdirSync(examplesDir) + .filter(file => file.endsWith(".reef")) + .sort() + +// Create a test for each example file +for (const file of exampleFiles) { + test(`examples/${file} runs without errors`, async () => { + const filePath = join(examplesDir, file) + const content = await Bun.file(filePath).text() + + // Parse and run the bytecode + const bytecode = toBytecode(content) + const vm = new VM(bytecode) + + // Should not throw + const result = await vm.run() + + // Result should be a valid Value + expect(result).toBeDefined() + expect(result).toHaveProperty("type") + expect(["null", "boolean", "number", "string", "array", "dict", "function"]).toContain(result.type) + }) +}