* Moved reader related tests from exceptions.test to reader.test.
[bpt/guile.git] / test-suite / tests / reader.test
1 ;;;; reader.test --- test the Guile parser -*- scheme -*-
2 ;;;; Jim Blandy <jimb@red-bean.com> --- September 1999
3
4 (define exception:eof
5 (cons 'misc-error "^end of file"))
6 (define exception:unexpected-rparen
7 (cons 'misc-error "^unexpected \")\""))
8
9 (define (read-string s)
10 (with-input-from-string s (lambda () (read))))
11
12 (with-test-prefix "reading"
13 (pass-if "0"
14 (equal? (read-string "0") 0))
15 (pass-if "1++i"
16 (equal? (read-string "1++i") '1++i))
17 (pass-if "1+i+i"
18 (equal? (read-string "1+i+i") '1+i+i))
19 (pass-if "1+e10000i"
20 (equal? (read-string "1+e10000i") '1+e10000i)))
21
22 (pass-if-exception "radix passed to number->string can't be zero"
23 exception:out-of-range
24 (number->string 10 0))
25 (pass-if-exception "radix passed to number->string can't be one either"
26 exception:out-of-range
27 (number->string 10 1))
28
29 (with-test-prefix "mismatching parentheses"
30 (pass-if-exception "opening parenthesis"
31 exception:eof
32 (read-string "("))
33 (pass-if-exception "closing parenthesis following mismatched opening"
34 exception:unexpected-rparen
35 (read-string ")"))
36 (pass-if-exception "opening vector parenthesis"
37 exception:eof
38 (read-string "#("))
39 (pass-if-exception "closing parenthesis following mismatched vector opening"
40 exception:unexpected-rparen
41 (read-string ")")))