| 1 | package main |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // A note's anchor is the file a page line belongs to, by the name a rename |
| 6 | // gives it, and the new-side line it sits on, which a removal and the |
| 7 | // no-newline marker do not move. Inside a hunk, a line that reads like a |
| 8 | // file header is a line of the diff, and anchors as one. |
| 9 | func TestAnchors(t *testing.T) { |
| 10 | page := []byte(`branch topic, log against origin/main: |
| 11 | |
| 12 | abc1234 rename and edit |
| 13 | diff --git a/old.md b/new.md |
| 14 | similarity index 90% |
| 15 | @@ -3,3 +3,3 @@ heading |
| 16 | kept 3 |
| 17 | -removed |
| 18 | \ No newline at end of file |
| 19 | +added 4 |
| 20 | diff --git a/quoted.diff b/quoted.diff |
| 21 | @@ -1,0 +1,2 @@ |
| 22 | +diff --git a/inner b/inner |
| 23 | +@@ -9 +9 @@ |
| 24 | `) |
| 25 | all := anchors(page) |
| 26 | for n, want := range map[int]string{ |
| 27 | 0: "(unanchored)", |
| 28 | 3: "(unanchored)", |
| 29 | 4: "new.md", |
| 30 | 7: "new.md:3", |
| 31 | 9: "new.md:3", |
| 32 | 10: "new.md:4", |
| 33 | 11: "quoted.diff", |
| 34 | 13: "quoted.diff:1", |
| 35 | 14: "quoted.diff:2", |
| 36 | 15: "(unanchored)", |
| 37 | } { |
| 38 | if got := anchorOf(all, n); got != want { |
| 39 | t.Errorf("a note after line %d is anchored to %s, want %s", n, got, want) |
| 40 | } |
| 41 | } |
| 42 | } |