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.

132 lines
1.9KB

  1. ; *** requirements ***
  2. ; ascii.h
  3. ; core
  4. ; stdio
  5. ; lib/ari
  6. ; lib/fmt
  7. testNum: .db 1
  8. ; Each time we call assertSP, we verify that our stack isn't imbalanced by
  9. ; comparing SP to its saved value. Whenever your "base" SP value change,
  10. ; generally at the beginning of a test routine, run "ld (testSP), sp" to have
  11. ; proper value saved to heap.
  12. testSP: .dw 0xffff
  13. STDIO_PUTC:
  14. out (0), a
  15. cp a
  16. ret
  17. STDIO_GETC:
  18. jp unsetZ
  19. assertZ:
  20. ret z
  21. ld hl, .msg
  22. call printstr
  23. jp fail
  24. .msg:
  25. .db "Z not set", CR, LF, 0
  26. assertNZ:
  27. ret nz
  28. ld hl, .msg
  29. call printstr
  30. jp fail
  31. .msg:
  32. .db "Z set", CR, LF, 0
  33. assertC:
  34. ret c
  35. ld hl, .msg
  36. call printstr
  37. jp fail
  38. .msg:
  39. .db "C not set", CR, LF, 0
  40. assertNC:
  41. ret nc
  42. ld hl, .msg
  43. call printstr
  44. jp fail
  45. .msg:
  46. .db "C set", CR, LF, 0
  47. ; Assert that A == B
  48. assertEQB:
  49. cp b
  50. ret z
  51. call printHex
  52. call printcrlf
  53. ld a, b
  54. call printHex
  55. call printcrlf
  56. ld hl, .msg
  57. call printstr
  58. jp fail
  59. .msg:
  60. .db "A != B", CR, LF, 0
  61. ; Assert that HL == DE
  62. assertEQW:
  63. ld a, h
  64. cp d
  65. jr nz, .fail
  66. ld a, l
  67. cp e
  68. ret z
  69. .fail:
  70. call printHexPair
  71. call printcrlf
  72. ex de, hl
  73. call printHexPair
  74. call printcrlf
  75. ld hl, .msg
  76. call printstr
  77. jp fail
  78. .msg:
  79. .db "HL != DE", CR, LF, 0
  80. ; Given a list of pointer to test data structures in HL and a pointer to a test
  81. ; routine in IX, call (IX) with HL pointing to the test structure until the list
  82. ; points to a zero. See testParseExpr in test_expr for an example usage.
  83. testList:
  84. push hl ; --> lvl 1
  85. call intoHL
  86. ld a, h
  87. or l
  88. jr z, .end
  89. call callIX
  90. call nexttest
  91. pop hl ; <-- lvl 1
  92. inc hl \ inc hl
  93. jr testList
  94. .end:
  95. pop hl ; <-- lvl 1
  96. ret
  97. ; test that SP == testSP
  98. assertSP:
  99. ld hl, (testSP)
  100. ; offset the fact that we call assertSP
  101. dec hl \ dec hl
  102. or a ; reset carry
  103. sbc hl, sp
  104. ret z
  105. ld hl, .msg
  106. call printstr
  107. jr fail
  108. .msg:
  109. .db "Wrong SP", CR, LF, 0
  110. nexttest:
  111. ld a, (testNum)
  112. inc a
  113. ld (testNum), a
  114. ret
  115. fail:
  116. ld a, (testNum)
  117. halt