libbb: add unit tests for is_prefixed_with()

Test corner cases too like looking for an empty prefix etc.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Bartosz Golaszewski 2015-08-25 13:09:59 +02:00 committed by Denys Vlasenko
parent d862717328
commit b432923e29

View File

@ -110,3 +110,22 @@ smallint FAST_FUNC yesno(const char *str)
return ret / 3;
}
#endif
#if ENABLE_UNIT_TEST
BBUNIT_DEFINE_TEST(is_prefixed_with)
{
BBUNIT_ASSERT_STREQ(" bar", is_prefixed_with("foo bar", "foo"));
BBUNIT_ASSERT_STREQ("bar", is_prefixed_with("foo bar", "foo "));
BBUNIT_ASSERT_STREQ("", is_prefixed_with("foo", "foo"));
BBUNIT_ASSERT_STREQ("foo", is_prefixed_with("foo", ""));
BBUNIT_ASSERT_STREQ("", is_prefixed_with("", ""));
BBUNIT_ASSERT_NULL(is_prefixed_with("foo", "bar foo"));
BBUNIT_ASSERT_NULL(is_prefixed_with("foo foo", "bar"));
BBUNIT_ASSERT_NULL(is_prefixed_with("", "foo"));
BBUNIT_ENDTEST;
}
#endif /* ENABLE_UNIT_TEST */