parent
c905af1214
commit
f872546c46
File diff suppressed because it is too large
Load Diff
@ -1,26 +1,38 @@ |
|||||||
|
import test from "ava"; |
||||||
|
import fs from "fs"; |
||||||
import { ButtonMachine } from '../src/buttons.js'; |
import { ButtonMachine } from '../src/buttons.js'; |
||||||
|
|
||||||
let code = [ |
const run_code = (source) => { |
||||||
['PUSH', -10], |
const machine = new ButtonMachine(); |
||||||
['PUSH', 1], |
const code = machine.parse(source.toString()); |
||||||
['ADD'], |
machine.load(code); |
||||||
['POKE', 1], |
machine.run(); |
||||||
['JNZ', 1], |
|
||||||
['STOR', 'IX'], |
return machine; |
||||||
['POP'], |
} |
||||||
['PEEK', 1], |
|
||||||
['JNZ', 6], |
test("parse and run file", t => { |
||||||
]; |
const test_src = [ |
||||||
|
["./tests/basic.btn", 74], |
||||||
let machine = new ButtonMachine(); |
["./tests/test2.btn", 0] |
||||||
machine.load(code); |
] |
||||||
|
|
||||||
const ops = ButtonMachine.operations(); |
for(let [source, expected] of test_src) { |
||||||
const registers = machine.register_names(); |
console.log("TESTING FILE", source, "EXPECTING", expected); |
||||||
|
const code = fs.readFileSync(source); |
||||||
machine.run(); |
const machine = run_code(code); |
||||||
|
|
||||||
console.log("STACK TOP", machine.stack_top); |
t.is(machine.stack_top, expected); |
||||||
console.log("REGISTERS", registers); |
|
||||||
console.log("STACK", machine.stack); |
console.log("STACK TOP", machine.stack_top); |
||||||
console.log("RAM", machine.ram); |
} |
||||||
|
}); |
||||||
|
|
||||||
|
test("fuzz the parser", t => { |
||||||
|
const code = fs.readFileSync("./tests/garbag1.btn"); |
||||||
|
const machine = run_code(code); |
||||||
|
|
||||||
|
t.is(machine.halted, true); |
||||||
|
t.is(machine.error_line, 0); |
||||||
|
|
||||||
|
}); |
||||||
|
@ -0,0 +1,9 @@ |
|||||||
|
asdlkj |
||||||
|
sadf |
||||||
|
sad |
||||||
|
fas |
||||||
|
f |
||||||
|
sadfg |
||||||
|
asdflkhja sdflk;jas |
||||||
|
|
||||||
|
sad'dfkjlsadflkjsadfjlsad |
@ -0,0 +1,9 @@ |
|||||||
|
PUSH -10 |
||||||
|
PUSH 1 |
||||||
|
ADD |
||||||
|
POKE 1 |
||||||
|
JNZ 1 |
||||||
|
STOR IX |
||||||
|
POP |
||||||
|
PEEK 1 |
||||||
|
JNZ 6 |
Loading…
Reference in new issue