Debian Codegraph @

btf/unmarshal_test.go

raw symbols SCIP
1 package btf
2
3 import (
4 "iter"
5 "math"
6 "testing"
7
8 "github.com/go-quicktest/qt"
9 )
10
11 func TestFuzzyStringIndex(t *testing.T) {
12 idx := newFuzzyStringIndex(10)
13 count := testing.AllocsPerRun(1, func() {
14 idx.Add([]byte("foo"), 1)
15 })
16 qt.Assert(t, qt.Equals(count, 0))
17
18 idx.entries = idx.entries[:0]
19 idx.Add([]byte("foo"), 1)
20 idx.Add([]byte("bar"), 2)
21 idx.Add([]byte("baz"), 3)
22 idx.Build()
23
24 all := func(it iter.Seq[TypeID]) (ids []TypeID) {
25 for id := range it {
26 ids = append(ids, id)
27 }
28 return
29 }
30
31 qt.Assert(t, qt.SliceContains(all(idx.Find("foo")), 1))
32 qt.Assert(t, qt.SliceContains(all(idx.Find("bar")), 2))
33 qt.Assert(t, qt.SliceContains(all(idx.Find("baz")), 3))
34
35 qt.Assert(t, qt.IsTrue(newFuzzyStringIndexEntry(0, math.MaxUint32) < newFuzzyStringIndexEntry(1, 0)))
36 }