GNU-style CLI flags, embedded data, and a literal format grammar #3
@@ -355,3 +355,10 @@ func TestRunUnknownFlagIsNamedByRune(t *testing.T) {
|
||||
t.Errorf("run(-ä) = %d, %q, want the flag named whole", code, errb)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunEmptyDataPathIsNamed(t *testing.T) {
|
||||
code, _, errb := runOut("--data-path=", "sv_SE.word")
|
||||
if code != 1 || !strings.Contains(errb, "empty") {
|
||||
t.Errorf("run(--data-path=) = %d, %q, want the empty path named", code, errb)
|
||||
}
|
||||
}
|
||||
|
||||
+22
-2
@@ -1,8 +1,11 @@
|
||||
package fejkdata
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"strings"
|
||||
"testing"
|
||||
"testing/fstest"
|
||||
)
|
||||
|
||||
// newGenerator creates a generator over a single data directory, failing on
|
||||
@@ -38,8 +41,25 @@ func fake(t *testing.T, f *Generator, path string) string {
|
||||
|
||||
func TestNewMissingDirectory(t *testing.T) {
|
||||
_, err := New(WithoutShippedData(), WithDataPath("data/de_DE"))
|
||||
if err == nil || !strings.Contains(err.Error(), "de_DE") {
|
||||
t.Fatalf("New(missing) error = %v, want it to name the path", err)
|
||||
if err == nil || !strings.Contains(err.Error(), "de_DE") || !errors.Is(err, fs.ErrNotExist) {
|
||||
t.Fatalf("New(missing) error = %v, want the real error, naming the path", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsAnEmptyDataPath(t *testing.T) {
|
||||
_, err := New(WithoutShippedData(), WithDataPath(""))
|
||||
if err == nil || !strings.Contains(err.Error(), "empty") {
|
||||
t.Fatalf("New(WithDataPath(\"\")) = %v, want the empty path named", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewReportsAnEntropyFailure(t *testing.T) {
|
||||
saved := randomBytes
|
||||
randomBytes = func([]byte) (int, error) { return 0, errors.New("no entropy") }
|
||||
defer func() { randomBytes = saved }()
|
||||
_, err := New(WithoutShippedData(), WithDataFS(fstest.MapFS{"w.json": {Data: []byte(`"x"`)}}))
|
||||
if err == nil || !strings.Contains(err.Error(), "no entropy") {
|
||||
t.Fatalf("New() without entropy = %v, want the failure reported", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -8,7 +8,13 @@ import (
|
||||
)
|
||||
|
||||
// engine builds a seeded generator with no loaded categories, for rendering tests.
|
||||
func engine(seed uint64) *Generator { return &Generator{rand: newRand(seed, true)} }
|
||||
func engine(seed uint64) *Generator {
|
||||
s, err := newRand(seed, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &Generator{rand: s}
|
||||
}
|
||||
|
||||
// parse unmarshals a JSON template fragment into its dynamic form.
|
||||
func parse(t *testing.T, s string) any {
|
||||
|
||||
Reference in New Issue
Block a user