|
5 | 5 | * |
6 | 6 | */ |
7 | 7 | import { unitTest } from "../../test.ts"; |
8 | | -import { assert } from "testing/asserts.ts"; |
| 8 | +import { assert, assertEquals } from "testing/asserts.ts"; |
9 | 9 | import { |
10 | 10 | asMappedString, |
11 | 11 | mappedDiff, |
12 | 12 | mappedString, |
13 | 13 | } from "../../../src/core/mapped-text.ts"; |
14 | | -import { mappedSubstring } from "../../../src/core/lib/mapped-text.ts"; |
| 14 | +import { |
| 15 | + mappedSubstring, |
| 16 | + mappedTrim, |
| 17 | + mappedTrimEnd, |
| 18 | + mappedTrimStart, |
| 19 | +} from "../../../src/core/lib/mapped-text.ts"; |
15 | 20 |
|
16 | 21 | // deno-lint-ignore require-await |
17 | 22 | unitTest("mapped-text - mappedString()", async () => { |
@@ -188,3 +193,28 @@ viewof x = Inputs.range([0, 100], label = "hello!", value = 20) |
188 | 193 |
|
189 | 194 | mappedDiff(asMappedString(text1), text2); |
190 | 195 | }); |
| 196 | + |
| 197 | +// deno-lint-ignore require-await |
| 198 | +unitTest("mapped-text - mappedTrim{,Start,End}()", async () => { |
| 199 | + const whitespace = "\u000A\u000D\u2028\u2029\u0009\u000B\u000C\uFEFF \t"; |
| 200 | + const content = "a \n"; |
| 201 | + for (let i = 0; i < 1000; ++i) { |
| 202 | + const startTrimLength = Math.random() * 10; |
| 203 | + const endTrimLength = Math.random() * 10; |
| 204 | + const contentLength = Math.random() * 10; |
| 205 | + const strContent = []; |
| 206 | + for (let j = 0; j < startTrimLength; ++j) { |
| 207 | + strContent.push(whitespace[~~(Math.random() * whitespace.length)]); |
| 208 | + } |
| 209 | + for (let j = 0; j < contentLength; ++j) { |
| 210 | + strContent.push(content[~~(Math.random() * content.length)]); |
| 211 | + } |
| 212 | + for (let j = 0; j < endTrimLength; ++j) { |
| 213 | + strContent.push(whitespace[~~(Math.random() * whitespace.length)]); |
| 214 | + } |
| 215 | + const mappedStr = asMappedString(strContent.join("")); |
| 216 | + assertEquals(mappedTrim(mappedStr).value, mappedStr.value.trim()); |
| 217 | + assertEquals(mappedTrimStart(mappedStr).value, mappedStr.value.trimStart()); |
| 218 | + assertEquals(mappedTrimEnd(mappedStr).value, mappedStr.value.trimEnd()); |
| 219 | + } |
| 220 | +}); |
0 commit comments