mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 03:30:27 +02:00
* test-suite/lib.scm (with-locale, with-locale*): new test functions * test-suite/tests/encoding-escapes: don't fail if en_US.utf8 doesn't exist * test-suite/tests/encoding-iso88591.test: set and restore locale, if possible * test-suite/tests/encoding-iso88597.test: set and restore locale, if possible * test-suite/tests/encoding-utf8.test: set and restore locale, if possible * test-suite/tests/srfi-14.test: don't need to setlocale to Latin-1 to test Latin-1 since string conversion is handled at read/compile time. Set and restore locale, if possible.
139 lines
3.6 KiB
Scheme
139 lines
3.6 KiB
Scheme
;;;; strings.test --- test suite for Guile's string functions -*- mode: scheme; coding: iso-8859-7 -*-
|
|
;;;;
|
|
;;;; Copyright (C) 2009 Free Software Foundation, Inc.
|
|
;;;;
|
|
;;;; This program is free software; you can redistribute it and/or modify
|
|
;;;; it under the terms of the GNU General Public License as published by
|
|
;;;; the Free Software Foundation; either version 2, or (at your option)
|
|
;;;; any later version.
|
|
;;;;
|
|
;;;; This program is distributed in the hope that it will be useful,
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;;;; GNU General Public License for more details.
|
|
;;;;
|
|
;;;; You should have received a copy of the GNU General Public License
|
|
;;;; along with this software; see the file COPYING. If not, write to
|
|
;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
;;;; Boston, MA 02110-1301 USA
|
|
|
|
(define-module (test-strings)
|
|
#:use-module (test-suite lib)
|
|
#:use-module (srfi srfi-1))
|
|
|
|
(define exception:conversion
|
|
(cons 'misc-error "^cannot convert to output locale"))
|
|
|
|
;; Create a string from integer char values, eg. (string-ints 65) => "A"
|
|
(define (string-ints . args)
|
|
(apply string (map integer->char args)))
|
|
|
|
(define oldlocale #f)
|
|
(if (defined? 'setlocale)
|
|
(set! oldlocale (setlocale LC_ALL "")))
|
|
|
|
(define s1 "Ðåñß")
|
|
(define s2 "ôçò")
|
|
(define s3 "êñéôéêÞò")
|
|
(define s4 "êáé")
|
|
|
|
(with-test-prefix "string length"
|
|
|
|
(pass-if "s1"
|
|
(eq? (string-length s1) 4))
|
|
|
|
(pass-if "s2"
|
|
(eq? (string-length s2) 3))
|
|
|
|
(pass-if "s3"
|
|
(eq? (string-length s3) 8))
|
|
|
|
(pass-if "s4"
|
|
(eq? (string-length s4) 3)))
|
|
|
|
(with-test-prefix "internal encoding"
|
|
|
|
(pass-if "s1"
|
|
(string=? s1 (string-ints #x03a0 #x03b5 #x03c1 #x03af)))
|
|
|
|
(pass-if "s2"
|
|
(string=? s2 (string-ints #x03c4 #x03b7 #x03c2)))
|
|
|
|
(pass-if "s3"
|
|
(string=? s3 (string-ints #x03ba #x03c1 #x03b9 #x03c4 #x03b9 #x03ba #x03ae #x03c2)))
|
|
|
|
(pass-if "s4"
|
|
(string=? s4 (string-ints #x03ba #x03b1 #x03b9))))
|
|
|
|
(with-test-prefix "chars"
|
|
|
|
(pass-if "s1"
|
|
(list= eqv? (string->list s1)
|
|
(list #\Ð #\å #\ñ #\ß)))
|
|
|
|
(pass-if "s2"
|
|
(list= eqv? (string->list s2)
|
|
(list #\ô #\ç #\ò)))
|
|
|
|
(pass-if "s3"
|
|
(list= eqv? (string->list s3)
|
|
(list #\ê #\ñ #\é #\ô #\é #\ê #\Þ #\ò)))
|
|
|
|
(pass-if "s4"
|
|
(list= eqv? (string->list s4)
|
|
(list #\ê #\á #\é))))
|
|
|
|
;; Testing that the display of the string is output in the ISO-8859-7
|
|
;; encoding
|
|
(with-test-prefix "display"
|
|
|
|
(pass-if "s1"
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-7")
|
|
(display s1 pt)
|
|
(list= eqv?
|
|
(list #xd0 #xe5 #xf1 #xdf)
|
|
(u8vector->list
|
|
(get-output-locale-u8vector pt)))))
|
|
(pass-if "s2"
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-7")
|
|
(display s2 pt)
|
|
(list= eqv?
|
|
(list #xf4 #xe7 #xf2)
|
|
(u8vector->list
|
|
(get-output-locale-u8vector pt))))))
|
|
|
|
(with-test-prefix "symbols == strings"
|
|
|
|
(pass-if "Ðåñß"
|
|
(eq? (string->symbol s1) 'Ðåñß))
|
|
|
|
(pass-if "ôçò"
|
|
(eq? (string->symbol s2) 'ôçò))
|
|
|
|
(pass-if "êñéôéêÞò"
|
|
(eq? (string->symbol s3) 'êñéôéêÞò))
|
|
|
|
(pass-if "êáé"
|
|
(eq? (string->symbol s4) 'êáé)))
|
|
|
|
(with-test-prefix "non-ascii variable names"
|
|
|
|
(pass-if "1"
|
|
(let ((á 1)
|
|
(ñ 2))
|
|
(eq? (+ á ñ) 3))))
|
|
|
|
(with-test-prefix "output errors"
|
|
|
|
(pass-if-exception "char #x0400"
|
|
exception:conversion
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-7")
|
|
(set-port-conversion-strategy! pt 'error)
|
|
(display (string-ints #x0400) pt))))
|
|
|
|
;; Reset locale
|
|
(if (defined? 'setlocale)
|
|
(setlocale LC_ALL oldlocale))
|