1 ;;;; encoding-iso88697.test --- test suite for Guile's string encodings -*- mode: scheme; coding: iso-8859-7 -*-
3 ;;;; Copyright (C) 2009, 2010, 2014 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 ;; Create a string from integer char values, eg. (string-ints 65) => "A"
24 (define (string-ints . args)
25 (apply string (map integer->char args)))
27 (when (defined? 'setlocale)
28 (setlocale LC_ALL ""))
30 (define ascii-a (integer->char 65)) ; LATIN CAPITAL LETTER A
31 (define a-acute (integer->char #x00c1)) ; LATIN CAPITAL LETTER A WITH ACUTE
32 (define alpha (integer->char #x03b1)) ; GREEK SMALL LETTER ALPHA
33 (define cherokee-a (integer->char #x13a0)) ; CHEROKEE LETTER A
35 (with-test-prefix "characters"
39 (pass-if "input alpha"
43 (let ((pt (open-output-string)))
44 (set-port-encoding! pt "ISO-8859-7")
45 (set-port-conversion-strategy! pt 'escape)
48 (get-output-string pt))))
50 (pass-if "display A acute"
51 (let ((pt (open-output-string)))
52 (set-port-encoding! pt "ISO-8859-7")
53 (set-port-conversion-strategy! pt 'escape)
56 (get-output-string pt))))
58 (pass-if "display alpha"
59 (let ((pt (open-output-string)))
60 (set-port-encoding! pt "ISO-8859-7")
61 (set-port-conversion-strategy! pt 'escape)
64 (get-output-string pt))))
66 (pass-if "display Cherokee A"
67 (let ((pt (open-output-string)))
68 (set-port-encoding! pt "ISO-8859-7")
69 (set-port-conversion-strategy! pt 'escape)
70 (display cherokee-a pt)
71 (string-ci=? "\\u13a0"
72 (get-output-string pt))))
75 (let ((pt (open-output-string)))
76 (set-port-encoding! pt "ISO-8859-7")
77 (set-port-conversion-strategy! pt 'escape)
80 (get-output-string pt))))
82 (pass-if "write alpha"
83 (let ((pt (open-output-string)))
84 (set-port-encoding! pt "ISO-8859-7")
85 (set-port-conversion-strategy! pt 'escape)
88 (get-output-string pt)))))
92 (define s3 "êñéôéêÞò")
95 (with-test-prefix "string length"
98 (eqv? (string-length s1) 4))
101 (eqv? (string-length s2) 3))
104 (eqv? (string-length s3) 8))
107 (eqv? (string-length s4) 3)))
109 (with-test-prefix "internal encoding"
112 (string=? s1 (string-ints #x03a0 #x03b5 #x03c1 #x03af)))
115 (string=? s2 (string-ints #x03c4 #x03b7 #x03c2)))
118 (string=? s3 (string-ints #x03ba #x03c1 #x03b9 #x03c4 #x03b9 #x03ba #x03ae #x03c2)))
121 (string=? s4 (string-ints #x03ba #x03b1 #x03b9))))
123 (with-test-prefix "chars"
126 (list= eqv? (string->list s1)
127 (list #\Ð #\å #\ñ #\ß)))
130 (list= eqv? (string->list s2)
134 (list= eqv? (string->list s3)
135 (list #\ê #\ñ #\é #\ô #\é #\ê #\Þ #\ò)))
138 (list= eqv? (string->list s4)
139 (list #\ê #\á #\é))))
141 (with-test-prefix "symbols == strings"
144 (eq? (string->symbol s1) 'Ðåñß))
147 (eq? (string->symbol s2) 'ôçò))
150 (eq? (string->symbol s3) 'êñéôéêÞò))
153 (eq? (string->symbol s4) 'êáé)))
155 (with-test-prefix "non-ascii variable names"
162 (with-test-prefix "output errors"
164 (pass-if-exception "char #x0400"
165 exception:encoding-error
166 (let ((pt (open-output-string)))
167 (set-port-encoding! pt "ISO-8859-7")
168 (set-port-conversion-strategy! pt 'error)
169 (display (string-ints #x0400) pt))))