Tests: no hint where a reference would mean something else, and every reference the help advertises resolves

This commit is contained in:
2026-09-03 21:11:11 +02:00
parent 1cd422352b
commit 8ed8d9bb51
2 changed files with 20 additions and 6 deletions
+10
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
@@ -333,6 +334,15 @@ func TestClassify(t *testing.T) {
}
}
func TestUsageReferencesResolve(t *testing.T) {
for _, token := range regexp.MustCompile(`\{/[^}]+\}`).FindAllString(usage, -1) {
code, out, errb := runOut("--seed", "1", token)
if code != 0 || strings.TrimSpace(out) == "" {
t.Errorf("usage advertises %s: run = %d, %q, stderr %q", token, code, out, errb)
}
}
}
func TestRunShapeMisuseBeforeLoad(t *testing.T) {
code, _, errb := runOut("--no-shipped-data", "[abc]")
if code != 2 || !strings.Contains(errb, "[abc]") || strings.Contains(errb, "--data-path") {
+10 -6
View File
@@ -83,12 +83,16 @@ func TestFieldlessTokenHint(t *testing.T) {
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)
if err == nil || !strings.Contains(err.Error(), `this template has none — write {/x}`) {
t.Errorf("FakeTemplate(fieldless object) = %v, want the hint without calling 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)
// A hint is only a drop-in where the name is the whole token: {/x} inside a
// transform or an alternation renders a different value, so none is offered.
for _, input := range []string{`{ /sv_SE.person.last }`, "{lowercase(x)}", "{x|y}"} {
_, err := f.FakeTemplate(input)
if err == nil || strings.Contains(err.Error(), "write {") {
t.Errorf("FakeTemplate(%q) = %v, want no hint naming a spelling that means something else", input, err)
}
}
}
@@ -105,7 +109,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"},
{`{"format":"{/misc.country.alpha2} {x}","x":"{/misc.country}"}`, "reads a path into"},
} {
_, err := f.FakeTemplate(c.input)
if err == nil || !strings.Contains(err.Error(), c.want) {