package languages import ( "testing" "github.com/zzet/gortex/internal/graph" ) func TestSvelteExtractor(t *testing.T) { const svelte = ` ` res, err := NewSvelteExtractor().Extract("Counter.svelte", []byte(svelte)) if err != nil { t.Fatal(err) } var comp, incr *graph.Node for _, n := range res.Nodes { if n.Kind == graph.KindType && n.Name == "Counter" { comp = n } if n.Name == "increment" { incr = n } } if comp == nil { t.Fatalf("no component node 'Counter' among %d nodes", len(res.Nodes)) } if comp.Meta["exported"] != true || comp.Language != "svelte" { t.Errorf("component meta/lang = %v / %q", comp.Meta, comp.Language) } if incr == nil { t.Fatalf("delegated function 'increment' was not extracted from

{$count}

{$name}

` res, err := NewSvelteExtractor().Extract("Counter.svelte", []byte(svelte)) if err != nil { t.Fatal(err) } stores := map[string]string{} for _, e := range res.Edges { if e.Meta == nil { continue } if v, _ := e.Meta["via"].(string); v != "svelte_store" { continue } s, _ := e.Meta["store"].(string) stores[s] = e.To if e.From != "Counter.svelte::Counter" { t.Errorf("store subscription should be attributed to the component, got %q", e.From) } if e.Kind != graph.EdgeReferences { t.Errorf("store subscription should be an EdgeReferences, got %v", e.Kind) } } if stores["count"] != "unresolved::import::./store::count" { t.Errorf("$count should resolve to the count store import, got %q", stores["count"]) } if stores["name"] != "unresolved::import::./store::name" { t.Errorf("$name should resolve to the name store import, got %q", stores["name"]) } }