Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
2.4KB

  1. .equ RAMSTART 0x4000
  2. ; declare DIREC_LASTVAL manually so that we don't have to include directive.asm
  3. .equ DIREC_LASTVAL RAMSTART
  4. jp test
  5. .inc "core.asm"
  6. .inc "str.asm"
  7. .inc "lib/util.asm"
  8. .inc "zasm/util.asm"
  9. .inc "lib/parse.asm"
  10. .inc "zasm/parse.asm"
  11. ; mocks. aren't used in tests
  12. zasmGetPC:
  13. zasmIsFirstPass:
  14. symSelect:
  15. symFindVal:
  16. jp fail
  17. testNum: .db 1
  18. s99: .db "99", 0
  19. s0x99: .db "0x99", 0
  20. s0x100: .db "0x100", 0
  21. s0b0101: .db "0b0101", 0
  22. s0b01010101: .db "0b01010101", 0
  23. sFoo: .db "Foo", 0
  24. test:
  25. ld hl, 0xffff
  26. ld sp, hl
  27. call testLiteral
  28. call testDecimal
  29. ; success
  30. xor a
  31. halt
  32. testLiteral:
  33. ld hl, s99
  34. call parseLiteral
  35. jp nz, fail
  36. push ix \ pop hl
  37. ld a, h
  38. or a
  39. jp nz, fail
  40. ld a, l
  41. cp 99
  42. jp nz, fail
  43. call nexttest
  44. ld hl, s0x100
  45. call parseLiteral
  46. jp nz, fail
  47. push ix \ pop hl
  48. ld a, h
  49. cp 1
  50. jp nz, fail
  51. ld a, l
  52. or a
  53. jp nz, fail
  54. call nexttest
  55. ld hl, sFoo
  56. call parseLiteral
  57. jp z, fail
  58. call nexttest
  59. ld hl, s0b0101
  60. call parseLiteral
  61. jp nz, fail
  62. push ix \ pop hl
  63. ld a, h
  64. or a
  65. jp nz, fail
  66. ld a, l
  67. cp 0b0101
  68. jp nz, fail
  69. call nexttest
  70. ld hl, s0b01010101
  71. call parseLiteral
  72. jp nz, fail
  73. push ix \ pop hl
  74. ld a, h
  75. or a
  76. jp nz, fail
  77. ld a, l
  78. cp 0b01010101
  79. jp nz, fail
  80. call nexttest
  81. .equ FOO 0x42
  82. .equ BAR @+1
  83. ld a, BAR
  84. cp 0x43
  85. jp nz, fail
  86. call nexttest
  87. ret
  88. testDecimal:
  89. ; test valid cases. We loop through tblDecimalValid for our cases
  90. ld b, 5
  91. ld hl, .valid
  92. .loop1:
  93. push hl ; --> lvl 1
  94. ; put expected number in DE
  95. ld e, (hl)
  96. inc hl
  97. ld d, (hl)
  98. inc hl
  99. call parseDecimal
  100. jp nz, fail
  101. push ix \ pop hl
  102. ld a, h
  103. cp d
  104. jp nz, fail
  105. ld a, l
  106. cp e
  107. jp nz, fail
  108. pop hl ; <-- lvl 1
  109. ld de, 8 ; row size
  110. add hl, de
  111. djnz .loop1
  112. call nexttest
  113. ; test invalid cases. We loop through tblDecimalInvalid for our cases
  114. ld b, 4
  115. ld hl, .invalid
  116. .loop2:
  117. call parseDecimal
  118. jp z, fail
  119. ld de, 7 ; row size
  120. add hl, de
  121. djnz .loop2
  122. call nexttest
  123. ret
  124. ; 2b int, 6b str, null-padded
  125. .valid:
  126. .dw 99
  127. .db "99", 0, 0, 0, 0
  128. .dw 65535
  129. .db "65535", 0
  130. ; Space is also accepted as a number "ender"
  131. .dw 42
  132. .db "42 x", 0, 0
  133. ; Tab too
  134. .dw 42
  135. .db "42", 0x09, 'x', 0, 0
  136. ; A simple "0" works too!
  137. .dw 0
  138. .db '0', 0, 0, 0, 0, 0
  139. ; 7b strings, null-padded
  140. .invalid:
  141. ; null string is invalid
  142. .db 0, 0, 0, 0, 0, 0, 0
  143. ; too big, 5 chars
  144. .db "65536", 0, 0
  145. .db "99999", 0, 0
  146. ; too big, 6 chars with rightmost chars being within bound
  147. .db "111111", 0
  148. nexttest:
  149. ld a, (testNum)
  150. inc a
  151. ld (testNum), a
  152. ret
  153. fail:
  154. ld a, (testNum)
  155. halt