Files
pad/internal/diff/linecounts_test.go
T
xarmian 7ba823004c feat(history): version rows carry their writer, line counts and create marker, plus a per-version diff endpoint (PLAN-2348 U2) (#1691)
* feat(history): version rows carry their writer, line counts and create marker; a diff endpoint pairs each row with its own change (PLAN-2348 U2)

* test(history): server legs, export/import leg; web type and API method for the version diff (PLAN-2348 U2)

* docs(history): the version diff endpoint and row fields in CLAUDE.md; FormatDiffSummary names what it counts (PLAN-2348 U2)

* fix(history): user_id already existed on item_versions (migration 012); a diff refuses a body the chain could not rebuild (PLAN-2348 U2, codex r1)
2026-09-30 10:02:41 -04:00

28 lines
914 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package diff
import "testing"
func TestLineCounts(t *testing.T) {
for _, c := range []struct {
name, old, new string
added, removed int
}{
{"create", "", "a\nb\nc\n", 3, 0},
{"clear", "a\nb\n", "", 0, 2},
{"one line edited", "a\nb\nc\n", "a\nB\nc\n", 1, 1},
{"one character edited is one line, not a chunk count", "alpha beta\n", "alpha Beta\n", 1, 1},
{"insert in the middle", "a\nc\n", "a\nb\nc\n", 1, 0},
// The old last line gains a newline, so it is removed and re-added: jsdiff's
// diffLines tokenises the same way and DiffView renders the same +2 −1.
{"appending past a last line with no newline", "a\nb", "a\nb\nc", 2, 1},
{"unchanged", "a\nb\n", "a\nb\n", 0, 0},
} {
t.Run(c.name, func(t *testing.T) {
a, r := LineCounts(c.old, c.new)
if a != c.added || r != c.removed {
t.Fatalf("LineCounts = +%d −%d, want +%d −%d", a, r, c.added, c.removed)
}
})
}
}