Files
zzet--gortex/internal/indexer/cpp_overload_e2e_test.go
wehub-resource-sync a06f331eb8
install-script / powershell-syntax (push) Waiting to run
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
install-script / install (macos-14) (push) Waiting to run
install-script / install (ubuntu-latest) (push) Waiting to run
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
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

59 lines
1.6 KiB
Go

package indexer
import (
"testing"
"github.com/zzet/gortex/internal/graph"
)
// callTargetName returns the resolved target's Name for the EdgeCalls edge from
// `caller` to a function named `callee` (the resolved overload's enclosing
// node's distinguishing meta).
func cppCallTarget(t *testing.T, g *graph.Graph, caller string) *graph.Node {
t.Helper()
for _, n := range g.AllNodes() {
if n.Name != caller {
continue
}
for _, e := range g.GetOutEdges(n.ID) {
if e.Kind != graph.EdgeCalls {
continue
}
if tn := g.GetNode(e.To); tn != nil && tn.Name == "process" {
return tn
}
}
}
return nil
}
// TestCppOverload_ResolvesArithmetic indexes overloaded C++ functions and
// asserts a call with a double literal resolves to process(double), and an int
// literal to process(int) — in-engine, no clangd.
func TestCppOverload_ResolvesArithmetic(t *testing.T) {
g := indexFixture(t, map[string]string{
"o.cpp": `void process(int x) { }
void process(double x) { }
void runDouble() { process(3.14); }
void runInt() { process(42); }
`,
})
dbl := cppCallTarget(t, g, "runDouble")
if dbl == nil {
t.Fatal("runDouble's process() call did not resolve")
}
if pt, _ := dbl.Meta["cpp_param_types"].(string); pt != "double" {
t.Errorf("runDouble should bind process(double), got param_types=%q (node %s)", pt, dbl.ID)
}
in := cppCallTarget(t, g, "runInt")
if in == nil {
t.Fatal("runInt's process() call did not resolve")
}
if pt, _ := in.Meta["cpp_param_types"].(string); pt != "int" {
t.Errorf("runInt should bind process(int), got param_types=%q (node %s)", pt, in.ID)
}
}