This commit is contained in:
Tomas Dvorak
2026-02-24 10:33:59 +01:00
parent 409acd2e08
commit 898a3c303f
1374 changed files with 290409 additions and 29187 deletions
+65
View File
@@ -0,0 +1,65 @@
package scraper
import (
"testing"
"github.com/yourorg/devour/pkg/tsdocs"
)
func TestTSDocsSubDocsFallbackToModuleURL(t *testing.T) {
s := &TSDocsScraper{}
module := &tsdocs.Module{
Name: "Module",
DocURL: "https://www.typescriptlang.org/docs/handbook/2/basic-types.html",
}
cases := []struct {
name string
build func() *Document
docType string
}{
{
name: "interface",
build: func() *Document {
return s.interfaceToDocument(&tsdocs.Interface{Name: "User", DocURL: ""}, module, "ts")
},
docType: "ts-interface",
},
{
name: "function",
build: func() *Document {
return s.functionToDocument(&tsdocs.Function{Name: "parse", DocURL: ""}, module, "ts")
},
docType: "ts-function",
},
{
name: "class",
build: func() *Document {
return s.classToDocument(&tsdocs.Class{Name: "Service", DocURL: ""}, module, "ts")
},
docType: "ts-class",
},
{
name: "type alias",
build: func() *Document {
return s.typeAliasToDocument(&tsdocs.TypeAlias{Name: "ID", Type: "string", DocURL: ""}, module, "ts")
},
docType: "ts-type",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
doc := tc.build()
if doc.URL != module.DocURL {
t.Fatalf("expected fallback URL %q, got %q", module.DocURL, doc.URL)
}
if got := doc.Metadata["doc_url"]; got != module.DocURL {
t.Fatalf("expected metadata doc_url %q, got %#v", module.DocURL, got)
}
if doc.Type != tc.docType {
t.Fatalf("expected doc type %q, got %q", tc.docType, doc.Type)
}
})
}
}