diff options
Diffstat (limited to 'src/test/test-string-util.c')
-rw-r--r-- | src/test/test-string-util.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index a7c863c89..8c7226e5f 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -6,6 +6,7 @@ ***/ #include "alloc-util.h" +//#include "locale-util.h" #include "macro.h" #include "string-util.h" #include "strv.h" @@ -79,6 +80,29 @@ static void test_ascii_strcasecmp_nn(void) { } #endif // 0 +static void test_cellescape(void) { + char buf[40]; + + assert_se(streq(cellescape(buf, 10, "1"), "1")); + assert_se(streq(cellescape(buf, 10, "12"), "12")); + assert_se(streq(cellescape(buf, 10, "123"), is_locale_utf8() ? "1…" : "1...")); + + assert_se(streq(cellescape(buf, 10, "1\011"), "1\\t")); + assert_se(streq(cellescape(buf, 10, "1\020"), "1\\020")); + assert_se(streq(cellescape(buf, 10, "1\020x"), is_locale_utf8() ? "1…" : "1...")); + + assert_se(streq(cellescape(buf, 40, "1\020"), "1\\020")); + assert_se(streq(cellescape(buf, 40, "1\020x"), "1\\020x")); + + assert_se(streq(cellescape(buf, 40, "\a\b\f\n\r\t\v\\\"'"), "\\a\\b\\f\\n\\r\\t\\v\\\\\\\"\\'")); + assert_se(streq(cellescape(buf, 10, "\a\b\f\n\r\t\v\\\"'"), is_locale_utf8() ? "\\a…" : "\\a...")); + assert_se(streq(cellescape(buf, 11, "\a\b\f\n\r\t\v\\\"'"), is_locale_utf8() ? "\\a…" : "\\a...")); + assert_se(streq(cellescape(buf, 12, "\a\b\f\n\r\t\v\\\"'"), is_locale_utf8() ? "\\a\\b…" : "\\a\\b...")); + + assert_se(streq(cellescape(buf, sizeof buf, "1\020"), "1\\020")); + assert_se(streq(cellescape(buf, sizeof buf, "1\020x"), "1\\020x")); +} + static void test_streq_ptr(void) { assert_se(streq_ptr(NULL, NULL)); assert_se(!streq_ptr("abc", "cdef")); @@ -432,6 +456,7 @@ int main(int argc, char *argv[]) { test_ascii_strcasecmp_n(); test_ascii_strcasecmp_nn(); #endif // 0 + test_cellescape(); test_streq_ptr(); test_strstrip(); test_strextend(); |