// EditorPositionMappingTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT #if os(macOS) import Testing @testable import LyrebirdLiveCompileUI @Suite("editorLineAndUTF16Char") struct EditorPositionMappingTests { @Test func offsetZeroIsOrigin() { let (line, char): (Int, Int) = editorLineAndUTF16Char(in: "abc\ndef", utf16Offset: 0) #expect(line == 0) #expect(char == 0) } @Test func withinFirstLineCountsColumns() { let (line, char): (Int, Int) = editorLineAndUTF16Char(in: "let x = OscSin.", utf16Offset: 15) #expect(line == 0) #expect(char == 15) } @Test func afterNewlineResetsColumn() { // "abc\nde" — offset 5 is the 'e' on line 1, column 2. let (line, char): (Int, Int) = editorLineAndUTF16Char(in: "abc\nde", utf16Offset: 5) #expect(line == 1) #expect(char == 1) } @Test func startOfSecondLineIsColumnZero() { let (line, char): (Int, Int) = editorLineAndUTF16Char(in: "ab\ncd", utf16Offset: 3) #expect(line == 1) #expect(char == 0) } @Test func offsetPastEndClampsToFinalPosition() { let (line, char): (Int, Int) = editorLineAndUTF16Char(in: "ab\ncd", utf16Offset: 999) #expect(line == 1) #expect(char == 2) } @Test func astralCharacterCountsAsTwoUTF16Units() { // "😀x" — the emoji is a surrogate pair (2 UTF-16 units); 'x' is at char 2. let (line, char): (Int, Int) = editorLineAndUTF16Char(in: "😀x", utf16Offset: 2) #expect(line == 0) #expect(char == 2) } } #endif