diff --git a/hold_test.go b/hold_test.go index 99b73f3..ab5a637 100644 --- a/hold_test.go +++ b/hold_test.go @@ -405,10 +405,10 @@ func TestPathIntoARepeatingLevelIsRejected(t *testing.T) { t.Fatalf("New = %v, want a path into a repeating level rejected", err) } _, err = New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{ - "cat": `{"format":"[{p.a}]","p":{"format":"{a}","a":"{/word.w}","group":"g"}}`, + "cat": `{"format":"[{p.a}]","p":{"format":"{a}","a":"{/word.w}","drawGroup":"g"}}`, "word": `{"format":"{w}","w":["x","y"]}`, }))) - if err == nil || !strings.Contains(err.Error(), `the level "p" carries a group`) { + if err == nil || !strings.Contains(err.Error(), `the level "p" carries a drawGroup`) { t.Fatalf("New = %v, want a path into a level carrying a group rejected", err) } } diff --git a/inline_test.go b/inline_test.go index 643fdaf..8cdb217 100644 --- a/inline_test.go +++ b/inline_test.go @@ -108,9 +108,9 @@ func TestFakeTemplateErrors(t *testing.T) { {`name: {/no.such.path}`, "no entry"}, {`name: {..nope}`, "write {/nope}"}, {`{"format":"x"}`, "is a string"}, - {`{/misc.country} {/misc.country.alpha2}`, "renders a level that {/misc.country.alpha2} reads a path into; name the fields you want instead, or draw them apart with a group"}, + {`{/misc.country} {/misc.country.alpha2}`, "renders a level that {/misc.country.alpha2} reads a path into; name the fields you want instead, or draw them apart with a drawGroup"}, {`{"format":"{/misc.country.alpha2} {x}","x":"{/misc.country}"}`, "reads a path into"}, - {`{"format":"{/misc.country.alpha2}","group":"g"}`, "nothing can reference"}, + {`{"format":"{/misc.country.alpha2}","drawGroup":"g"}`, "nothing can reference"}, } { _, err := f.FakeTemplate(c.input) if err == nil || !strings.Contains(err.Error(), c.want) { diff --git a/one_spelling_test.go b/one_spelling_test.go index b5d6707..6f1f559 100644 --- a/one_spelling_test.go +++ b/one_spelling_test.go @@ -31,21 +31,21 @@ func TestRepeatedChoiceItemIsRejected(t *testing.T) { func TestInertObjectIsRejected(t *testing.T) { for src, want := range map[string]string{ - `{"format":"Malmö"}`: `write "Malmö"`, - `{"format":"{digits(3)}"}`: `write "{digits(3)}"`, - `[{"format":"a","weight":1},"b"]`: "weight 1", - `{"format":"{x}","x":"v","repeat":1}`: "repeat 1", - `{"format":"{x}","x":"v","separator":","}`: "separator", - `{"format":"{x}","x":"v","repeat":2,"separator":""}`: "default", - `{"format":"","n":{"format":"1","datatype":"string"}}`: `datatype "string" is the default`, - `{"format":"{x}","x":{"format":"{y}","y":"v","group":""}}`: `group "" is the default`, - `{"format":"{x}","x":{"format":"{y}","y":"v","group":1}}`: "group must be a string", + `{"format":"Malmö"}`: `write "Malmö"`, + `{"format":"{digits(3)}"}`: `write "{digits(3)}"`, + `[{"format":"a","weight":1},"b"]`: "weight 1", + `{"format":"{x}","x":"v","repeat":1}`: "repeat 1", + `{"format":"{x}","x":"v","separator":","}`: "separator", + `{"format":"{x}","x":"v","repeat":2,"separator":""}`: "default", + `{"format":"","n":{"format":"1","datatype":"string"}}`: `datatype "string" is the default`, + `{"format":"{x}","x":{"format":"{y}","y":"v","drawGroup":""}}`: `drawGroup "" is the default`, + `{"format":"{x}","x":{"format":"{y}","y":"v","drawGroup":1}}`: "drawGroup must be a string", } { if _, err := compile(parse(t, src)); err == nil || !strings.Contains(err.Error(), want) { t.Errorf("compile(%s) = %v, want an error mentioning %s", src, err, want) } } - for _, ok := range []string{`[{"format":"a","weight":2},"b"]`, `{"format":"ab","repeat":2}`, `{"format":"{x}","x":"v"}`, `"{digits(3)}"`, `{"format":"{/cat.x}","group":"g"}`} { + for _, ok := range []string{`[{"format":"a","weight":2},"b"]`, `{"format":"ab","repeat":2}`, `{"format":"{x}","x":"v"}`, `"{digits(3)}"`, `{"format":"{/cat.x}","drawGroup":"g"}`} { if _, err := compile(parse(t, ok)); err != nil { t.Errorf("compile(%s) = %v", ok, err) } @@ -55,15 +55,16 @@ func TestInertObjectIsRejected(t *testing.T) { func TestAGroupThatSplitsNothingIsRejected(t *testing.T) { files := map[string]string{"mail": `"{/word.w}@example.com"`, "word": `{"format":"{w}","w":["a","b"]}`} for src, want := range map[string]string{ - `{"format":"{x}","x":{"format":"{y}","y":["a","b"],"group":"g"}}`: `group "g" splits nothing`, - `{"format":"{x}","x":{"format":"{/word}","group":"g"}}`: `group "g" splits nothing`, - `{"format":"{x}","x":{"format":"{r}","group":"g","r":{"format":"{/word.w}","repeat":2}}}`: `group "g" splits nothing`, - `{"format":"{x}","x":{"format":"{y}","y":"{/word.w}","repeat":2,"group":"g"}}`: `group "g" on a repeat`, - `{"format":"{x}","x":{"format":"{/word.w} {y}","group":"g","y":{"format":"{/word.w}!","group":"g"}}}`: `"y" names group "g", the group this template draws in already`, - `{"format":"{/word.w}","group":"g"}`: "", - `{"format":"{x}","x":{"format":"{/mail}","group":"g"}}`: "", - `{"format":"{x}","x":{"format":"{/word.w} {y}","group":"g","y":{"format":"{/word.w}!","group":"h"}}}`: "", - `{"format":"{x}","x":{"format":"{/word.w} {r}","group":"g","r":{"format":"{y}","repeat":2,"y":{"format":"{/word.w}","group":"g"}}}}`: "", + `{"format":"{x}","x":{"format":"{y}","y":["a","b"],"drawGroup":"g"}}`: `drawGroup "g" splits nothing`, + `{"format":"{x}","x":{"format":"{/word}","drawGroup":"g"}}`: `drawGroup "g" splits nothing`, + `{"format":"{x}","x":{"format":"{r}","drawGroup":"g","r":{"format":"{/word.w}","repeat":2}}}`: `drawGroup "g" splits nothing`, + `{"format":"{x}","x":{"format":"{y}","drawGroup":"g","y":{"format":"{/word.w}","drawGroup":"h"}}}`: `drawGroup "g" splits nothing`, + `{"format":"{x}","x":{"format":"{y}","y":"{/word.w}","repeat":2,"drawGroup":"g"}}`: `drawGroup "g" on a repeat`, + `{"format":"{x}","x":{"format":"{/word.w} {y}","drawGroup":"g","y":{"format":"{/word.w}!","drawGroup":"g"}}}`: `"y" names drawGroup "g", the draw group this template draws in already`, + `{"format":"{/word.w}","drawGroup":"g"}`: "", + `{"format":"{x}","x":{"format":"{/mail}","drawGroup":"g"}}`: "", + `{"format":"{x}","x":{"format":"{/word.w} {y}","drawGroup":"g","y":{"format":"{/word.w}!","drawGroup":"h"}}}`: "", + `{"format":"{x}","x":{"format":"{/word.w} {r}","drawGroup":"g","r":{"format":"{y}","repeat":2,"y":{"format":"{/word.w}","drawGroup":"g"}}}}`: "", } { files["cat"] = src _, err := New(WithoutShippedData(), WithDataPath(writeData(t, files))) diff --git a/record_test.go b/record_test.go index 384d41a..ee8b97f 100644 --- a/record_test.go +++ b/record_test.go @@ -203,7 +203,7 @@ func TestRecordRejectsOverlappingReferenceColumns(t *testing.T) { cat := `{"format":"{a}","a":[{"format":"A={b}","b":"1"},{"format":"A={b}","b":"2"}]}` for _, c := range []struct{ name, row string }{ {"through a column repeat, which draws anew", `{"format":"","whole":"{/cat.a}","inner":{"format":"{/cat.a.b}","repeat":2,"separator":"-"}}`}, - {"in a group of its own", `{"format":"","whole":{"format":"{/cat.a}","group":"g"},"inner":"{/cat.a.b}"}`}, + {"in a group of its own", `{"format":"","whole":{"format":"{/cat.a}","drawGroup":"g"},"inner":"{/cat.a.b}"}`}, } { f := newGenerator(t, writeData(t, map[string]string{"cat": cat, "row": c.row}), WithSeed(1)) if _, err := f.FakeRecord("row"); err != nil { @@ -384,7 +384,7 @@ func TestRepeatIterationsDrawReferencesAnew(t *testing.T) { func TestRecordGroupsDrawApart(t *testing.T) { dir := writeData(t, map[string]string{ "person": drawPeople, - "transfer": `{"format":"{from_first} {from_last} to {to_first} {to_last}","from_first":{"format":"{/person.first}","group":"from"},"from_last":{"format":"{/person.last}","group":"from"},"to_first":{"format":"{/person.first}","group":"to"},"to_last":{"format":"{/person.last}","group":"to"}}`, + "transfer": `{"format":"{from_first} {from_last} to {to_first} {to_last}","from_first":{"format":"{/person.first}","drawGroup":"from"},"from_last":{"format":"{/person.last}","drawGroup":"from"},"to_first":{"format":"{/person.first}","drawGroup":"to"},"to_last":{"format":"{/person.last}","drawGroup":"to"}}`, }) f := newGenerator(t, dir, WithSeed(1)) apart := map[string]bool{} diff --git a/reference_test.go b/reference_test.go index b7c5b94..62cedbf 100644 --- a/reference_test.go +++ b/reference_test.go @@ -269,7 +269,7 @@ func TestReferenceOverlapIsRejected(t *testing.T) { } } if _, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{ - "cat": `{"format":"{a} {b}","a":{"format":"{/cat.p}","group":"g"},"b":"{/cat.p.first}","p":` + p + `}`, + "cat": `{"format":"{a} {b}","a":{"format":"{/cat.p}","drawGroup":"g"},"b":"{/cat.p.first}","p":` + p + `}`, }))); err != nil { t.Errorf("New = %v, want a level and a path into it accepted in groups of their own", err) } @@ -285,13 +285,13 @@ func onePerson(name string) bool { func TestAReferencePathIsOneDrawPerRender(t *testing.T) { dir := writeData(t, map[string]string{ - "apart": `{"format":"{a} & {b}","a":{"format":"{/person.first} {/person.last}","group":"x"},"b":{"format":"{/person.first} {/person.last}","group":"y"}}`, - "caller": `{"format":"{a} & {b}","a":{"format":"{/person.first} {/person.last}","group":"x"},"b":"{/pay}"}`, + "apart": `{"format":"{a} & {b}","a":{"format":"{/person.first} {/person.last}","drawGroup":"x"},"b":{"format":"{/person.first} {/person.last}","drawGroup":"y"}}`, + "caller": `{"format":"{a} & {b}","a":{"format":"{/person.first} {/person.last}","drawGroup":"x"},"b":"{/pay}"}`, "contact": `{"format":"{first} {last} <{email}>","email":"{lowercase(/person.first)}.{lowercase(/person.last)}@example.com","first":"{/person.first}","last":"{/person.last}"}`, - "iterations": `{"format":"{/person.first} {r}","group":"outer","r":{"format":"{a}={b}","repeat":3,"separator":",","a":"{/person.first}","b":{"format":"{/person.first}","group":"outer"}}}`, + "iterations": `{"format":"{/person.first} {r}","drawGroup":"outer","r":{"format":"{a}={b}","repeat":3,"separator":",","a":"{/person.first}","b":{"format":"{/person.first}","drawGroup":"outer"}}}`, "nested": `{"format":"{/person.first} {inner}","inner":"{/person.last}"}`, "pair": `{"format":"{a} & {b}","a":"{/person.first} {/person.last}","b":"{/person.first} {/person.last}"}`, - "pay": `{"format":"{p}","p":{"format":"{/person.first} {/person.last}","group":"x"}}`, + "pay": `{"format":"{p}","p":{"format":"{/person.first} {/person.last}","drawGroup":"x"}}`, "person": drawPeople, }) f := newGenerator(t, dir, WithSeed(1))