preprocessor tests

svn: r11787
This commit is contained in:
Eli Barzilay 2008-09-17 14:19:55 +00:00
parent 639ba223cc
commit ffde7e7b42
9 changed files with 98 additions and 1 deletions

View File

@ -1,6 +1,8 @@
#lang scheme/base #lang scheme/base
(require tests/eli-tester scribble/text/syntax-utils) (require tests/eli-tester scribble/text/syntax-utils scheme/runtime-path)
(define-runtime-path text-dir "text")
(test (test
@ -76,4 +78,17 @@
(f 3 #:> "]" #:< "[")) (f 3 #:> "]" #:< "["))
=> '(1 ("<" 1 ">") ("[" 2 ">") ("[" 3 "]")) => '(1 ("<" 1 ">") ("[" 2 ">") ("[" 3 "]"))
;; preprocessor functionality
(parameterize ([current-directory text-dir])
(for ([ifile (map path->string (directory-list))]
#:when (and (file-exists? ifile)
(regexp-match? #rx"^i[0-9]+$" ifile)))
(define ofile (regexp-replace #rx"^i" ifile "o"))
(define expected (call-with-input-file ofile
(lambda (i) (read-bytes (file-size ofile) i))))
(define o (open-output-bytes))
(parameterize ([current-output-port o])
(dynamic-require (path->complete-path ifile) #f))
(test (get-output-bytes o) => expected)))
) )

View File

@ -0,0 +1,3 @@
#lang scribble/text
foo

View File

@ -0,0 +1,25 @@
#lang scribble/text
@define[name]{PLT Scheme}
Suggested price list for "@name"
@; test mutual recursion, throwing away inter-definition spaces
@; <-- this is needed to get one line of space only
@(define (items-num)
(length items))
@(define average
(delay (/ (apply + (map car items)) (length items))))
@(define items
(list @list[99]{Home}
@list[149]{Professional}
@list[349]{Enterprize}))
@(for/list ([i items] [n (in-naturals)])
@list{@|n|. @name @cadr[i] edition: $@car[i].99
@||})@; <-- also needed
Total: @items-num items
Average price: $@|average|.99

View File

@ -0,0 +1,18 @@
#lang scribble/text
---***---
@(define (angled . body) (list "<" body ">"))
@(define (shout . body) @angled[(map string-upcase body)])
@define[z]{blah}
blah @angled{blah @shout{@z} blah} blah
@(define-syntax-rule @twice[x]
(list x ", " x))
@twice{@twice{blah}}
@include{i3a}
@(let ([name "Eli"]) (let ([foo (include "i3b")]) (list foo "\n" foo)))
Repeating yourself much?

View File

@ -0,0 +1 @@
Warning: blah overdose might be fatal

View File

@ -0,0 +1,12 @@
@(define (foo . xs) (bar xs))
@(begin (define (isname) @list{is @foo{@name}})
(define-syntax-rule (DEF x y) (define x y)))
@(DEF (bar x) (list z " " x))
@(define-syntax-rule (BEG x ...) (begin x ...))
@(BEG (define z "zee"))
My name @isname
@DEF[x]{Foo!}
... and to that I say "@x", I think.

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1,8 @@
Suggested price list for "PLT Scheme"
0. PLT Scheme Home edition: $99.99
1. PLT Scheme Professional edition: $149.99
2. PLT Scheme Enterprize edition: $349.99
Total: 3 items
Average price: $199.99

View File

@ -0,0 +1,14 @@
---***---
blah <blah <BLAH> blah> blah
blah, blah, blah, blah
Warning: blah overdose might be fatal
My name is zee Eli
... and to that I say "Foo!", I think.
My name is zee Eli
... and to that I say "Foo!", I think.
Repeating yourself much?