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

45 lines
1.6 KiB
Go

package languages
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zzet/gortex/internal/graph"
)
// `new Foo(arg)` inside a method must emit a calls candidate targeting the
// flat `Foo.<init>` constructor node, alongside the existing instantiates
// edge. The candidate is class-qualified so resolution binds it precisely.
func TestJavaExtractor_ConstructorCallEdge(t *testing.T) {
src := []byte(`public class Fixture {
void run() {
PetTypeFormatter f = new PetTypeFormatter(types);
var v = new Visit();
doThing(new Owner("x"));
}
}
`)
e := NewJavaExtractor()
result, err := e.Extract("Fixture.java", src)
require.NoError(t, err)
ctorCalls := map[string]string{} // target -> receiver_type
var sawInstantiate bool
for _, edge := range result.Edges {
if edge.Kind == graph.EdgeCalls && edge.From == "Fixture.java::Fixture.run" {
if rt, _ := edge.Meta["via"].(string); rt == "constructor" {
ctorCalls[edge.To], _ = edge.Meta["receiver_type"].(string)
}
}
if edge.Kind == graph.EdgeInstantiates {
sawInstantiate = true
}
}
assert.Equal(t, "PetTypeFormatter", ctorCalls["unresolved::*.PetTypeFormatter.<init>"],
"new PetTypeFormatter(types) must emit a constructor calls candidate")
assert.Contains(t, ctorCalls, "unresolved::*.Visit.<init>", "new Visit() must emit a constructor calls candidate")
assert.Contains(t, ctorCalls, "unresolved::*.Owner.<init>", "argument-position new Owner() must emit a constructor calls candidate")
assert.True(t, sawInstantiate, "the instantiates edge must still be emitted alongside the calls candidate")
}