brainfuck.test 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ;;;; test brainfuck compilation -*- scheme -*-
  2. ;;;;
  3. ;;;; This library is free software; you can redistribute it and/or
  4. ;;;; modify it under the terms of the GNU Lesser General Public
  5. ;;;; License as published by the Free Software Foundation; either
  6. ;;;; version 3 of the License, or (at your option) any later version.
  7. ;;;;
  8. ;;;; This library is distributed in the hope that it will be useful,
  9. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. ;;;; Lesser General Public License for more details.
  12. ;;;;
  13. ;;;; You should have received a copy of the GNU Lesser General Public
  14. ;;;; License along with this library; if not, write to the Free Software
  15. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. (define-module (tests brainfuck)
  17. #:use-module (test-suite lib)
  18. #:use-module (system base compile))
  19. ;; This program taken from Wikipedia's brainfuck introduction page.
  20. (define prog "
  21. +++ +++ +++ + initialize counter (cell #0) to 10
  22. [ use loop to set the next four cells to 70/100/30/10
  23. > +++ +++ + add 7 to cell #1
  24. > +++ +++ +++ + add 10 to cell #2
  25. > +++ add 3 to cell #3
  26. > + add 1 to cell #4
  27. <<< < - decrement counter (cell #0)
  28. ]
  29. >++ . print 'H'
  30. >+. print 'e'
  31. +++ +++ +. print 'l'
  32. . print 'l'
  33. +++ . print 'o'
  34. >++ . print ' '
  35. <<+ +++ +++ +++ +++ ++. print 'W'
  36. >. print 'o'
  37. +++ . print 'r'
  38. --- --- . print 'l'
  39. --- --- --. print 'd'
  40. >+. print '!'")
  41. (pass-if
  42. (equal? (with-output-to-string
  43. (lambda ()
  44. (call-with-input-string
  45. prog
  46. (lambda (port)
  47. (read-and-compile port #:from 'brainfuck #:to 'value)))))
  48. "Hello World!"))