|
1 | | -import { isNullOrEmpty, isNullOrWhitespace, capitalize, uncapitalize, truncate } from "./string"; |
| 1 | +import { isNullOrEmpty, isNullOrWhitespace, capitalize, uncapitalize, truncate, ltrim, rtrim, trim } from "./string"; |
2 | 2 |
|
3 | 3 | describe("string tests", () => { |
4 | 4 | test.each([ |
@@ -120,4 +120,64 @@ describe("string tests", () => { |
120 | 120 | ])("truncate without suffix parameter", (value, maxLength, expected) => { |
121 | 121 | expect(truncate(value, maxLength)).toBe(expected); |
122 | 122 | }); |
| 123 | + |
| 124 | + test.each([ |
| 125 | + [null as unknown as string, " ", null], |
| 126 | + [undefined as unknown as string, " ", undefined], |
| 127 | + [" hello world", " ", "hello world"], |
| 128 | + [" hello world", " ", "hello world"], |
| 129 | + [" hello world", " ", "hello world"], |
| 130 | + ])("left trim", (haystack, needle, expected) => { |
| 131 | + expect(ltrim(haystack, needle)).toBe(expected); |
| 132 | + }); |
| 133 | + |
| 134 | + test.each([ |
| 135 | + [null as unknown as string, " ", null], |
| 136 | + [undefined as unknown as string, " ", undefined], |
| 137 | + [" hello world", "", " hello world"], |
| 138 | + [" hello world", "", " hello world"], |
| 139 | + [" hello world", "", " hello world"], |
| 140 | + ])("left trim without needle", (haystack, needle, expected) => { |
| 141 | + expect(ltrim(haystack, needle)).toBe(expected); |
| 142 | + }); |
| 143 | + |
| 144 | + test.each([ |
| 145 | + [null as unknown as string, " ", null], |
| 146 | + [undefined as unknown as string, " ", undefined], |
| 147 | + ["hello world ", " ", "hello world"], |
| 148 | + ["hello world ", " ", "hello world"], |
| 149 | + ["hello world ", " ", "hello world"], |
| 150 | + ])("right trim", (haystack, needle, expected) => { |
| 151 | + expect(rtrim(haystack, needle)).toBe(expected); |
| 152 | + }); |
| 153 | + |
| 154 | + test.each([ |
| 155 | + [null as unknown as string, " ", null], |
| 156 | + [undefined as unknown as string, " ", undefined], |
| 157 | + ["hello world ", "", "hello world "], |
| 158 | + ["hello world ", "", "hello world "], |
| 159 | + ["hello world ", "", "hello world "], |
| 160 | + ])("right trim without needle", (haystack, needle, expected) => { |
| 161 | + expect(rtrim(haystack, needle)).toBe(expected); |
| 162 | + }); |
| 163 | + |
| 164 | + test.each([ |
| 165 | + [null as unknown as string, " ", null], |
| 166 | + [undefined as unknown as string, " ", undefined], |
| 167 | + [" hello world ", " ", "hello world"], |
| 168 | + [" hello world ", " ", "hello world"], |
| 169 | + [" hello world ", " ", "hello world"], |
| 170 | + ])("trim", (haystack, needle, expected) => { |
| 171 | + expect(trim(haystack, needle)).toBe(expected); |
| 172 | + }); |
| 173 | + |
| 174 | + test.each([ |
| 175 | + [null as unknown as string, " ", null], |
| 176 | + [undefined as unknown as string, " ", undefined], |
| 177 | + [" hello world ", "", " hello world "], |
| 178 | + [" hello world ", "", " hello world "], |
| 179 | + [" hello world ", "", " hello world "], |
| 180 | + ])("trim without needle", (haystack, needle, expected) => { |
| 181 | + expect(trim(haystack, needle)).toBe(expected); |
| 182 | + }); |
123 | 183 | }); |
0 commit comments