package blocks import "testing" func TestPoweredBlockRoundTrip(t *testing.T) { marker := PoweredBlock("
{{ x }}
", map[string]any{"x": "y"}) pr, ok := DecodePoweredBlock(marker) if !ok { t.Fatal("DecodePoweredBlock did not recognize its own marker") } if pr.Template != "{{ x }}
" { t.Errorf("template = %q", pr.Template) } if pr.Data["x"] != "y" { t.Errorf("data = %v", pr.Data) } } func TestDecodePoweredBlockRejectsPlainHTML(t *testing.T) { if _, ok := DecodePoweredBlock("hello
"); ok { t.Error("plain HTML must not decode as a powered block") } if _, ok := DecodePoweredBlock(""); ok { t.Error("empty string must not decode as a powered block") } } func TestTagFilterRegistry(t *testing.T) { ResetRegisteredTagsAndFilters() t.Cleanup(ResetRegisteredTagsAndFilters) RegisterTag("b", func(map[string]any, RenderContext) (string, error) { return "b", nil }) RegisterTag("a", func(map[string]any, RenderContext) (string, error) { return "a", nil }) RegisterFilter("f", func(string, map[string]any) (string, error) { return "f", nil }) // Empty name / nil fn are ignored. RegisterTag("", nil) RegisterFilter("g", nil) if names := RegisteredTagNames(); len(names) != 2 || names[0] != "a" || names[1] != "b" { t.Errorf("tag names = %v, want sorted [a b]", names) } if names := RegisteredFilterNames(); len(names) != 1 || names[0] != "f" { t.Errorf("filter names = %v, want [f]", names) } if _, ok := LookupTag("a"); !ok { t.Error("LookupTag(a) missing") } if _, ok := LookupFilter("f"); !ok { t.Error("LookupFilter(f) missing") } if _, ok := LookupTag("missing"); ok { t.Error("LookupTag(missing) should be absent") } ResetRegisteredTagsAndFilters() if RegisteredTagNames() != nil || RegisteredFilterNames() != nil { t.Error("reset did not clear registries") } }