Tests/OrgCoreTests/LineDiffTests.swift
24 lines · 998 bytes
1import Foundation
2import Testing
3@testable import OrgCore
4
5struct LineDiffTests {
6 @Test func splitsAnEditSpanningSeveralLinesIntoTheLinesItChanges() {
7 let text = "* Top\nText here.\n* Folded\n** Child\nbody\n* End\n"
8 let new = "* Top\nText here.[fn:1]\n* Folded\n** Child\nbody\n* End\n\n* Footnotes\n\n[fn:1] \n"
9 let one = TextEdit.between(text, new)
10 #expect(one.count == 1)
11 let split = splitByLines(one[0], in: text)
12 #expect(split.count == 2)
13 #expect(split.allSatisfy { !(text as NSString).substring(with: NSRange($0.range)).contains("* Folded") })
14 var result = text
15 for edit in split.sorted(by: { $0.range.lowerBound > $1.range.lowerBound }) { result = edit.apply(to: result) }
16 #expect(result == new)
17 }
18
19 @Test func leavesAnEditWithinALineAlone() {
20 let text = "* a\nbc\n"
21 let edit = TextEdit(range: 4..<5, replacement: "x")
22 #expect(splitByLines(edit, in: text) == [edit])
23 }
24}