Files
ggbond268--mactools/Plugins/Translator/Tests/AccessibilitySelectedTextCaptureTests.swift
wehub-resource-sync 1d1286fadb
Build / Build and test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:18:38 +08:00

25 lines
824 B
Swift

import Foundation
import XCTest
@testable import TranslatorPlugin
final class AccessibilitySelectedTextCaptureTests: XCTestCase {
func testSubstringRejectsOverflowingUTF16Range() {
let text = "selected"
let range = CFRange(location: Int.max, length: Int.max)
let result = AccessibilitySelectedTextCapture.substring(in: text, utf16Range: range)
XCTAssertNil(result)
}
func testSubstringUsesUTF16OffsetsSafely() {
let text = "Hi 👋 world"
let start = text.utf16.distance(from: text.utf16.startIndex, to: text.firstIndex(of: "w")!.samePosition(in: text.utf16)!)
let range = CFRange(location: start, length: 5)
let result = AccessibilitySelectedTextCapture.substring(in: text, utf16Range: range)
XCTAssertEqual(result, "world")
}
}