48 lines
881 B
TypeScript
48 lines
881 B
TypeScript
import { test, expect } from "bun:test"
|
|
import { run } from "#index"
|
|
import { toBytecode } from "#bytecode"
|
|
|
|
test("adding numbers", async () => {
|
|
const str = `
|
|
PUSH 1
|
|
PUSH 5
|
|
ADD
|
|
`
|
|
expect(await run(toBytecode(str))).toEqual({ type: 'number', value: 6 })
|
|
|
|
const str2 = `
|
|
PUSH 100
|
|
PUSH 500
|
|
ADD
|
|
`
|
|
expect(await run(toBytecode(str2))).toEqual({ type: 'number', value: 600 })
|
|
})
|
|
|
|
test("subtracting numbers", async () => {
|
|
const str = `
|
|
PUSH 5
|
|
PUSH 2
|
|
SUB
|
|
`
|
|
expect(await run(toBytecode(str))).toEqual({ type: 'number', value: 3 })
|
|
})
|
|
|
|
test("multiplying numbers", async () => {
|
|
const str = `
|
|
PUSH 5
|
|
PUSH 2
|
|
MUL
|
|
`
|
|
expect(await run(toBytecode(str))).toEqual({ type: 'number', value: 10 })
|
|
})
|
|
|
|
test("dividing numbers", async () => {
|
|
const str = `
|
|
PUSH 10
|
|
PUSH 2
|
|
DIV
|
|
`
|
|
expect(await run(toBytecode(str))).toEqual({ type: 'number', value: 5 })
|
|
})
|
|
|