Files
marqdo/plugins/web/internal/artifact/artifact_test.go
T
cflmyandCursor 67bac1bf02 feat(web): Document/Endpoint/Resource artifact rewrite (ADR 0007)
Replace the monolithic compose_*/configure author surface with file-level
web|endpoint artifacts, split ext/{web,data,security,net}, and lock
no-degrade rules so the model cannot regress to God-object APIs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 11:06:38 +08:00

56 lines
1.2 KiB
Go

package artifact
import "testing"
func TestMetaType(t *testing.T) {
if MetaType(map[string]string{"type": "web"}) != "web" {
t.Fatal("en web")
}
if MetaType(map[string]string{"类型": "网页"}) != "web" {
t.Fatal("zh web")
}
if MetaType(map[string]string{"type": "endpoint"}) != "endpoint" {
t.Fatal("endpoint")
}
}
func TestParseFrontmatter(t *testing.T) {
src := "---\ntype: web\nroute: /x\n---\n\n# Hi\n"
meta, body := ParseFrontmatter(src)
if meta["type"] != "web" || meta["route"] != "/x" {
t.Fatalf("meta=%v", meta)
}
if body == "" || body[0] != '#' {
t.Fatalf("body=%q", body)
}
}
func TestRenderNodes(t *testing.T) {
nodes := map[string]any{
"type": []any{"title", "text"},
"slot": []any{"title", "lede"},
"value": []any{"Marqdo", "Hello"},
"attrs": []any{"", ""},
"style": []any{"title", "lede"},
}
html, err := RenderNodes(nodes)
if err != nil {
t.Fatal(err)
}
if !contains(html, "Marqdo") || !contains(html, "mq-view") {
t.Fatalf("html=%s", html)
}
}
func contains(s, sub string) bool {
return len(s) >= len(sub) && (s == sub || len(sub) == 0 ||
(func() bool {
for i := 0; i+len(sub) <= len(s); i++ {
if s[i:i+len(sub)] == sub {
return true
}
}
return false
})())
}