(load-relative "../tagged-netstring") (import tagged-netstring) (use test) (define-syntax test-read (syntax-rules () ((_ expect input) (test-read expect expect input)) ((_ msg expect input) (test (->string msg) expect (with-input-from-string input tagged-netstring-read))))) (define-syntax test-read-error (syntax-rules () ((_ input) (test-error (with-input-from-string input tagged-netstring-read))))) (define-syntax test-write (syntax-rules () ((_ expect input) (test-write expect expect input)) ((_ msg expect input) (test (->string msg) expect (with-output-to-string (lambda () (tagged-netstring-write input))))))) (define-syntax test-read/write (syntax-rules () ((_ expect input) (begin (test-read expect input) (test-write input expect))))) (test-read "reading strings" "hehe" "4:hehe,") (test-write "wrting strings" "4:hehe," "hehe") (test-group "integers" (test-read/write 42 "2:42#") (test-read-error "3:xxx#")) (test-group "booleans" (test-read/write #t "4:true!") (test-read/write #f "5:false!") (test-read-error "2:no!")) (test-group "lists" (test-read/write '#() "0:]") (test-read/write '#("x") "4:1:x,]") (test-read/write '#("foo" #("bar" "baz") "qux") "28:3:foo,12:3:bar,3:baz,]3:qux,]") (test-read-error "10:foo]")) (test-group "dicts" (test-read/write '() "0:}") (test-read/write '((foo . ((bar . 123)))) "22:3:foo,12:3:bar,3:123#}}") (test-read-error "12:3:123#3:foo,}"))