aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/posix/wcwidth.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:52 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 18:24:51 -0500
commitf5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (patch)
tree93b156621dc0303816b37f60ba88051b702d92f6 /lib/mlibc/tests/posix/wcwidth.c
parentbd5969fc876a10b18613302db7087ef3c40f18e1 (diff)
build: Build mlibc + add distclean target
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/posix/wcwidth.c')
-rw-r--r--lib/mlibc/tests/posix/wcwidth.c67
1 files changed, 0 insertions, 67 deletions
diff --git a/lib/mlibc/tests/posix/wcwidth.c b/lib/mlibc/tests/posix/wcwidth.c
deleted file mode 100644
index 2e6fc8c..0000000
--- a/lib/mlibc/tests/posix/wcwidth.c
+++ /dev/null
@@ -1,67 +0,0 @@
-#include <assert.h>
-#include <locale.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <wchar.h>
-
-#if UINTPTR_MAX == UINT64_MAX
-#define WCHAR_SPEC ""
-#else
-#define WCHAR_SPEC "l"
-#endif
-
-/*
- * The code in this test is taken from https://github.com/termux/wcwidth/,
- * under the following license:
- *
- * Copyright (C) Fredrik Fornwall 2016.
- * Distributed under the MIT License.
- *
- * Implementation of wcwidth(3) as a C port of:
- * https://github.com/jquast/wcwidth
- *
- * Report issues at:
- * https://github.com/termux/wcwidth
- */
-
-static int tests_run;
-static int test_failures;
-
-void assertWidthIs(int expected_width, wchar_t c) {
- tests_run++;
- int actual_width = wcwidth(c);
- if (actual_width != expected_width) {
- fprintf(stderr, "ERROR: wcwidth(U+%04" WCHAR_SPEC "x, '%lc') returned %d, expected %d\n", c, (wint_t) c, actual_width, expected_width);
- test_failures++;
- }
-}
-
-int main() {
- setlocale(LC_CTYPE, "C.UTF-8");
- assertWidthIs(1, 'a');
- assertWidthIs(1, L'ö');
-
- // Some wide:
- assertWidthIs(2, L'A');
- assertWidthIs(2, L'B');
- assertWidthIs(2, L'C');
- assertWidthIs(2, L'中');
- assertWidthIs(2, L'文');
- assertWidthIs(2, 0x679C);
- assertWidthIs(2, 0x679D);
- assertWidthIs(2, 0x2070E);
- assertWidthIs(2, 0x20731);
-
-#ifndef USE_HOST_LIBC
- assertWidthIs(1, 0x11A3);
-#endif
-
- assertWidthIs(2, 0x1F428); // Koala emoji.
- assertWidthIs(2, 0x231a); // Watch emoji.
-
- if (test_failures > 0) printf("%d tests FAILED, ", test_failures);
- printf("%d tests OK\n", tests_run - test_failures);
- return (test_failures == 0) ? 0 : 1;
-}