Skip to content
Myr

Fix #149 - panic on empty string filter

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 3dddbfd · Browse files · 2 files+20 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−0 removed

  • other:+20 added−0 removed

2 files+20 added−0 removed

modified:src/algo/algo_test.go+8 added
40 unmodified lines
41 assertMatch(t, SuffixMatch, false, "fooBarbaz", "Foo", -1, -1)42 assertMatch(t, SuffixMatch, false, "fooBarbaz", "baz", 6, 9)43 assertMatch(t, SuffixMatch, true, "fooBarbaz", "Baz", -1, -1)44}4546func TestEmptyPattern(t *testing.T) {47 assertMatch(t, FuzzyMatch, true, "foobar", "", 0, 0)48 assertMatch(t, ExactMatchStrings, true, "foobar", "", 0, 0)49 assertMatch(t, ExactMatchNaive, true, "foobar", "", 0, 0)50 assertMatch(t, PrefixMatch, true, "foobar", "", 0, 0)51 assertMatch(t, SuffixMatch, true, "foobar", "", 6, 6)52}
modified:src/algo/algo.go+12 added
10 unmodified lines
11 */1213// FuzzyMatch performs fuzzy-match14func FuzzyMatch(caseSensitive bool, input *string, pattern []rune) (int, int) {15 if len(pattern) == 0 {16 return 0, 017 }1819 runes := []rune(*input)2021 // 0. (FIXME) How to find the shortest match?22 // a_____b__c__abc
46 unmodified lines
6970// ExactMatchStrings performs exact-match using strings package.71// Currently not used.72func ExactMatchStrings(caseSensitive bool, input *string, pattern []rune) (int, int) {73 if len(pattern) == 0 {74 return 0, 075 }7677 var str string78 if caseSensitive {79 str = *input80 } else {
14 unmodified lines
95//96// We might try to implement better algorithms in the future:97// http://en.wikipedia.org/wiki/String_searching_algorithm98func ExactMatchNaive(caseSensitive bool, input *string, pattern []rune) (int, int) {99 if len(pattern) == 0 {100 return 0, 0101 }102103 runes := []rune(*input)104 numRunes := len(runes)105 plen := len(pattern)106 if numRunes < plen {
61 unmodified lines