|
1 | | -import { isNullOrEmpty, isNullOrWhitespace, capitalize, uncapitalize, truncate, splitLines } from "./string"; |
| 1 | +import { isNullOrEmpty, isNullOrWhitespace, capitalize, uncapitalize, truncate, splitLines, trimStart, trimEnd, trim } from "./string"; |
2 | 2 |
|
3 | 3 | describe("string tests", () => { |
4 | 4 | test.each([ |
@@ -121,6 +121,42 @@ describe("string tests", () => { |
121 | 121 | expect(truncate(value, maxLength)).toBe(expected); |
122 | 122 | }); |
123 | 123 |
|
| 124 | + test.each([ |
| 125 | + [null as unknown as string, " ", null as unknown as string], |
| 126 | + [undefined as unknown as string, " ", undefined as unknown as string], |
| 127 | + ["hello world", "hello world", ""], |
| 128 | + ["hello world", " ", "hello world"], |
| 129 | + [" hello world", " ", "hello world"], |
| 130 | + ["hello world hello world", "hello world", " hello world"], |
| 131 | + ["hello worldhello world", "hello world", ""], |
| 132 | + ])("left trim", (haystack, needle, expected) => { |
| 133 | + expect(trimStart(haystack, needle)).toBe(expected); |
| 134 | + }); |
| 135 | + |
| 136 | + test.each([ |
| 137 | + [null as unknown as string, " ", null as unknown as string], |
| 138 | + [undefined as unknown as string, " ", undefined as unknown as string], |
| 139 | + ["hello world", "hello world", ""], |
| 140 | + ["hello world ", " ", "hello world"], |
| 141 | + ["hello world", " ", "hello world"], |
| 142 | + ["hello world hello world", "hello world", "hello world "], |
| 143 | + ["hello worldhello world", "hello world", ""], |
| 144 | + ])("right trim", (haystack, needle, expected) => { |
| 145 | + expect(trimEnd(haystack, needle)).toBe(expected); |
| 146 | + }); |
| 147 | + |
| 148 | + test.each([ |
| 149 | + [null as unknown as string, " ", null as unknown as string], |
| 150 | + [undefined as unknown as string, " ", undefined as unknown as string], |
| 151 | + ["hello world", "", "hello world"], |
| 152 | + [" hello world ", " ", "hello world"], |
| 153 | + ["hello world ", " ", "hello world"], |
| 154 | + [" hello world", " ", "hello world"], |
| 155 | + ["hello worldhello world", "hello world", ""], |
| 156 | + ])("trim", (haystack, needle, expected) => { |
| 157 | + expect(trim(haystack, needle)).toBe(expected); |
| 158 | + }); |
| 159 | + |
124 | 160 | test.each([ |
125 | 161 | ["", false, false, []], |
126 | 162 | [null as unknown as string, false, false, []], |
|
0 commit comments