|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(use-modules (test-suite lib)) |
|
|
|
|
|
(use-modules ((srfi srfi-6) |
|
#:select ((open-input-string . open-input-string) |
|
(open-output-string . open-output-string) |
|
(get-output-string . get-output-string)))) |
|
|
|
|
|
(with-test-prefix "open-input-string" |
|
|
|
(pass-if "eof on empty" |
|
(let ((port (open-input-string ""))) |
|
(eof-object? (read-char port)))) |
|
|
|
(pass-if "read-char" |
|
(let ((port (open-input-string "xyz"))) |
|
(and (char=? #\x (read-char port)) |
|
(char=? #\y (read-char port)) |
|
(char=? #\z (read-char port)) |
|
(eof-object? (read-char port))))) |
|
|
|
(pass-if "read-char, Unicode" |
|
|
|
|
|
(with-fluids ((%default-port-encoding "ISO-8859-1")) |
|
(let ((port (open-input-string "位渭"))) |
|
(and (char=? #\位 (read-char port)) |
|
(char=? #\渭 (read-char port)))))) |
|
|
|
(with-test-prefix "unread-char" |
|
|
|
(pass-if "one char" |
|
(let ((port (open-input-string ""))) |
|
(unread-char #\x port) |
|
(and (char=? #\x (read-char port)) |
|
(eof-object? (read-char port))))) |
|
|
|
(pass-if "after eof" |
|
(let ((port (open-input-string ""))) |
|
(and (eof-object? (read-char port)) |
|
(begin |
|
(unread-char #\x port) |
|
(and (char=? #\x (read-char port)) |
|
(eof-object? (read-char port))))))) |
|
|
|
(pass-if "order" |
|
(let ((port (open-input-string ""))) |
|
(unread-char #\x port) |
|
(unread-char #\y port) |
|
(unread-char #\z port) |
|
(and (char=? #\z (read-char port)) |
|
(char=? #\y (read-char port)) |
|
(char=? #\x (read-char port)) |
|
(eof-object? (read-char port))))))) |
|
|
|
|
|
(with-test-prefix "open-output-string" |
|
|
|
(pass-if "empty" |
|
(let ((port (open-output-string))) |
|
(string=? "" (get-output-string port)))) |
|
|
|
(pass-if "xyz" |
|
(let ((port (open-output-string))) |
|
(display "xyz" port) |
|
(string=? "xyz" (get-output-string port)))) |
|
|
|
(pass-if "位" |
|
|
|
|
|
(with-fluids ((%default-port-encoding "ISO-8859-1")) |
|
(let ((port (open-output-string))) |
|
(display "位" port) |
|
(string=? "位" (get-output-string port))))) |
|
|
|
(pass-if "seek" |
|
(let ((port (open-output-string))) |
|
(display "abcdef" port) |
|
(seek port 2 SEEK_SET) |
|
(display "--" port) |
|
(string=? "ab--ef" (get-output-string port))))) |
|
|