From 30d18bf48582a152d51e5635e5d41d3e0bf37b60 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Sat, 3 Oct 2026 02:12:24 +0200 Subject: [PATCH] Test one name across draw groups, two names on one category, and a repeat of a name's allocations --- name_test.go | 30 ++++++++++++++++++++++++++++++ perf_test.go | 1 + 2 files changed, 31 insertions(+) diff --git a/name_test.go b/name_test.go index 9111c7d..e3a07d7 100644 --- a/name_test.go +++ b/name_test.go @@ -323,3 +323,33 @@ func TestANameIsATransformOperand(t *testing.T) { } } } + +func TestOneRenderReadsOneNameAcrossDrawGroups(t *testing.T) { + dir := writeData(t, map[string]string{ + "word": `["a","b","c","d","e","f","g","h"]`, + "other": `{"format":"{x}","x":["1","2"]}`, + "cat": `{"format":"{/word as w}{a}","a":{"format":"{w}|{b}","b":{"format":"{w}{/other.x}","drawGroup":"g"}}}`, + }) + f := newGenerator(t, dir, WithSeed(59)) + for i := 0; i < 50; i++ { + if got := fake(t, f, "cat.a"); got[0] != got[2] { + t.Fatalf("cat.a = %q, want one pick of w in both draw groups", got) + } + } +} + +func TestTwoNamesOnOneCategoryAreTwoPicks(t *testing.T) { + dir := writeData(t, map[string]string{ + "given": `{"format":"{first}","first":["Ada","Bo","Cy","Di","Ed","Flo","Gus","Hal"]}`, + "person": `"{/given.first}"`, + "card": `"{/person as p}{/person as q}{p}|{q}"`, + }) + f := newGenerator(t, dir, WithSeed(53)) + for i := 0; i < 50; i++ { + got := strings.Split(fake(t, f, "card"), "|") + if got[0] != got[1] { + return + } + } + t.Fatal("card printed one person for p and q in 50 renders, want two picks") +} diff --git a/perf_test.go b/perf_test.go index 8a0d2c7..92cc738 100644 --- a/perf_test.go +++ b/perf_test.go @@ -64,6 +64,7 @@ func TestNoReferenceAllocRegression(t *testing.T) { }{ {"a repeat of a reference path", `{"format":"{r}","r":{"format":"{/word.w}","repeat":20,"separator":", "}}`, 66}, {"a named draw group", `{"format":"{a}","a":{"format":"{/word.w}","drawGroup":"g"}}`, 11}, + {"a repeat of a name", `{"format":"{r}","r":{"format":"{/word as n}{n.w}","repeat":20,"separator":", "}}`, 205}, } { f, err := New(WithoutShippedData(), WithDataFS(fstest.MapFS{ "word.json": {Data: []byte(word)},