Tests: padded and stray-brace arguments, the inline held fence, a template under concurrent use, and the fieldless-token hint

This commit is contained in:
2026-09-03 20:57:25 +02:00
parent 71cccaf4c9
commit d8048df169
3 changed files with 29 additions and 11 deletions
+12 -3
View File
@@ -76,12 +76,20 @@ func TestFakeTemplateDeterministic(t *testing.T) {
}
}
func TestBareStringReferenceHint(t *testing.T) {
func TestFieldlessTokenHint(t *testing.T) {
f := shipped(t)
_, err := f.FakeTemplate(`{sv_SE.person.last}`)
if err == nil || !strings.Contains(err.Error(), "write {/sv_SE.person.last}") {
t.Fatalf("FakeTemplate(bare token) = %v, want a hint naming {/sv_SE.person.last}", err)
}
_, err = f.FakeTemplate(`{"format":"{x}","repeat":2}`)
if err == nil || strings.Contains(err.Error(), "bare string") {
t.Errorf("FakeTemplate(fieldless object) = %v, want an error that does not call it a bare string", err)
}
_, err = f.FakeTemplate(`{ /sv_SE.person.last }`)
if err == nil || strings.Contains(err.Error(), "write {") {
t.Errorf("FakeTemplate(malformed token) = %v, want no hint naming a spelling that fails too", err)
}
}
func TestFakeTemplateErrors(t *testing.T) {
@@ -97,6 +105,7 @@ func TestFakeTemplateErrors(t *testing.T) {
{`name: {..nope}`, "write {/nope}"},
{`{"format":"x"}`, "is a string"},
{`{/misc.country} {/misc.country.alpha2}`, "renders a level"},
{`{"format":"{/misc.country.alpha2} {x}","x":"{/misc.country}"}`, "renders"},
} {
_, err := f.FakeTemplate(c.input)
if err == nil || !strings.Contains(err.Error(), c.want) {
@@ -124,13 +133,13 @@ func TestPaddedJSONIsRejected(t *testing.T) {
func TestNewTemplateReusable(t *testing.T) {
f := shipped(t)
tmpl, err := f.NewTemplate(`{digits(2)}`)
reusable, err := f.NewTemplate(`{digits(2)}`)
if err != nil {
t.Fatalf("NewTemplate: %v", err)
}
seen := map[string]bool{}
for i := 0; i < 50; i++ {
seen[tmpl.Fake()] = true
seen[reusable.Fake()] = true
}
if len(seen) < 2 {
t.Fatalf("Template.Fake() repeated %v, want varied draws from one compile", seen)