Blob


1 /* See LICENSE file for copyright and license details. */
2 #include <stdbool.h>
3 #include <stdint.h>
5 #include "../gen/character-test.h"
6 #include "../grapheme.h"
7 #include "util.h"
9 static const struct unit_test_next_break next_character_break[] = {
10 {
11 .description = "NULL input",
12 .input = {
13 .src = NULL,
14 .srclen = 0,
15 },
16 .output = { 0 },
17 },
18 {
19 .description = "empty input",
20 .input = {
21 .src = (uint_least32_t *)(uint_least32_t[]){ 0x0 },
22 .srclen = 0,
23 },
24 .output = { 0 },
25 },
26 {
27 .description = "empty input, null-terminated",
28 .input = {
29 .src = (uint_least32_t *)(uint_least32_t[]){ 0x0 },
30 .srclen = SIZE_MAX,
31 },
32 .output = { 0 },
33 },
34 {
35 .description = "one character",
36 .input = {
37 .src = (uint_least32_t *)(uint_least32_t[]){ 0x1F1E9, 0x1F1EA, 0x2A },
38 .srclen = 3,
39 },
40 .output = { 2 },
41 },
42 {
43 .description = "one character, null-terminated",
44 .input = {
45 .src = (uint_least32_t *)(uint_least32_t[]){ 0x1F1E9, 0x1F1EA, 0x0 },
46 .srclen = SIZE_MAX,
47 },
48 .output = { 2 },
49 },
50 };
52 static const struct unit_test_next_break_utf8 next_character_break_utf8[] = {
53 {
54 .description = "NULL input",
55 .input = {
56 .src = NULL,
57 .srclen = 0,
58 },
59 .output = { 0 },
60 },
61 {
62 .description = "empty input",
63 .input = { "", 0 },
64 .output = { 0 },
65 },
66 {
67 .description = "empty input, NUL-terminated",
68 .input = { "", SIZE_MAX },
69 .output = { 0 },
70 },
71 {
72 .description = "one character",
73 .input = { "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA*", 9 },
74 .output = { 8 },
75 },
76 {
77 .description = "one character, fragment",
78 .input = { "\xF0\x9F\x87\xA9\xF0", 5 },
79 .output = { 4 },
80 },
81 {
82 .description = "one character, NUL-terminated",
83 .input = { "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA", SIZE_MAX },
84 .output = { 8 },
85 },
86 {
87 .description = "one character, fragment, NUL-terminated",
88 .input = { "\xF0\x9F\x87\xA9\xF0\x9F", SIZE_MAX },
89 .output = { 4 },
90 },
91 };
93 static int
94 unit_test_callback_next_character_break(const void *t, size_t off,
95 const char *name,
96 const char *argv0)
97 {
98 return unit_test_callback_next_break(t, off,
99 grapheme_next_character_break,
100 name, argv0);
103 static int
104 unit_test_callback_next_character_break_utf8(const void *t, size_t off,
105 const char *name,
106 const char *argv0)
108 return unit_test_callback_next_break_utf8(t, off,
109 grapheme_next_character_break_utf8,
110 name, argv0);
113 int
114 main(int argc, char *argv[])
116 (void)argc;
118 return run_break_tests(grapheme_next_character_break,
119 character_break_test, LEN(character_break_test), argv[0]) +
120 run_unit_tests(unit_test_callback_next_character_break,
121 next_character_break, LEN(next_character_break),
122 "grapheme_next_character_break", argv[0]) +
123 run_unit_tests(unit_test_callback_next_character_break_utf8,
124 next_character_break_utf8, LEN(next_character_break_utf8),
125 "grapheme_next_character_break_utf8", argv[0]);