Robert Findley | 88346e9 | 2020-04-17 05:28:48 +0100 | [diff] [blame] | 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 ( |
Robert Findley | 88346e9 | 2020-04-17 05:28:48 +0100 | [diff] [blame] | 8 | "testing" |
| 9 | ) |
| 10 | |
Rob Findley | ea3a2cd | 2020-08-13 15:53:33 -0400 | [diff] [blame] | 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) |
Rob Findley | 0d28b7d | 2021-07-30 13:14:24 -0400 | [diff] [blame] | 42 | if _, score := matcher([]string{test.s}); score > 0 != test.wantMatch { |
Rob Findley | ea3a2cd | 2020-08-13 15:53:33 -0400 | [diff] [blame] | 43 | t.Errorf("parseQuery(%q) match for %q: %.2g, want match: %t", test.query, test.s, score, test.wantMatch) |
| 44 | } |
| 45 | } |
| 46 | } |