Remove locale u8vector functions
[bpt/guile.git] / test-suite / tests / encoding-iso88597.test
1 ;;;; strings.test --- test suite for Guile's string functions -*- mode: scheme; coding: iso-8859-7 -*-
2 ;;;;
3 ;;;; Copyright (C) 2009 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This program is free software; you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation; either version 2, or (at your option)
8 ;;;; any later version.
9 ;;;;
10 ;;;; This program 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
13 ;;;; GNU General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with this software; see the file COPYING. If not, write to
17 ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;;; Boston, MA 02110-1301 USA
19
20 (define-module (test-strings)
21 #:use-module (test-suite lib)
22 #:use-module (srfi srfi-1))
23
24 (define exception:conversion
25 (cons 'misc-error "^cannot convert to output locale"))
26
27 ;; Create a string from integer char values, eg. (string-ints 65) => "A"
28 (define (string-ints . args)
29 (apply string (map integer->char args)))
30
31 (define oldlocale #f)
32 (if (defined? 'setlocale)
33 (set! oldlocale (setlocale LC_ALL "")))
34 (define ascii-a (integer->char 65)) ; LATIN CAPITAL LETTER A
35 (define a-acute (integer->char #x00c1)) ; LATIN CAPITAL LETTER A WITH ACUTE
36 (define alpha (integer->char #x03b1)) ; GREEK SMALL LETTER ALPHA
37 (define cherokee-a (integer->char #x13a0)) ; CHEROKEE LETTER A
38
39 (with-test-prefix "characters"
40 (pass-if "input A"
41 (char=? ascii-a #\A))
42
43 (pass-if "input alpha"
44 (char=? alpha #\á))
45
46 (pass-if "display A"
47 (let ((pt (open-output-string)))
48 (set-port-encoding! pt "ISO-8859-7")
49 (set-port-conversion-strategy! pt 'escape)
50 (display ascii-a pt)
51 (string=? "A"
52 (get-output-string pt))))
53
54 (pass-if "display A acute"
55 (let ((pt (open-output-string)))
56 (set-port-encoding! pt "ISO-8859-7")
57 (set-port-conversion-strategy! pt 'escape)
58 (display a-acute pt)
59 (string-ci=? "\\xc1"
60 (get-output-string pt))))
61
62 (pass-if "display alpha"
63 (let ((pt (open-output-string)))
64 (set-port-encoding! pt "ISO-8859-7")
65 (set-port-conversion-strategy! pt 'escape)
66 (display alpha pt)
67 (string-ci=? "á"
68 (get-output-string pt))))
69
70 (pass-if "display Cherokee A"
71 (let ((pt (open-output-string)))
72 (set-port-encoding! pt "ISO-8859-7")
73 (set-port-conversion-strategy! pt 'escape)
74 (display cherokee-a pt)
75 (string-ci=? "\\u13a0"
76 (get-output-string pt))))
77
78 (pass-if "write A"
79 (let ((pt (open-output-string)))
80 (set-port-encoding! pt "ISO-8859-7")
81 (set-port-conversion-strategy! pt 'escape)
82 (write ascii-a pt)
83 (string=? "#\\A"
84 (get-output-string pt))))
85
86 (pass-if "write alpha"
87 (let ((pt (open-output-string)))
88 (set-port-encoding! pt "ISO-8859-7")
89 (set-port-conversion-strategy! pt 'escape)
90 (write alpha pt)
91 (string=? "#\\á"
92 (get-output-string pt)))))
93
94 (define s1 "Ðåñß")
95 (define s2 "ôçò")
96 (define s3 "êñéôéêÞò")
97 (define s4 "êáé")
98
99 (with-test-prefix "string length"
100
101 (pass-if "s1"
102 (eq? (string-length s1) 4))
103
104 (pass-if "s2"
105 (eq? (string-length s2) 3))
106
107 (pass-if "s3"
108 (eq? (string-length s3) 8))
109
110 (pass-if "s4"
111 (eq? (string-length s4) 3)))
112
113 (with-test-prefix "internal encoding"
114
115 (pass-if "s1"
116 (string=? s1 (string-ints #x03a0 #x03b5 #x03c1 #x03af)))
117
118 (pass-if "s2"
119 (string=? s2 (string-ints #x03c4 #x03b7 #x03c2)))
120
121 (pass-if "s3"
122 (string=? s3 (string-ints #x03ba #x03c1 #x03b9 #x03c4 #x03b9 #x03ba #x03ae #x03c2)))
123
124 (pass-if "s4"
125 (string=? s4 (string-ints #x03ba #x03b1 #x03b9))))
126
127 (with-test-prefix "chars"
128
129 (pass-if "s1"
130 (list= eqv? (string->list s1)
131 (list #\Ð #\å #\ñ #\ß)))
132
133 (pass-if "s2"
134 (list= eqv? (string->list s2)
135 (list #\ô #\ç #\ò)))
136
137 (pass-if "s3"
138 (list= eqv? (string->list s3)
139 (list #\ê #\ñ #\é #\ô #\é #\ê #\Þ #\ò)))
140
141 (pass-if "s4"
142 (list= eqv? (string->list s4)
143 (list #\ê #\á #\é))))
144
145 (with-test-prefix "symbols == strings"
146
147 (pass-if "Ðåñß"
148 (eq? (string->symbol s1) 'Ðåñß))
149
150 (pass-if "ôçò"
151 (eq? (string->symbol s2) 'ôçò))
152
153 (pass-if "êñéôéêÞò"
154 (eq? (string->symbol s3) 'êñéôéêÞò))
155
156 (pass-if "êáé"
157 (eq? (string->symbol s4) 'êáé)))
158
159 (with-test-prefix "non-ascii variable names"
160
161 (pass-if "1"
162 (let ((á 1)
163 (ñ 2))
164 (eq? (+ á ñ) 3))))
165
166 (with-test-prefix "output errors"
167
168 (pass-if-exception "char #x0400"
169 exception:conversion
170 (let ((pt (open-output-string)))
171 (set-port-encoding! pt "ISO-8859-7")
172 (set-port-conversion-strategy! pt 'error)
173 (display (string-ints #x0400) pt))))
174
175 ;; Reset locale
176 (if (defined? 'setlocale)
177 (setlocale LC_ALL oldlocale))