mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 20:00:19 +02:00
* test-suite/tests/00-socket.test: * test-suite/tests/alist.test: * test-suite/tests/elisp.test: * test-suite/tests/encoding-iso88591.test: * test-suite/tests/encoding-iso88597.test: * test-suite/tests/encoding-utf8.test: * test-suite/tests/hash.test: * test-suite/tests/i18n.test: * test-suite/tests/modules.test: * test-suite/tests/ports.test: * test-suite/tests/srfi-35.test: Make tests use eqv? instead of eq? when comparing numbers, characters. Checked also for similar uses of assq[-ref]. * test-suite/tests/vlist.test ("vhash-delete honors HASH"): Change test to use eqv-ness, not eq-ness, which should not impact its purpose as these two are equivalent for strings.
183 lines
5.6 KiB
Scheme
183 lines
5.6 KiB
Scheme
;;;; encoding-iso88591.test --- test suite for Guile's string encodings -*- mode: scheme; coding: iso-8859-1 -*-
|
|
;;;;
|
|
;;;; 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)))
|
|
|
|
;; Set locale to the environment's locale, so that the prints look OK.
|
|
(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 A acute"
|
|
(char=? a-acute #\Á))
|
|
|
|
(pass-if "display A"
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-1")
|
|
(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-1")
|
|
(set-port-conversion-strategy! pt 'escape)
|
|
(display a-acute pt)
|
|
(string=? "Á"
|
|
(get-output-string pt))))
|
|
|
|
(pass-if "display alpha"
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-1")
|
|
(set-port-conversion-strategy! pt 'escape)
|
|
(display alpha pt)
|
|
(string-ci=? "\\u03b1"
|
|
(get-output-string pt))))
|
|
|
|
(pass-if "display Cherokee a"
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-1")
|
|
(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-1")
|
|
(set-port-conversion-strategy! pt 'escape)
|
|
(write ascii-a pt)
|
|
(string=? "#\\A"
|
|
(get-output-string pt))))
|
|
|
|
(pass-if "write A acute"
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-1")
|
|
(set-port-conversion-strategy! pt 'escape)
|
|
(write a-acute pt)
|
|
(string=? "#\\Á"
|
|
(get-output-string pt))))
|
|
|
|
(pass-if "write A followed by combining accent"
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-1")
|
|
(set-port-conversion-strategy! pt 'escape)
|
|
(write (string #\A (integer->char #x030f)) pt)
|
|
(string-ci=? "\"A\\u030f\""
|
|
(get-output-string pt)))))
|
|
|
|
|
|
(define s1 "última")
|
|
(define s2 "cédula")
|
|
(define s3 "años")
|
|
(define s4 "¿Cómo?")
|
|
|
|
(with-test-prefix "string length"
|
|
|
|
(pass-if "última"
|
|
(eqv? (string-length s1) 6))
|
|
|
|
(pass-if "cédula"
|
|
(eqv? (string-length s2) 6))
|
|
|
|
(pass-if "años"
|
|
(eqv? (string-length s3) 4))
|
|
|
|
(pass-if "¿Cómo?"
|
|
(eqv? (string-length s4) 6)))
|
|
|
|
(with-test-prefix "internal encoding"
|
|
|
|
(pass-if "última"
|
|
(string=? s1 (string-ints #xfa #x6c #x74 #x69 #x6d #x61)))
|
|
|
|
(pass-if "cédula"
|
|
(string=? s2 (string-ints #x63 #xe9 #x64 #x75 #x6c #x61)))
|
|
|
|
(pass-if "años"
|
|
(string=? s3 (string-ints #x61 #xf1 #x6f #x73)))
|
|
|
|
(pass-if "¿Cómo?"
|
|
(string=? s4 (string-ints #xbf #x43 #xf3 #x6d #x6f #x3f))))
|
|
|
|
(with-test-prefix "chars"
|
|
|
|
(pass-if "última"
|
|
(list= eqv? (string->list s1)
|
|
(list #\ú #\l #\t #\i #\m #\a)))
|
|
|
|
(pass-if "cédula"
|
|
(list= eqv? (string->list s2)
|
|
(list #\c #\é #\d #\u #\l #\a)))
|
|
|
|
(pass-if "años"
|
|
(list= eqv? (string->list s3)
|
|
(list #\a #\ñ #\o #\s)))
|
|
|
|
(pass-if "¿Cómo?"
|
|
(list= eqv? (string->list s4)
|
|
(list #\¿ #\C #\ó #\m #\o #\?))))
|
|
|
|
(with-test-prefix "symbols == strings"
|
|
|
|
(pass-if "última"
|
|
(eq? (string->symbol s1) 'última))
|
|
|
|
(pass-if "cédula"
|
|
(eq? (string->symbol s2) 'cédula))
|
|
|
|
(pass-if "años"
|
|
(eq? (string->symbol s3) 'años))
|
|
|
|
(pass-if "¿Cómo?"
|
|
(eq? (string->symbol s4) '¿Cómo?)))
|
|
|
|
(with-test-prefix "non-ascii variable names"
|
|
|
|
(pass-if "1"
|
|
(let ((á 1)
|
|
(ñ 2))
|
|
(eqv? (+ á ñ) 3))))
|
|
|
|
(with-test-prefix "output errors"
|
|
|
|
(pass-if-exception "char 256" exception:encoding-error
|
|
(let ((pt (open-output-string)))
|
|
(set-port-encoding! pt "ISO-8859-1")
|
|
(set-port-conversion-strategy! pt 'error)
|
|
(display (string-ints 256) pt))))
|
|
|
|
;; Reset locales
|
|
(if (defined? 'setlocale)
|
|
(setlocale LC_ALL oldlocale))
|