blob: 89c754db09ddd9fc47b721bf555ee4a22e6b0007 [file] [log] [blame]
Robert Findley88346e92020-04-17 05:28:48 +01001// 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
5package source
6
7import (
Robert Findley88346e92020-04-17 05:28:48 +01008 "testing"
9)
10
Rob Findleyea3a2cd2020-08-13 15:53:33 -040011func 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 Findley0d28b7d2021-07-30 13:14:24 -040042 if _, score := matcher([]string{test.s}); score > 0 != test.wantMatch {
Rob Findleyea3a2cd2020-08-13 15:53:33 -040043 t.Errorf("parseQuery(%q) match for %q: %.2g, want match: %t", test.query, test.s, score, test.wantMatch)
44 }
45 }
46}