|
| 1 | +import Foundation |
| 2 | +import Testing |
| 3 | +@testable import TauTUI |
| 4 | + |
| 5 | +private func type(_ text: String, into editor: Editor) { |
| 6 | + for char in text { |
| 7 | + editor.handle(input: .key(.character(char))) |
| 8 | + } |
| 9 | +} |
| 10 | + |
| 11 | +@Suite("Editor + Unicode") |
| 12 | +struct EditorUnicodeTests { |
| 13 | + @Test |
| 14 | + func insertsMixedUnicode() async throws { |
| 15 | + let editor = Editor() |
| 16 | + type("Hello äöü 😀", into: editor) |
| 17 | + #expect(editor.getText() == "Hello äöü 😀") |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + func backspaceHandlesSingleAndMultiScalarCharacters() async throws { |
| 22 | + let editor = Editor() |
| 23 | + type("ä👍", into: editor) |
| 24 | + |
| 25 | + editor.handle(input: .key(.backspace)) // remove 👍 |
| 26 | + #expect(editor.getText() == "ä") |
| 27 | + |
| 28 | + editor.handle(input: .key(.backspace)) // remove ä |
| 29 | + #expect(editor.getText().isEmpty) |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + func arrowNavigationAcrossEmoji() async throws { |
| 34 | + let editor = Editor() |
| 35 | + type("😀👍", into: editor) |
| 36 | + editor.handle(input: .key(.arrowLeft)) |
| 37 | + editor.handle(input: .key(.character("x"))) |
| 38 | + #expect(editor.getText() == "😀x👍") |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + func insertAfterCursorMoveOverUmlauts() async throws { |
| 43 | + let editor = Editor() |
| 44 | + type("äöü", into: editor) |
| 45 | + editor.handle(input: .key(.arrowLeft)) |
| 46 | + editor.handle(input: .key(.arrowLeft)) |
| 47 | + editor.handle(input: .key(.character("x"))) |
| 48 | + #expect(editor.getText() == "äxöü") |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + func pastePreservesUnicodeAndStripsControlChars() async throws { |
| 53 | + let editor = Editor() |
| 54 | + editor.handle(input: .paste("Hällö\u{0007} Wörld! 😀 äöüÄÖÜß")) |
| 55 | + #expect(editor.getText() == "Hällö Wörld! 😀 äöüÄÖÜß") |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + func preservesUmlautsAcrossLineBreaks() async throws { |
| 60 | + let editor = Editor() |
| 61 | + type("äöü\nÄÖÜ", into: editor) |
| 62 | + #expect(editor.getText() == "äöü\nÄÖÜ") |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + func setTextReplacesDocumentWithUnicode() async throws { |
| 67 | + let editor = Editor() |
| 68 | + editor.setText("Hällö Wörld! 😀 äöüÄÖÜß") |
| 69 | + #expect(editor.getText() == "Hällö Wörld! 😀 äöüÄÖÜß") |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + func ctrlAMoveThenInsertWithUnicodePresent() async throws { |
| 74 | + let editor = Editor() |
| 75 | + type("äöü", into: editor) |
| 76 | + editor.handle(input: .key(.character("a"), modifiers: [.control])) |
| 77 | + editor.handle(input: .key(.character("X"))) |
| 78 | + #expect(editor.getText() == "Xäöü") |
| 79 | + } |
| 80 | +} |
0 commit comments