pattern_test.go
This file
Path
src/pattern_test.go
132 lines · 4.6 KiB · Go
Last changed by
Make --extended defaultJunegunn Choibefore adoption81a8869
History of this fileTake it
The walk stopped after 200 commits: lines older than 26a141c point at it.
[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 1–3why, one step back1package fzf23import (Performance tuning - eager rune array conversionJunegunn Choibefore adoption0ea6632
line 4why, one step back4 "reflect"[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 5–10why, one step back5 "testing"67 "github.com/junegunn/fzf/src/algo"8)910func TestParseTermsExtended(t *testing.T) {Make --extended defaultJunegunn Choibefore adoption81a8869
line 11why, one step back11 terms := parseTerms(true, CaseSmart,Allow ^EqualMatch$Junegunn Choibefore adoption0be4cea
lines 12–13why, one step back12 "aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$ ^iii$")13 if len(terms) != 9 ||[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 14–20why, one step back14 terms[0].typ != termFuzzy || terms[0].inv ||15 terms[1].typ != termExact || terms[1].inv ||16 terms[2].typ != termPrefix || terms[2].inv ||17 terms[3].typ != termSuffix || terms[3].inv ||18 terms[4].typ != termFuzzy || !terms[4].inv ||19 terms[5].typ != termExact || !terms[5].inv ||20 terms[6].typ != termPrefix || !terms[6].inv ||Allow ^EqualMatch$Junegunn Choibefore adoption0be4cea
lines 21–22why, one step back21 terms[7].typ != termSuffix || !terms[7].inv ||22 terms[8].typ != termEqual || terms[8].inv {[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 23–35why, one step back23 t.Errorf("%s", terms)24 }25 for idx, term := range terms {26 if len(term.text) != 3 {27 t.Errorf("%s", term)28 }29 if idx > 0 && len(term.origText) != 4+idx/5 {30 t.Errorf("%s", term)31 }32 }33}3435func TestParseTermsExtendedExact(t *testing.T) {Make --extended defaultJunegunn Choibefore adoption81a8869
line 36why, one step back36 terms := parseTerms(false, CaseSmart,[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 37–39why, one step back37 "aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$")38 if len(terms) != 8 ||39 terms[0].typ != termExact || terms[0].inv || len(terms[0].text) != 3 ||Make it possible to unquote the term in extended-exact modeJunegunn Choibefore adoption9017e29
line 40why, one step back40 terms[1].typ != termFuzzy || terms[1].inv || len(terms[1].text) != 3 ||[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 41–43why, one step back41 terms[2].typ != termPrefix || terms[2].inv || len(terms[2].text) != 3 ||42 terms[3].typ != termSuffix || terms[3].inv || len(terms[3].text) != 3 ||43 terms[4].typ != termExact || !terms[4].inv || len(terms[4].text) != 3 ||Make it possible to unquote the term in extended-exact modeJunegunn Choibefore adoption9017e29
line 44why, one step back44 terms[5].typ != termFuzzy || !terms[5].inv || len(terms[5].text) != 3 ||[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 45–51why, one step back45 terms[6].typ != termPrefix || !terms[6].inv || len(terms[6].text) != 3 ||46 terms[7].typ != termSuffix || !terms[7].inv || len(terms[7].text) != 3 {47 t.Errorf("%s", terms)48 }49}5051func TestParseTermsEmpty(t *testing.T) {Make --extended defaultJunegunn Choibefore adoption81a8869
line 52why, one step back52 terms := parseTerms(true, CaseSmart, "' $ ^ !' !^ !$")[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 53–60why, one step back53 if len(terms) != 0 {54 t.Errorf("%s", terms)55 }56}5758func TestExact(t *testing.T) {59 defer clearPatternCache()60 clearPatternCache()Make --extended defaultJunegunn Choibefore adoption81a8869
line 61why, one step back61 pattern := BuildPattern(true, true, CaseSmart, true,Fix --with-nth performance; avoid regex if possibleJunegunn Choibefore adoption766427d
line 62why, one step back62 []Range{}, Delimiter{}, []rune("'abc"))Performance tuning - eager rune array conversionJunegunn Choibefore adoption0ea6632
line 63why, one step back63 sidx, eidx := algo.ExactMatchNaive(Fix #344 - Backward scan when `--tiebreak=end`Junegunn Choibefore adoption6444322
line 64why, one step back64 pattern.caseSensitive, pattern.forward, []rune("aabbcc abc"), pattern.terms[0].text)[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 65–67why, one step back65 if sidx != 7 || eidx != 10 {66 t.Errorf("%s / %d / %d", pattern.terms, sidx, eidx)67 }Allow ^EqualMatch$Junegunn Choibefore adoption0be4cea
lines 68–72why, one step back68}6970func TestEqual(t *testing.T) {71 defer clearPatternCache()72 clearPatternCache()Make --extended defaultJunegunn Choibefore adoption81a8869
line 73why, one step back73 pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("^AbC$"))Allow ^EqualMatch$Junegunn Choibefore adoption0be4cea
lines 74–75why, one step back7475 match := func(str string, sidxExpected int, eidxExpected int) {Performance tuning - eager rune array conversionJunegunn Choibefore adoption0ea6632
line 76why, one step back76 sidx, eidx := algo.EqualMatch(Fix #344 - Backward scan when `--tiebreak=end`Junegunn Choibefore adoption6444322
line 77why, one step back77 pattern.caseSensitive, pattern.forward, []rune(str), pattern.terms[0].text)Allow ^EqualMatch$Junegunn Choibefore adoption0be4cea
lines 78–83why, one step back78 if sidx != sidxExpected || eidx != eidxExpected {79 t.Errorf("%s / %d / %d", pattern.terms, sidx, eidx)80 }81 }82 match("ABC", -1, -1)83 match("AbC", 0, 3)[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 84–88why, one step back84}8586func TestCaseSensitivity(t *testing.T) {87 defer clearPatternCache()88 clearPatternCache()Make --extended defaultJunegunn Choibefore adoption81a8869
line 89why, one step back89 pat1 := BuildPattern(true, false, CaseSmart, true, []Range{}, Delimiter{}, []rune("abc"))[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
line 90why, one step back90 clearPatternCache()Make --extended defaultJunegunn Choibefore adoption81a8869
line 91why, one step back91 pat2 := BuildPattern(true, false, CaseSmart, true, []Range{}, Delimiter{}, []rune("Abc"))[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
line 92why, one step back92 clearPatternCache()Make --extended defaultJunegunn Choibefore adoption81a8869
line 93why, one step back93 pat3 := BuildPattern(true, false, CaseIgnore, true, []Range{}, Delimiter{}, []rune("abc"))[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
line 94why, one step back94 clearPatternCache()Make --extended defaultJunegunn Choibefore adoption81a8869
line 95why, one step back95 pat4 := BuildPattern(true, false, CaseIgnore, true, []Range{}, Delimiter{}, []rune("Abc"))[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
line 96why, one step back96 clearPatternCache()Make --extended defaultJunegunn Choibefore adoption81a8869
line 97why, one step back97 pat5 := BuildPattern(true, false, CaseRespect, true, []Range{}, Delimiter{}, []rune("abc"))[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
line 98why, one step back98 clearPatternCache()Make --extended defaultJunegunn Choibefore adoption81a8869
line 99why, one step back99 pat6 := BuildPattern(true, false, CaseRespect, true, []Range{}, Delimiter{}, []rune("Abc"))[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 100–111why, one step back100101 if string(pat1.text) != "abc" || pat1.caseSensitive != false ||102 string(pat2.text) != "Abc" || pat2.caseSensitive != true ||103 string(pat3.text) != "abc" || pat3.caseSensitive != false ||104 string(pat4.text) != "abc" || pat4.caseSensitive != false ||105 string(pat5.text) != "abc" || pat5.caseSensitive != true ||106 string(pat6.text) != "Abc" || pat6.caseSensitive != true {107 t.Error("Invalid case conversion")108 }109}110111func TestOrigTextAndTransformed(t *testing.T) {Make --extended defaultJunegunn Choibefore adoption81a8869
line 112why, one step back112 pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("jg"))Fix --with-nth performance; avoid regex if possibleJunegunn Choibefore adoption766427d
line 113why, one step back113 tokens := Tokenize([]rune("junegunn"), Delimiter{})[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 114–115why, one step back114 trans := Transform(tokens, []Range{Range{1, 1}})115Performance tuning - eager rune array conversionJunegunn Choibefore adoption0ea6632
line 116why, one step back116 origRunes := []rune("junegunn.choi")Make --extended defaultJunegunn Choibefore adoption81a8869
line 117why, one step back117 for _, extended := range []bool{false, true} {[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 118–119why, one step back118 chunk := Chunk{119 &Item{Performance tuning - eager rune array conversionJunegunn Choibefore adoption0ea6632
lines 120–121why, one step back120 text: []rune("junegunn"),121 origText: &origRunes,[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 122–123why, one step back122 transformed: trans},123 }Make --extended defaultJunegunn Choibefore adoption81a8869
line 124why, one step back124 pattern.extended = extended[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
line 125why, one step back125 matches := pattern.matchChunk(&chunk)Performance tuning - eager rune array conversionJunegunn Choibefore adoption0ea6632
line 126why, one step back126 if string(matches[0].text) != "junegunn" || string(*matches[0].origText) != "junegunn.choi" ||[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
line 127why, one step back127 matches[0].offsets[0][0] != 0 || matches[0].offsets[0][1] != 5 ||Performance tuning - eager rune array conversionJunegunn Choibefore adoption0ea6632
line 128why, one step back128 !reflect.DeepEqual(matches[0].transformed, trans) {[zsh-completion] Fix `~USERNAME**` (#230)Junegunn Choibefore adoption26a141c
lines 129–132why, one step back129 t.Error("Invalid match result", matches)130 }131 }132}