|
| 1 | +import { toCodePoints } from "@keybr/unicode"; |
1 | 2 | import test from "ava";
|
2 | 3 | import { TextInput } from "./textinput.ts";
|
3 | 4 | import { Attr, type Char, Feedback, type Step } from "./types.ts";
|
@@ -638,20 +639,30 @@ test("space skips words in the middle of a word, remove garbage", (t) => {
|
638 | 639 | });
|
639 | 640 |
|
640 | 641 | test("normalize characters", (t) => {
|
641 |
| - const textInput = new TextInput("«a»", { |
642 |
| - stopOnError: true, |
643 |
| - forgiveErrors: false, |
644 |
| - spaceSkipsWords: false, |
645 |
| - }); |
646 |
| - |
647 |
| - t.is(textInput.appendChar(/* " */ 0x0022, 100), Feedback.Succeeded); |
648 |
| - t.is(textInput.appendChar(A, 200), Feedback.Succeeded); |
649 |
| - t.is(textInput.appendChar(/* " */ 0x0022, 300), Feedback.Succeeded); |
650 |
| - t.is(stepsString(textInput.steps), '",100|a,200|",300'); |
651 |
| - t.is(charsString(textInput.chars), "«|a|»"); |
652 |
| - t.is(textInput.length, 3); |
653 |
| - t.is(textInput.pos, 3); |
654 |
| - t.true(textInput.completed); |
| 642 | + const check = (text: string, input: string) => { |
| 643 | + const textInput = new TextInput(text, { |
| 644 | + stopOnError: true, |
| 645 | + forgiveErrors: false, |
| 646 | + spaceSkipsWords: false, |
| 647 | + }); |
| 648 | + t.is(textInput.text, text); |
| 649 | + let timeStamp = 0; |
| 650 | + for (const codePoint of toCodePoints(input)) { |
| 651 | + t.is( |
| 652 | + textInput.appendChar(codePoint, (timeStamp += 100)), |
| 653 | + Feedback.Succeeded, |
| 654 | + ); |
| 655 | + } |
| 656 | + }; |
| 657 | + |
| 658 | + check(`‘’`, `''`); |
| 659 | + check(`‘’`, `‘’`); |
| 660 | + check(`“”`, `""`); |
| 661 | + check(`“”`, `“”`); |
| 662 | + check(`«»`, `""`); |
| 663 | + check(`«»`, `«»`); |
| 664 | + check(`¿?¡!`, `??!!`); |
| 665 | + check(`¿?¡!`, `¿?¡!`); |
655 | 666 | });
|
656 | 667 |
|
657 | 668 | test("whitespace", (t) => {
|
|
0 commit comments