|
4 | 4 | "testing"
|
5 | 5 |
|
6 | 6 | "github.com/google/go-cmp/cmp"
|
| 7 | + "github.com/stretchr/testify/require" |
| 8 | + "golang.org/x/exp/slices" |
| 9 | + "pgregory.net/rapid" |
7 | 10 | )
|
8 | 11 |
|
9 | 12 | func TestFindOccurrences(t *testing.T) {
|
@@ -122,3 +125,34 @@ func TestSortRanges(t *testing.T) {
|
122 | 125 | t.Errorf("unexpected occurrence order (-want +got):\n%s", diff)
|
123 | 126 | }
|
124 | 127 | }
|
| 128 | + |
| 129 | +func genSymbolInfo() *rapid.Generator[*SymbolInformation] { |
| 130 | + return rapid.Custom(func(t *rapid.T) *SymbolInformation { |
| 131 | + return &SymbolInformation{Symbol: rapid.String().Draw(t, "symbol")} |
| 132 | + }) |
| 133 | +} |
| 134 | + |
| 135 | +func TestFindSymbolBinarySearch(t *testing.T) { |
| 136 | + rapid.Check(t, func(t *rapid.T) { |
| 137 | + symbolInfoGen := genSymbolInfo() |
| 138 | + symbolInfos := rapid.SliceOfN(symbolInfoGen, 0, 10).Draw(t, "symbolInfos") |
| 139 | + doc := &Document{Symbols: symbolInfos} |
| 140 | + canonicalDoc := CanonicalizeDocument(doc) |
| 141 | + for _, symbolInfo := range symbolInfos { |
| 142 | + got := FindSymbolBinarySearch(canonicalDoc, symbolInfo.Symbol) |
| 143 | + require.NotNil(t, got) |
| 144 | + require.Equal(t, symbolInfo.Symbol, got.Symbol) |
| 145 | + } |
| 146 | + other := rapid.String().Draw(t, "otherSymbol") |
| 147 | + isInOriginalSlice := slices.ContainsFunc(symbolInfos, func(info *SymbolInformation) bool { |
| 148 | + return info.Symbol == other |
| 149 | + }) |
| 150 | + got := FindSymbolBinarySearch(canonicalDoc, other) |
| 151 | + if isInOriginalSlice { |
| 152 | + require.NotNil(t, got) |
| 153 | + require.Equal(t, other, got.Symbol) |
| 154 | + } else { |
| 155 | + require.Nil(t, got) |
| 156 | + } |
| 157 | + }) |
| 158 | +} |
0 commit comments