libbb: add unit tests for is_prefixed_with()
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 25 Aug 2015 11:09:59 +0000 (13:09 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 25 Aug 2015 13:00:24 +0000 (15:00 +0200)
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>
libbb/compare_string_array.c

index e24815a03f3ac2151430aaacc2841c6b65f6951e..450916c3a985e74ce205affeab798fc50031e9da 100644 (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 */