From 7cb6928995c92ed5141fccaab410b99f1283d175 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 15 Sep 2026 17:11:10 +0200 Subject: [PATCH] Tests: fake:"-" leaves an embedded struct unfilled, a leading / is refused naming the path, and a name may not be - --- inline_test.go | 1 + loading_test.go | 4 ++++ struct_test.go | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/inline_test.go b/inline_test.go index bb5b7f5..0ee9a8c 100644 --- a/inline_test.go +++ b/inline_test.go @@ -181,6 +181,7 @@ func TestIsTemplate(t *testing.T) { "{/sv_SE.person.last}": "{/sv_SE.person.last} is the path sv_SE.person.last written as a template; write sv_SE.person.last", `"{/sv_SE.person}"`: "write sv_SE.person", "{.person.last}": "write person.last", + "/sv_SE.person": "write sv_SE.person", } { if _, err := IsTemplate(arg); err == nil || !strings.Contains(err.Error(), want) { t.Errorf("IsTemplate(%q) = %v; want it rejected naming %s", arg, err, want) diff --git a/loading_test.go b/loading_test.go index 681fe67..bd947af 100644 --- a/loading_test.go +++ b/loading_test.go @@ -298,6 +298,10 @@ func TestNewErrors(t *testing.T) { map[string]string{"a(b/cat": `"1"`}, `folder "a(b" contains "("`, }, + "field name a struct tag reserves": { + map[string]string{"a": `{"format":"{x}","x":"1","-":"2"}`}, + `field "-" is reserved`, + }, // A repeated arm skews an alternation, which weight is the spelling for. "repeated alternation arm": { map[string]string{"a": `{"format":"{x|x}","x":"1"}`}, diff --git a/struct_test.go b/struct_test.go index 7e5c18b..eb348d2 100644 --- a/struct_test.go +++ b/struct_test.go @@ -106,6 +106,13 @@ func TestFakeStructFillsEmbeddedFieldsIntoItsRecord(t *testing.T) { t.Fatalf("%+v, %+v: want the promoted fields one person with the struct's own, the embedded pointer allocated", e, e.StructFamily) } } + var skipped struct { + structGiven `fake:"-"` + Email string `fake:"{lowercase(/person.first)}@example.com"` + } + if err := f.FakeStruct(&skipped); err != nil || skipped.First != "" || skipped.Email == "" { + t.Errorf("FakeStruct = %v, %+v; want the embedded struct under fake:\"-\" left unfilled beside the filled field", err, skipped) + } } func TestFakeStructDrawsANestedStructApart(t *testing.T) {