1 ;;;; encoding-iso88697.test --- test suite for Guile's string encodings -*- mode: scheme; coding: iso-8859-7 -*-
3 ;;;; Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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
19 (define-module (test-strings)
20 #:use-module (test-suite lib)
21 #:use-module (srfi srfi-1))
23 (define exception:conversion
24 (cons 'misc-error "^cannot convert to output locale"))
26 ;; Create a string from integer char values, eg. (string-ints 65) => "A"
27 (define (string-ints . args)
28 (apply string (map integer->char args)))
31 (if (defined? 'setlocale)
32 (set! oldlocale (setlocale LC_ALL "")))
33 (define ascii-a (integer->char 65)) ; LATIN CAPITAL LETTER A
34 (define a-acute (integer->char #x00c1)) ; LATIN CAPITAL LETTER A WITH ACUTE
35 (define alpha (integer->char #x03b1)) ; GREEK SMALL LETTER ALPHA
36 (define cherokee-a (integer->char #x13a0)) ; CHEROKEE LETTER A
38 (with-test-prefix "characters"
42 (pass-if "input alpha"
46 (let ((pt (open-output-string)))
47 (set-port-encoding! pt "ISO-8859-7")
48 (set-port-conversion-strategy! pt 'escape)
51 (get-output-string pt))))
53 (pass-if "display A acute"
54 (let ((pt (open-output-string)))
55 (set-port-encoding! pt "ISO-8859-7")
56 (set-port-conversion-strategy! pt 'escape)
59 (get-output-string pt))))
61 (pass-if "display alpha"
62 (let ((pt (open-output-string)))
63 (set-port-encoding! pt "ISO-8859-7")
64 (set-port-conversion-strategy! pt 'escape)
67 (get-output-string pt))))
69 (pass-if "display Cherokee A"
70 (let ((pt (open-output-string)))
71 (set-port-encoding! pt "ISO-8859-7")
72 (set-port-conversion-strategy! pt 'escape)
73 (display cherokee-a pt)
74 (string-ci=? "\\u13a0"
75 (get-output-string pt))))
78 (let ((pt (open-output-string)))
79 (set-port-encoding! pt "ISO-8859-7")
80 (set-port-conversion-strategy! pt 'escape)
83 (get-output-string pt))))
85 (pass-if "write alpha"
86 (let ((pt (open-output-string)))
87 (set-port-encoding! pt "ISO-8859-7")
88 (set-port-conversion-strategy! pt 'escape)
91 (get-output-string pt)))))
95 (define s3 "êñéôéêÞò")
98 (with-test-prefix "string length"
101 (eq? (string-length s1) 4))
104 (eq? (string-length s2) 3))
107 (eq? (string-length s3) 8))
110 (eq? (string-length s4) 3)))
112 (with-test-prefix "internal encoding"
115 (string=? s1 (string-ints #x03a0 #x03b5 #x03c1 #x03af)))
118 (string=? s2 (string-ints #x03c4 #x03b7 #x03c2)))
121 (string=? s3 (string-ints #x03ba #x03c1 #x03b9 #x03c4 #x03b9 #x03ba #x03ae #x03c2)))
124 (string=? s4 (string-ints #x03ba #x03b1 #x03b9))))
126 (with-test-prefix "chars"
129 (list= eqv? (string->list s1)
130 (list #\Ð #\å #\ñ #\ß)))
133 (list= eqv? (string->list s2)
137 (list= eqv? (string->list s3)
138 (list #\ê #\ñ #\é #\ô #\é #\ê #\Þ #\ò)))
141 (list= eqv? (string->list s4)
142 (list #\ê #\á #\é))))
144 (with-test-prefix "symbols == strings"
147 (eq? (string->symbol s1) 'Ðåñß))
150 (eq? (string->symbol s2) 'ôçò))
153 (eq? (string->symbol s3) 'êñéôéêÞò))
156 (eq? (string->symbol s4) 'êáé)))
158 (with-test-prefix "non-ascii variable names"
165 (with-test-prefix "output errors"
167 (pass-if-exception "char #x0400"
169 (let ((pt (open-output-string)))
170 (set-port-encoding! pt "ISO-8859-7")
171 (set-port-conversion-strategy! pt 'error)
172 (display (string-ints #x0400) pt))))
175 (if (defined? 'setlocale)
176 (setlocale LC_ALL oldlocale))