(load-relative "../netstring") (import netstring) (use test) (test "12:hello, world," (string->netstring "hello, world")) (test "0:," (string->netstring "")) (test "hello, world" (netstring->string "12:hello, world,")) (test "" (netstring->string "0:,")) (test "3:foo," (with-output-to-string (lambda () (netstring-write "foo")))) (test "foo" (with-input-from-string "3:foo," netstring-read)) (test "1:x#" (call-with-output-string (lambda (p) (netstring-write "x" p #\#)))) (test #!eof (with-input-from-string "" netstring-read)) (test-error (netstring->string "foo")) (test-error (netstring->string "3 foo,")) (test-error (netstring->string "10:foo,")) (test-error (netstring->string "4:foo,")) (test-error (netstring->string "3:foo")) (call-with-input-string "4:hehe," (lambda (p) (test "hehe" (netstring-read p)) (test #!eof (read-char p)))) (call-with-input-string "4:hehe," (lambda (p) (test "hehe" (netstring-read p #f)) (test #\, (read-char p))))