chore: import upstream snapshot with attribution
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
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
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package languages
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/zzet/gortex/internal/graph"
|
||||
)
|
||||
|
||||
func TestLiquidJSONExtractor_SectionLinks(t *testing.T) {
|
||||
src := []byte(`{
|
||||
"sections": {
|
||||
"main": { "type": "main-product" },
|
||||
"rel": { "type": "related-products" },
|
||||
"dup": { "type": "main-product" }
|
||||
},
|
||||
"order": ["main", "rel", "dup"]
|
||||
}`)
|
||||
res, err := NewLiquidJSONExtractor().Extract("templates/product.json", src)
|
||||
require.NoError(t, err)
|
||||
|
||||
// One EdgeImports per distinct section type (the duplicate main-product
|
||||
// section dedupes), normalized to the same target a `{% section %}` tag uses.
|
||||
importTargets := map[string]int{}
|
||||
for _, e := range res.Edges {
|
||||
if e.Kind == graph.EdgeImports {
|
||||
importTargets[e.To]++
|
||||
}
|
||||
}
|
||||
assert.Equal(t, 1, importTargets["unresolved::import::sections/main-product.liquid"],
|
||||
"main-product linked once despite two sections of that type")
|
||||
assert.Equal(t, 1, importTargets["unresolved::import::sections/related-products.liquid"])
|
||||
|
||||
// A searchable import node per distinct type, tagged json_section.
|
||||
imports := map[string]*graph.Node{}
|
||||
for _, n := range res.Nodes {
|
||||
if n.Kind == graph.KindImport {
|
||||
imports[n.Name] = n
|
||||
}
|
||||
}
|
||||
require.Len(t, imports, 2)
|
||||
require.NotNil(t, imports["main-product"])
|
||||
assert.Equal(t, "json_section", imports["main-product"].Meta["liquid_tag"])
|
||||
assert.Equal(t, "sections/main-product.liquid", imports["main-product"].Meta["target"])
|
||||
}
|
||||
|
||||
func TestLiquidJSONExtractor_NonTemplateJSON(t *testing.T) {
|
||||
// A JSON without a parseable `sections` map links nothing (just a file node).
|
||||
res, err := NewLiquidJSONExtractor().Extract("templates/x.json", []byte(`{"foo": "bar"}`))
|
||||
require.NoError(t, err)
|
||||
for _, e := range res.Edges {
|
||||
if e.Kind == graph.EdgeImports {
|
||||
t.Errorf("a non-section JSON must not emit import edges, got %s", e.To)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user