From bb0502ff4429580e363be708ff301c35479144e3 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 28 Feb 2021 18:28:21 +0900 Subject: [PATCH] Check gofmt in `make test` --- Makefile | 1 + src/cache_test.go | 4 ++-- src/options_test.go | 2 +- src/pattern.go | 4 ++-- src/pattern_test.go | 2 +- src/result_test.go | 12 ++++++------ 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index dec742e..f246508 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ endif all: target/$(BINARY) test: $(SOURCES) + [ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1) SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" \ github.com/junegunn/fzf/src \ github.com/junegunn/fzf/src/algo \ diff --git a/src/cache_test.go b/src/cache_test.go index 5d9c5cc..0242534 100644 --- a/src/cache_test.go +++ b/src/cache_test.go @@ -6,8 +6,8 @@ func TestChunkCache(t *testing.T) { cache := NewChunkCache() chunk1p := &Chunk{} chunk2p := &Chunk{count: chunkSize} - items1 := []Result{Result{}} - items2 := []Result{Result{}, Result{}} + items1 := []Result{{}} + items2 := []Result{{}, {}} cache.Add(chunk1p, "foo", items1) cache.Add(chunk2p, "foo", items1) cache.Add(chunk2p, "bar", items2) diff --git a/src/options_test.go b/src/options_test.go index b106896..791b55d 100644 --- a/src/options_test.go +++ b/src/options_test.go @@ -102,7 +102,7 @@ func TestIrrelevantNth(t *testing.T) { t.Errorf("nth should be empty: %v", opts.Nth) } } - for _, words := range [][]string{[]string{"--nth", "..,3", "+x"}, []string{"--nth", "3,1..", "+x"}, []string{"--nth", "..-1,1", "+x"}} { + for _, words := range [][]string{{"--nth", "..,3", "+x"}, {"--nth", "3,1..", "+x"}, {"--nth", "..-1,1", "+x"}} { { opts := defaultOptions() parseOptions(opts, words) diff --git a/src/pattern.go b/src/pattern.go index 56dc830..4a7a87a 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -337,7 +337,7 @@ func (p *Pattern) MatchItem(item *Item, withPos bool, slab *util.Slab) (*Result, func (p *Pattern) basicMatch(item *Item, withPos bool, slab *util.Slab) (Offset, int, *[]int) { var input []Token if len(p.nth) == 0 { - input = []Token{Token{text: &item.text, prefixLength: 0}} + input = []Token{{text: &item.text, prefixLength: 0}} } else { input = p.transformInput(item) } @@ -350,7 +350,7 @@ func (p *Pattern) basicMatch(item *Item, withPos bool, slab *util.Slab) (Offset, func (p *Pattern) extendedMatch(item *Item, withPos bool, slab *util.Slab) ([]Offset, int, *[]int) { var input []Token if len(p.nth) == 0 { - input = []Token{Token{text: &item.text, prefixLength: 0}} + input = []Token{{text: &item.text, prefixLength: 0}} } else { input = p.transformInput(item) } diff --git a/src/pattern_test.go b/src/pattern_test.go index 5a62295..b95d151 100644 --- a/src/pattern_test.go +++ b/src/pattern_test.go @@ -131,7 +131,7 @@ func TestCaseSensitivity(t *testing.T) { func TestOrigTextAndTransformed(t *testing.T) { pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("jg")) tokens := Tokenize("junegunn", Delimiter{}) - trans := Transform(tokens, []Range{Range{1, 1}}) + trans := Transform(tokens, []Range{{1, 1}}) origBytes := []byte("junegunn.choi") for _, extended := range []bool{false, true} { diff --git a/src/result_test.go b/src/result_test.go index 1f3d338..4084fdb 100644 --- a/src/result_test.go +++ b/src/result_test.go @@ -18,8 +18,8 @@ func withIndex(i *Item, index int) *Item { func TestOffsetSort(t *testing.T) { offsets := []Offset{ - Offset{3, 5}, Offset{2, 7}, - Offset{1, 3}, Offset{2, 9}} + {3, 5}, {2, 7}, + {1, 3}, {2, 9}} sort.Sort(ByOrder(offsets)) if offsets[0][0] != 1 || offsets[0][1] != 3 || @@ -84,13 +84,13 @@ func TestResultRank(t *testing.T) { // Sort by relevance item3 := buildResult( - withIndex(&Item{}, 2), []Offset{Offset{1, 3}, Offset{5, 7}}, 3) + withIndex(&Item{}, 2), []Offset{{1, 3}, {5, 7}}, 3) item4 := buildResult( - withIndex(&Item{}, 2), []Offset{Offset{1, 2}, Offset{6, 7}}, 4) + withIndex(&Item{}, 2), []Offset{{1, 2}, {6, 7}}, 4) item5 := buildResult( - withIndex(&Item{}, 2), []Offset{Offset{1, 3}, Offset{5, 7}}, 5) + withIndex(&Item{}, 2), []Offset{{1, 3}, {5, 7}}, 5) item6 := buildResult( - withIndex(&Item{}, 2), []Offset{Offset{1, 2}, Offset{6, 7}}, 6) + withIndex(&Item{}, 2), []Offset{{1, 2}, {6, 7}}, 6) items = []Result{item1, item2, item3, item4, item5, item6} sort.Sort(ByRelevance(items)) if !(items[0] == item6 && items[1] == item5 &&