| 1 | package server |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "gitlab.com/Timfa/bluegit/internal/gitrepo" |
| 7 | ) |
| 8 | |
| 9 | func TestTreeRowsOpen(t *testing.T) { |
| 10 | entries := []gitrepo.Entry{ |
| 11 | {Type: "tree", Name: "src"}, |
| 12 | {Type: "tree", Name: "src/pkg"}, |
| 13 | {Type: "blob", Name: "src/main.go"}, |
| 14 | {Type: "blob", Name: "src/pkg/util.go"}, |
| 15 | {Type: "tree", Name: "docs"}, |
| 16 | {Type: "blob", Name: "docs/a.md"}, |
| 17 | } |
| 18 | rows := treeRows(entries, "src/main.go") |
| 19 | by := map[string]FileRow{} |
| 20 | for _, r := range rows { |
| 21 | by[r.Path] = r |
| 22 | } |
| 23 | if !by["src"].Dir || !by["src"].Open || !by["src"].Active || by["src"].Depth != 0 { |
| 24 | t.Fatalf("src: %+v", by["src"]) |
| 25 | } |
| 26 | if by["src/pkg"].Open || by["src/pkg"].Active || !by["src/pkg"].Dir { |
| 27 | t.Fatalf("src/pkg: %+v", by["src/pkg"]) |
| 28 | } |
| 29 | if by["src/main.go"].Dir || by["src/main.go"].Open || !by["src/main.go"].Active || by["src/main.go"].Depth != 1 { |
| 30 | t.Fatalf("main: %+v", by["src/main.go"]) |
| 31 | } |
| 32 | if by["docs"].Open || by["docs"].Active || !by["docs"].Dir { |
| 33 | t.Fatalf("docs: %+v", by["docs"]) |
| 34 | } |
| 35 | if by["docs/a.md"].Active || by["docs/a.md"].Open { |
| 36 | t.Fatalf("a.md: %+v", by["docs/a.md"]) |
| 37 | } |
| 38 | |
| 39 | nested := treeRows(entries, "src/pkg/util.go") |
| 40 | open := map[string]bool{} |
| 41 | for _, r := range nested { |
| 42 | open[r.Path] = r.Open |
| 43 | if r.Path == "src/pkg/util.go" && (r.Dir || !r.Active || r.Open) { |
| 44 | t.Fatalf("util: %+v", r) |
| 45 | } |
| 46 | } |
| 47 | if !open["src"] || !open["src/pkg"] || open["docs"] { |
| 48 | t.Fatalf("voorouders: %v", open) |
| 49 | } |
| 50 | |
| 51 | folder := treeRows(entries, "docs") |
| 52 | for _, r := range folder { |
| 53 | if r.Path == "docs" && (!r.Open || !r.Active) { |
| 54 | t.Fatalf("docs als huidige map: %+v", r) |
| 55 | } |
| 56 | if r.Path == "src" && r.Open { |
| 57 | t.Fatalf("src hoort dicht: %+v", r) |
| 58 | } |
| 59 | } |
| 60 | } |