base-check.scm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; Tests for stuff in the base language.
  3. (define-test-suite base-tests)
  4. ; adapted from the R6RS document
  5. (define-test-case quasiquote base-tests
  6. (check `(list ,(+ 1 2) 4) => '(list 3 4))
  7. (check (let ((name 'a)) `(list ,name ',name))
  8. => '(list a (quote a)))
  9. (check `(a ,(+ 1 2) ,@(map abs '(4 -5 6)) b)
  10. => '(a 3 4 5 6 b))
  11. (check `((foo ,(- 10 3)) ,@(cdr '(c)) . ,(car '(cons)))
  12. => '((foo 7) . cons))
  13. (check `#(10 5 ,(even? 4) ,@(map even? '(2 3 5 7)) 8)
  14. => '#(10 5 #t #t #f #f #f 8))
  15. (check (let ((name 'foo))
  16. `((unquote name name name)))
  17. => '(foo foo foo))
  18. (check (let ((name '(foo)))
  19. `((unquote-splicing name name name)))
  20. => '(foo foo foo))
  21. (check (let ((q '((append x y) (even? 9))))
  22. ``(foo ,,@q))
  23. => '`(foo (unquote (append x y) (even? 9))))
  24. (check (let ((x '(2 3))
  25. (y '(4 5)))
  26. `(foo (unquote (append x y) (even? 9))))
  27. => '(foo (2 3 4 5) #f))
  28. (check `(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f)
  29. => '(a `(b ,(+ 1 2) ,(foo 4 d) e) f))
  30. (check (let ((name1 'x)
  31. (name2 'y))
  32. `(a `(b ,,name1 ,',name2 d) e))
  33. => '(a `(b ,x ,'y d) e)))
  34. (define-test-case dynamic-wind base-tests
  35. (let* ((f (make-fluid 'top))
  36. (log '())
  37. (report (lambda (foo)
  38. (set! log (cons (cons foo (fluid f)) log)))))
  39. ((call-with-current-continuation
  40. (lambda (k1)
  41. (let-fluid f 1
  42. (lambda ()
  43. (dynamic-wind
  44. (lambda () (report 'wind-1))
  45. (lambda ()
  46. (let-fluid f 2
  47. (lambda ()
  48. (dynamic-wind
  49. (lambda () (report 'wind-2))
  50. (lambda ()
  51. (let-fluid f 3
  52. (lambda ()
  53. (report 'before-throw-out)
  54. (call-with-current-continuation
  55. (lambda (k2)
  56. (k1 (lambda ()
  57. (report 'after-throw-out)
  58. (k2 #f)))))
  59. (report 'after-throw-in)
  60. (lambda () (report 'done)))))
  61. (lambda () (report 'unwind-2))))))
  62. (lambda () (report 'unwind-1))))))))
  63. (check log
  64. => '((done . top)
  65. (unwind-1 . 1)
  66. (unwind-2 . 2)
  67. (after-throw-in . 3)
  68. (wind-2 . 1)
  69. (wind-1 . top)
  70. (after-throw-out . top)
  71. (unwind-1 . 1)
  72. (unwind-2 . 2)
  73. (before-throw-out . 3)
  74. (wind-2 . 2)
  75. (wind-1 . 1)))))