import HelderCore import Testing @Suite struct DiffViewsTests { private func actual(_ original: String, _ updated: String) -> [ViewLine] { DiffViews.actual(LineDiff.build(original: original, updated: updated, status: .modified)) } @Test("a rewritten line is tinted in place and draws no gap rule") func rewrittenLine() { let lines = actual("a\nold\nb", "a\nnew\nb") #expect(lines.map(\.text) == ["a", "new", "b"]) #expect(lines[1].style == .added) #expect(lines.allSatisfy { $0.gap == nil }) } @Test("a pure deletion marks the next line's top edge") func deletionMarksNextLine() { let lines = actual("a\ngone\nb", "a\nb") #expect(lines[1].text == "b") #expect(lines[1].gap == .above) #expect(lines[1].style == nil) } @Test("a deletion at the end of the file rules under the last line") func deletionAtEnd() { let lines = actual("a\nb\ntail", "a\nb") #expect(lines[1].gap == .below) #expect(lines[0].gap == nil) } @Test("a deletion at the start of the file rules above the first line") func deletionAtStart() { let lines = actual("gone\na", "a") #expect(lines == [ViewLine(no: 1, text: "a", gap: .above)]) } @Test("an insertion is tinted and leaves its neighbours alone") func insertion() { let lines = actual("a\nb", "a\nNEW\nb") #expect(lines[1].style == .added) #expect(lines.allSatisfy { $0.gap == nil }) } @Test("an unchanged file carries no marks") func unchanged() { let lines = actual("a\nb\n", "a\nb\n") #expect(lines.allSatisfy { $0.style == nil && $0.gap == nil }) } @Test("a deleted file has no Actual lines") func deletedFile() { #expect(DiffViews.actual(LineDiff.build(original: "a\nb", updated: "", status: .deleted)).isEmpty) } @Test("the removed line only leaves one rule") func onlyOneRule() { let lines = actual("keep\ngone\ntail\n", "keep\ntail\n") #expect(lines.filter { $0.gap != nil }.count == 1) #expect(lines.filter { $0.style != nil }.isEmpty) } @Test("a plain file is numbered from 1 and drops one trailing newline") func plain() { #expect(DiffViews.plain("x\ny\n") == [ViewLine(no: 1, text: "x"), ViewLine(no: 2, text: "y")]) #expect(DiffViews.plain("") == [ViewLine(no: 1, text: "")]) } } @Suite struct DiffViewsLineEndingTests { @Test("a CRLF file keeps one line per CRLF in the plain view") func crlfPlain() { #expect(DiffViews.plain("a\r\nb\r\n").map(\.text) == ["a\r", "b\r"]) } }