mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
more refactoring, fixed bug in shell mode output, fixed default
Separator and fixed #3
This commit is contained in:
@@ -52,6 +52,7 @@ func TestPrepareColumns(t *testing.T) {
|
||||
}{
|
||||
{"1,2,3", []int{1, 2, 3}, false},
|
||||
{"1,2,", []int{}, true},
|
||||
{"a,b", []int{}, true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -71,3 +72,46 @@ func TestPrepareColumns(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReduceColumns(t *testing.T) {
|
||||
var tests = []struct {
|
||||
expect [][]string
|
||||
columns []int
|
||||
}{
|
||||
{
|
||||
expect: [][]string{[]string{"a", "b"}},
|
||||
columns: []int{1, 2},
|
||||
},
|
||||
{
|
||||
expect: [][]string{[]string{"a", "c"}},
|
||||
columns: []int{1, 3},
|
||||
},
|
||||
{
|
||||
expect: [][]string{[]string{"a"}},
|
||||
columns: []int{1},
|
||||
},
|
||||
{
|
||||
expect: [][]string{nil},
|
||||
columns: []int{4},
|
||||
},
|
||||
}
|
||||
|
||||
input := [][]string{[]string{"a", "b", "c"}}
|
||||
|
||||
Columns = "y" // used as a flag with len(Columns)...
|
||||
|
||||
for _, tt := range tests {
|
||||
testname := fmt.Sprintf("reduce-columns-by-%+v", tt.columns)
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
UseColumns = tt.columns
|
||||
data := Tabdata{entries: input}
|
||||
reduceColumns(&data)
|
||||
if !reflect.DeepEqual(data.entries, tt.expect) {
|
||||
t.Errorf("reduceColumns returned invalid data:\ngot: %+v\nexp: %+v", data.entries, tt.expect)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Columns = "" // reset for other tests
|
||||
UseColumns = nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user