Tests: name the draw option drawGroup, and refuse a draw group whose reads all sit behind a nested one
This commit is contained in:
+2
-2
@@ -405,10 +405,10 @@ func TestPathIntoARepeatingLevelIsRejected(t *testing.T) {
|
|||||||
t.Fatalf("New = %v, want a path into a repeating level rejected", err)
|
t.Fatalf("New = %v, want a path into a repeating level rejected", err)
|
||||||
}
|
}
|
||||||
_, err = New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{
|
_, 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"]}`,
|
"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)
|
t.Fatalf("New = %v, want a path into a level carrying a group rejected", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -108,9 +108,9 @@ func TestFakeTemplateErrors(t *testing.T) {
|
|||||||
{`name: {/no.such.path}`, "no entry"},
|
{`name: {/no.such.path}`, "no entry"},
|
||||||
{`name: {..nope}`, "write {/nope}"},
|
{`name: {..nope}`, "write {/nope}"},
|
||||||
{`{"format":"x"}`, "is a string"},
|
{`{"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} {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)
|
_, err := f.FakeTemplate(c.input)
|
||||||
if err == nil || !strings.Contains(err.Error(), c.want) {
|
if err == nil || !strings.Contains(err.Error(), c.want) {
|
||||||
|
|||||||
+13
-12
@@ -38,14 +38,14 @@ func TestInertObjectIsRejected(t *testing.T) {
|
|||||||
`{"format":"{x}","x":"v","separator":","}`: "separator",
|
`{"format":"{x}","x":"v","separator":","}`: "separator",
|
||||||
`{"format":"{x}","x":"v","repeat":2,"separator":""}`: "default",
|
`{"format":"{x}","x":"v","repeat":2,"separator":""}`: "default",
|
||||||
`{"format":"","n":{"format":"1","datatype":"string"}}`: `datatype "string" is the 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","drawGroup":""}}`: `drawGroup "" is the default`,
|
||||||
`{"format":"{x}","x":{"format":"{y}","y":"v","group":1}}`: "group must be a string",
|
`{"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) {
|
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)
|
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 {
|
if _, err := compile(parse(t, ok)); err != nil {
|
||||||
t.Errorf("compile(%s) = %v", ok, err)
|
t.Errorf("compile(%s) = %v", ok, err)
|
||||||
}
|
}
|
||||||
@@ -55,15 +55,16 @@ func TestInertObjectIsRejected(t *testing.T) {
|
|||||||
func TestAGroupThatSplitsNothingIsRejected(t *testing.T) {
|
func TestAGroupThatSplitsNothingIsRejected(t *testing.T) {
|
||||||
files := map[string]string{"mail": `"{/word.w}@example.com"`, "word": `{"format":"{w}","w":["a","b"]}`}
|
files := map[string]string{"mail": `"{/word.w}@example.com"`, "word": `{"format":"{w}","w":["a","b"]}`}
|
||||||
for src, want := range map[string]string{
|
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":"{y}","y":["a","b"],"drawGroup":"g"}}`: `drawGroup "g" splits nothing`,
|
||||||
`{"format":"{x}","x":{"format":"{/word}","group":"g"}}`: `group "g" splits nothing`,
|
`{"format":"{x}","x":{"format":"{/word}","drawGroup":"g"}}`: `drawGroup "g" splits nothing`,
|
||||||
`{"format":"{x}","x":{"format":"{r}","group":"g","r":{"format":"{/word.w}","repeat":2}}}`: `group "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}","y":"{/word.w}","repeat":2,"group":"g"}}`: `group "g" on a repeat`,
|
`{"format":"{x}","x":{"format":"{y}","drawGroup":"g","y":{"format":"{/word.w}","drawGroup":"h"}}}`: `drawGroup "g" splits nothing`,
|
||||||
`{"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":"{x}","x":{"format":"{y}","y":"{/word.w}","repeat":2,"drawGroup":"g"}}`: `drawGroup "g" on a repeat`,
|
||||||
`{"format":"{/word.w}","group":"g"}`: "",
|
`{"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":"{x}","x":{"format":"{/mail}","group":"g"}}`: "",
|
`{"format":"{/word.w}","drawGroup":"g"}`: "",
|
||||||
`{"format":"{x}","x":{"format":"{/word.w} {y}","group":"g","y":{"format":"{/word.w}!","group":"h"}}}`: "",
|
`{"format":"{x}","x":{"format":"{/mail}","drawGroup":"g"}}`: "",
|
||||||
`{"format":"{x}","x":{"format":"{/word.w} {r}","group":"g","r":{"format":"{y}","repeat":2,"y":{"format":"{/word.w}","group":"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
|
files["cat"] = src
|
||||||
_, err := New(WithoutShippedData(), WithDataPath(writeData(t, files)))
|
_, err := New(WithoutShippedData(), WithDataPath(writeData(t, files)))
|
||||||
|
|||||||
+2
-2
@@ -203,7 +203,7 @@ func TestRecordRejectsOverlappingReferenceColumns(t *testing.T) {
|
|||||||
cat := `{"format":"{a}","a":[{"format":"A={b}","b":"1"},{"format":"A={b}","b":"2"}]}`
|
cat := `{"format":"{a}","a":[{"format":"A={b}","b":"1"},{"format":"A={b}","b":"2"}]}`
|
||||||
for _, c := range []struct{ name, row string }{
|
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":"-"}}`},
|
{"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))
|
f := newGenerator(t, writeData(t, map[string]string{"cat": cat, "row": c.row}), WithSeed(1))
|
||||||
if _, err := f.FakeRecord("row"); err != nil {
|
if _, err := f.FakeRecord("row"); err != nil {
|
||||||
@@ -384,7 +384,7 @@ func TestRepeatIterationsDrawReferencesAnew(t *testing.T) {
|
|||||||
func TestRecordGroupsDrawApart(t *testing.T) {
|
func TestRecordGroupsDrawApart(t *testing.T) {
|
||||||
dir := writeData(t, map[string]string{
|
dir := writeData(t, map[string]string{
|
||||||
"person": drawPeople,
|
"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))
|
f := newGenerator(t, dir, WithSeed(1))
|
||||||
apart := map[string]bool{}
|
apart := map[string]bool{}
|
||||||
|
|||||||
+5
-5
@@ -269,7 +269,7 @@ func TestReferenceOverlapIsRejected(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{
|
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 {
|
}))); err != nil {
|
||||||
t.Errorf("New = %v, want a level and a path into it accepted in groups of their own", err)
|
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) {
|
func TestAReferencePathIsOneDrawPerRender(t *testing.T) {
|
||||||
dir := writeData(t, map[string]string{
|
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"}}`,
|
"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}","group":"x"},"b":"{/pay}"}`,
|
"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}"}`,
|
"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}"}`,
|
"nested": `{"format":"{/person.first} {inner}","inner":"{/person.last}"}`,
|
||||||
"pair": `{"format":"{a} & {b}","a":"{/person.first} {/person.last}","b":"{/person.first} {/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,
|
"person": drawPeople,
|
||||||
})
|
})
|
||||||
f := newGenerator(t, dir, WithSeed(1))
|
f := newGenerator(t, dir, WithSeed(1))
|
||||||
|
|||||||
Reference in New Issue
Block a user