summaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2018-07-14 15:01:03 +0300
committerOxore <oxore@protonmail.com>2018-07-14 15:01:03 +0300
commite3614f6eef762ca0c2e14736c8a20760c6d5661b (patch)
treef8834e1137050246bdc99ef476088251707d9917 /src/target
parentd3fddd7d28f314a6738f2a0ba4d9f58024b01984 (diff)
Add utf8_strlen tests, refactor unicode module
Diffstat (limited to 'src/target')
-rw-r--r--src/target/test.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/src/target/test.c b/src/target/test.c
index 60439a5..0959eaa 100644
--- a/src/target/test.c
+++ b/src/target/test.c
@@ -7,51 +7,63 @@ struct u_pair {
wchar_t *utf32;
};
-struct u_pair *text_fixture;
+struct u_pair text_fixture[] = {
+ {
+ .utf8 = "Single byte ascii symbols string",
+ .utf32 = L"Single byte ascii symbols string"
+ },
+ {
+ .utf8 = "\u041A\u0438\u0440\u0438\u043B\u043B\u0438\u0446\u0430",
+ .utf32 = L"\u041A\u0438\u0440\u0438\u043B\u043B\u0438\u0446\u0430"
+ },
+ {
+ .utf8 = "\u0814\u0820\u080C\u081D\u0813\u0829\u0809\u080C",
+ .utf32 = L"\u0814\u0820\u080C\u081D\u0813\u0829\u0809\u080C"
+ },
+ {
+ .utf8 = "𓁹",
+ .utf32 = L"𓁹"
+ }
+};
+
-static void *test_text_setup(const MunitParameter params[], void *user_data) {
+static void *test_utf8_strlen_setup(const MunitParameter params[], void *user_data) {
(void) params;
(void) user_data;
return text_fixture;
}
-static MunitResult test_text(const MunitParameter params[], void *fixture) {
+static MunitResult test_utf8_strlen(const MunitParameter params[], void *fixture) {
(void) params;
struct u_pair *f = fixture;
munit_assert_ulong(utf8_strlen(f[0].utf8), ==, strlen(f[0].utf8));
+ munit_assert_ulong(utf8_strlen(f[1].utf8) * 2, ==, strlen(f[1].utf8));
+ munit_assert_ulong(utf8_strlen(f[2].utf8) * 3, ==, strlen(f[2].utf8));
+ munit_assert_ulong(utf8_strlen(f[3].utf8) * 4, ==, strlen(f[3].utf8));
return MUNIT_OK;
}
-static MunitTest test_suite_tests[] = {
- {
- "/example/parameters",
- test_text,
- test_text_setup,
- NULL,
- MUNIT_TEST_OPTION_NONE,
- NULL
- },
- {NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}
-};
-
static const MunitSuite test_suite = {
"unit",
- test_suite_tests,
+ (MunitTest[]){
+ {
+ "/unicode/utf8_strlen",
+ test_utf8_strlen,
+ test_utf8_strlen_setup,
+ NULL,
+ MUNIT_TEST_OPTION_NONE,
+ NULL
+ },
+ {NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}
+ },
NULL,
1,
MUNIT_SUITE_OPTION_NONE
};
int main(int argc, char **argv) {
- text_fixture = (struct u_pair []){
- {
- .utf8 = "Single byte ascii symbols string",
- .utf32 = L"Single byte ascii symbols string"
- }
- };
-
return munit_suite_main(&test_suite, NULL, argc, argv);
}