diff options
Diffstat (limited to 'lib/tests/misc.nix')
| -rw-r--r-- | lib/tests/misc.nix | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 6774939023d2..32e3f7507a73 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -352,6 +352,72 @@ runTests { expected = "hellohellohellohellohello"; }; + # Test various strings are trimmed correctly + testTrimString = { + expr = + let + testValues = f: mapAttrs (_: f) { + empty = ""; + cr = "\r"; + lf = "\n"; + tab = "\t"; + spaces = " "; + leading = " Hello, world"; + trailing = "Hello, world "; + mixed = " Hello, world "; + mixed-tabs = " \t\tHello, world \t \t "; + multiline = " Hello,\n world! "; + multiline-crlf = " Hello,\r\n world! "; + }; + in + { + leading = testValues (strings.trimWith { start = true; }); + trailing = testValues (strings.trimWith { end = true; }); + both = testValues strings.trim; + }; + expected = { + leading = { + empty = ""; + cr = ""; + lf = ""; + tab = ""; + spaces = ""; + leading = "Hello, world"; + trailing = "Hello, world "; + mixed = "Hello, world "; + mixed-tabs = "Hello, world \t \t "; + multiline = "Hello,\n world! "; + multiline-crlf = "Hello,\r\n world! "; + }; + trailing = { + empty = ""; + cr = ""; + lf = ""; + tab = ""; + spaces = ""; + leading = " Hello, world"; + trailing = "Hello, world"; + mixed = " Hello, world"; + mixed-tabs = " \t\tHello, world"; + multiline = " Hello,\n world!"; + multiline-crlf = " Hello,\r\n world!"; + }; + both = { + empty = ""; + cr = ""; + lf = ""; + tab = ""; + spaces = ""; + leading = "Hello, world"; + trailing = "Hello, world"; + mixed = "Hello, world"; + mixed-tabs = "Hello, world"; + multiline = "Hello,\n world!"; + multiline-crlf = "Hello,\r\n world!"; + }; + }; + }; + testSplitStringsSimple = { expr = strings.splitString "." "a.b.c.d"; expected = [ "a" "b" "c" "d" ]; |
