Enable the show value labels feature
[pspp] / tests / libpspp / i18n.at
1 AT_BANNER([i18n recoding])
2
3 # CHECK_I18N_RECODE([TITLE], [FROM-CODING], [TO-CODING],
4 #                   [FROM-TEXT], [TO-TEXT])
5 #
6 # Converts FROM-TEXT from FROM-CODING to TO-CODING and checks that the result
7 # is TO-TEXT.  The "printf" program is applied to both FROM-TEXT and TO-TEXT to
8 # allow for backslash-escapes.  (Hex escapes are not portable; use octal
9 # escapes instead.)
10 m4_define([CHECK_I18N_RECODE],
11   [AT_SETUP([convert $1])
12    AT_KEYWORDS([i18n])
13
14    dnl Skip the test if this host doesn't know the source and target encodings.
15    AT_CHECK([i18n-test supports_encodings '$2' '$3'])
16    AT_CHECK_UNQUOTED([i18n-test recode '$2' '$3' `printf '$4'`], [0], [`printf '$5'`
17 ])
18    AT_CLEANUP])
19      
20 CHECK_I18N_RECODE([reflexively], [ASCII], [ASCII], [abc], [abc])
21 CHECK_I18N_RECODE([without any change], [ASCII], [UTF-8], [abc], [abc])
22
23 CHECK_I18N_RECODE([from ISO-8859-1 to UTF-8], [ISO-8859-1], [UTF-8],
24                   [\242], [\302\242])
25 CHECK_I18N_RECODE([from UTF-8 to ISO-8859-1], [UTF-8], [ISO-8859-1],
26                   [\302\242], [\242])
27
28 # 0xc0 == 0300 is invalid in UTF-8
29 CHECK_I18N_RECODE([invalid UTF-8 to ISO-8859-1], [UTF-8], [ISO-8859-1],
30                   [xy\300z], [xy?z])
31 # 0xc2 == 0302 is the first byte of a 2-byte UTF-8 sequence
32 CHECK_I18N_RECODE([truncated UTF-8 to ISO-8559-1], [UTF-8], [ISO-8859-1],
33                   [xy\302], [xy?])
34
35 # Checks for a bug that caused the last character to be dropped in conversions
36 # from encodings that have combining diacritics (e.g. windows-1258).
37 CHECK_I18N_RECODE([dropped final character in windows-1258], [windows-1258],
38                   [UTF-8], [aeiou], [aeiou])
39
40 dnl The input to this test is 7 bytes long and the expected output is 9 bytes.
41 dnl So it should exercise the E2BIG case 
42 CHECK_I18N_RECODE([from ISO-8859-1 to UTF-8 with overflow], 
43                   [ISO-8859-1], [UTF-8],
44                   [Tsch\374\337!], [Tsch\303\274\303\237!])
45
46 AT_SETUP([convert unknown encoding])
47 AT_KEYWORDS([i18n])
48 AT_CHECK([i18n-test recode nonexistent1 nonexistent2 asdf], [0], [asdf
49 ],
50   [Warning: cannot create a converter for `nonexistent1' to `nonexistent2': Invalid argument
51 ])
52 AT_CLEANUP
53 \f
54 AT_BANNER([i18n concatenation])
55
56 # CHECK_I18N_CONCAT([HEAD], [TAIL], [ENCODING], [MAX-LEN], [ANSWER])
57 #
58 # Concatenates HEAD and TAIL, omitting as many characters from HEAD as needed
59 # to make the result come out to no more than MAX-LEN bytes if it was expressed
60 # in ENCODING, and checks that the answer matches ANSWER.  HEAD, TAIL, and
61 # ANSWER are all in UTF-8.  The "printf" program is applied to HEAD, TAIL, and
62 # ANSWER to allow for backslash-escapes.  (Hex escapes are not portable; use
63 # octal escapes instead.)
64 m4_define([CHECK_I18N_CONCAT],
65   [AT_SETUP([m4_if([$2], [], [truncate "$1" to $4 bytes in $3],
66                              [truncate "$1" + "$2" to $4 bytes in $3])])
67    AT_KEYWORDS([i18n])
68
69    dnl Skip the test if this host doesn't know the encoding.
70    AT_CHECK([i18n-test supports_encodings '$3'])
71    AT_CHECK_UNQUOTED(
72      [i18n-test concat "`printf '$1'`" "`printf '$2'`" '$3' '$4'], [0],
73      [`printf '$5'`
74 ])
75    AT_CLEANUP])
76
77 CHECK_I18N_CONCAT([abc], [], [UTF-8], [6], [abc])
78 CHECK_I18N_CONCAT([], [xyz], [UTF-8], [6], [xyz])
79 CHECK_I18N_CONCAT([], [], [UTF-8], [6], [])
80 CHECK_I18N_CONCAT([abcdefghij], [], [UTF-8], [6], [abcdef])
81 CHECK_I18N_CONCAT([], [tuvwxyz], [UTF-8], [6], [tuvwxyz])
82
83 CHECK_I18N_CONCAT([abc], [xyz], [UTF-8], [6], [abcxyz])
84 CHECK_I18N_CONCAT([abcd], [xyz], [UTF-8], [6], [abcxyz])
85 CHECK_I18N_CONCAT([abc], [uvwxyz], [UTF-8], [6], [uvwxyz])
86
87 # x in a box ( x⃞ ) is U+0078, U+20DE, 4 bytes in UTF-8, and one grapheme
88 # cluster.
89 CHECK_I18N_CONCAT([x\342\203\236], [y], [UTF-8], [0], [y])
90 CHECK_I18N_CONCAT([x\342\203\236], [y], [UTF-8], [1], [y])
91 CHECK_I18N_CONCAT([x\342\203\236], [y], [UTF-8], [2], [y])
92 CHECK_I18N_CONCAT([x\342\203\236], [y], [UTF-8], [3], [y])
93 CHECK_I18N_CONCAT([x\342\203\236], [y], [UTF-8], [4], [y])
94 CHECK_I18N_CONCAT([x\342\203\236], [y], [UTF-8], [5], [x\342\203\236y])
95
96 # éèä is only 3 bytes in ISO-8859-1.
97 CHECK_I18N_CONCAT([\303\251\303\250\303\244], [xyz], [ISO-8859-1], [0], [xyz])
98 CHECK_I18N_CONCAT([\303\251\303\250\303\244], [xyz], [ISO-8859-1], [1], [xyz])
99 CHECK_I18N_CONCAT([\303\251\303\250\303\244], [xyz], [ISO-8859-1], [2], [xyz])
100 CHECK_I18N_CONCAT([\303\251\303\250\303\244], [xyz], [ISO-8859-1], [3], [xyz])
101 CHECK_I18N_CONCAT([\303\251\303\250\303\244], [xyz], [ISO-8859-1], [4], 
102                   [\303\251xyz])
103 CHECK_I18N_CONCAT([\303\251\303\250\303\244], [xyz], [ISO-8859-1], [5],
104                   [\303\251\303\250xyz])
105 CHECK_I18N_CONCAT([\303\251\303\250\303\244], [xyz], [ISO-8859-1], [6],
106                   [\303\251\303\250\303\244xyz])