GoPLS Viewer

Home|gopls/internal/fuzzy/symbol_test.go
1// Copyright 2021 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 fuzzy_test
6
7import (
8    "testing"
9
10    . "golang.org/x/tools/internal/fuzzy"
11)
12
13func TestSymbolMatchIndex(t *testing.T) {
14    tests := []struct {
15        patterninput string
16        want           int
17    }{
18        {"test""foo.TestFoo"4},
19        {"test""test"0},
20        {"test""Test"0},
21        {"test""est", -1},
22        {"t""shortest"7},
23        {"""foo", -1},
24        {""string([]rune{0}), -1}, // verify that we don't default to an empty pattern.
25        {"anything""", -1},
26    }
27
28    for _test := range tests {
29        matcher := NewSymbolMatcher(test.pattern)
30        if got_ := matcher.Match([]string{test.input}); got != test.want {
31            t.Errorf("NewSymbolMatcher(%q).Match(%q) = %v, _, want %v, _"test.patterntest.inputgottest.want)
32        }
33    }
34}
35
36func TestSymbolRanking(t *testing.T) {
37    matcher := NewSymbolMatcher("test")
38
39    // symbols to match, in ascending order of ranking.
40    symbols := []string{
41        "this.is.better.than.most",
42        "test.foo.bar",
43        "atest",
44        "thebest",
45        "test.foo",
46        "test.foo",
47        "tTest",
48        "testage",
49        "foo.test",
50        "test",
51    }
52    prev := 0.0
53    for _sym := range symbols {
54        _score := matcher.Match([]string{sym})
55        t.Logf("Match(%q) = %v"symscore)
56        if score < prev {
57            t.Errorf("Match(%q) = _, %v, want > %v"symscoreprev)
58        }
59        prev = score
60    }
61}
62
63func TestChunkedMatch(t *testing.T) {
64    matcher := NewSymbolMatcher("test")
65
66    chunked := [][]string{
67        {"test"},
68        {"""test"},
69        {"test"""},
70        {"te""st"},
71    }
72
73    for _chunks := range chunked {
74        offsetscore := matcher.Match(chunks)
75        if offset != 0 || score != 1.0 {
76            t.Errorf("Match(%v) = %v, %v, want 0, 1.0"chunksoffsetscore)
77        }
78    }
79}
80
MembersX
.
TestSymbolMatchIndex
TestSymbolMatchIndex.RangeStmt_611.test
TestSymbolMatchIndex.RangeStmt_611.BlockStmt._
TestChunkedMatch.RangeStmt_1574.chunks
TestChunkedMatch.RangeStmt_1574.BlockStmt.score
TestSymbolMatchIndex.tests
TestSymbolRanking.symbols
TestSymbolRanking.RangeStmt_1190.sym
TestSymbolRanking.RangeStmt_1190.BlockStmt.score
TestChunkedMatch.matcher
TestChunkedMatch.t
TestSymbolMatchIndex.t
TestSymbolRanking
TestSymbolRanking.t
TestSymbolRanking.matcher
TestSymbolRanking.prev
TestSymbolRanking.RangeStmt_1190.BlockStmt._
TestChunkedMatch
TestChunkedMatch.chunked
TestSymbolMatchIndex.RangeStmt_611.BlockStmt.matcher
TestSymbolMatchIndex.RangeStmt_611.BlockStmt.got
TestChunkedMatch.RangeStmt_1574.BlockStmt.offset
Members
X