1 3448adb0 2022-11-02 op /* See LICENSE file for copyright and license details. */
2 3448adb0 2022-11-02 op #include <stdbool.h>
3 3448adb0 2022-11-02 op #include <stdint.h>
5 3448adb0 2022-11-02 op #include "../gen/word-test.h"
6 3448adb0 2022-11-02 op #include "../grapheme.h"
7 3448adb0 2022-11-02 op #include "util.h"
9 3448adb0 2022-11-02 op static const struct unit_test_next_break next_word_break[] = {
11 3448adb0 2022-11-02 op .description = "NULL input",
16 3448adb0 2022-11-02 op .output = { 0 },
19 3448adb0 2022-11-02 op .description = "empty input",
21 3448adb0 2022-11-02 op .src = (uint_least32_t *)(uint_least32_t[]){ 0x0 },
24 3448adb0 2022-11-02 op .output = { 0 },
27 3448adb0 2022-11-02 op .description = "empty input, null-terminated",
29 3448adb0 2022-11-02 op .src = (uint_least32_t *)(uint_least32_t[]){ 0x0 },
30 3448adb0 2022-11-02 op .srclen = SIZE_MAX,
32 3448adb0 2022-11-02 op .output = { 0 },
35 3448adb0 2022-11-02 op .description = "one word",
37 3448adb0 2022-11-02 op .src = (uint_least32_t *)(uint_least32_t[]){ 0x1F1E9, 0x1F1EA, 0x20, 0x2A },
40 3448adb0 2022-11-02 op .output = { 2 },
43 3448adb0 2022-11-02 op .description = "one word, null-terminated",
45 3448adb0 2022-11-02 op .src = (uint_least32_t *)(uint_least32_t[]){ 0x1F1E9, 0x1F1EA, 0x20, 0x2A, 0x0 },
46 3448adb0 2022-11-02 op .srclen = SIZE_MAX,
48 3448adb0 2022-11-02 op .output = { 2 },
52 3448adb0 2022-11-02 op static const struct unit_test_next_break_utf8 next_word_break_utf8[] = {
54 3448adb0 2022-11-02 op .description = "NULL input",
59 3448adb0 2022-11-02 op .output = { 0 },
62 3448adb0 2022-11-02 op .description = "empty input",
63 3448adb0 2022-11-02 op .input = { "", 0 },
64 3448adb0 2022-11-02 op .output = { 0 },
67 3448adb0 2022-11-02 op .description = "empty input, NUL-terminated",
68 3448adb0 2022-11-02 op .input = { "", SIZE_MAX },
69 3448adb0 2022-11-02 op .output = { 0 },
72 3448adb0 2022-11-02 op .description = "one word",
73 3448adb0 2022-11-02 op .input = { "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA is", 11 },
74 3448adb0 2022-11-02 op .output = { 8 },
77 3448adb0 2022-11-02 op .description = "one word, fragment",
78 3448adb0 2022-11-02 op .input = { "\xF0\x9F\x87\xA9\xF0", 5 },
79 3448adb0 2022-11-02 op .output = { 4 },
82 3448adb0 2022-11-02 op .description = "one word, NUL-terminated",
83 3448adb0 2022-11-02 op .input = { "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA is", SIZE_MAX },
84 3448adb0 2022-11-02 op .output = { 8 },
87 3448adb0 2022-11-02 op .description = "one word, fragment, NUL-terminated",
88 3448adb0 2022-11-02 op .input = { "\xF0\x9F\x87\xA9\xF0\x9F", SIZE_MAX },
89 3448adb0 2022-11-02 op .output = { 4 },
94 3448adb0 2022-11-02 op unit_test_callback_next_word_break(const void *t, size_t off,
95 3448adb0 2022-11-02 op const char *name,
96 3448adb0 2022-11-02 op const char *argv0)
98 3448adb0 2022-11-02 op return unit_test_callback_next_break(t, off,
99 3448adb0 2022-11-02 op grapheme_next_word_break,
100 3448adb0 2022-11-02 op name, argv0);
104 3448adb0 2022-11-02 op unit_test_callback_next_word_break_utf8(const void *t, size_t off,
105 3448adb0 2022-11-02 op const char *name,
106 3448adb0 2022-11-02 op const char *argv0)
108 3448adb0 2022-11-02 op return unit_test_callback_next_break_utf8(t, off,
109 3448adb0 2022-11-02 op grapheme_next_word_break_utf8,
110 3448adb0 2022-11-02 op name, argv0);
114 3448adb0 2022-11-02 op main(int argc, char *argv[])
118 3448adb0 2022-11-02 op return run_break_tests(grapheme_next_word_break, word_break_test,
119 3448adb0 2022-11-02 op LEN(word_break_test), argv[0]) +
120 3448adb0 2022-11-02 op run_unit_tests(unit_test_callback_next_word_break,
121 3448adb0 2022-11-02 op next_word_break, LEN(next_word_break),
122 3448adb0 2022-11-02 op "grapheme_next_word_break", argv[0]) +
123 3448adb0 2022-11-02 op run_unit_tests(unit_test_callback_next_word_break_utf8,
124 3448adb0 2022-11-02 op next_word_break_utf8, LEN(next_word_break_utf8),
125 3448adb0 2022-11-02 op "grapheme_next_word_break_utf8", argv[0]);