fix: trying to fix error in matching code

This commit is contained in:
Max Richter
2025-09-28 14:40:29 +02:00
parent fb0b80be78
commit 57ea1f6e3e
12 changed files with 39 additions and 14 deletions

View File

@@ -3,6 +3,8 @@ package template_test
import (
"testing"
"fmt"
"git.max-richter.dev/max/marka/registry"
"git.max-richter.dev/max/marka/template"
)
@@ -10,13 +12,13 @@ import (
func TestExtractBlocks(t *testing.T) {
src, err := registry.GetTemplate("Recipe")
if err != nil {
t.Errorf("Failed to extract blocks: %s", err.Error())
t.Errorf("failed to load template 'Recipe' -> %s", err.Error())
t.FailNow()
}
templateBlocks, err := template.CompileTemplate(src)
if err != nil {
t.Errorf("Failed to extract blocks: %s", err.Error())
t.Errorf("failed to compile template -> %s", err.Error())
t.FailNow()
}
@@ -58,6 +60,8 @@ func TestExtractBlocks(t *testing.T) {
{Type: template.MatchingBlock},
{Type: template.DataBlock, Path: "name", Codec: "text"},
{Type: template.MatchingBlock},
{Type: template.DataBlock, Path: "keywords", Codec: "hashtags", Optional: true},
{Type: template.MatchingBlock},
{Type: template.DataBlock, Path: "description", Codec: "text"},
{Type: template.MatchingBlock},
{Type: template.DataBlock, Path: "recipeIngredient", Codec: "list", ListTemplate: "- { . }"},
@@ -69,6 +73,9 @@ func TestExtractBlocks(t *testing.T) {
t.Fatalf("expected %d blocks, got %d", len(expected), len(templateBlocks))
}
fmt.Printf("%+v\n", templateBlocks[0]);
fmt.Printf("Content: %q\n", templateBlocks[0].GetContent());
for i, b := range templateBlocks {
exp := expected[i]
if b.Type != exp.Type {