fix
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package aiprompts
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeriveDescriptionFormulaFromLegacyParts(t *testing.T) {
|
||||
t.Parallel()
|
||||
legacy := `Ustvari nov opis
|
||||
|
||||
GPT predloga:
|
||||
<name>{Napiši novo ime izdelka po formuli: "znamka", "tip izdelka lowercase". Ne uporabljaj vejic.}</name>
|
||||
<metaDescription>{Najprej napiši Novo_ime_izdelka in potem nadaljuj dokler nisi zapisal 140 znakov}</metaDescription>
|
||||
|
||||
<H2>{Napiši Novo ime izdelka in izpostavi en benefit}</H2>
|
||||
<p>{Napiši odstavek, ki je dolg 100 besed.}</p>
|
||||
<b>{Tehnične specifikacije}</b><ul><li>{Napiši 3-10 tehničnih specifikacij v alinejah}</li></ul>`
|
||||
|
||||
parts := ParseLegacyCombinedEnhancePrompt(legacy)
|
||||
if !parts.WasLegacy {
|
||||
t.Fatal("expected legacy parse")
|
||||
}
|
||||
f := DeriveDescriptionFormulaFromLegacyParts(parts)
|
||||
if strings.TrimSpace(f.MetaDescription) == "" || !strings.Contains(f.MetaDescription, "140") {
|
||||
t.Fatalf("metaDescription=%q", f.MetaDescription)
|
||||
}
|
||||
if len(f.Sections) < 3 {
|
||||
t.Fatalf("want >=3 sections, got %#v", f.Sections)
|
||||
}
|
||||
if f.Sections[0].Type != "h2" {
|
||||
t.Fatalf("first section should be h2 (document order), got %#v", f.Sections[0])
|
||||
}
|
||||
last := f.Sections[len(f.Sections)-1]
|
||||
if last.Type != "ul" {
|
||||
t.Fatalf("last section should be ul specs, got %#v", last)
|
||||
}
|
||||
var sawH2, sawP, sawUL bool
|
||||
for _, s := range f.Sections {
|
||||
switch s.Type {
|
||||
case "h2":
|
||||
sawH2 = true
|
||||
case "p":
|
||||
sawP = true
|
||||
case "ul":
|
||||
sawUL = true
|
||||
}
|
||||
}
|
||||
if !sawH2 || !sawP || !sawUL {
|
||||
t.Fatalf("missing section types: %#v", f.Sections)
|
||||
}
|
||||
raw := DeriveDescriptionTemplateJSON(parts)
|
||||
if raw == "" || DescriptionTemplateNeedsRepair([]byte(raw)) {
|
||||
t.Fatalf("derived template should be OK: %s", raw)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user