diff --git a/cmd/fejkdata/main_test.go b/cmd/fejkdata/main_test.go index 5798565..258f740 100644 --- a/cmd/fejkdata/main_test.go +++ b/cmd/fejkdata/main_test.go @@ -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") { diff --git a/inline_test.go b/inline_test.go index f2e04e4..f44e164 100644 --- a/inline_test.go +++ b/inline_test.go @@ -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) {