mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
Add JSON input support (#74)
* added basic json input support * add coverage to make test * enhanced unit tests, switch to testify/assert * reduce ci runs
This commit is contained in:
@@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
const DefaultSeparator string = `(\s\s+|\t)`
|
||||
const Version string = "v1.5.5"
|
||||
const Version string = "v1.5.6"
|
||||
const MAXPARTS = 2
|
||||
|
||||
var DefaultConfigfile = os.Getenv("HOME") + "/.config/tablizer/config"
|
||||
@@ -79,6 +79,7 @@ type Config struct {
|
||||
UseFuzzySearch bool
|
||||
UseHighlight bool
|
||||
Interactive bool
|
||||
InputJSON bool
|
||||
|
||||
SortMode string
|
||||
SortDescending bool
|
||||
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
"fmt"
|
||||
// "reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPrepareModeFlags(t *testing.T) {
|
||||
@@ -44,9 +46,8 @@ func TestPrepareModeFlags(t *testing.T) {
|
||||
conf := Config{}
|
||||
|
||||
conf.PrepareModeFlags(testdata.flag)
|
||||
if conf.OutputMode != testdata.expect {
|
||||
t.Errorf("got: %d, expect: %d", conf.OutputMode, testdata.expect)
|
||||
}
|
||||
|
||||
assert.EqualValues(t, testdata.expect, conf.OutputMode)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -70,9 +71,7 @@ func TestPrepareSortFlags(t *testing.T) {
|
||||
|
||||
conf.PrepareSortFlags(testdata.flag)
|
||||
|
||||
if conf.SortMode != testdata.expect {
|
||||
t.Errorf("got: %s, expect: %s", conf.SortMode, testdata.expect)
|
||||
}
|
||||
assert.EqualValues(t, testdata.expect, conf.SortMode)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -81,7 +80,7 @@ func TestPreparePattern(t *testing.T) {
|
||||
var tests = []struct {
|
||||
patterns []*Pattern
|
||||
name string
|
||||
wanterr bool
|
||||
wanterror bool
|
||||
wanticase bool
|
||||
wantneg bool
|
||||
}{
|
||||
@@ -123,16 +122,16 @@ func TestPreparePattern(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testdata := range tests {
|
||||
testname := fmt.Sprintf("PreparePattern-pattern-%s-wanterr-%t", testdata.name, testdata.wanterr)
|
||||
testname := fmt.Sprintf("PreparePattern-pattern-%s-wanterr-%t", testdata.name, testdata.wanterror)
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
conf := Config{}
|
||||
|
||||
err := conf.PreparePattern(testdata.patterns)
|
||||
|
||||
if err != nil {
|
||||
if !testdata.wanterr {
|
||||
t.Errorf("PreparePattern returned error: %s", err)
|
||||
}
|
||||
if testdata.wanterror {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user