Implement new clarified decomposition of Hangul syllables.
[gnulib.git] / tests / uninorm / test-decomposition.c
1 /* Test of decomposition of Unicode characters.
2    Copyright (C) 2009 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
18
19 #include <config.h>
20
21 #include "uninorm.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #define ASSERT(expr) \
27   do                                                                         \
28     {                                                                        \
29       if (!(expr))                                                           \
30         {                                                                    \
31           fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
32           fflush (stderr);                                                   \
33           abort ();                                                          \
34         }                                                                    \
35     }                                                                        \
36   while (0)
37
38 int
39 main ()
40 {
41   ucs4_t decomposed[UC_DECOMPOSITION_MAX_LENGTH];
42   int tag;
43   int ret;
44
45   /* SPACE */
46   ret = uc_decomposition (0x0020, &tag, decomposed);
47   ASSERT (ret == -1);
48
49   /* LATIN CAPITAL LETTER A WITH DIAERESIS */
50   ret = uc_decomposition (0x00C4, &tag, decomposed);
51   ASSERT (ret == 2);
52   ASSERT (tag == UC_DECOMP_CANONICAL);
53   ASSERT (decomposed[0] == 0x0041);
54   ASSERT (decomposed[1] == 0x0308);
55
56   /* LATIN CAPITAL LETTER A WITH DIAERESIS AND MACRON */
57   ret = uc_decomposition (0x01DE, &tag, decomposed);
58   ASSERT (ret == 2);
59   ASSERT (tag == UC_DECOMP_CANONICAL);
60   ASSERT (decomposed[0] == 0x00C4);
61   ASSERT (decomposed[1] == 0x0304);
62
63   /* GREEK DIALYTIKA AND PERISPOMENI */
64   ret = uc_decomposition (0x1FC1, &tag, decomposed);
65   ASSERT (ret == 2);
66   ASSERT (tag == UC_DECOMP_CANONICAL);
67   ASSERT (decomposed[0] == 0x00A8);
68   ASSERT (decomposed[1] == 0x0342);
69
70   /* SCRIPT SMALL L */
71   ret = uc_decomposition (0x2113, &tag, decomposed);
72   ASSERT (ret == 1);
73   ASSERT (tag == UC_DECOMP_FONT);
74   ASSERT (decomposed[0] == 0x006C);
75
76   /* NO-BREAK SPACE */
77   ret = uc_decomposition (0x00A0, &tag, decomposed);
78   ASSERT (ret == 1);
79   ASSERT (tag == UC_DECOMP_NOBREAK);
80   ASSERT (decomposed[0] == 0x0020);
81
82   /* ARABIC LETTER VEH INITIAL FORM */
83   ret = uc_decomposition (0xFB6C, &tag, decomposed);
84   ASSERT (ret == 1);
85   ASSERT (tag == UC_DECOMP_INITIAL);
86   ASSERT (decomposed[0] == 0x06A4);
87
88   /* ARABIC LETTER VEH MEDIAL FORM */
89   ret = uc_decomposition (0xFB6D, &tag, decomposed);
90   ASSERT (ret == 1);
91   ASSERT (tag == UC_DECOMP_MEDIAL);
92   ASSERT (decomposed[0] == 0x06A4);
93
94   /* ARABIC LETTER VEH FINAL FORM */
95   ret = uc_decomposition (0xFB6B, &tag, decomposed);
96   ASSERT (ret == 1);
97   ASSERT (tag == UC_DECOMP_FINAL);
98   ASSERT (decomposed[0] == 0x06A4);
99
100   /* ARABIC LETTER VEH ISOLATED FORM */
101   ret = uc_decomposition (0xFB6A, &tag, decomposed);
102   ASSERT (ret == 1);
103   ASSERT (tag == UC_DECOMP_ISOLATED);
104   ASSERT (decomposed[0] == 0x06A4);
105
106   /* CIRCLED NUMBER FIFTEEN */
107   ret = uc_decomposition (0x246E, &tag, decomposed);
108   ASSERT (ret == 2);
109   ASSERT (tag == UC_DECOMP_CIRCLE);
110   ASSERT (decomposed[0] == 0x0031);
111   ASSERT (decomposed[1] == 0x0035);
112
113   /* TRADE MARK SIGN */
114   ret = uc_decomposition (0x2122, &tag, decomposed);
115   ASSERT (ret == 2);
116   ASSERT (tag == UC_DECOMP_SUPER);
117   ASSERT (decomposed[0] == 0x0054);
118   ASSERT (decomposed[1] == 0x004D);
119
120   /* LATIN SUBSCRIPT SMALL LETTER I */
121   ret = uc_decomposition (0x1D62, &tag, decomposed);
122   ASSERT (ret == 1);
123   ASSERT (tag == UC_DECOMP_SUB);
124   ASSERT (decomposed[0] == 0x0069);
125
126   /* PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS */
127   ret = uc_decomposition (0xFE35, &tag, decomposed);
128   ASSERT (ret == 1);
129   ASSERT (tag == UC_DECOMP_VERTICAL);
130   ASSERT (decomposed[0] == 0x0028);
131
132   /* FULLWIDTH LATIN CAPITAL LETTER A */
133   ret = uc_decomposition (0xFF21, &tag, decomposed);
134   ASSERT (ret == 1);
135   ASSERT (tag == UC_DECOMP_WIDE);
136   ASSERT (decomposed[0] == 0x0041);
137
138   /* HALFWIDTH IDEOGRAPHIC COMMA */
139   ret = uc_decomposition (0xFF64, &tag, decomposed);
140   ASSERT (ret == 1);
141   ASSERT (tag == UC_DECOMP_NARROW);
142   ASSERT (decomposed[0] == 0x3001);
143
144   /* SMALL IDEOGRAPHIC COMMA */
145   ret = uc_decomposition (0xFE51, &tag, decomposed);
146   ASSERT (ret == 1);
147   ASSERT (tag == UC_DECOMP_SMALL);
148   ASSERT (decomposed[0] == 0x3001);
149
150   /* SQUARE MHZ */
151   ret = uc_decomposition (0x3392, &tag, decomposed);
152   ASSERT (ret == 3);
153   ASSERT (tag == UC_DECOMP_SQUARE);
154   ASSERT (decomposed[0] == 0x004D);
155   ASSERT (decomposed[1] == 0x0048);
156   ASSERT (decomposed[2] == 0x007A);
157
158   /* VULGAR FRACTION THREE EIGHTHS */
159   ret = uc_decomposition (0x215C, &tag, decomposed);
160   ASSERT (ret == 3);
161   ASSERT (tag == UC_DECOMP_FRACTION);
162   ASSERT (decomposed[0] == 0x0033);
163   ASSERT (decomposed[1] == 0x2044);
164   ASSERT (decomposed[2] == 0x0038);
165
166   /* MICRO SIGN */
167   ret = uc_decomposition (0x00B5, &tag, decomposed);
168   ASSERT (ret == 1);
169   ASSERT (tag == UC_DECOMP_COMPAT);
170   ASSERT (decomposed[0] == 0x03BC);
171
172   /* ARABIC LIGATURE SALLALLAHOU ALAYHE WASALLAM */
173   ret = uc_decomposition (0xFDFA, &tag, decomposed);
174   ASSERT (ret == 18);
175   ASSERT (tag == UC_DECOMP_ISOLATED);
176   ASSERT (decomposed[0] == 0x0635);
177   ASSERT (decomposed[1] == 0x0644);
178   ASSERT (decomposed[2] == 0x0649);
179   ASSERT (decomposed[3] == 0x0020);
180   ASSERT (decomposed[4] == 0x0627);
181   ASSERT (decomposed[5] == 0x0644);
182   ASSERT (decomposed[6] == 0x0644);
183   ASSERT (decomposed[7] == 0x0647);
184   ASSERT (decomposed[8] == 0x0020);
185   ASSERT (decomposed[9] == 0x0639);
186   ASSERT (decomposed[10] == 0x0644);
187   ASSERT (decomposed[11] == 0x064A);
188   ASSERT (decomposed[12] == 0x0647);
189   ASSERT (decomposed[13] == 0x0020);
190   ASSERT (decomposed[14] == 0x0648);
191   ASSERT (decomposed[15] == 0x0633);
192   ASSERT (decomposed[16] == 0x0644);
193   ASSERT (decomposed[17] == 0x0645);
194
195   /* HANGUL SYLLABLE GEUL */
196   ret = uc_decomposition (0xAE00, &tag, decomposed);
197   /* See the clarification at <http://www.unicode.org/versions/Unicode5.1.0/>,
198      section "Clarification of Hangul Jamo Handling".  */
199 #if 1
200   ASSERT (ret == 2);
201   ASSERT (tag == UC_DECOMP_CANONICAL);
202   ASSERT (decomposed[0] == 0xADF8);
203   ASSERT (decomposed[1] == 0x11AF);
204 #else
205   ASSERT (ret == 3);
206   ASSERT (tag == UC_DECOMP_CANONICAL);
207   ASSERT (decomposed[0] == 0x1100);
208   ASSERT (decomposed[1] == 0x1173);
209   ASSERT (decomposed[2] == 0x11AF);
210 #endif
211
212   /* HANGUL SYLLABLE GEU */
213   ret = uc_decomposition (0xADF8, &tag, decomposed);
214   ASSERT (ret == 2);
215   ASSERT (tag == UC_DECOMP_CANONICAL);
216   ASSERT (decomposed[0] == 0x1100);
217   ASSERT (decomposed[1] == 0x1173);
218
219   return 0;
220 }