test-comments-round-trip.rkt (1908B)
1 #lang racket 2 3 (require rackunit 4 "../../comments/hide-comments.rkt" 5 "../../comments/restore-comments.rkt" 6 "same-syntax.rkt") 7 8 (define round-trip (compose restore-#%comment hide-#%comment)) 9 10 (define-syntax (check-round-trip stx) 11 (syntax-case stx () 12 [(_ a) 13 (datum->syntax #'here 14 `(begin 15 (check-same-syntax (round-trip ,#'a) ,#'a) 16 (check-equal? (syntax->datum (round-trip ,#'a)) 17 (syntax->datum ,#'a))) 18 stx)])) 19 20 ;; ============================================================================= 21 22 (let ([stx #'(a b c)]) 23 (check-same-syntax stx (hide-#%comment stx))) 24 25 (check-round-trip #'(a (#%comment "b") c)) 26 27 (check-round-trip #'((#%comment "0") (#%comment "1") 28 a 29 (#%comment "b") 30 (#%comment "bb") 31 c 32 (#%comment "d") 33 (#%comment "dd"))) 34 (check-round-trip #'([#%comment c1] 35 a 36 [#%comment c2] 37 . ([#%comment c3] b [#%comment c4]))) 38 (check-round-trip #'([#%comment c1] 39 a 40 [#%comment c2] 41 . ([#%comment c3] 42 . ([#%comment c4] b [#%comment c5])))) 43 (check-round-trip #'([#%comment c1] 44 a 45 [#%comment c2] 46 . ([#%comment c3] 47 . ([#%comment c4] [#%comment c5])))) 48 (check-round-trip #'([#%comment c1] 49 a 50 ([#%comment c2]) 51 b)) 52 (check-round-trip #'([#%comment c1] 53 a 54 ([#%comment c2] . b) 55 c))