mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-10-26 14:30:13 +00:00
7ba823004c
* 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)
28 lines
914 B
Go
28 lines
914 B
Go
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)
|
||
}
|
||
})
|
||
}
|
||
}
|