Prelude of builtin functions #7
|
|
@ -78,7 +78,7 @@ export const globalFunctions = {
|
|||
},
|
||||
|
||||
// modules
|
||||
use: async function (this: VM, path: string): Promise<Record<string, Value>> {
|
||||
load: async function (this: VM, path: string): Promise<Record<string, Value>> {
|
||||
const scope = this.scope
|
||||
const pc = this.pc
|
||||
|
||||
|
|
|
|||
|
|
@ -4,38 +4,38 @@ import { globalFunctions } from '#prelude'
|
|||
describe('use', () => {
|
||||
test(`imports all a file's functions`, async () => {
|
||||
expect(`
|
||||
math = use ./src/prelude/tests/math
|
||||
math = load ./src/prelude/tests/math
|
||||
math.double 4
|
||||
`).toEvaluateTo(8, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = use ./src/prelude/tests/math
|
||||
math = load ./src/prelude/tests/math
|
||||
math.double (math.double 4)
|
||||
`).toEvaluateTo(16, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = use ./src/prelude/tests/math
|
||||
math = load ./src/prelude/tests/math
|
||||
dbl = math.double
|
||||
dbl (dbl 2)
|
||||
`).toEvaluateTo(8, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = use ./src/prelude/tests/math
|
||||
math = load ./src/prelude/tests/math
|
||||
math.pi
|
||||
`).toEvaluateTo(3.14, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = use ./src/prelude/tests/math
|
||||
math = load ./src/prelude/tests/math
|
||||
math | at 🥧
|
||||
`).toEvaluateTo(3.14159265359, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = use ./src/prelude/tests/math
|
||||
math = load ./src/prelude/tests/math
|
||||
math.🥧
|
||||
`).toEvaluateTo(3.14159265359, globalFunctions)
|
||||
|
||||
expect(`
|
||||
math = use ./src/prelude/tests/math
|
||||
math = load ./src/prelude/tests/math
|
||||
math.add1 5
|
||||
`).toEvaluateTo(6, globalFunctions)
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user