string_split(): Add tests for edge cases
This adds two missing test cases for string_split():
- string_split(" ") - only whitespace when splitting on whitespace
- string_split("||", "|") - only separators
Change-Id: I77b7f36633520919bdcf594470e44e88e3cf09ac
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/6600
Reviewed-by: Petr Hosek <phosek@google.com>
Commit-Queue: Petr Hosek <phosek@google.com>
diff --git a/src/gn/functions_unittest.cc b/src/gn/functions_unittest.cc
index 5b2218e..40ac5d9 100644
--- a/src/gn/functions_unittest.cc
+++ b/src/gn/functions_unittest.cc
@@ -302,6 +302,9 @@
# Split on all whitespace: empty string.
print(string_split(""))
+ # Split on all whitespace: string is only whitespace
+ print(string_split(" "))
+
# Split on all whitespace: leading, trailing, runs; one element.
print(string_split("hello"))
print(string_split(" hello"))
@@ -319,6 +322,7 @@
# Split on string.
print(string_split("", "|")) # Empty string
print(string_split("|", "|")) # Only a separator
+ print(string_split("||", "|")) # Only separators
print(string_split("ab", "|")) # String is missing separator
print(string_split("a|b", "|")) # Two elements
print(string_split("|a|b", "|")) # Leading separator
@@ -339,6 +343,9 @@
// Split on all whitespace: empty string.
"[]\n"
+ // Split on all whitespace: string is only whitespace.
+ "[]\n"
+
// Split on all whitespace: leading, trailing, runs; one element.
"[\"hello\"]\n"
"[\"hello\"]\n"
@@ -356,6 +363,7 @@
// Split on string.
"[\"\"]\n" // Empty string (like Python)
"[\"\", \"\"]\n" // Only a separator
+ "[\"\", \"\", \"\"]\n" // Only separators
"[\"ab\"]\n" // String is missing separator
"[\"a\", \"b\"]\n" // Two elements
"[\"\", \"a\", \"b\"]\n" // Leading