1 ;;;; strings.test --- test suite for Guile's string functions -*- mode: scheme; coding: utf-8 -*-
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)))
38 (with-test-prefix "string length"
41 (eq? (string-length s1) 6))
44 (eq? (string-length s2) 6))
47 (eq? (string-length s3) 4))
50 (eq? (string-length s4) 3)))
52 (with-test-prefix "internal encoding"
55 (string=? s1 (string-ints #xfa #x6c #x74 #x69 #x6d #x61)))
58 (string=? s2 (string-ints #x63 #xe9 #x64 #x75 #x6c #x61)))
61 (string=? s3 (string-ints #x61 #xf1 #x6f #x73)))
64 (string=? s4 (string-ints #x7f85 #x751f #x9580))))
66 (with-test-prefix "chars"
69 (list= eqv? (string->list s1)
70 (list #\ú #\l #\t #\i #\m #\a)))
73 (list= eqv? (string->list s2)
74 (list #\c #\é #\d #\u #\l #\a)))
77 (list= eqv? (string->list s3)
78 (list #\a #\ñ #\o #\s)))
81 (list= eqv? (string->list s4)
84 (with-test-prefix "symbols == strings"
87 (eq? (string->symbol s1) 'última))
90 (eq? (string->symbol s2) 'cédula))
93 (eq? (string->symbol s3) 'años))
96 (eq? (string->symbol s4) '羅生門)))
98 (with-test-prefix "non-ascii variable names"
103 (eq? (+ 芥川龍之介 ñ) 3))))