Test what stability round 1 found untested: a parent's zero-weight rows, a frame per draw of a choice item, ignored flags against the run without them, two leading slashes, and an option too close to 0

This commit is contained in:
2026-10-08 12:11:14 +02:00
committed by Lillem4n
parent 2c2cbbb633
commit c337dc4436
9 changed files with 96 additions and 58 deletions
+22 -2
View File
@@ -7,8 +7,15 @@ import (
)
func TestAnOptionOfTheWrongKindIsNamedByItsJSONKind(t *testing.T) {
if _, err := resolved(t, `{"format":"x","repeat":2,"separator":5}`); err == nil || !strings.Contains(err.Error(), "separator must be a string, not a number") {
t.Errorf("separator 5 = %v, want the kind named", err)
for src, want := range map[string]string{
`{"format":"x","repeat":2,"separator":5}`: "separator must be a string, not a number",
`{"format":"x","repeat":true}`: "repeat must be a number, not a boolean",
`{"format":"x","repeat":2,"separator":{}}`: "separator must be a string, not an object",
`[{"format":"a","weight":-1}]`: "weight must be a finite number of 0 or more",
} {
if _, err := resolved(t, src); err == nil || !strings.Contains(err.Error(), want) {
t.Errorf("compile(%s) = %v, want %q", src, err, want)
}
}
_, err := New(WithoutShippedData(), WithDataPath(writeFiles(t, map[string]string{"t.json": `{"format":"{a}","rows":"t.tsv","key":5}`, "t.tsv": "a\nx\n"})))
if err == nil || !strings.Contains(err.Error(), "key must be a string, not a number") {
@@ -16,6 +23,19 @@ func TestAnOptionOfTheWrongKindIsNamedByItsJSONKind(t *testing.T) {
}
}
func TestAnOptionTooCloseToZeroIsRefused(t *testing.T) {
for _, src := range []string{`[{"format":"a","weight":1e-400},"b"]`, `{"format":"{x}","x":"a","repeat":1e-400}`} {
if _, err := resolved(t, src); err == nil || !strings.Contains(err.Error(), "1e-400") {
t.Errorf("compile(%s) = %v, want the number too close to 0 named", src, err)
}
}
for _, src := range []string{`[{"format":"a","weight":0.0},"b"]`, `{"format":"x","repeat":0e5}`} {
if _, err := resolved(t, src); err != nil {
t.Errorf("compile(%s) = %v, want a zero written as zero loaded", src, err)
}
}
}
func TestWeightSkewsDistribution(t *testing.T) {
f := engine(9)
heavy := 0