Skip to content

Commit

Permalink
feat: rendering candidate sources for set paths
Browse files Browse the repository at this point in the history
  • Loading branch information
d-led committed Dec 31, 2023
1 parent f403f17 commit 7488e12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
16 changes: 13 additions & 3 deletions render/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package render

import (
"fmt"
"runtime"
"strings"

"github.com/d-led/pathdebug/common"
Expand All @@ -16,14 +17,23 @@ func RenderTableToString(results []common.ResultRow) string {

func RenderTable(b *strings.Builder, results []common.ResultRow) {
t := table.NewWriter()
t.AppendHeader(table.Row{"#", "Dup[#]", "Bad", "Path"})
headers := table.Row{"#", "Dup[#]", "Bad", "Path"}
addSources := runtime.GOOS != "windows"
if addSources {
headers = append(headers, "±Sources")
}
t.AppendHeader(headers)
for _, row := range results {
t.AppendRow(table.Row{
r := table.Row{
row.Id,
FormatList(row.Duplicates),
StatusOfDir(row),
row.Path,
})
}
if addSources {
r = append(r, FormatList(row.CandidateSources))
}
t.AppendRow(r)
}
b.WriteString(t.Render())
}
Expand Down
13 changes: 13 additions & 0 deletions render/table_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package render

import (
"runtime"
"testing"

"github.com/d-led/pathdebug/common"
Expand All @@ -22,3 +23,15 @@ func Test_table_rendering(t *testing.T) {
assert.Contains(t, table, "F")
assert.Contains(t, table, "X")
}

func Test_rendering_candidate_sources(t *testing.T) {
if runtime.GOOS == "windows" {
t.SkipNow()
}
table := RenderTableToString([]common.ResultRow{
{Id: 42, Path: "/ok", CandidateSources: []string{".mySource"}},
})

assert.Contains(t, table, "/ok")
assert.Contains(t, table, ".mySource")
}

0 comments on commit 7488e12

Please sign in to comment.