mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
step, draw and LiveWidget run programs from a bounded cache of compiled programs (Runtime.compile, the 32 last used). LiveWidget's host functions throw through psychoscript/effect defects, so an error for posting a function (or an unknown canvas key) reports the call's line and column, as the interpreter's own argument errors do.
13 lines
623 B
TypeScript
13 lines
623 B
TypeScript
import { expect, test } from "bun:test"
|
|
import { compiled } from "../src/compiled.js"
|
|
|
|
test("a program is compiled once, the cache keeps the 32 last used, and code that doesn't compile stays text", () => {
|
|
const first = compiled("return 1")
|
|
expect(typeof first).not.toBe("string")
|
|
expect(compiled("return 1")).toBe(first)
|
|
Array.from({ length: 31 }, (_, index) => compiled(`return ${index + 2}`))
|
|
expect(compiled("return 1")).toBe(first)
|
|
Array.from({ length: 32 }, (_, index) => compiled(`return ${index + 100}`))
|
|
expect(compiled("return 1")).not.toBe(first)
|
|
expect(compiled("return (")).toBe("return (")
|
|
})
|