edn/tests/run.scm

59 lines
2 KiB
Scheme
Raw Normal View History

2022-10-30 21:37:47 +00:00
(import r7rs chalk)
2020-03-03 23:17:41 +00:00
(require-extension srfi-69 srfi-64 srfi-88 srfi-1)
;;(import (chicken port))
2020-02-19 00:29:52 +00:00
(include "../edn-impl.scm")
;; (run-hahn -o edn.wiki edn.scm edn-impl.scm)
(define s->k string->keyword)
(test-begin "EDN writing")
(test-equal (parse-entry keyword:) ":keyword")
(test-equal (parse-entry #t) "true")
(test-equal (parse-entry #f) "false")
(test-equal (parse-entry '()) "nil")
(test-equal (parse-entry #\a) "\\a")
(test-equal (parse-entry "String") "\"String\"")
(test-equal (parse-entry (cons edn/reader-tag: neat:)) "#neat")
(test-equal (list->edn parse-entry '(1 2 3 4)) "(1 2 3 4)")
(test-equal (vector->edn parse-entry #(a: b: c: d:)) "[:a :b :c :d]")
2020-03-03 23:17:41 +00:00
(test-equal
(let ((port (open-output-string)))
(write-edn port '((a: . "Hi")
(b: . i-am:)
(c: . (a list))))
(get-output-string port))
"{:a \"Hi\" :b :i-am :c (a list)}")
2020-02-19 00:29:52 +00:00
(test-end "EDN writing")
(test-begin "EDN reading")
2020-03-03 23:17:41 +00:00
(define (wifs str proc)
(call-with-port (open-input-string str) proc))
2020-02-19 00:29:52 +00:00
(test-equal (wifs "(:keyword)" read-edn) '(keyword:))
(test-equal (wifs "(123)" read-edn) '(123))
(test-equal (wifs "(\"Hello World!\")" read-edn) '("Hello World!"))
(test-equal (wifs "(false)" read-edn) '(#f))
(test-equal (wifs "(true)" read-edn) '(#t))
(test-equal (wifs "(:Hello \"World\" 1)" read-edn) '(Hello: "World" 1))
(test-equal (wifs "[:a :b :c :d]" read-edn) #(a: b: c: d:))
(test-assert
((lambda (a b)
(and (equal? (hash-table-ref b a:) "Hi")
(equal? (hash-table-ref b b:) i-am:)
(equal? (hash-table-ref b c:) `(a list))))
(alist->hash-table '((a: . "Hi") (b: . i-am:) (c: . (a list))))
(wifs "{:a \"Hi\" :b :i-am :c (a list)}" read-edn)))
(test-end "EDN reading")
(test-begin "Tag handling")
(test-equal (wifs "(1 2 #_ 3 4)" read-edn) '(1 2 4))
2022-10-30 21:37:47 +00:00
(tag-handlers (cons (cons keywordify:
2020-02-19 00:29:52 +00:00
(lambda (input)
(string->keyword (symbol->string input))))
2022-10-30 21:37:47 +00:00
(tag-handlers)))
2020-02-19 00:29:52 +00:00
(test-equal (wifs "(asdf #keywordify qwertz)" read-edn) '(asdf qwertz:))
(test-end "Tag handling")