This source file includes following definitions.
- test_u8_grapheme_prev
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22 #include <unigbrk.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include "macros.h"
28
29 static void
30 test_u8_grapheme_prev (const char *input, size_t n, size_t len)
31 {
32 const uint8_t *s = (const uint8_t *) input;
33 const uint8_t *end = s + n;
34 const uint8_t *prev = u8_grapheme_prev (end, s);
35 if (prev != end - len)
36 {
37 size_t i;
38
39 if (prev == NULL)
40 fputs ("u8_grapheme_prev returned NULL", stderr);
41 else
42 fprintf (stderr, "u8_grapheme_prev skipped %zu bytes", end - prev);
43 fprintf (stderr, ", expected %zu:\n", len);
44 for (i = 0; i < n; i++)
45 fprintf (stderr, " %02x", s[i]);
46 putc ('\n', stderr);
47 abort ();
48 }
49 }
50
51 int
52 main (void)
53 {
54 static const uint8_t s[] = "abc";
55
56
57 ASSERT (u8_grapheme_prev (NULL, NULL) == NULL);
58 ASSERT (u8_grapheme_prev (s, s) == NULL);
59
60
61 test_u8_grapheme_prev ("a", 1, 1);
62 test_u8_grapheme_prev ("ab", 2, 1);
63 test_u8_grapheme_prev ("abc", 3, 1);
64
65
66 #define HIRAGANA_A "\343\201\202"
67 test_u8_grapheme_prev (HIRAGANA_A, 3, 3);
68 test_u8_grapheme_prev (HIRAGANA_A"x", 4, 1);
69 test_u8_grapheme_prev (HIRAGANA_A HIRAGANA_A, 6, 3);
70
71
72 #define GRAVE "\314\200"
73 #define ACUTE "\314\201"
74 test_u8_grapheme_prev ("e"ACUTE, 3, 3);
75 test_u8_grapheme_prev ("e"ACUTE GRAVE, 5, 5);
76 test_u8_grapheme_prev ("e"ACUTE"x", 4, 1);
77 test_u8_grapheme_prev ("e"ACUTE "e"ACUTE, 6, 3);
78
79 return 0;
80 }