TEST(String, Replace) { char *str; WEE_TEST_STR(NULL, string_replace (NULL, NULL, NULL)); WEE_TEST_STR(NULL, string_replace ("string", NULL, NULL)); WEE_TEST_STR(NULL, string_replace (NULL, "search", NULL)); WEE_TEST_STR(NULL, string_replace (NULL, NULL, "replace")); WEE_TEST_STR(NULL, string_replace ("string", "search", NULL)); WEE_TEST_STR(NULL, string_replace ("string", NULL, "replace")); WEE_TEST_STR(NULL, string_replace (NULL, "search", "replace")); WEE_TEST_STR("test abc def", string_replace("test abc def", "xyz", "xxx")); WEE_TEST_STR("test xxx def", string_replace("test abc def", "abc", "xxx")); WEE_TEST_STR("xxx test xxx def xxx", string_replace("abc test abc def abc", "abc", "xxx")); }
TEST(String, Strip) { char *str; WEE_TEST_STR(NULL, string_strip (NULL, 1, 1, NULL)); WEE_TEST_STR(NULL, string_strip (NULL, 1, 1, ".;")); WEE_TEST_STR("test", string_strip ("test", 1, 1, NULL)); WEE_TEST_STR("test", string_strip ("test", 1, 1, ".;")); WEE_TEST_STR(".-test.-", string_strip (".-test.-", 0, 0, ".-")); WEE_TEST_STR("test", string_strip (".-test.-", 1, 1, ".-")); WEE_TEST_STR("test.-", string_strip (".-test.-", 1, 0, ".-")); WEE_TEST_STR(".-test", string_strip (".-test.-", 0, 1, ".-")); }
TEST(String, MaskToRegex) { char *str; WEE_TEST_STR(NULL, string_mask_to_regex (NULL)); WEE_TEST_STR("", string_mask_to_regex ("")); WEE_TEST_STR("test", string_mask_to_regex ("test")); WEE_TEST_STR("test.*", string_mask_to_regex ("test*")); WEE_TEST_STR(".*test.*", string_mask_to_regex ("*test*")); WEE_TEST_STR(".*te.*st.*", string_mask_to_regex ("*te*st*")); WEE_TEST_STR("test\\.\\[\\]\\{\\}\\(\\)\\?\\+\\|\\^\\$\\\\", string_mask_to_regex ("test.[]{}()?+|^$\\")); }
TEST(Utf8, Duplicate) { char *str; WEE_TEST_STR("", utf8_strndup (noel_valid, 0)); WEE_TEST_STR("n", utf8_strndup (noel_valid, 1)); WEE_TEST_STR("no", utf8_strndup (noel_valid, 2)); WEE_TEST_STR("noë", utf8_strndup (noel_valid, 3)); WEE_TEST_STR("noël", utf8_strndup (noel_valid, 4)); WEE_TEST_STR("noël", utf8_strndup (noel_valid, 5)); }
TEST(String, Iconv) { const char *noel_utf8 = "no\xc3\xabl"; /* noël */ const char *noel_iso = "no\xebl"; char *str; FILE *f; /* string_iconv */ WEE_TEST_STR(NULL, string_iconv (0, NULL, NULL, NULL)); WEE_TEST_STR("", string_iconv (0, NULL, NULL, "")); WEE_TEST_STR("abc", string_iconv (0, NULL, NULL, "abc")); WEE_TEST_STR("abc", string_iconv (1, "UTF-8", "ISO-8859-15", "abc")); WEE_TEST_STR(noel_iso, string_iconv (1, "UTF-8", "ISO-8859-15", noel_utf8)); WEE_TEST_STR(noel_utf8, string_iconv (0, "ISO-8859-15", "UTF-8", noel_iso)); /* string_iconv_to_internal */ WEE_TEST_STR(NULL, string_iconv_to_internal (NULL, NULL)); WEE_TEST_STR("", string_iconv_to_internal (NULL, "")); WEE_TEST_STR("abc", string_iconv_to_internal (NULL, "abc")); WEE_TEST_STR(noel_utf8, string_iconv_to_internal ("ISO-8859-15", noel_iso)); /* string_iconv_from_internal */ WEE_TEST_STR(NULL, string_iconv_from_internal (NULL, NULL)); WEE_TEST_STR("", string_iconv_from_internal (NULL, "")); WEE_TEST_STR("abc", string_iconv_from_internal (NULL, "abc")); WEE_TEST_STR(noel_iso, string_iconv_from_internal ("ISO-8859-15", noel_utf8)); /* string_iconv_fprintf */ f = fopen ("/dev/null", "w"); LONGS_EQUAL(0, string_iconv_fprintf (f, NULL)); LONGS_EQUAL(1, string_iconv_fprintf (f, "abc")); LONGS_EQUAL(1, string_iconv_fprintf (f, noel_utf8)); LONGS_EQUAL(1, string_iconv_fprintf (f, noel_iso)); fclose (f); }
TEST(String, ConvertEscapedChars) { char *str; WEE_TEST_STR(NULL, string_convert_escaped_chars (NULL)); WEE_TEST_STR("", string_convert_escaped_chars ("")); WEE_TEST_STR("", string_convert_escaped_chars ("\\")); WEE_TEST_STR("\"", string_convert_escaped_chars ("\\\"")); WEE_TEST_STR("\\", string_convert_escaped_chars ("\\\\")); WEE_TEST_STR("\a", string_convert_escaped_chars ("\\a")); WEE_TEST_STR("\a", string_convert_escaped_chars ("\\a")); WEE_TEST_STR("\b", string_convert_escaped_chars ("\\b")); WEE_TEST_STR("\e", string_convert_escaped_chars ("\\e")); WEE_TEST_STR("\f", string_convert_escaped_chars ("\\f")); WEE_TEST_STR("\n", string_convert_escaped_chars ("\\n")); WEE_TEST_STR("\r", string_convert_escaped_chars ("\\r")); WEE_TEST_STR("\t", string_convert_escaped_chars ("\\t")); WEE_TEST_STR("\v", string_convert_escaped_chars ("\\v")); WEE_TEST_STR("\123", string_convert_escaped_chars ("\\0123")); WEE_TEST_STR("\123", string_convert_escaped_chars ("\\0123")); /* invalid */ WEE_TEST_STR("\x41", string_convert_escaped_chars ("\\x41")); WEE_TEST_STR("\x04z", string_convert_escaped_chars ("\\x4z")); WEE_TEST_STR(" zz", string_convert_escaped_chars ("\\u20zz")); WEE_TEST_STR("\U00012345", string_convert_escaped_chars ("\\U00012345")); WEE_TEST_STR("\U00000123zzz", string_convert_escaped_chars ("\\U00123zzz")); WEE_TEST_STR("", string_convert_escaped_chars ("\\U12345678")); /* invalid */ }
TEST(String, RemoveQuotes) { char *str; WEE_TEST_STR(NULL, string_remove_quotes (NULL, NULL)); WEE_TEST_STR(NULL, string_remove_quotes (NULL, "abc")); WEE_TEST_STR(NULL, string_remove_quotes ("abc", NULL)); WEE_TEST_STR("", string_remove_quotes("", "")); WEE_TEST_STR("", string_remove_quotes("", "\"'")); WEE_TEST_STR("abc", string_remove_quotes("abc", "\"'")); WEE_TEST_STR(" abc ", string_remove_quotes(" abc ", "\"'")); WEE_TEST_STR("abc", string_remove_quotes("'abc'", "\"'")); WEE_TEST_STR("abc", string_remove_quotes(" 'abc' ", "\"'")); WEE_TEST_STR("'abc'", string_remove_quotes("\"'abc'\"", "\"'")); WEE_TEST_STR("'abc'", string_remove_quotes(" \"'abc'\" ", "\"'")); WEE_TEST_STR("'a'b'c'", string_remove_quotes("\"'a'b'c'\"", "\"'")); WEE_TEST_STR("'a'b'c'", string_remove_quotes(" \"'a'b'c'\" ", "\"'")); }