-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(export repr-test) | ||
|
||
(import | ||
:gerbil/expander | ||
:gerbil/gambit | ||
:std/format | ||
:std/iter | ||
:std/misc/repr | ||
:std/pregexp | ||
:std/sugar | ||
:std/test) | ||
|
||
(defclass foo (a b) transparent: #t) | ||
(defclass bar (a b)) | ||
(defclass baz (a b)) | ||
(defmethod {:pr baz} | ||
(lambda (object (port (current-output-port)) (options (current-representation-options))) | ||
(fprintf port "#~d #;(baz a: ~r b: ~r)" | ||
(object->serial-number object) (@ object a) (@ object b)))) | ||
|
||
(def repr-test | ||
(test-suite "test suite for std/misc/repr" | ||
(import-module ':std/sugar #t #t) | ||
(defsyntax (stx-read stx) | ||
(syntax-case stx () | ||
((s r) (datum->syntax #'s (call-with-input-string (syntax->datum #'r) read))))) | ||
(defrule (representable-checks r ...) | ||
(begin | ||
(test-case r | ||
(check-equal? (repr (stx-read r)) r)) ...)) | ||
(representable-checks | ||
"0" | ||
"(vector -42 3.14 +inf.0 #f #t \"simple\" #\\$ #!void keyword: #!eof)" | ||
"identity" ;; function with a global name | ||
"['symbol []]" ;; symbol, empty list | ||
"[1 2 [3 . 4] [5 #u8(114 101 112 114) ...]]" | ||
"(vector #f #!void #!eof)" | ||
;;"(hash (a 1) (b 2) (,(vector 'x 'y) 'xyzzy))" | ||
"(hash-eq (a 1) (b 2))" | ||
"(hash-eqv (1 'a) (2 'b))" | ||
"(foo a: 1 b: 2)" | ||
"(values 1 2 3)" | ||
"(values)") | ||
(defrule (unrepresentable-checks (oo rr) ...) | ||
(begin | ||
(test-case oo | ||
(check-equal? | ||
(let (o (stx-read oo)) | ||
(match (pregexp-match (string-append "^#([0-9]+) #;" rr) (repr o)) | ||
([_ sn . _] (equal? (serial-number->object (string->number sn)) o)) | ||
(else (repr o)))) #t)) ...)) | ||
(unrepresentable-checks | ||
("(lambda (lambda) lambda)" "\"#<procedure #[0-9]+>\"") | ||
("(bar a: 1 b: 2)" "\"#<bar #[0-9]+>\"")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters