1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 23:08:06 +11:00

Add tests for parseArgs

This commit is contained in:
Virgil Dupras 2019-11-08 10:18:54 -05:00
parent e972dfe220
commit a3c47f6272

View File

@ -8,14 +8,19 @@ zasmGetPC:
testNum: .db 1 testNum: .db 1
sFoo: .db "Foo", 0
saB: .db "aB", 0
s99: .db "99", 0
test: test:
ld hl, 0xffff ld hl, 0xffff
ld sp, hl ld sp, hl
call testParseHex
call testParseHexPair
call testParseArgs
; success
xor a
halt
testParseHex:
ld a, '8' ld a, '8'
call parseHex call parseHex
jp c, fail jp c, fail
@ -34,29 +39,86 @@ test:
call parseHex call parseHex
jp nc, fail jp nc, fail
call nexttest call nexttest
ret
ld hl, s99 testParseHexPair:
ld hl, .s99
call parseHexPair call parseHexPair
jp c, fail jp c, fail
cp 0x99 cp 0x99
jp nz, fail jp nz, fail
call nexttest call nexttest
ld hl, saB ld hl, .saB
call parseHexPair call parseHexPair
jp c, fail jp c, fail
cp 0xab cp 0xab
jp nz, fail jp nz, fail
call nexttest call nexttest
ld hl, sFoo ld hl, .sFoo
call parseHexPair call parseHexPair
jp nc, fail jp nc, fail
call nexttest call nexttest
ret
; success .sFoo: .db "Foo", 0
xor a .saB: .db "aB", 0
halt .s99: .db "99", 0
testParseArgs:
ld hl, .t1+6
ld de, .t1
ld iy, .t1+3
call .testargs
ld hl, .t2+6
ld de, .t2
ld iy, .t2+3
call .testargs
ld hl, .t3+6
ld de, .t3
ld iy, .t3+3
call .testargs
ret
; HL and DE must be set, and IY must point to expected results in IX
.testargs:
ld ix, sandbox
call parseArgs
jp nz, fail
ld a, (ix)
cp (iy)
jp nz, fail
ld a, (ix+1)
cp (iy+1)
jp nz, fail
ld a, (ix+2)
cp (iy+2)
jp nz, fail
jp nexttest
; Test data format: 3 bytes specs, 3 bytes expected (IX), then the arg string.
; Empty args with empty specs
.t1:
.db 0b0000, 0b0000, 0b0000
.db 0, 0, 0
.db 0
; One arg, one byte spec
.t2:
.db 0b0001, 0b0000, 0b0000
.db 0xe4, 0, 0
.db "e4", 0
; 3 args, 3 bytes spec
.t3:
.db 0b0001, 0b0001, 0b0001
.db 0xe4, 0xab, 0x99
.db "e4 ab 99", 0
nexttest: nexttest:
ld a, (testNum) ld a, (testNum)
@ -67,3 +129,6 @@ nexttest:
fail: fail:
ld a, (testNum) ld a, (testNum)
halt halt
; used as RAM
sandbox: