Compare commits
1 Commits
1b1b93b35f
...
d72d326de5
| Author | SHA1 | Date | |
|---|---|---|---|
| d72d326de5 |
@@ -218,3 +218,26 @@ func TestCalcHoldIsPerTemplate(t *testing.T) {
|
||||
t.Fatal("the nested template never differed from its parent, want its own draw")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalcOverANeverNumericOperandIsRejected(t *testing.T) {
|
||||
for src, want := range map[string]string{
|
||||
`{"format":"{calc(x * 2)}","x":"abc"}`: `"abc"`,
|
||||
`{"format":"{calc(x * 2)}","x":["a","b"]}`: `"x"`,
|
||||
`{"format":"{calc(x + y)}","x":"1","y":"{{2}}"}`: `"{2}"`,
|
||||
} {
|
||||
_, err := compile(parse(t, src))
|
||||
if err == nil || !strings.Contains(err.Error(), want) || !strings.Contains(err.Error(), "never a number") {
|
||||
t.Errorf("compile(%s) = %v, want the operand rejected naming %s", src, err, want)
|
||||
}
|
||||
}
|
||||
for _, ok := range []string{
|
||||
`{"format":"{calc(x * 2)}","x":"3"}`,
|
||||
`{"format":"{calc(x * 2)}","x":" 2.5 "}`,
|
||||
`{"format":"{calc(x * 2)}","x":["1","abc"]}`,
|
||||
`{"format":"{calc(x * 2)}","x":"{digits(2)}"}`,
|
||||
} {
|
||||
if _, err := compile(parse(t, ok)); err != nil {
|
||||
t.Errorf("compile(%s) = %v, want it accepted", ok, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,4 +311,8 @@ func TestRunNoShippedData(t *testing.T) {
|
||||
if code != 0 || strings.TrimSpace(out) == "" {
|
||||
t.Errorf("run = %d, out=%q", code, out)
|
||||
}
|
||||
code, _, errb = runOut("--no-shipped-data", "sv_SE.person")
|
||||
if code != 2 || !strings.Contains(errb, "--no-shipped-data needs at least one --data-path") {
|
||||
t.Errorf("--no-shipped-data alone = %d, %q, want misuse naming --data-path", code, errb)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,3 +181,23 @@ func TestHiddenEntriesAreSkipped(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepeatProductAlongAPathIsCapped(t *testing.T) {
|
||||
for name, files := range map[string]map[string]string{
|
||||
"nested": {"cat": `{"format":"{a}","repeat":2048,"a":{"format":"{b}","repeat":2048,"b":"x"}}`},
|
||||
"through a reference": {
|
||||
"a": `{"format":"{..b}","repeat":2048}`,
|
||||
"b": `{"format":"x","repeat":2048}`,
|
||||
},
|
||||
} {
|
||||
_, err := New(WithoutShippedData(), WithDataPath(writeData(t, files)))
|
||||
if err == nil || !strings.Contains(err.Error(), "repeat") || !strings.Contains(err.Error(), "1048576") {
|
||||
t.Errorf("%s: New = %v, want the repeat product rejected naming the maximum", name, err)
|
||||
}
|
||||
}
|
||||
if _, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{
|
||||
"cat": `{"format":"{a}{c}","repeat":1024,"a":{"format":"{b}","repeat":1024,"b":"x"},"c":{"format":"y","repeat":1024}}`,
|
||||
}))); err != nil {
|
||||
t.Errorf("New = %v, want 1024 x 1024 along one path accepted", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fejkdata
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -55,8 +56,8 @@ func TestUserDataMayReferenceShipped(t *testing.T) {
|
||||
|
||||
func TestWithoutShippedDataNeedsASource(t *testing.T) {
|
||||
_, err := New(WithoutShippedData())
|
||||
if err == nil || !strings.Contains(err.Error(), "WithDataPath") {
|
||||
t.Fatalf("New(WithoutShippedData()) = %v, want an error naming WithDataPath", err)
|
||||
if err == nil || !strings.Contains(err.Error(), "WithDataPath") || !errors.Is(err, ErrNoData) {
|
||||
t.Fatalf("New(WithoutShippedData()) = %v, want ErrNoData naming WithDataPath", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -121,12 +121,10 @@ func TestAlternationPicksOneField(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeightZeroNeverChosen(t *testing.T) {
|
||||
f := engine(5)
|
||||
for i := 0; i < 200; i++ {
|
||||
if got := mustRender(t, f, `[{"format":"X","weight":0},"Y"]`); got != "Y" {
|
||||
t.Fatalf("weight-0 variant chosen: %q", got)
|
||||
}
|
||||
func TestWeightZeroIsRejected(t *testing.T) {
|
||||
_, err := compile(parse(t, `[{"format":"X","weight":0},"Y"]`))
|
||||
if err == nil || !strings.Contains(err.Error(), "weight 0") || !strings.Contains(err.Error(), "remove") {
|
||||
t.Fatalf("compile(weight 0) = %v, want it rejected naming the fix", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user