summaryrefslogtreecommitdiff
path: root/libbb/compare_string_array.c
diff options
context:
space:
mode:
authorBartosz Golaszewski2015-08-25 13:09:59 +0200
committerDenys Vlasenko2015-08-25 15:00:24 +0200
commitb432923e29dcd8c6f3a528bb9d61952de68e790c (patch)
tree9c7127016e93c26ccb1587fbdbbc184ed2174715 /libbb/compare_string_array.c
parentd86271732828117d32270e9f7b3d128d77e9fa57 (diff)
downloadbusybox-b432923e29dcd8c6f3a528bb9d61952de68e790c.zip
busybox-b432923e29dcd8c6f3a528bb9d61952de68e790c.tar.gz
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>
Diffstat (limited to 'libbb/compare_string_array.c')
-rw-r--r--libbb/compare_string_array.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index e24815a..450916c 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 */