fix: most of the template blocks

This commit is contained in:
Max Richter
2025-09-30 19:28:56 +02:00
parent d35f3e5e2e
commit 2a1572f99d
20 changed files with 210 additions and 187 deletions

View File

@@ -10,7 +10,7 @@ import (
"git.max-richter.dev/max/marka/testdata"
)
func TestFuzzyFindAll(t *testing.T) {
func TestMatch_FuzzyFindAll(t *testing.T) {
recipeMd := testdata.Read(t, "baguette/input.md")
tests := []struct {
@@ -36,13 +36,14 @@ func TestFuzzyFindAll(t *testing.T) {
}
}
func TestFuzzyBlockMatch(t *testing.T) {
func TestMatch_FuzzyBlockBaguette(t *testing.T) {
recipeMd := testdata.Read(t, "baguette/input.md")
schemaMd, err := registry.GetTemplate("Recipe")
if err != nil {
t.Errorf("Failed to load template: %s", err.Error())
t.FailNow()
}
blocks, err := template.CompileTemplate(schemaMd)
if err != nil {
t.Errorf("Failed to compile template: %s", err.Error())
@@ -51,9 +52,8 @@ func TestFuzzyBlockMatch(t *testing.T) {
matches := matcher.MatchBlocksFuzzy(string(recipeMd), blocks, 0.3)
for _, b := range blocks {
fmt.Printf("Block: %+v\n", b)
fmt.Printf("Content: '%q'\n\n", b.GetContent())
for _, m := range matches {
fmt.Printf("Content: '%s'->'%q'\n\n", m.Block.Path, m.GetContent())
}
expected := []struct {
@@ -66,10 +66,7 @@ func TestFuzzyBlockMatch(t *testing.T) {
value: "Baguette",
},
{
value: "\nMy favourite baguette recipe",
},
{
value: "",
value: "My favourite baguette recipe",
},
{
value: "- Flour\n- Water\n- Salt",
@@ -87,11 +84,10 @@ func TestFuzzyBlockMatch(t *testing.T) {
if expected[i].value != m.GetContent() {
t.Errorf("Match %d did not match expected: %q", i, expected[i].value)
}
fmt.Printf("match: %s->%q\n", m.Block.Path, m.GetContent())
}
}
func TestFuzzyBlockMatchSalad(t *testing.T) {
func TestMatch_FuzzyBlockSalad(t *testing.T) {
recipeMd := testdata.Read(t, "recipe_salad/input.md")
schemaMd, err := registry.GetTemplate("Recipe")
if err != nil {
@@ -115,9 +111,6 @@ func TestFuzzyBlockMatchSalad(t *testing.T) {
{
value: "Simple Salad",
},
{
value: "#healthy #salad",
},
{
value: "A quick green salad.",
},