Fix bit-count* bug
[bpt/guile.git] / test-suite / tests / srfi-6.test
1 ;;;; srfi-6.test --- test suite for SRFI-6 -*- scheme -*-
2 ;;;;
3 ;;;; Copyright (C) 2003, 2006, 2012 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
9 ;;;;
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free Software
17 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 (use-modules (test-suite lib))
20
21 ;; use #:select to see that the bindings we expect are indeed exported
22 (use-modules ((srfi srfi-6)
23 #:select ((open-input-string . open-input-string)
24 (open-output-string . open-output-string)
25 (get-output-string . get-output-string))))
26
27
28 (with-test-prefix "open-input-string"
29
30 (pass-if "eof on empty"
31 (let ((port (open-input-string "")))
32 (eof-object? (read-char port))))
33
34 (pass-if "read-char"
35 (let ((port (open-input-string "xyz")))
36 (and (char=? #\x (read-char port))
37 (char=? #\y (read-char port))
38 (char=? #\z (read-char port))
39 (eof-object? (read-char port)))))
40
41 (pass-if "read-char, Unicode"
42 ;; String ports should always be Unicode-capable.
43 ;; See <http://bugs.gnu.org/11197>.
44 (with-fluids ((%default-port-encoding "ISO-8859-1"))
45 (let ((port (open-input-string "λμ")))
46 (and (char=? #\λ (read-char port))
47 (char=? #\μ (read-char port))))))
48
49 (with-test-prefix "unread-char"
50
51 (pass-if "one char"
52 (let ((port (open-input-string "")))
53 (unread-char #\x port)
54 (and (char=? #\x (read-char port))
55 (eof-object? (read-char port)))))
56
57 (pass-if "after eof"
58 (let ((port (open-input-string "")))
59 (and (eof-object? (read-char port))
60 (begin
61 (unread-char #\x port)
62 (and (char=? #\x (read-char port))
63 (eof-object? (read-char port)))))))
64
65 (pass-if "order"
66 (let ((port (open-input-string "")))
67 (unread-char #\x port)
68 (unread-char #\y port)
69 (unread-char #\z port)
70 (and (char=? #\z (read-char port))
71 (char=? #\y (read-char port))
72 (char=? #\x (read-char port))
73 (eof-object? (read-char port)))))))
74
75
76 (with-test-prefix "open-output-string"
77
78 (pass-if "empty"
79 (let ((port (open-output-string)))
80 (string=? "" (get-output-string port))))
81
82 (pass-if "xyz"
83 (let ((port (open-output-string)))
84 (display "xyz" port)
85 (string=? "xyz" (get-output-string port))))
86
87 (pass-if "λ"
88 ;; Writing to an output string should always work.
89 ;; See <http://bugs.gnu.org/11197>.
90 (with-fluids ((%default-port-encoding "ISO-8859-1"))
91 (let ((port (open-output-string)))
92 (display "λ" port)
93 (string=? "λ" (get-output-string port)))))
94
95 (pass-if "seek"
96 (let ((port (open-output-string)))
97 (display "abcdef" port)
98 (seek port 2 SEEK_SET)
99 (display "--" port)
100 (string=? "ab--ef" (get-output-string port)))))