6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-07 06:40:38 +00:00

Improve the implementation of the smart tree printer

It now correctly indents lines with branches status
This commit is contained in:
Grzegorz Dlugoszewski
2020-06-06 16:54:03 +02:00
parent 13c03bc2ef
commit 29c21cb78d
3 changed files with 45 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ package pkg
import (
"fmt"
"strings"
"testing"
)
@@ -91,14 +92,15 @@ gitlab.com/
for i, test := range tests {
var repos []*Repo
for _, path := range test.paths {
repos = append(repos, &Repo{path: path})
repos = append(repos, newRepo(nil, path)) //&Repo{path: path})
}
tree := BuildTree("root", repos)
// Leading and trailing newlines are added to test cases for readability. We also need to add them to the rendering result.
got := fmt.Sprintf("\n%s\n", RenderTree(tree))
got := fmt.Sprintf("\n%s\n", RenderSmartTree(tree))
if got != test.want {
// Rendered tree uses spaces for indentation but the test cases use tabs.
if got != strings.ReplaceAll(test.want, "\t", " ") {
t.Errorf("Failed test case %d, got: %+v; want: %+v", i, got, test.want)
}
}