1 /* Test of u16_prev() function.
2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
26 check (const uint16_t *input
, size_t input_length
, ucs4_t
*puc
)
30 /* Test recognition when at the beginning of the string. */
31 if (u16_prev (&uc
, input
+ input_length
, input
) != input
)
34 /* Test recognition when preceded by a 1-unit character. */
43 for (i
= 0; i
< input_length
; i
++)
46 if (u16_prev (&uc1
, ptr
+ input_length
, buf
) != ptr
)
52 /* Test recognition when preceded by a 2-unit character. */
62 for (i
= 0; i
< input_length
; i
++)
65 if (u16_prev (&uc1
, ptr
+ input_length
, buf
) != ptr
)
76 check_invalid (const uint16_t *input
, size_t input_length
)
80 /* Test recognition when at the beginning of the string. */
82 if (u16_prev (&uc
, input
+ input_length
, input
) != NULL
)
87 /* Test recognition when preceded by a 1-unit character. */
95 for (i
= 0; i
< input_length
; i
++)
99 if (u16_prev (&uc
, ptr
+ input_length
, buf
) != NULL
)
105 /* Test recognition when preceded by a 2-unit character. */
114 for (i
= 0; i
< input_length
; i
++)
118 if (u16_prev (&uc
, ptr
+ input_length
, buf
) != NULL
)
132 /* Test ISO 646 unit input. */
137 for (c
= 0; c
< 0x80; c
++)
141 ASSERT (check (buf
, 1, &uc
) == 0);
146 /* Test BMP unit input. */
148 static const uint16_t input
[] = { 0x20AC };
150 ASSERT (check (input
, SIZEOF (input
), &uc
) == 0);
151 ASSERT (uc
== 0x20AC);
154 /* Test 2-units character input. */
156 static const uint16_t input
[] = { 0xD835, 0xDD1F };
158 ASSERT (check (input
, SIZEOF (input
), &uc
) == 0);
159 ASSERT (uc
== 0x1D51F);
162 /* Test incomplete/invalid 1-unit input. */
164 static const uint16_t input
[] = { 0xD835 };
165 ASSERT (check_invalid (input
, SIZEOF (input
)) == 0);
168 static const uint16_t input
[] = { 0xDD1F };
169 ASSERT (check_invalid (input
, SIZEOF (input
)) == 0);