github.com/jhump/golang-x-tools@v0.0.0-20220218190644-4958d6d39439/internal/lsp/source/workspace_symbol_test.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package source 6 7 import ( 8 "testing" 9 ) 10 11 func TestParseQuery(t *testing.T) { 12 tests := []struct { 13 query, s string 14 wantMatch bool 15 }{ 16 {"", "anything", false}, 17 {"any", "anything", true}, 18 {"any$", "anything", false}, 19 {"ing$", "anything", true}, 20 {"ing$", "anythinG", true}, 21 {"inG$", "anything", false}, 22 {"^any", "anything", true}, 23 {"^any", "Anything", true}, 24 {"^Any", "anything", false}, 25 {"at", "anything", true}, 26 // TODO: this appears to be a bug in the fuzzy matching algorithm. 'At' 27 // should cause a case-sensitive match. 28 // {"At", "anything", false}, 29 {"At", "Anything", true}, 30 {"'yth", "Anything", true}, 31 {"'yti", "Anything", false}, 32 {"'any 'thing", "Anything", true}, 33 {"anythn nythg", "Anything", true}, 34 {"ntx", "Anything", false}, 35 {"anythn", "anything", true}, 36 {"ing", "anything", true}, 37 {"anythn nythgx", "anything", false}, 38 } 39 40 for _, test := range tests { 41 matcher := parseQuery(test.query, newFuzzyMatcher) 42 if _, score := matcher([]string{test.s}); score > 0 != test.wantMatch { 43 t.Errorf("parseQuery(%q) match for %q: %.2g, want match: %t", test.query, test.s, score, test.wantMatch) 44 } 45 } 46 }