Tests/OrgDocumentTests/DiffTests.swift
19 lines · 906 bytes
1import Testing
2@testable import OrgDocument
3
4struct DiffTests {
5 @Test func diffsLines() {
6 let diff = lineDiff(old: "a\nb\nc\n", new: "a\nB\nc\nd\n")
7 #expect(diff == [
8 DiffLine(kind: .same, text: "a\n"), DiffLine(kind: .removed, text: "b\n"), DiffLine(kind: .added, text: "B\n"),
9 DiffLine(kind: .same, text: "c\n"), DiffLine(kind: .added, text: "d\n"),
10 ])
11 }
12
13 @Test func mergesWithMarkers() {
14 let merged = mergeWithMarkers(base: "a\nb\nc\nd\n", ours: "a\nB1\nc\nd\nmine\n", theirs: "x\na\nB2\nc\nd\n", oursLabel: "mine", theirsLabel: "disk")
15 #expect(merged == "x\na\n<<<<<<< mine\nB1\n=======\nB2\n>>>>>>> disk\nc\nd\nmine\n")
16 let twoWay = mergeWithMarkers(base: nil, ours: "a\nb\n", theirs: "a\nc", oursLabel: "file", theirsLabel: "copy")
17 #expect(twoWay == "a\n<<<<<<< file\nb\n=======\nc\n>>>>>>> copy\n")
18 }
19}