Add full Unicode capability to ports and the default reader
[bpt/guile.git] / test-suite / tests / encoding-utf8.test
1 ;;;; strings.test --- test suite for Guile's string functions -*- mode: scheme; coding: utf-8 -*-
2 ;;;;
3 ;;;; Copyright (C) 2009 Free Software Foundation, Inc.
4 ;;;;
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.
9 ;;;;
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.
14 ;;;;
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
19
20 (define-module (test-strings)
21 #:use-module (test-suite lib)
22 #:use-module (srfi srfi-1))
23
24 (define exception:conversion
25 (cons 'misc-error "^cannot convert to output locale"))
26
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)))
30
31 (setlocale LC_ALL "")
32
33 (define s1 "última")
34 (define s2 "cédula")
35 (define s3 "años")
36 (define s4 "羅生門")
37
38 (with-test-prefix "string length"
39
40 (pass-if "última"
41 (eq? (string-length s1) 6))
42
43 (pass-if "cédula"
44 (eq? (string-length s2) 6))
45
46 (pass-if "años"
47 (eq? (string-length s3) 4))
48
49 (pass-if "羅生門"
50 (eq? (string-length s4) 3)))
51
52 (with-test-prefix "internal encoding"
53
54 (pass-if "última"
55 (string=? s1 (string-ints #xfa #x6c #x74 #x69 #x6d #x61)))
56
57 (pass-if "cédula"
58 (string=? s2 (string-ints #x63 #xe9 #x64 #x75 #x6c #x61)))
59
60 (pass-if "años"
61 (string=? s3 (string-ints #x61 #xf1 #x6f #x73)))
62
63 (pass-if "羅生門"
64 (string=? s4 (string-ints #x7f85 #x751f #x9580))))
65
66 (with-test-prefix "chars"
67
68 (pass-if "última"
69 (list= eqv? (string->list s1)
70 (list #\ú #\l #\t #\i #\m #\a)))
71
72 (pass-if "cédula"
73 (list= eqv? (string->list s2)
74 (list #\c #\é #\d #\u #\l #\a)))
75
76 (pass-if "años"
77 (list= eqv? (string->list s3)
78 (list #\a #\ñ #\o #\s)))
79
80 (pass-if "羅生門"
81 (list= eqv? (string->list s4)
82 (list #\羅 #\生 #\門))))
83
84 (with-test-prefix "symbols == strings"
85
86 (pass-if "última"
87 (eq? (string->symbol s1) 'última))
88
89 (pass-if "cédula"
90 (eq? (string->symbol s2) 'cédula))
91
92 (pass-if "años"
93 (eq? (string->symbol s3) 'años))
94
95 (pass-if "羅生門"
96 (eq? (string->symbol s4) '羅生門)))
97
98 (with-test-prefix "non-ascii variable names"
99
100 (pass-if "1"
101 (let ((芥川龍之介 1)
102 (ñ 2))
103 (eq? (+ 芥川龍之介 ñ) 3))))
104
105