libs: make splitString also split last separator (#23851)
* libs: make splitString also split last separator * libs: add tests for splitStrings
This commit is contained in:
parent
e99bc64552
commit
da6619cffe
@ -291,7 +291,7 @@ rec {
|
||||
|
||||
recurse = index: startAt:
|
||||
let cutUntil = i: [(substring startAt (i - startAt) s)]; in
|
||||
if index < lastSearch then
|
||||
if index <= lastSearch then
|
||||
if startWithSep index then
|
||||
let restartAt = index + sepLen; in
|
||||
cutUntil index ++ recurse restartAt restartAt
|
||||
|
@ -220,4 +220,34 @@ runTests {
|
||||
expected = builtins.toJSON val;
|
||||
};
|
||||
|
||||
testSplitStringsSimple = {
|
||||
expr = strings.splitString "." "a.b.c.d";
|
||||
expected = [ "a" "b" "c" "d" ];
|
||||
};
|
||||
|
||||
testSplitStringsEmpty = {
|
||||
expr = strings.splitString "." "a..b";
|
||||
expected = [ "a" "" "b" ];
|
||||
};
|
||||
|
||||
testSplitStringsOne = {
|
||||
expr = strings.splitString ":" "a.b";
|
||||
expected = [ "a.b" ];
|
||||
};
|
||||
|
||||
testSplitStringsNone = {
|
||||
expr = strings.splitString "." "";
|
||||
expected = [ "" ];
|
||||
};
|
||||
|
||||
testSplitStringsFirstEmpty = {
|
||||
expr = strings.splitString "/" "/a/b/c";
|
||||
expected = [ "" "a" "b" "c" ];
|
||||
};
|
||||
|
||||
testSplitStringsLastEmpty = {
|
||||
expr = strings.splitString ":" "2001:db8:0:0042::8a2e:370:";
|
||||
expected = [ "2001" "db8" "0" "0042" "" "8a2e" "370" "" ];
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user