Blame


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>
4 3448adb0 2022-11-02 op
5 3448adb0 2022-11-02 op #include "../gen/sentence-test.h"
6 3448adb0 2022-11-02 op #include "../grapheme.h"
7 3448adb0 2022-11-02 op #include "util.h"
8 3448adb0 2022-11-02 op
9 3448adb0 2022-11-02 op static const struct unit_test_next_break next_sentence_break[] = {
10 3448adb0 2022-11-02 op {
11 3448adb0 2022-11-02 op .description = "NULL input",
12 3448adb0 2022-11-02 op .input = {
13 3448adb0 2022-11-02 op .src = NULL,
14 3448adb0 2022-11-02 op .srclen = 0,
15 3448adb0 2022-11-02 op },
16 3448adb0 2022-11-02 op .output = { 0 },
17 3448adb0 2022-11-02 op },
18 3448adb0 2022-11-02 op {
19 3448adb0 2022-11-02 op .description = "empty input",
20 3448adb0 2022-11-02 op .input = {
21 3448adb0 2022-11-02 op .src = (uint_least32_t *)(uint_least32_t[]){ 0x0 },
22 3448adb0 2022-11-02 op .srclen = 0,
23 3448adb0 2022-11-02 op },
24 3448adb0 2022-11-02 op .output = { 0 },
25 3448adb0 2022-11-02 op },
26 3448adb0 2022-11-02 op {
27 3448adb0 2022-11-02 op .description = "empty input, null-terminated",
28 3448adb0 2022-11-02 op .input = {
29 3448adb0 2022-11-02 op .src = (uint_least32_t *)(uint_least32_t[]){ 0x0 },
30 3448adb0 2022-11-02 op .srclen = SIZE_MAX,
31 3448adb0 2022-11-02 op },
32 3448adb0 2022-11-02 op .output = { 0 },
33 3448adb0 2022-11-02 op },
34 3448adb0 2022-11-02 op {
35 3448adb0 2022-11-02 op .description = "one sentence",
36 3448adb0 2022-11-02 op .input = {
37 3448adb0 2022-11-02 op .src = (uint_least32_t *)(uint_least32_t[]){ 0x1F1E9, 0x1F1EA, 0x2E, 0x20, 0x2A },
38 3448adb0 2022-11-02 op .srclen = 5,
39 3448adb0 2022-11-02 op },
40 3448adb0 2022-11-02 op .output = { 4 },
41 3448adb0 2022-11-02 op },
42 3448adb0 2022-11-02 op {
43 3448adb0 2022-11-02 op .description = "one sentence, null-terminated",
44 3448adb0 2022-11-02 op .input = {
45 3448adb0 2022-11-02 op .src = (uint_least32_t *)(uint_least32_t[]){ 0x1F1E9, 0x1F1EA, 0x2E, 0x20, 0x2A, 0x0 },
46 3448adb0 2022-11-02 op .srclen = SIZE_MAX,
47 3448adb0 2022-11-02 op },
48 3448adb0 2022-11-02 op .output = { 4 },
49 3448adb0 2022-11-02 op },
50 3448adb0 2022-11-02 op };
51 3448adb0 2022-11-02 op
52 3448adb0 2022-11-02 op static const struct unit_test_next_break_utf8 next_sentence_break_utf8[] = {
53 3448adb0 2022-11-02 op {
54 3448adb0 2022-11-02 op .description = "NULL input",
55 3448adb0 2022-11-02 op .input = {
56 3448adb0 2022-11-02 op .src = NULL,
57 3448adb0 2022-11-02 op .srclen = 0,
58 3448adb0 2022-11-02 op },
59 3448adb0 2022-11-02 op .output = { 0 },
60 3448adb0 2022-11-02 op },
61 3448adb0 2022-11-02 op {
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 },
65 3448adb0 2022-11-02 op },
66 3448adb0 2022-11-02 op {
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 },
70 3448adb0 2022-11-02 op },
71 3448adb0 2022-11-02 op {
72 3448adb0 2022-11-02 op .description = "one sentence",
73 3448adb0 2022-11-02 op .input = { "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA is the flag of Germany. It", 36 },
74 3448adb0 2022-11-02 op .output = { 34 },
75 3448adb0 2022-11-02 op },
76 3448adb0 2022-11-02 op {
77 3448adb0 2022-11-02 op .description = "one sentence, fragment",
78 3448adb0 2022-11-02 op .input = { "\xF0\x9F\x87\xA9\xF0", 5 },
79 3448adb0 2022-11-02 op .output = { 4 },
80 3448adb0 2022-11-02 op },
81 3448adb0 2022-11-02 op {
82 3448adb0 2022-11-02 op .description = "one sentence, NUL-terminated",
83 3448adb0 2022-11-02 op .input = { "\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA is the flag of Germany. It", SIZE_MAX },
84 3448adb0 2022-11-02 op .output = { 34 },
85 3448adb0 2022-11-02 op },
86 3448adb0 2022-11-02 op {
87 3448adb0 2022-11-02 op .description = "one sentence, 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 = { 6 },
90 3448adb0 2022-11-02 op },
91 3448adb0 2022-11-02 op };
92 3448adb0 2022-11-02 op
93 3448adb0 2022-11-02 op static int
94 3448adb0 2022-11-02 op unit_test_callback_next_sentence_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)
97 3448adb0 2022-11-02 op {
98 3448adb0 2022-11-02 op return unit_test_callback_next_break(t, off,
99 3448adb0 2022-11-02 op grapheme_next_sentence_break,
100 3448adb0 2022-11-02 op name, argv0);
101 3448adb0 2022-11-02 op }
102 3448adb0 2022-11-02 op
103 3448adb0 2022-11-02 op static int
104 3448adb0 2022-11-02 op unit_test_callback_next_sentence_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)
107 3448adb0 2022-11-02 op {
108 3448adb0 2022-11-02 op return unit_test_callback_next_break_utf8(t, off,
109 3448adb0 2022-11-02 op grapheme_next_sentence_break_utf8,
110 3448adb0 2022-11-02 op name, argv0);
111 3448adb0 2022-11-02 op }
112 3448adb0 2022-11-02 op
113 3448adb0 2022-11-02 op int
114 3448adb0 2022-11-02 op main(int argc, char *argv[])
115 3448adb0 2022-11-02 op {
116 3448adb0 2022-11-02 op (void)argc;
117 3448adb0 2022-11-02 op
118 3448adb0 2022-11-02 op return run_break_tests(grapheme_next_sentence_break,
119 3448adb0 2022-11-02 op sentence_break_test,
120 3448adb0 2022-11-02 op LEN(sentence_break_test), argv[0]) +
121 3448adb0 2022-11-02 op run_unit_tests(unit_test_callback_next_sentence_break,
122 3448adb0 2022-11-02 op next_sentence_break, LEN(next_sentence_break),
123 3448adb0 2022-11-02 op "grapheme_next_sentence_break", argv[0]) +
124 3448adb0 2022-11-02 op run_unit_tests(unit_test_callback_next_sentence_break_utf8,
125 3448adb0 2022-11-02 op next_sentence_break_utf8, LEN(next_sentence_break_utf8),
126 3448adb0 2022-11-02 op "grapheme_next_character_break_utf8", argv[0]);
127 3448adb0 2022-11-02 op }