inicheck.joy 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. (* inicheck.joy -- primitive unit test combinators.
  2. Copyright © 2016 Eric Bavier <bavier@member.fsf.org>
  3. Joy is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 3 of the License, or (at your
  6. option) any later version.
  7. Joy is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  9. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  10. License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with Joy. If not, see <http://www.gnu.org/licenses/>.
  13. *)
  14. (* Commentary:
  15. Test routines that make use of only Joy primitives, so that the
  16. standard library routines may be tested.
  17. Code: *)
  18. DEFINE
  19. (* private *)
  20. newline == '\n putch ;
  21. puts == putchars newline ;
  22. primitive-check ==
  23. putchars " " putchars
  24. ["ok" puts] ["fail" puts]
  25. choice infra ;
  26. (* Use these combinators in the following way:
  27. "foo" [P] satisfies [P'] ? .
  28. P is executed, immediately followed by a predicate P', which
  29. should leave true or false on the top of the stack to indicate
  30. success or failure of the test. If succesful, "foo ok" is
  31. printed to stdout, otherwise "foo fail". *)
  32. satisfies == swap putchars [] swap infra ;
  33. ? == infra uncons pop
  34. [" ok" puts] [" fail" puts]
  35. choice [] swap infra pop ;
  36. END
  37. (* Before exporting these test routines, do what sanity checking we
  38. can do on our primitives. *)
  39. [] [true] uncons pop "choice" primitive-check
  40. [] 3 3 = "=" primitive-check
  41. [] 1 3 + 4 = "+" primitive-check
  42. [] 4 2 - 2 = "=" primitive-check
  43. [] 2 4 < "<" primitive-check
  44. [] 4 2 > ">" primitive-check
  45. [] 2 dup + 4 = "dup" primitive-check
  46. [] 2 4 pop 2 = "pop" primitive-check
  47. [] [3 1] dup [+] infra uncons pop 4 = "dup list" primitive-check
  48. [] [true] uncons pop logical "logical" primitive-check
  49. [] [false] uncons pop logical "logical false" primitive-check
  50. [] 'b char "char" primitive-check
  51. [] 2 integer "integer" primitive-check
  52. [] "foo" string "string" primitive-check
  53. [] ['b 2] string [false] uncons pop = "list!string" primitive-check
  54. [] 2 string [false] uncons pop = "num!string" primitive-check
  55. [] [2] list "list" primitive-check