test-string-util: test empty_to_null on a char array
Unfortunately empty_to_null(t) where t is char[] fails. But it works with &t[0].
This commit is contained in:
@@ -617,6 +617,28 @@ TEST(split_pair) {
|
||||
ASSERT_STREQ(b, "=");
|
||||
}
|
||||
|
||||
TEST(empty_to_null) {
|
||||
const char *s = "asdf", *n = NULL, *e = "";
|
||||
char *t = (char*) "asdf";
|
||||
const char p[] = "asdf";
|
||||
char q[] = "asdf";
|
||||
|
||||
/* empty_to_null cannot be used with constant strings, e.g.
|
||||
* empty_to_null("") fails with 'error: cast specifies array type'. */
|
||||
|
||||
ASSERT_NULL(empty_to_null(NULL));
|
||||
ASSERT_NULL(empty_to_null(n));
|
||||
ASSERT_NULL(empty_to_null(e));
|
||||
ASSERT_STREQ(empty_to_null(s), "asdf");
|
||||
ASSERT_NULL(empty_to_null(s + 4));
|
||||
ASSERT_STREQ(empty_to_null(t), "asdf");
|
||||
ASSERT_NULL(empty_to_null(t + 4));
|
||||
ASSERT_STREQ(empty_to_null(&p[0]), "asdf");
|
||||
ASSERT_NULL(empty_to_null(&p[0] + 4));
|
||||
ASSERT_STREQ(empty_to_null(&q[0]), "asdf");
|
||||
ASSERT_NULL(empty_to_null(&q[0] + 4));
|
||||
}
|
||||
|
||||
TEST(first_word) {
|
||||
assert_se(first_word("Hello", ""));
|
||||
assert_se(first_word("Hello", "Hello"));
|
||||
|
||||
Reference in New Issue
Block a user