From: Bartosz Golaszewski Date: Tue, 25 Aug 2015 11:09:59 +0000 (+0200) Subject: libbb: add unit tests for is_prefixed_with() X-Git-Tag: 1_24_0~58 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b432923e29dcd8c6f3a528bb9d61952de68e790c;p=oweals%2Fbusybox.git libbb: add unit tests for is_prefixed_with() Test corner cases too like looking for an empty prefix etc. Signed-off-by: Bartosz Golaszewski Signed-off-by: Denys Vlasenko --- diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c index e24815a03..450916c3a 100644 --- a/libbb/compare_string_array.c +++ b/libbb/compare_string_array.c @@ -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 */