Skip to content

Commit 098e7a2

Browse files
committed
move test parser/unparser
1 parent 7154b58 commit 098e7a2

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

editor.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -294,27 +294,6 @@ namespace microcode {
294294
this.app.save(SAVESLOT_AUTO, this.progdef.toBuffer())
295295
} else {
296296
this.progdef = ProgramDefn.fromBuffer(new BufferReader(buf))
297-
if (true) {
298-
progToString(this.progdef)
299-
const pas1 = progToStringRet
300-
const buf1 = this.progdef.toBuffer()
301-
// console.log(`PAS1\n${pas1}`)
302-
parseProg(pas1)
303-
const progFromString = parseProgRet
304-
const buf2 = progFromString.toBuffer()
305-
progToString(progFromString)
306-
const pas2 = progToStringRet
307-
// check the programs are the same
308-
for (let i = 0; i < buf.length && i < buf2.length; i++) {
309-
if (buf1[i] != buf2[i]) {
310-
control.assert(
311-
false,
312-
`buf/buf2[${i}] = ${buf[i]}/${buf2[i]}`
313-
)
314-
}
315-
}
316-
assert(buf1.length == buf2.length, `bufs not same length`)
317-
}
318297
}
319298
this.configureP1Keys()
320299
}

mcparser.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,33 @@ namespace microcode {
171171
prog.pages.push(currPage)
172172
parseProgRet = prog
173173
}
174+
175+
//% shim=TD_NOOP
176+
function testSamples() {
177+
const samples = microcode.samples(false)
178+
for (const sample of samples) {
179+
console.log(`check sample ${sample.label}`)
180+
const buf = sample.source
181+
const prog = ProgramDefn.fromBuffer(new BufferReader(buf))
182+
progToString(prog)
183+
const pas1 = progToStringRet
184+
const buf1 = this.progdef.toBuffer()
185+
parseProg(pas1)
186+
const progFromString = parseProgRet
187+
const buf2 = progFromString.toBuffer()
188+
progToString(progFromString)
189+
const pas2 = progToStringRet
190+
// check the programs are the same
191+
for (let i = 0; i < buf.length && i < buf2.length; i++) {
192+
if (buf1[i] != buf2[i]) {
193+
control.assert(
194+
false,
195+
`buf/buf2[${i}] = ${buf[i]}/${buf2[i]}`
196+
)
197+
}
198+
}
199+
assert(buf1.length == buf2.length, `bufs not same length`)
200+
console.log(`${sample.label}\n${pas2}`)
201+
}
202+
}
174203
}

0 commit comments

Comments
 (0)