Made lexer unit tests compilable
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
# Fudge-chez
|
# Fudge-chez
|
||||||
This is the Fudge programming language implemented in Chez scheme. For the origin project, go to Wannie's [repository](https://shit-co.de/wanniepannie/fudge2.1).
|
This is the Fudge programming language implemented in Chez scheme.
|
||||||
|
For the original project, go to Wannie's
|
||||||
|
[repository](https://shit-co.de/wanniepannie/fudge2.1).
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
To run fudge-chez, install [Chez](https://scheme.com) and run the program with ```chez --program fudge-chez.ss```
|
To run fudge-chez, install [Chez](https://scheme.com) and run the
|
||||||
|
program with ```chez --program fudge-chez.ss```
|
||||||
|
|
||||||
## Why Chez scheme?
|
## Why Chez scheme?
|
||||||
Because Scheme is elegant. (In theory.)
|
Because Scheme is elegant. (In theory.)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
(lambda (file)
|
(lambda (file)
|
||||||
(let ([c (lookahead-char file)])
|
(let ([c (lookahead-char file)])
|
||||||
(cond
|
(cond
|
||||||
|
[(eof-object? c) ""]
|
||||||
[(char-alphabetic? c)
|
[(char-alphabetic? c)
|
||||||
(get-char file)
|
(get-char file)
|
||||||
(string-append (string c) (get-word file))]
|
(string-append (string c) (get-word file))]
|
||||||
@@ -55,13 +56,46 @@
|
|||||||
(let ([file (open-input-file filename)])
|
(let ([file (open-input-file filename)])
|
||||||
(get-tokens file))))
|
(get-tokens file))))
|
||||||
|
|
||||||
|
(define test-lexer-fail
|
||||||
|
(lambda (input want got)
|
||||||
|
(display "text-lexer-fail: input=")
|
||||||
|
(write input)
|
||||||
|
(display "; want: ")
|
||||||
|
(write want)
|
||||||
|
(display "; got: ")
|
||||||
|
(write got)
|
||||||
|
(display ".")
|
||||||
|
(newline)))
|
||||||
|
|
||||||
|
(define test-lexer-success
|
||||||
|
(lambda (input got)
|
||||||
|
(display "text-lexer-success: input=")
|
||||||
|
(write input)
|
||||||
|
(display "; got: ")
|
||||||
|
(write got)
|
||||||
|
(display ".")
|
||||||
|
(newline)))
|
||||||
|
|
||||||
(define test-lexer
|
(define test-lexer
|
||||||
(lambda (input want)
|
(lambda (input want)
|
||||||
(let ([port (open-string-input-port input)])
|
(let ([port (open-string-input-port input)])
|
||||||
(let ([got (get-tokens port)])
|
(call/cc
|
||||||
(unless (eq? got want)
|
(lambda (i-got-exception)
|
||||||
(text-lexer-fail input want got))))))
|
(with-exception-handler
|
||||||
|
(lambda (x)
|
||||||
|
(display "test-lexer-fail: input ")
|
||||||
|
(write input)
|
||||||
|
(display " throws ")
|
||||||
|
(write x)
|
||||||
|
(display ".")
|
||||||
|
(newline)
|
||||||
|
(i-got-exception x))
|
||||||
|
(lambda ()
|
||||||
|
(let ([got (get-tokens port)])
|
||||||
|
(if (equal? got want)
|
||||||
|
(test-lexer-success input got)
|
||||||
|
(test-lexer-fail input want got))))))))))
|
||||||
|
|
||||||
(test-lexer "hello world" '("hello" "world"))
|
(test-lexer "hello world" '("hello" "world"))
|
||||||
(test-lexer "+ * / -", '(+ * / -))
|
(test-lexer "+ * / -" '(+ * / -))
|
||||||
(test-lexer "identifier = 14", '("identifier" = 14))
|
(test-lexer "identifier = 14" '("identifier" = 14))
|
||||||
|
|||||||
Reference in New Issue
Block a user