1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
guile/test-suite/tests/encoding-iso88597.test
Ludovic Courtès a3d7d5d508 Use encoding-error' instead of misc-error' for string encoding errors.
* libguile/strings.c (scm_encoding_error): New function.
  (scm_from_stringn, scm_to_stringn): Use it instead of `scm_misc_error ()'.

* test-suite/lib.scm (exception:encoding-error): Adjust accordingly.

* test-suite/tests/encoding-escapes.test (exception:conversion):
  Remove.  Use `exception:encoding-error' instead.

* test-suite/tests/encoding-iso88591.test: Likewise.

* test-suite/tests/encoding-iso88597.test: Likewise.

* test-suite/tests/encoding-utf8.test: Likewise.
2010-01-07 11:10:35 +01:00

173 lines
5.1 KiB
Scheme

;;;; encoding-iso88697.test --- test suite for Guile's string encodings -*- mode: scheme; coding: iso-8859-7 -*-
;;;;
;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;;
;;;; This library 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
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; 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))
;; 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 ascii-a (integer->char 65)) ; LATIN CAPITAL LETTER A
(define a-acute (integer->char #x00c1)) ; LATIN CAPITAL LETTER A WITH ACUTE
(define alpha (integer->char #x03b1)) ; GREEK SMALL LETTER ALPHA
(define cherokee-a (integer->char #x13a0)) ; CHEROKEE LETTER A
(with-test-prefix "characters"
(pass-if "input A"
(char=? ascii-a #\A))
(pass-if "input alpha"
(char=? alpha #\á))
(pass-if "display A"
(let ((pt (open-output-string)))
(set-port-encoding! pt "ISO-8859-7")
(set-port-conversion-strategy! pt 'escape)
(display ascii-a pt)
(string=? "A"
(get-output-string pt))))
(pass-if "display A acute"
(let ((pt (open-output-string)))
(set-port-encoding! pt "ISO-8859-7")
(set-port-conversion-strategy! pt 'escape)
(display a-acute pt)
(string-ci=? "\\xc1"
(get-output-string pt))))
(pass-if "display alpha"
(let ((pt (open-output-string)))
(set-port-encoding! pt "ISO-8859-7")
(set-port-conversion-strategy! pt 'escape)
(display alpha pt)
(string-ci=? "á"
(get-output-string pt))))
(pass-if "display Cherokee A"
(let ((pt (open-output-string)))
(set-port-encoding! pt "ISO-8859-7")
(set-port-conversion-strategy! pt 'escape)
(display cherokee-a pt)
(string-ci=? "\\u13a0"
(get-output-string pt))))
(pass-if "write A"
(let ((pt (open-output-string)))
(set-port-encoding! pt "ISO-8859-7")
(set-port-conversion-strategy! pt 'escape)
(write ascii-a pt)
(string=? "#\\A"
(get-output-string pt))))
(pass-if "write alpha"
(let ((pt (open-output-string)))
(set-port-encoding! pt "ISO-8859-7")
(set-port-conversion-strategy! pt 'escape)
(write alpha pt)
(string=? "#\\á"
(get-output-string pt)))))
(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 #\ê #\á #\é))))
(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:encoding-error
(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))