summaryrefslogtreecommitdiff
path: root/test/lib/string.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2025-05-01 05:10:09 -0600
committerSimon Glass <sjg@chromium.org>2025-05-16 06:21:37 +0200
commit13223f8ea1ed102055362bc7ee242bf992443ca1 (patch)
tree9f834024d5cc36cbf113be01aa7d24d8d0655a70 /test/lib/string.c
parentaea684a0c31cb2b0442eab965c2b08ed8d1abfd0 (diff)
test: Add a test for strim()
This function trims whitespace from the start and end of a string. Add a test for it. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/lib/string.c')
-rw-r--r--test/lib/string.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/lib/string.c b/test/lib/string.c
index 31391a387b9..f56c2e4c946 100644
--- a/test/lib/string.c
+++ b/test/lib/string.c
@@ -261,3 +261,40 @@ static int lib_strstr(struct unit_test_state *uts)
return 0;
}
LIB_TEST(lib_strstr, 0);
+
+static int lib_strim(struct unit_test_state *uts)
+{
+ char buf[BUFLEN], *p;
+
+ strcpy(buf, "abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* leading space */
+ strcpy(buf, " abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* multiple leading spaces */
+ strcpy(buf, " abc");
+ ut_asserteq_str("abc", strim(buf));
+
+ /* multiple internal spaces */
+ strcpy(buf, " a bc");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with trailing space */
+ strcpy(buf, " a bc ");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with multiple trailing spaces */
+ strcpy(buf, " a bc ");
+ ut_asserteq_str("a bc", strim(buf));
+
+ /* with only spaces */
+ strcpy(buf, " ");
+ p = strim(buf);
+ ut_asserteq_ptr(p, buf);
+ ut_asserteq_str("", p);
+
+ return 0;
+}
+LIB_TEST(lib_strim, 0);