Add full Unicode capability to ports and the default reader
[bpt/guile.git] / test-suite / tests / encoding-iso88597.test
1 ;;;; strings.test --- test suite for Guile's string functions -*- mode: scheme; coding: iso-8859-7 -*-
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 "Ðåñß")
34 (define s2 "ôçò")
35 (define s3 "êñéôéêÞò")
36 (define s4 "êáé")
37
38 (with-test-prefix "string length"
39
40 (pass-if "s1"
41 (eq? (string-length s1) 4))
42
43 (pass-if "s2"
44 (eq? (string-length s2) 3))
45
46 (pass-if "s3"
47 (eq? (string-length s3) 8))
48
49 (pass-if "s4"
50 (eq? (string-length s4) 3)))
51
52 (with-test-prefix "internal encoding"
53
54 (pass-if "s1"
55 (string=? s1 (string-ints #x03a0 #x03b5 #x03c1 #x03af)))
56
57 (pass-if "s2"
58 (string=? s2 (string-ints #x03c4 #x03b7 #x03c2)))
59
60 (pass-if "s3"
61 (string=? s3 (string-ints #x03ba #x03c1 #x03b9 #x03c4 #x03b9 #x03ba #x03ae #x03c2)))
62
63 (pass-if "s4"
64 (string=? s4 (string-ints #x03ba #x03b1 #x03b9))))
65
66 (with-test-prefix "chars"
67
68 (pass-if "s1"
69 (list= eqv? (string->list s1)
70 (list #\Ð #\å #\ñ #\ß)))
71
72 (pass-if "s2"
73 (list= eqv? (string->list s2)
74 (list #\ô #\ç #\ò)))
75
76 (pass-if "s3"
77 (list= eqv? (string->list s3)
78 (list #\ê #\ñ #\é #\ô #\é #\ê #\Þ #\ò)))
79
80 (pass-if "s4"
81 (list= eqv? (string->list s4)
82 (list #\ê #\á #\é))))
83
84 ;; Testing that the display of the string is output in the ISO-8859-7
85 ;; encoding
86 (with-test-prefix "display"
87
88 (pass-if "s1"
89 (let ((pt (open-output-string)))
90 (set-port-encoding! pt "ISO-8859-7")
91 (display s1 pt)
92 (list= eqv?
93 (list #xd0 #xe5 #xf1 #xdf)
94 (u8vector->list
95 (get-output-locale-u8vector pt)))))
96 (pass-if "s2"
97 (let ((pt (open-output-string)))
98 (set-port-encoding! pt "ISO-8859-7")
99 (display s2 pt)
100 (list= eqv?
101 (list #xf4 #xe7 #xf2)
102 (u8vector->list
103 (get-output-locale-u8vector pt))))))
104
105 (with-test-prefix "symbols == strings"
106
107 (pass-if "Ðåñß"
108 (eq? (string->symbol s1) 'Ðåñß))
109
110 (pass-if "ôçò"
111 (eq? (string->symbol s2) 'ôçò))
112
113 (pass-if "êñéôéêÞò"
114 (eq? (string->symbol s3) 'êñéôéêÞò))
115
116 (pass-if "êáé"
117 (eq? (string->symbol s4) 'êáé)))
118
119 (with-test-prefix "non-ascii variable names"
120
121 (pass-if "1"
122 (let ((á 1)
123 (ñ 2))
124 (eq? (+ á ñ) 3))))
125
126 (with-test-prefix "output errors"
127
128 (pass-if-exception "char #x0400"
129 exception:conversion
130 (let ((pt (open-output-string)))
131 (set-port-encoding! pt "ISO-8859-7")
132 (set-port-conversion-strategy! pt 'error)
133 (display (string-ints #x0400) pt))))
134
135 ;; Reset locale
136 (setlocale LC_ALL "C")