Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

47 lines
1.3 KiB
Go

package contracts
import (
"testing"
)
// stubResolver is a BindingResolver that returns predetermined types.
type stubResolver struct {
results map[int]string // line → type
}
func (r *stubResolver) LookupTypeAtLine(filePath string, line int) (string, bool) {
t, ok := r.results[line]
return t, ok
}
// TestBindingResolver_OverridesGraphWalk confirms the resolver hook is
// consulted and its result is preferred over the graph walk. The
// indexer's lookupVarTypeForContract calls CurrentBindingResolver
// before falling back to the graph; this test exercises the contracts
// package's wiring.
func TestBindingResolver_WireUp(t *testing.T) {
prev := CurrentBindingResolver()
t.Cleanup(func() { SetBindingResolver(prev) })
r := &stubResolver{results: map[int]string{42: "Foo"}}
SetBindingResolver(r)
got := CurrentBindingResolver()
if got != r {
t.Fatalf("CurrentBindingResolver: want stub, got %v", got)
}
tn, ok := got.LookupTypeAtLine("anywhere.go", 42)
if !ok || tn != "Foo" {
t.Errorf("stub lookup: want (Foo, true), got (%q, %v)", tn, ok)
}
}
func TestBindingResolver_NilWhenUnset(t *testing.T) {
prev := CurrentBindingResolver()
t.Cleanup(func() { SetBindingResolver(prev) })
SetBindingResolver(nil)
if CurrentBindingResolver() != nil {
t.Errorf("CurrentBindingResolver after nil: want nil")
}
}