1 ;;;; strings.test --- test suite for Guile's string functions -*- mode: scheme; coding: iso-8859-7 -*-
3 ;;;; Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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
20 (define-module (test-strings)
21 #:use-module (test-suite lib)
22 #:use-module (srfi srfi-1))
24 (define exception:conversion
25 (cons 'misc-error "^cannot convert to output locale"))
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)))
32 (if (defined? 'setlocale)
33 (set! oldlocale (setlocale LC_ALL "")))
37 (define s3 "êñéôéêÞò")
40 (with-test-prefix "string length"
43 (eq? (string-length s1) 4))
46 (eq? (string-length s2) 3))
49 (eq? (string-length s3) 8))
52 (eq? (string-length s4) 3)))
54 (with-test-prefix "internal encoding"
57 (string=? s1 (string-ints #x03a0 #x03b5 #x03c1 #x03af)))
60 (string=? s2 (string-ints #x03c4 #x03b7 #x03c2)))
63 (string=? s3 (string-ints #x03ba #x03c1 #x03b9 #x03c4 #x03b9 #x03ba #x03ae #x03c2)))
66 (string=? s4 (string-ints #x03ba #x03b1 #x03b9))))
68 (with-test-prefix "chars"
71 (list= eqv? (string->list s1)
72 (list #\Ð #\å #\ñ #\ß)))
75 (list= eqv? (string->list s2)
79 (list= eqv? (string->list s3)
80 (list #\ê #\ñ #\é #\ô #\é #\ê #\Þ #\ò)))
83 (list= eqv? (string->list s4)
86 ;; Testing that the display of the string is output in the ISO-8859-7
88 (with-test-prefix "display"
91 (let ((pt (open-output-string)))
92 (set-port-encoding! pt "ISO-8859-7")
95 (list #xd0 #xe5 #xf1 #xdf)
97 (get-output-locale-u8vector pt)))))
99 (let ((pt (open-output-string)))
100 (set-port-encoding! pt "ISO-8859-7")
103 (list #xf4 #xe7 #xf2)
105 (get-output-locale-u8vector pt))))))
107 (with-test-prefix "symbols == strings"
110 (eq? (string->symbol s1) 'Ðåñß))
113 (eq? (string->symbol s2) 'ôçò))
116 (eq? (string->symbol s3) 'êñéôéêÞò))
119 (eq? (string->symbol s4) 'êáé)))
121 (with-test-prefix "non-ascii variable names"
128 (with-test-prefix "output errors"
130 (pass-if-exception "char #x0400"
132 (let ((pt (open-output-string)))
133 (set-port-encoding! pt "ISO-8859-7")
134 (set-port-conversion-strategy! pt 'error)
135 (display (string-ints #x0400) pt))))
138 (if (defined? 'setlocale)
139 (setlocale LC_ALL oldlocale))