mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 12:31:06 +01:00
continued refactoring, added more tests, better error handling
This commit is contained in:
@@ -19,20 +19,22 @@ package lib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestArrayContains(t *testing.T) {
|
||||
func Testcontains(t *testing.T) {
|
||||
var tests = []struct {
|
||||
list []int
|
||||
search int
|
||||
want bool
|
||||
}{
|
||||
{[]int{1, 2, 3}, 2, true},
|
||||
{[]int{2, 3, 4}, 5, false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
testname := fmt.Sprintf("%d,%d,%t", tt.list, tt.search, tt.want)
|
||||
testname := fmt.Sprintf("contains-%d,%d,%t", tt.list, tt.search, tt.want)
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
answer := contains(tt.list, tt.search)
|
||||
if answer != tt.want {
|
||||
@@ -41,3 +43,31 @@ func TestArrayContains(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareColumns(t *testing.T) {
|
||||
var tests = []struct {
|
||||
input string
|
||||
exp []int
|
||||
wanterror bool // expect error
|
||||
}{
|
||||
{"1,2,3", []int{1, 2, 3}, false},
|
||||
{"1,2,", []int{}, true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
testname := fmt.Sprintf("PrepareColumns-%s-%t", tt.input, tt.wanterror)
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
Columns = tt.input
|
||||
err := PrepareColumns()
|
||||
if err != nil {
|
||||
if !tt.wanterror {
|
||||
t.Errorf("got error: %v", err)
|
||||
}
|
||||
} else {
|
||||
if !reflect.DeepEqual(UseColumns, tt.exp) {
|
||||
t.Errorf("got: %v, expected: %v", UseColumns, tt.exp)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user