Added some reader tests -- some fail due to bugs in the current code.

This file is left here, and is intended for distribution with the code since it
can be used as a good reference for people who are new to the syntax.

svn: r6694
This commit is contained in:
Eli Barzilay 2007-06-19 08:46:56 +00:00
parent c14f363505
commit 10516c3d91

126
collects/scribble/test-reader.ss Executable file
View File

@ -0,0 +1,126 @@
#!/bin/sh
#| -*- scheme -*-
exec mzscheme -r "$0" "$@"
|#
(require (lib "string.ss"))
#reader(lib "reader.ss" "scribble")
(define tests
`(
[@foo
foo]
[@foo{}
(foo)]
[@foo{bar}
(foo "bar")]
[@foo{bar baz
blah}
(foo "bar baz" "\n" "blah")]
['@foo{bar}
'(foo "bar")]
[@'foo{bar}
'(foo "bar")]
,'
[@'`,foo{bar}
'`,(foo "bar")]
,' ; <- to avoid the above openning quasiquote
[@'`,@,foo{bar}
'`,@,(foo "bar")]
,'
[@`',@foo{blah}
`@',@foo{blah}]
,'
[@`',@foo{blah}
`',@@foo{blah}]
[@(lambda (x) x){blah}
((lambda (x) x) "blah")]
[@{foo bar
baz}
("foo bar" "\n" "baz")]
[@'{foo bar
baz}
'("foo bar" "\n" "baz")]
[(1 2 @; comment
3 4)
(1 2 3 4)]
[(1 2@; comment, 2 touches 3 but there is a comment syntax between them
3 4)
(1 2 3 4)]
[@foo{bar @; comment, note the extra space
baz}
(foo "bar baz")]
[@foo{bar@; comment, no space
baz}
(foo "barbaz")]
#; ;!!!
[@foo{bar @; comment, with space and newline
baz}
(foo "bar " "\n" "baz")]
[@@foo{bar}{baz}
((foo "bar") "baz")]
[(define |@foo| '\@bar)
,(read-from-string "(define @foo '@bar)")]
[@foo{
bar
}
@foo{bar}]
[@foo{ bar }
(foo " bar ")]
[@foo{ bar
}
(foo " bar")]
[@foo{
bar }
(foo "bar ")]
[@foo{a @bar{b} c}
(foo "a " (bar "b") " c")]
;; !!! to be fixed
;; [@foo{a @bar c}
;; (foo "a " bar " c")]
;; [@foo{a @(bar 2) c}
;; (foo "a " (bar 2) " c")]
))
(define failures 0)
(define (test val expect)
(unless (equal? val expect)
(set! failures (add1 failures))
(printf "Failure, got: ~s\n expected: ~s\n" val expect)))
(for-each (lambda (t) (apply test t)) tests)
(if (zero? failures)
(printf "All tests passed\n")
(begin (printf "~s failures\n" failures) (exit 1)))