| 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 | |
| 5 | //go:build go1.13 |
| 6 | |
| 7 | package triescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/ |
| 8 | |
| 9 | import ( |
| 10 | "reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/" |
| 11 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 12 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 13 | ) |
| 14 | |
| 15 | func TestScopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestScope().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 16 | def := Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Scope#{} |
| 17 | s0, s1 := newScopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/newScope().(), newScopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/newScope().() |
| 18 | if s0 == def || s1 == def { |
| 19 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("newScope() should never be == to the default scope") |
| 20 | } |
| 21 | if s0 == s1 { |
| 22 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("newScope() %q and %q should not be ==", s0, s1) |
| 23 | } |
| 24 | if s0.idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Scope#id. == 0 { |
| 25 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("s0.id is 0") |
| 26 | } |
| 27 | if s1.idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Scope#id. == 0 { |
| 28 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("s1.id is 0") |
| 29 | } |
| 30 | got := s0.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Scope#String().() |
| 31 | if _, err := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.0 strconv/Atoi().(got); err != nil { |
| 32 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("scope{%s}.String() is not an int: got %s with error %s", s0, got, err) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestCollisionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestCollision().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 37 | var x any = 1 |
| 38 | var y any = 2 |
| 39 | |
| 40 | if v := TakeLhsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TakeLhs().(x, y); v != x { |
| 41 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("TakeLhs(%s, %s) got %s. want %s", x, y, v, x) |
| 42 | } |
| 43 | if v := TakeRhsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TakeRhs().(x, y); v != y { |
| 44 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("TakeRhs(%s, %s) got %s. want %s", x, y, v, y) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func TestDefaultscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestDefault().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 49 | def := Mapscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#{} |
| 50 | |
| 51 | if def.Sizescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Size().() != 0 { |
| 52 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("default node has non-0 size %d", def.Sizescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Size().()) |
| 53 | } |
| 54 | if want, got := (Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Scope#{}), def.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().(); got != want { |
| 55 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("default is in a non default scope (%s) from b (%s)", got, want) |
| 56 | } |
| 57 | if v, ok := def.Lookupscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Lookup().(123); !(v == nil && !ok) { |
| 58 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Scope{}.Lookup() = (%s, %v) not (nil, false)", v, ok) |
| 59 | } |
| 60 | if !def.Rangescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Range().(func(k uint64, v any) bool { |
| 61 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Scope{}.Range() called it callback on %d:%s", k, v) |
| 62 | return true |
| 63 | }) { |
| 64 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("Scope{}.Range() always iterates through all elements") |
| 65 | } |
| 66 | |
| 67 | if got, want := def.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#String().(), "{}"; got != want { |
| 68 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Scope{}.String() got %s. want %s", got, want) |
| 69 | } |
| 70 | |
| 71 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 72 | if def == b.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().() { |
| 73 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("Scope{} == to an empty node from a builder") |
| 74 | } |
| 75 | if b.Clonescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Clone().(def) != b.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().() { |
| 76 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("b.Clone(Scope{}) should equal b.Empty()") |
| 77 | } |
| 78 | if !def.DeepEqualscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#DeepEqual().(b.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().()) { |
| 79 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("Scope{}.DeepEqual(b.Empty()) should hold") |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func TestBuildersscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestBuilders().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 84 | b0, b1 := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().(), NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 85 | if b0.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Scope().() == b1.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Scope().() { |
| 86 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("builders have the same scope %s", b0.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Scope().()) |
| 87 | } |
| 88 | |
| 89 | if b0.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().() == b1.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().() { |
| 90 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("empty nodes from different scopes are disequal") |
| 91 | } |
| 92 | if !b0.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().().DeepEqualscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#DeepEqual().(b1.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().()) { |
| 93 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("empty nodes from different scopes are not DeepEqual") |
| 94 | } |
| 95 | |
| 96 | clone := b1.Clonescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Clone().(b0.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().()) |
| 97 | if clone != b1.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().() { |
| 98 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Clone() empty nodes %v != %v", clone, b1.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().()) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | func TestEmptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestEmpty().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 103 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 104 | e := b.Emptyscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Empty().() |
| 105 | if e.Sizescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Size().() != 0 { |
| 106 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("empty nodes has non-0 size %d", e.Sizescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Size().()) |
| 107 | } |
| 108 | if e.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().() != b.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Scope().() { |
| 109 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("b.Empty() is in a different scope (%s) from b (%s)", e.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().(), b.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Scope().()) |
| 110 | } |
| 111 | if v, ok := e.Lookupscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Lookup().(123); !(v == nil && !ok) { |
| 112 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("empty.Lookup() = (%s, %v) not (nil, false)", v, ok) |
| 113 | } |
| 114 | if l := e.nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#n..findscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/node#find.(123); l != nil { |
| 115 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("empty.find(123) got %v. want nil", l) |
| 116 | } |
| 117 | e.Rangescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Range().(func(k uint64, v any) bool { |
| 118 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("empty.Range() called it callback on %d:%s", k, v) |
| 119 | return true |
| 120 | }) |
| 121 | |
| 122 | want := "{}" |
| 123 | if got := e.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#String().(); got != want { |
| 124 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("empty.String(123) got %s. want %s", got, want) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | func TestCreatescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestCreate().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 129 | // The node orders are printed in lexicographic little-endian. |
| 130 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 131 | for _, c := range []struct { |
| 132 | m map[uint64]any |
| 133 | want string |
| 134 | }{ |
| 135 | { |
| 136 | map[uint64]any{}, |
| 137 | "{}", |
| 138 | }, |
| 139 | { |
| 140 | map[uint64]any{1: "a"}, |
| 141 | "{1: a}", |
| 142 | }, |
| 143 | { |
| 144 | map[uint64]any{2: "b", 1: "a"}, |
| 145 | "{1: a, 2: b}", |
| 146 | }, |
| 147 | { |
| 148 | map[uint64]any{1: "x", 4: "y", 5: "z"}, |
| 149 | "{1: x, 4: y, 5: z}", |
| 150 | }, |
| 151 | } { |
| 152 | m := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(c.m) |
| 153 | if got := m.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#String().(); got != c.want { |
| 154 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Create(%v) got %q. want %q ", c.m, got, c.want) |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | func TestElemsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestElems().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 160 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 161 | for _, orig := range []map[uint64]any{ |
| 162 | {}, |
| 163 | {1: "a"}, |
| 164 | {1: "a", 2: "b"}, |
| 165 | {1: "x", 4: "y", 5: "z"}, |
| 166 | {1: "x", 4: "y", 5: "z", 123: "abc"}, |
| 167 | } { |
| 168 | m := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(orig) |
| 169 | if elems := Elemsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Elems().(m); !reflectscip-go gomod github.com/golang/go/src go1.25.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.0 reflect/DeepEqual().(orig, elems) { |
| 170 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Elems(%v) got %q. want %q ", m, elems, orig) |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | func TestRangescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestRange().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 176 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 177 | m := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(map[uint64]any{1: "x", 3: "y", 5: "z", 6: "stop", 8: "a"}) |
| 178 | |
| 179 | calls := 0 |
| 180 | cb := func(k uint64, v any) bool { |
| 181 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("visiting (%d, %v)", k, v) |
| 182 | calls++ |
| 183 | return k%2 != 0 // stop after the first even number. |
| 184 | } |
| 185 | // The nodes are visited in increasing order. |
| 186 | all := m.Rangescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Range().(cb) |
| 187 | if all { |
| 188 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("expected to stop early") |
| 189 | } |
| 190 | want := 4 |
| 191 | if calls != want { |
| 192 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("# of callbacks (%d) was expected to equal %d (1 + # of evens)", |
| 193 | calls, want) |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | func TestDeepEqualscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestDeepEqual().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 198 | for _, m := range []map[uint64]any{ |
| 199 | {}, |
| 200 | {1: "x"}, |
| 201 | {1: "x", 2: "y"}, |
| 202 | } { |
| 203 | l := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().().Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(m) |
| 204 | r := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().().Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(m) |
| 205 | if !l.DeepEqualscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#DeepEqual().(r) { |
| 206 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expect %v to be DeepEqual() to %v", l, r) |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | func TestNotDeepEqualscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestNotDeepEqual().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 212 | for _, c := range []struct { |
| 213 | left map[uint64]any |
| 214 | right map[uint64]any |
| 215 | }{ |
| 216 | { |
| 217 | map[uint64]any{1: "x"}, |
| 218 | map[uint64]any{}, |
| 219 | }, |
| 220 | { |
| 221 | map[uint64]any{}, |
| 222 | map[uint64]any{1: "y"}, |
| 223 | }, |
| 224 | { |
| 225 | map[uint64]any{1: "x"}, |
| 226 | map[uint64]any{1: "y"}, |
| 227 | }, |
| 228 | { |
| 229 | map[uint64]any{1: "x"}, |
| 230 | map[uint64]any{1: "x", 2: "Y"}, |
| 231 | }, |
| 232 | { |
| 233 | map[uint64]any{1: "x", 2: "Y"}, |
| 234 | map[uint64]any{1: "x"}, |
| 235 | }, |
| 236 | { |
| 237 | map[uint64]any{1: "x", 2: "y"}, |
| 238 | map[uint64]any{1: "x", 2: "Y"}, |
| 239 | }, |
| 240 | } { |
| 241 | l := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().().Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(c.left) |
| 242 | r := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().().Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(c.right) |
| 243 | if l.DeepEqualscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#DeepEqual().(r) { |
| 244 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expect %v to be !DeepEqual() to %v", l, r) |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | func TestMergescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestMerge().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 250 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 251 | for _, c := range []struct { |
| 252 | left map[uint64]any |
| 253 | right map[uint64]any |
| 254 | want string |
| 255 | }{ |
| 256 | { |
| 257 | map[uint64]any{}, |
| 258 | map[uint64]any{}, |
| 259 | "{}", |
| 260 | }, |
| 261 | { |
| 262 | map[uint64]any{}, |
| 263 | map[uint64]any{1: "a"}, |
| 264 | "{1: a}", |
| 265 | }, |
| 266 | { |
| 267 | map[uint64]any{1: "a"}, |
| 268 | map[uint64]any{}, |
| 269 | "{1: a}", |
| 270 | }, |
| 271 | { |
| 272 | map[uint64]any{1: "a", 2: "b"}, |
| 273 | map[uint64]any{}, |
| 274 | "{1: a, 2: b}", |
| 275 | }, |
| 276 | { |
| 277 | map[uint64]any{1: "x"}, |
| 278 | map[uint64]any{1: "y"}, |
| 279 | "{1: x}", // default collision is left |
| 280 | }, |
| 281 | { |
| 282 | map[uint64]any{1: "x"}, |
| 283 | map[uint64]any{2: "y"}, |
| 284 | "{1: x, 2: y}", |
| 285 | }, |
| 286 | { |
| 287 | map[uint64]any{4: "y", 5: "z"}, |
| 288 | map[uint64]any{1: "x"}, |
| 289 | "{1: x, 4: y, 5: z}", |
| 290 | }, |
| 291 | { |
| 292 | map[uint64]any{1: "x", 5: "z"}, |
| 293 | map[uint64]any{4: "y"}, |
| 294 | "{1: x, 4: y, 5: z}", |
| 295 | }, |
| 296 | { |
| 297 | map[uint64]any{1: "x", 4: "y"}, |
| 298 | map[uint64]any{5: "z"}, |
| 299 | "{1: x, 4: y, 5: z}", |
| 300 | }, |
| 301 | { |
| 302 | map[uint64]any{1: "a", 4: "c"}, |
| 303 | map[uint64]any{2: "b", 5: "d"}, |
| 304 | "{1: a, 2: b, 4: c, 5: d}", |
| 305 | }, |
| 306 | { |
| 307 | map[uint64]any{1: "a", 4: "c"}, |
| 308 | map[uint64]any{2: "b", 5 + 8: "d"}, |
| 309 | "{1: a, 2: b, 4: c, 13: d}", |
| 310 | }, |
| 311 | { |
| 312 | map[uint64]any{2: "b", 5 + 8: "d"}, |
| 313 | map[uint64]any{1: "a", 4: "c"}, |
| 314 | "{1: a, 2: b, 4: c, 13: d}", |
| 315 | }, |
| 316 | { |
| 317 | map[uint64]any{1: "a", 4: "c"}, |
| 318 | map[uint64]any{2: "b", 5 + 8: "d"}, |
| 319 | "{1: a, 2: b, 4: c, 13: d}", |
| 320 | }, |
| 321 | { |
| 322 | map[uint64]any{2: "b", 5 + 8: "d"}, |
| 323 | map[uint64]any{1: "a", 4: "c"}, |
| 324 | "{1: a, 2: b, 4: c, 13: d}", |
| 325 | }, |
| 326 | { |
| 327 | map[uint64]any{2: "b", 5 + 8: "d"}, |
| 328 | map[uint64]any{2: "", 3: "a"}, |
| 329 | "{2: b, 3: a, 13: d}", |
| 330 | }, |
| 331 | |
| 332 | { |
| 333 | // crafted for `!prefixesOverlap(p, m, q, n)` |
| 334 | left: map[uint64]any{1: "a", 2 + 1: "b"}, |
| 335 | right: map[uint64]any{4 + 1: "c", 4 + 2: "d"}, |
| 336 | // p: 5, m: 2 q: 1, n: 2 |
| 337 | want: "{1: a, 3: b, 5: c, 6: d}", |
| 338 | }, |
| 339 | { |
| 340 | // crafted for `ord(m, n) && !zeroBit(q, m)` |
| 341 | left: map[uint64]any{8 + 2 + 1: "a", 16 + 4: "b"}, |
| 342 | right: map[uint64]any{16 + 8 + 2 + 1: "c", 16 + 8 + 4 + 2 + 1: "d"}, |
| 343 | // left: p: 15, m: 16 |
| 344 | // right: q: 27, n: 4 |
| 345 | want: "{11: a, 20: b, 27: c, 31: d}", |
| 346 | }, |
| 347 | { |
| 348 | // crafted for `ord(n, m) && !zeroBit(p, n)` |
| 349 | // p: 6, m: 1 q: 5, n: 2 |
| 350 | left: map[uint64]any{4 + 2: "b", 4 + 2 + 1: "c"}, |
| 351 | right: map[uint64]any{4: "a", 4 + 2 + 1: "dropped"}, |
| 352 | want: "{4: a, 6: b, 7: c}", |
| 353 | }, |
| 354 | } { |
| 355 | l, r := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(c.left), b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(c.right) |
| 356 | m := b.Mergescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Merge().(l, r) |
| 357 | if got := m.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#String().(); got != c.want { |
| 358 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Merge(%s, %s) got %q. want %q ", l, r, got, c.want) |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | func TestIntersectscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestIntersect().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 364 | // Most of the test cases go after specific branches of intersect. |
| 365 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 366 | for _, c := range []struct { |
| 367 | left map[uint64]any |
| 368 | right map[uint64]any |
| 369 | want string |
| 370 | }{ |
| 371 | { |
| 372 | left: map[uint64]any{10: "a", 39: "b"}, |
| 373 | right: map[uint64]any{10: "A", 39: "B", 75: "C"}, |
| 374 | want: "{10: a, 39: b}", |
| 375 | }, |
| 376 | { |
| 377 | left: map[uint64]any{10: "a", 39: "b"}, |
| 378 | right: map[uint64]any{}, |
| 379 | want: "{}", |
| 380 | }, |
| 381 | { |
| 382 | left: map[uint64]any{}, |
| 383 | right: map[uint64]any{10: "A", 39: "B", 75: "C"}, |
| 384 | want: "{}", |
| 385 | }, |
| 386 | { // m == n && p == q && left.(*empty) case |
| 387 | left: map[uint64]any{4: 1, 6: 3, 10: 8, 15: "on left"}, |
| 388 | right: map[uint64]any{0: 8, 7: 6, 11: 0, 15: "on right"}, |
| 389 | want: "{15: on left}", |
| 390 | }, |
| 391 | { // m == n && p == q && right.(*empty) case |
| 392 | left: map[uint64]any{0: "on left", 1: 2, 2: 3, 3: 1, 7: 3}, |
| 393 | right: map[uint64]any{0: "on right", 5: 1, 6: 8}, |
| 394 | want: "{0: on left}", |
| 395 | }, |
| 396 | { // m == n && p == q && both left and right are not empty |
| 397 | left: map[uint64]any{1: "a", 2: "b", 3: "c"}, |
| 398 | right: map[uint64]any{0: "A", 1: "B", 2: "C"}, |
| 399 | want: "{1: a, 2: b}", |
| 400 | }, |
| 401 | { // m == n && p == q && both left and right are not empty |
| 402 | left: map[uint64]any{1: "a", 2: "b", 3: "c"}, |
| 403 | right: map[uint64]any{0: "A", 1: "B", 2: "C"}, |
| 404 | want: "{1: a, 2: b}", |
| 405 | }, |
| 406 | { // !prefixesOverlap(p, m, q, n) |
| 407 | // p = 1, m = 2, q = 5, n = 2 |
| 408 | left: map[uint64]any{0b001: 1, 0b011: 3}, |
| 409 | right: map[uint64]any{0b100: 4, 0b111: 7}, |
| 410 | want: "{}", |
| 411 | }, |
| 412 | { // ord(m, n) && zeroBit(q, m) |
| 413 | // p = 3, m = 4, q = 0, n = 1 |
| 414 | left: map[uint64]any{0b010: 2, 0b101: 5}, |
| 415 | right: map[uint64]any{0b000: 0, 0b001: 1}, |
| 416 | want: "{}", |
| 417 | }, |
| 418 | |
| 419 | { // ord(m, n) && !zeroBit(q, m) |
| 420 | // p = 29, m = 2, q = 30, n = 1 |
| 421 | left: map[uint64]any{ |
| 422 | 0b11101: "29", |
| 423 | 0b11110: "30", |
| 424 | }, |
| 425 | right: map[uint64]any{ |
| 426 | 0b11110: "30 on right", |
| 427 | 0b11111: "31", |
| 428 | }, |
| 429 | want: "{30: 30}", |
| 430 | }, |
| 431 | { // ord(n, m) && zeroBit(p, n) |
| 432 | // p = 5, m = 2, q = 3, n = 4 |
| 433 | left: map[uint64]any{0b000: 0, 0b001: 1}, |
| 434 | right: map[uint64]any{0b010: 2, 0b101: 5}, |
| 435 | want: "{}", |
| 436 | }, |
| 437 | { // default case |
| 438 | // p = 5, m = 2, q = 3, n = 4 |
| 439 | left: map[uint64]any{0b100: 1, 0b110: 3}, |
| 440 | right: map[uint64]any{0b000: 8, 0b111: 6}, |
| 441 | want: "{}", |
| 442 | }, |
| 443 | } { |
| 444 | l, r := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(c.left), b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(c.right) |
| 445 | m := b.Intersectscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Intersect().(l, r) |
| 446 | if got := m.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#String().(); got != c.want { |
| 447 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Intersect(%s, %s) got %q. want %q ", l, r, got, c.want) |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | func TestIntersectWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestIntersectWith().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 453 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 454 | l := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(map[uint64]any{10: 2.0, 39: 32.0}) |
| 455 | r := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(map[uint64]any{10: 6.0, 39: 10.0, 75: 1.0}) |
| 456 | |
| 457 | prodIfDifferent := func(x any, y any) any { |
| 458 | if x, ok := x.(float64); ok { |
| 459 | if y, ok := y.(float64); ok { |
| 460 | if x == y { |
| 461 | return x |
| 462 | } |
| 463 | return x * y |
| 464 | } |
| 465 | } |
| 466 | return x |
| 467 | } |
| 468 | |
| 469 | m := b.IntersectWithscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#IntersectWith().(prodIfDifferent, l, r) |
| 470 | |
| 471 | want := "{10: %!s(float64=12), 39: %!s(float64=320)}" |
| 472 | if got := m.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#String().(); got != want { |
| 473 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("IntersectWith(min, %s, %s) got %q. want %q ", l, r, got, want) |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | func TestRemovescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestRemove().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 478 | // Most of the test cases go after specific branches of intersect. |
| 479 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 480 | for _, c := range []struct { |
| 481 | m map[uint64]any |
| 482 | key uint64 |
| 483 | want string |
| 484 | }{ |
| 485 | {map[uint64]any{}, 10, "{}"}, |
| 486 | {map[uint64]any{10: "a"}, 10, "{}"}, |
| 487 | {map[uint64]any{39: "b"}, 10, "{39: b}"}, |
| 488 | // Branch cases: |
| 489 | // !matchPrefix(kp, br.prefix, br.branching) |
| 490 | {map[uint64]any{10: "a", 39: "b"}, 128, "{10: a, 39: b}"}, |
| 491 | // case: left == br.left && right == br.right |
| 492 | {map[uint64]any{10: "a", 39: "b"}, 16, "{10: a, 39: b}"}, |
| 493 | // left updated and is empty. |
| 494 | {map[uint64]any{10: "a", 39: "b"}, 10, "{39: b}"}, |
| 495 | // right updated and is empty. |
| 496 | {map[uint64]any{10: "a", 39: "b"}, 39, "{10: a}"}, |
| 497 | // final b.mkBranch(...) case. |
| 498 | {map[uint64]any{10: "a", 39: "b", 128: "c"}, 39, "{10: a, 128: c}"}, |
| 499 | } { |
| 500 | pre := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(c.m) |
| 501 | post := b.Removescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Remove().(pre, c.key) |
| 502 | if got := post.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#String().(); got != c.want { |
| 503 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Remove(%s, %d) got %q. want %q ", pre, c.key, got, c.want) |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | func TestRescopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestRescope().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 509 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 510 | l := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(map[uint64]any{10: "a", 39: "b"}) |
| 511 | r := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(map[uint64]any{10: "A", 39: "B", 75: "C"}) |
| 512 | |
| 513 | b.Rescopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Rescope().() |
| 514 | |
| 515 | m := b.Intersectscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Intersect().(l, r) |
| 516 | if got, want := m.Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#String().(), "{10: a, 39: b}"; got != want { |
| 517 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Intersect(%s, %s) got %q. want %q", l, r, got, want) |
| 518 | } |
| 519 | if m.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().() == l.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().() { |
| 520 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("m.Scope() = %v should not equal l.Scope() = %v", m.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().(), l.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().()) |
| 521 | } |
| 522 | if m.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().() == r.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().() { |
| 523 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("m.Scope() = %v should not equal r.Scope() = %v", m.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().(), r.Scopescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#Scope().()) |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | func TestSharingscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/TestSharing().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 528 | b := NewBuilderscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/NewBuilder().() |
| 529 | l := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(map[uint64]any{0: "a", 1: "b"}) |
| 530 | r := b.Createscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Create().(map[uint64]any{1: "B", 2: "C"}) |
| 531 | |
| 532 | rleftold := r.nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#n..(*branchscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/branch#).leftscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/branch#left. |
| 533 | |
| 534 | m := b.Mergescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Builder#Merge().(l, r) |
| 535 | if mleft := m.nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#n..(*branchscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/branch#).leftscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/branch#left.; mleft != l.nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#n. { |
| 536 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("unexpected value for left branch of %v. want %v got %v", m, l, mleft) |
| 537 | } |
| 538 | |
| 539 | if rleftnow := r.nscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/Map#n..(*branchscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/branch#).leftscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/callgraph/vta/internal/trie`/branch#left.; rleftnow != rleftold { |
| 540 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("r.n.(*branch).left was modified by the Merge operation. was %v now %v", rleftold, rleftnow) |
| 541 | } |
| 542 | } |