diff --git a/prog_test.go b/prog_test.go index 21d028a..65d97a7 100644 --- a/prog_test.go +++ b/prog_test.go @@ -87,25 +87,32 @@ func TestFS(t *testing.T) { func TestDry(t *testing.T) { const q = `snapshot("\(.).json"; [.])` p := Program{} - files := func() string { + ls := func() string { rt := must(fs.Glob(p.FS, "*")) return strings.Join(rt, " ") } + cat := func(filename string) string { + data, err := fs.ReadFile(p.FS, filename) + if err != nil { + return "error" + } + return string(data) + } for range 3 { p.Args = []string{"--dry-run", q} testRun(t, `false`, `false false.json`, &p) - assertEqual(t, files(), "") - assertEqual(t, fileText(p.FS, "false.json"), "error") + assertEqual(t, ls(), "") + assertEqual(t, cat("false.json"), "error") p.Args = []string{q} testRun(t, `false`, `false`, &p) - assertEqual(t, files(), "false.json") - assertEqual(t, fileText(p.FS, "false.json"), "[false]") + assertEqual(t, ls(), "false.json") + assertEqual(t, cat("false.json"), "[false]") p.Args = []string{"-t", q} testRun(t, `false`, `false`, &p) - assertEqual(t, files(), "false.json") - assertEqual(t, fileText(p.FS, "false.json"), "[\n\tfalse\n]") + assertEqual(t, ls(), "false.json") + assertEqual(t, cat("false.json"), "[\n\tfalse\n]") } } diff --git a/util_test.go b/util_test.go index 0c8d91a..4f4d1a1 100644 --- a/util_test.go +++ b/util_test.go @@ -1,7 +1,6 @@ package jqx import ( - "io/fs" "testing" ) @@ -12,11 +11,3 @@ func assertEqual[T comparable](t *testing.T, got T, want T) { t.Error("want", want) } } - -func fileText(fsys fs.FS, filename string) string { - data, err := fs.ReadFile(fsys, filename) - if err != nil { - return "error" - } - return string(data) -}