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

48 lines
1.9 KiB
Go

package query
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zzet/gortex/internal/graph"
)
// Import / re-export statements are usages: pyright and tsserver both
// count `from x import name` / `export {name} from …` lines in their
// reference sets, and a symbol consumed only through a façade module
// otherwise reports zero usages ("likely unused") despite live consumers.
func TestFindUsages_IncludesImportAndReExportEdges(t *testing.T) {
g := graph.New()
g.AddNode(&graph.Node{ID: "src/vanilla.ts::createStore", Kind: graph.KindFunction, Name: "createStore", FilePath: "src/vanilla.ts"})
g.AddNode(&graph.Node{ID: "src/index.ts", Kind: graph.KindFile, Name: "index.ts", FilePath: "src/index.ts"})
g.AddNode(&graph.Node{ID: "tests/basic.test.tsx", Kind: graph.KindFile, Name: "basic.test.tsx", FilePath: "tests/basic.test.tsx"})
g.AddEdge(&graph.Edge{
From: "tests/basic.test.tsx", To: "src/vanilla.ts::createStore",
Kind: graph.EdgeImports, FilePath: "tests/basic.test.tsx", Line: 3,
Origin: graph.OriginASTResolved,
})
g.AddEdge(&graph.Edge{
From: "src/index.ts", To: "src/vanilla.ts::createStore",
Kind: graph.EdgeReExports, FilePath: "src/index.ts", Line: 1,
Origin: graph.OriginASTResolved,
})
e := NewEngine(g)
sg := e.FindUsagesScoped("src/vanilla.ts::createStore", QueryOptions{})
kinds := map[graph.EdgeKind]int{}
for _, edge := range sg.Edges {
kinds[edge.Kind]++
}
assert.Equal(t, 1, kinds[graph.EdgeImports], "import statement must count as a usage")
assert.Equal(t, 1, kinds[graph.EdgeReExports], "re-export statement must count as a usage")
}
func TestRefContextOf_ImportEdges(t *testing.T) {
imp := &graph.Edge{Kind: graph.EdgeImports}
assert.Equal(t, graph.RefContextImport, graph.RefContextOf(imp, graph.KindFile))
rex := &graph.Edge{Kind: graph.EdgeReExports}
assert.Equal(t, graph.RefContextImport, graph.RefContextOf(rex, graph.KindFile))
}