Fix bytevector-copy when applied to SRFI-4 homogeneous numeric vectors.
[bpt/guile.git] / test-suite / tests / iconv.test
CommitLineData
f05bb849
AW
1;;;; iconv.test --- Exercise the iconv API. -*- coding: utf-8; mode: scheme; -*-
2;;;;
3;;;; Copyright (C) 2013 Free Software Foundation, Inc.
4;;;; Andy Wingo
5;;;;
6;;;; This library is free software; you can redistribute it and/or
7;;;; modify it under the terms of the GNU Lesser General Public
8;;;; License as published by the Free Software Foundation; either
9;;;; version 3 of the License, or (at your option) any later version.
10;;;;
11;;;; This library is distributed in the hope that it will be useful,
12;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14;;;; Lesser General Public License for more details.
15;;;;
16;;;; You should have received a copy of the GNU Lesser General Public
17;;;; License along with this library; if not, write to the Free Software
18;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20(define-module (test-suite iconv)
21 #:use-module (ice-9 iconv)
22 #:use-module (rnrs bytevectors)
23 #:use-module (test-suite lib))
24
25
26(define exception:encoding-error
27 '(encoding-error . ""))
28
29(define exception:decoding-error
30 '(decoding-error . ""))
31
32\f
33(with-test-prefix "ascii string"
34 (let ((s "Hello, World!"))
35 ;; For ASCII, all of these encodings should be the same.
36
37 (pass-if "to ascii bytevector"
38 (equal? (string->bytevector s "ASCII")
39 #vu8(72 101 108 108 111 44 32 87 111 114 108 100 33)))
40
41 (pass-if "to ascii bytevector (length check)"
42 (equal? (string-length s)
43 (bytevector-length (string->bytevector s "ascii"))))
44
45 (pass-if "from ascii bytevector"
46 (equal? s
47 (bytevector->string (string->bytevector s "ascii") "ascii")))
48
49 (pass-if "to utf-8 bytevector"
50 (equal? (string->bytevector s "ASCII")
51 (string->bytevector s "utf-8")))
52
53 (pass-if "to UTF-8 bytevector (testing encoding case sensitivity)"
54 (equal? (string->bytevector s "ascii")
55 (string->bytevector s "UTF-8")))
56
57 (pass-if "from utf-8 bytevector"
58 (equal? s
59 (bytevector->string (string->bytevector s "utf-8") "utf-8")))
60
61 (pass-if "to latin1 bytevector"
62 (equal? (string->bytevector s "ASCII")
63 (string->bytevector s "latin1")))
64
65 (pass-if "from latin1 bytevector"
66 (equal? s
67 (bytevector->string (string->bytevector s "utf-8") "utf-8")))))
68
69(with-test-prefix "narrow non-ascii string"
70 (let ((s "été"))
71 (pass-if "to latin1 bytevector"
72 (equal? (string->bytevector s "latin1")
73 #vu8(233 116 233)))
74
75 (pass-if "to latin1 bytevector (length check)"
76 (equal? (string-length s)
77 (bytevector-length (string->bytevector s "latin1"))))
78
79 (pass-if "from latin1 bytevector"
80 (equal? s
81 (bytevector->string (string->bytevector s "latin1") "latin1")))
82
83 (pass-if "to utf-8 bytevector"
84 (equal? (string->bytevector s "utf-8")
85 #vu8(195 169 116 195 169)))
86
87 (pass-if "from utf-8 bytevector"
88 (equal? s
89 (bytevector->string (string->bytevector s "utf-8") "utf-8")))
90
91 (pass-if-exception "encode latin1 as ascii" exception:encoding-error
92 (string->bytevector s "ascii"))
93
94 (pass-if-exception "misparse latin1 as utf8" exception:decoding-error
95 (bytevector->string (string->bytevector s "latin1") "utf-8"))
96
97 (pass-if-exception "misparse latin1 as ascii" exception:decoding-error
98 (bytevector->string (string->bytevector s "latin1") "ascii"))))
99
100
101(with-test-prefix "wide non-ascii string"
102 (let ((s "ΧΑΟΣ"))
103 (pass-if "to utf-8 bytevector"
104 (equal? (string->bytevector s "utf-8")
105 #vu8(206 167 206 145 206 159 206 163) ))
106
107 (pass-if "from utf-8 bytevector"
108 (equal? s
109 (bytevector->string (string->bytevector s "utf-8") "utf-8")))
110
111 (pass-if-exception "encode as ascii" exception:encoding-error
112 (string->bytevector s "ascii"))
113
114 (pass-if-exception "encode as latin1" exception:encoding-error
5ed4ea90
AW
115 (string->bytevector s "latin1"))
116
117 (pass-if "encode as ascii with substitutions"
118 (equal? (make-string (string-length s) #\?)
119 (bytevector->string (string->bytevector s "ascii" 'substitute)
120 "ascii")))))