forked from defunkt/ReefVM
test examples
This commit is contained in:
parent
ec2b1a9b22
commit
d8e97c0f20
31
tests/examples.test.ts
Normal file
31
tests/examples.test.ts
Normal file
|
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user