/collects/tests/macro-debugger/tests/hiding.rkt

http://github.com/gmarceau/PLT · Racket · 209 lines · 84 code · 7 blank · 118 comment · 3 complexity · 2c90ca959ae0602f1edec691b6ccba3b MD5 · raw file

  1. #lang scheme/base
  2. (require rackunit)
  3. (require macro-debugger/model/debug
  4. "../test-setup.rkt")
  5. (provide specialized-hiding-tests)
  6. ;; == Macro hiding
  7. (define-syntax test-hiding/policy
  8. (syntax-rules ()
  9. [(th form hidden-e2 policy)
  10. (test-case (format "~s" 'form)
  11. (let-values ([(steps binders uses stx exn)
  12. (parameterize ((macro-policy policy))
  13. (reductions+ (trace/k 'form)))])
  14. (check-pred syntax? stx)
  15. (check-equal? (syntax->datum stx) 'hidden-e2)))]))
  16. (define-syntax test-trivial-hiding
  17. (syntax-rules ()
  18. [(tth form hidden-e2)
  19. (test-hiding/policy form hidden-e2 (lambda (m) #t))]))
  20. (define-syntax test-trivial-hiding/id
  21. (syntax-rules ()
  22. [(tthi form)
  23. (test-trivial-hiding form form)]))
  24. (define-syntax-rule (test-T-hiding form hidden-e2)
  25. (test-hiding/policy form hidden-e2 T-policy))
  26. (define-syntax-rule (test-T-hiding/id form)
  27. (test-T-hiding form form))
  28. (define-syntax-rule (test-Tm-hiding form hidden-e2)
  29. (test-hiding/policy form hidden-e2 Tm-policy))
  30. (define-syntax-rule (test-Tm-hiding/id form)
  31. (test-Tm-hiding form form))
  32. (define specialized-hiding-tests
  33. (test-suite "Specialized macro hiding tests"
  34. (test-suite "Result tests for trivial hiding"
  35. (test-suite "Atomic expressions"
  36. (test-trivial-hiding/id *)
  37. (test-trivial-hiding 1 '1)
  38. (test-trivial-hiding (#%datum . 1) '1)
  39. (test-trivial-hiding unbound-var (#%top . unbound-var)))
  40. (test-suite "Basic expressions"
  41. (test-trivial-hiding/id (if * * *))
  42. (test-trivial-hiding/id (with-continuation-mark * * *))
  43. (test-trivial-hiding/id (define-values (x) *))
  44. (test-trivial-hiding/id (define-syntaxes (x) *)))
  45. (test-suite "Binding expressions"
  46. (test-trivial-hiding/id (lambda (x) *))
  47. (test-trivial-hiding/id (case-lambda [(x) *] [(x y) *]))
  48. (test-trivial-hiding/id (let-values ([(x) *]) *))
  49. (test-trivial-hiding/id (letrec-values ([(x) *]) *)))
  50. (test-suite "Blocks"
  51. (test-trivial-hiding/id (lambda (x y) x y))
  52. (test-trivial-hiding (lambda (x y z) (begin x y) z)
  53. (lambda (x y z) x y z))
  54. (test-trivial-hiding (lambda (x y z) x (begin y z))
  55. (lambda (x y z) x y z))
  56. (test-trivial-hiding (lambda (x) (define-values (y) x) y)
  57. (lambda (x) (letrec-values ([(y) x]) y)))
  58. (test-trivial-hiding (lambda (x) (begin (define-values (y) x)) y)
  59. (lambda (x) (letrec-values ([(y) x]) y)))
  60. (test-trivial-hiding (lambda (x) (begin (define-values (y) x) y) x)
  61. (lambda (x) (letrec-values ([(y) x]) y x)))
  62. (test-trivial-hiding (lambda (x) (id (define-values (y) x)) x)
  63. (lambda (x) (letrec-values ([(y) x]) x)))
  64. (test-trivial-hiding (lambda (x) (id (begin (define-values (y) x) x)))
  65. (lambda (x) (letrec-values ([(y) x]) x)))
  66. (test-trivial-hiding (lambda (x) (define-values (y) (id x)) y)
  67. (lambda (x) (letrec-values ([(y) x]) y)))
  68. (test-trivial-hiding (lambda (x y) x (id y))
  69. (lambda (x y) x y))
  70. (test-trivial-hiding (lambda (x) (define-values (y) (id x)) y)
  71. (lambda (x) (letrec-values ([(y) x]) y))))
  72. #|
  73. ;; Old hiding mechanism never did letrec transformation (unless forced)
  74. (test-suite "Block normalization"
  75. (test-trivial-hiding/id (lambda (x y) x y))
  76. (test-trivial-hiding/id (lambda (x y z) (begin x y) z))
  77. (test-trivial-hiding/id (lambda (x y z) x (begin y z)))
  78. (test-trivial-hiding/id (lambda (x) (define-values (y) x) y))
  79. (test-trivial-hiding/id (lambda (x) (begin (define-values (y) x)) y))
  80. (test-trivial-hiding/id (lambda (x) (begin (define-values (y) x) y) x))
  81. (test-trivial-hiding (lambda (x) (id x))
  82. (lambda (x) x))
  83. (test-trivial-hiding (lambda (x) (id (begin (define-values (y) x) x)))
  84. (lambda (x) (begin (define-values (y) x) x)))
  85. (test-trivial-hiding (lambda (x) (define-values (y) (id x)) y)
  86. (lambda (x) (define-values (y) x) y)))
  87. |#
  88. )
  89. (test-suite "Result tests for T hiding"
  90. (test-suite "Atomic expressions"
  91. (test-T-hiding/id *)
  92. (test-T-hiding/id 1)
  93. (test-T-hiding/id unbound-var))
  94. (test-suite "Basic expressions"
  95. (test-T-hiding/id (if 1 2 3))
  96. (test-T-hiding/id (with-continuation-mark 1 2 3))
  97. (test-T-hiding/id (define-values (x) 1))
  98. (test-T-hiding/id (define-syntaxes (x) 1)))
  99. (test-suite "Opaque macros"
  100. (test-T-hiding/id (id '1))
  101. (test-T-hiding/id (id 1))
  102. (test-T-hiding/id (id (id '1)))
  103. ;; app is hidden:
  104. (test-T-hiding/id (+ '1 '2)))
  105. (test-suite "Transparent macros"
  106. (test-T-hiding (Tlist x)
  107. (list x))
  108. (test-T-hiding (Tid x) x)
  109. (test-T-hiding (Tlist (id x))
  110. (list (id x)))
  111. (test-T-hiding (Tid (id x))
  112. (id x))
  113. (test-T-hiding (id (Tlist x))
  114. (id (list x)))
  115. (test-T-hiding (id (Tid x))
  116. (id x)))
  117. (test-suite "Blocks"
  118. (test-T-hiding/id (lambda (x y) x y))
  119. (test-T-hiding (lambda (x y z) (begin x y) z)
  120. (lambda (x y z) x y z))
  121. (test-T-hiding (lambda (x y z) x (begin y z))
  122. (lambda (x y z) x y z))
  123. (test-T-hiding (lambda (x) (define-values (y) x) y)
  124. (lambda (x) (letrec-values ([(y) x]) y)))
  125. (test-T-hiding (lambda (x) (begin (define-values (y) x)) y)
  126. (lambda (x) (letrec-values ([(y) x]) y)))
  127. (test-T-hiding (lambda (x) (begin (define-values (y) x) y) x)
  128. (lambda (x) (letrec-values ([(y) x]) y x)))
  129. (test-T-hiding (lambda (x) (id x))
  130. (lambda (x) (id x)))
  131. (test-T-hiding (lambda (x) (Tid x))
  132. (lambda (x) x))
  133. (test-T-hiding/id (lambda (x) (id (define-values (y) x)) x))
  134. (test-T-hiding (lambda (x) (id (define-values (y) x)) (Tid x))
  135. (lambda (x) (id (define-values (y) x)) x))
  136. (test-T-hiding/id (lambda (x) (id (begin (define-values (y) x) x))))
  137. (test-T-hiding (lambda (x) (begin (id (define-values (y) x)) y))
  138. (lambda (x) (id (define-values (y) x)) y))
  139. (test-T-hiding (lambda (x) (id (begin (Tid (define-values (y) x)))) (Tid y))
  140. (lambda (x) (id (begin (define-values (y) x))) y))
  141. (test-T-hiding (lambda (x) (id (begin (Tid (define-values (y) x)))) x (Tid y))
  142. (lambda (x) (id (begin (define-values (y) x))) x y))
  143. (test-T-hiding (lambda (x) (define-values (y) (id x)) y)
  144. (lambda (x) (letrec-values ([(y) (id x)]) y)))
  145. (test-T-hiding (lambda (x y) x (id y))
  146. (lambda (x y) x (id y)))
  147. (test-T-hiding (lambda (x y) x (Tid y))
  148. (lambda (x y) x y))
  149. (test-T-hiding (lambda (x) (id (define-values (y) x)) x (Tid y))
  150. (lambda (x) (id (define-values (y) x)) x y))
  151. (test-T-hiding/id (lambda (x) (id (define-values (y) (id x))) y))
  152. (test-T-hiding (lambda (x) (id (define-values (y) (Tid x))) y)
  153. (lambda (x) (id (define-values (y) x)) y)))
  154. (test-suite "Binding expressions"
  155. (test-T-hiding/id (lambda (x) x))
  156. (test-T-hiding/id (lambda (x) (id x))))
  157. (test-suite "Module declarations"
  158. (test-T-hiding (module m mzscheme
  159. (require 'helper)
  160. (define x 1))
  161. (module m mzscheme
  162. (require 'helper)
  163. (define x 1)))
  164. (test-Tm-hiding (module m mzscheme
  165. (require 'helper)
  166. (define x 1))
  167. (module m mzscheme
  168. (#%module-begin
  169. (require 'helper)
  170. (define x 1))))
  171. (test-T-hiding (module m mzscheme
  172. (require 'helper)
  173. (define x (Tlist 1)))
  174. (module m mzscheme
  175. (require 'helper)
  176. (define x (list 1))))
  177. (test-Tm-hiding (module m mzscheme
  178. (require 'helper)
  179. (define x (Tlist 1)))
  180. (module m mzscheme
  181. (#%module-begin
  182. (require 'helper)
  183. (define x (list 1)))))
  184. (test-T-hiding (module m mzscheme
  185. (#%plain-module-begin
  186. (require 'helper)
  187. (define x (Tlist 1))))
  188. (module m mzscheme
  189. (#%plain-module-begin
  190. (require 'helper)
  191. (define x (list 1)))))
  192. (test-Tm-hiding (module m mzscheme
  193. (#%plain-module-begin
  194. (require 'helper)
  195. (define x (Tlist 1))))
  196. (module m mzscheme
  197. (#%plain-module-begin
  198. (require 'helper)
  199. (define x (list 1)))))))))