A few more tests

This commit is contained in:
Jay McCarthy 2015-10-02 19:54:20 -04:00
parent e9967c389b
commit df019df8a3

View File

@ -1,33 +1,50 @@
#lang racket/base #lang racket/base
read-accept-dot (define STX? #f)
read-accept-infix-dot
(define (read-remix) (define (remix-f f)
(parameterize ([read-square-bracket-as-paren #f] (parameterize ([read-square-bracket-as-paren #f]
[read-curly-brace-as-paren #f] [read-curly-brace-as-paren #f]
[read-square-bracket-with-tag #t] [read-square-bracket-with-tag #t]
[read-curly-brace-with-tag #t]) [read-curly-brace-with-tag #t]
(read))) [read-accept-dot #f]
[read-accept-infix-dot #f]
[read-cdot #t])
(f)))
(define (remix-read) (remix-f read))
(define (remix-read-syntax) (remix-f read-syntax))
(module+ test (module+ test
(require rackunit (require rackunit
racket/port) racket/port)
(define-syntax-rule (testit* t ...) (define-syntax-rule (testit* t ...)
(begin (testit . t) ...)) (begin (testit . t) ...))
(define-syntax-rule (testit str d)
(testit-f str 'd #'d))
(define (testit-f str qd stx)
(check-equal? (with-input-from-string str remix-read) qd)
(when STX?
(check-equal? (with-input-from-string str remix-read-syntax) stx)))
(define (testit str qd) (check-false (read-square-bracket-with-tag))
(check-equal? (with-input-from-string str read-remix) qd)) (check-false (read-curly-brace-with-tag))
(check-false (read-cdot))
(testit* (testit*
["[1 2 3]" '(#%brackets 1 2 3)] ["[1 2 3]" (#%brackets 1 2 3)]
["{1 2 3}" '(#%braces 1 2 3)] ["{1 2 3}" (#%braces 1 2 3)]
["a.b" '(#%dot a b)] ["a.b" (#%dot a b)]
["1.a" '(#%dot 1 a)] ["a .b" (#%dot a b)]
["1.2.a" '(#%dot 1.2 a)] ["a. b" (#%dot a b)]
["a.1.2" '(#%dot a 1.2)] ["a . b" (#%dot a b)]
["a.b.c" '(#%dot a (#%dot b c))] ["1.a" (#%dot 1 a)]
["a.(b c)" '(#%dot a (b c))] ["1.2.a" (#%dot 1.2 a)]
["(a b).c" '(#%dot (a b) c)] ["1 .2.a" (#%dot 1 (#%dot 2 a))]
["(a b).(c d)" '(#%dot (a b) (c d))] ["a.1.2" (#%dot a 1.2)]
["(a b).[3]" '(#%dot (a b) (#%brackets 3))])) ["a.b.c" (#%dot a (#%dot b c))]
["a.(b c)" (#%dot a (b c))]
["(a b).c" (#%dot (a b) c)]
["(a b).(c d)" (#%dot (a b) (c d))]
["(a b).[3]" (#%dot (a b) (#%brackets 3))]))