import Foundation import Testing @testable import OrgCore struct ToggleCommandTests { static let oracle = ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil static let text = """ Intro line # a comment * TODO [#A] Task :tag: SCHEDULED: <2026-10-05 Mon> :PROPERTIES: :X: 1 :END: Body text indented body - plain item - [ ] open box - [X] done box - nested item ** COMMENT Commented *** Deep 1. first 2) second * DONE Closed one last """ /// Runs `command` with `selection` (a caret when empty) and returns the text and caret. static func ours(_ command: any OrgCommand, _ text: String, _ selection: Range) -> (String, Int) { let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [selection], options: .org) guard case .commit(let result) = command.run(in: context) else { return (text, selection.upperBound) } var new = text for edit in result.edits.sorted(by: { $0.range.lowerBound > $1.range.lowerBound }) { new = edit.apply(to: new) } return (new, result.selection?.first?.lowerBound ?? selection.upperBound) } static func compare(_ command: any OrgCommand, _ form: String, regions: [(String, String)] = []) throws { let text = Self.text let ns = text as NSString var cases: [EmacsOracle.Case] = [] var mine: [(String, Int)] = [] var labels: [String] = [] // Each line's start and a point inside it. var lineStart = 0 while lineStart < ns.length { let line = ns.lineRange(for: NSRange(location: lineStart, length: 0)) for offset in Set([line.location, min(line.location + 3, NSMaxRange(line) - 1)]).sorted() { cases.append(EmacsOracle.Case(text: text, point: EmacsOracle.point(offset, in: text), form: form)) mine.append(ours(command, text, offset.. String in let context = EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [offset..