diff --git a/Makefile b/Makefile index 148c0af7..16cbbb5f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ EXE := elvish -PKGS := edit eval parse util sys store errutil sysutil strutil +PKGS := edit eval parse sys store errutil sysutil strutil print PKG_PATHS := $(addprefix ./,$(PKGS)) # go tools want an explicit ./ PKG_COVERS := $(addprefix cover/,$(PKGS)) diff --git a/parse/parse_test.go b/parse/parse_test.go index 00f3ed13..71f6135b 100644 --- a/parse/parse_test.go +++ b/parse/parse_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/elves/elvish/util" + "github.com/elves/elvish/print" ) func compoundOfOnePrimary(p *Primary) *Compound { @@ -197,7 +197,7 @@ func TestParse(t *testing.T) { for i, tt := range parseTests { out, err := Parse(fmt.Sprintf("", i), tt.in) if !reflect.DeepEqual(out, tt.wanted) || err != nil { - t.Errorf("Parse(*, %q) =>\n(%s, %v), want\n(%s, ) (up to DeepEqual)", tt.in, util.DeepPrint(out), err, util.DeepPrint(tt.wanted)) + t.Errorf("Parse(*, %q) =>\n(%s, %v), want\n(%s, ) (up to DeepEqual)", tt.in, print.Deep(out), err, print.Deep(tt.wanted)) } } } diff --git a/util/deepprint.go b/print/deep.go similarity index 75% rename from util/deepprint.go rename to print/deep.go index 38e3d8a7..d9eba8e7 100644 --- a/util/deepprint.go +++ b/print/deep.go @@ -1,4 +1,4 @@ -package util +package print import ( "bytes" @@ -6,15 +6,15 @@ import ( "reflect" ) -// DeepPrint is like printing with the %#v formatter of fmt, but it prints +// Deep is like printing with the %#v formatter of fmt, but it prints // pointer fields recursively. -func DeepPrint(x interface{}) string { +func Deep(x interface{}) string { b := &bytes.Buffer{} - deepPrint(b, reflect.ValueOf(x)) + deep(b, reflect.ValueOf(x)) return b.String() } -func deepPrint(b *bytes.Buffer, v reflect.Value) { +func deep(b *bytes.Buffer, v reflect.Value) { i := v.Interface() t := v.Type() @@ -44,7 +44,7 @@ func deepPrint(b *bytes.Buffer, v reflect.Value) { if i > 0 { b.WriteString(", ") } - deepPrint(b, v.Index(i)) + deep(b, v.Index(i)) } case reflect.Map: keys := v.MapKeys() @@ -52,9 +52,9 @@ func deepPrint(b *bytes.Buffer, v reflect.Value) { if i > 0 { b.WriteString(", ") } - deepPrint(b, k) + deep(b, k) b.WriteString(": ") - deepPrint(b, v.MapIndex(k)) + deep(b, v.MapIndex(k)) } case reflect.Struct: for i := 0; i < t.NumField(); i++ { @@ -63,16 +63,16 @@ func deepPrint(b *bytes.Buffer, v reflect.Value) { } b.WriteString(t.Field(i).Name) b.WriteString(": ") - deepPrint(b, v.Field(i)) + deep(b, v.Field(i)) } } b.WriteRune('}') case reflect.Ptr: b.WriteRune('&') - deepPrint(b, reflect.Indirect(v)) + deep(b, reflect.Indirect(v)) return case reflect.Interface: - deepPrint(b, v.Elem()) + deep(b, v.Elem()) return default: fmt.Fprintf(b, "%#v", i) diff --git a/util/deepprint_test.go b/print/deep_test.go similarity index 59% rename from util/deepprint_test.go rename to print/deep_test.go index bd68a1ad..70bdb089 100644 --- a/util/deepprint_test.go +++ b/print/deep_test.go @@ -1,4 +1,4 @@ -package util +package print import ( "testing" @@ -27,7 +27,7 @@ func (g G) GoString() string { return "" } -var deepPrintTests = []struct { +var deepTests = []struct { in interface{} wanted string }{ @@ -38,14 +38,14 @@ var deepPrintTests = []struct { {[]int(nil), `nil`}, {(*int)(nil), `nil`}, {&S{42, "DON'T PANIC", &T{map[string]string{"foo": "bar"}}, G{}}, - `&util.S{I: 42, S: "DON'T PANIC", Pt: &util.T{M: map[string]string{"foo": "bar"}}, G: }`}, - {[]interface{}{&U{42, "DON'T PANIC"}, 42, "DON'T PANIC"}, `[]interface {}{&util.U{I: 42, S: "DON'T PANIC"}, 42, "DON'T PANIC"}`}, + `&print.S{I: 42, S: "DON'T PANIC", Pt: &print.T{M: map[string]string{"foo": "bar"}}, G: }`}, + {[]interface{}{&U{42, "DON'T PANIC"}, 42, "DON'T PANIC"}, `[]interface {}{&print.U{I: 42, S: "DON'T PANIC"}, 42, "DON'T PANIC"}`}, } -func TestDeepPrint(t *testing.T) { - for _, tt := range deepPrintTests { - if out := DeepPrint(tt.in); out != tt.wanted { - t.Errorf("GoPrint(%v) => %#q, want %#q", tt.in, out, tt.wanted) +func TestDeep(t *testing.T) { + for _, tt := range deepTests { + if out := Deep(tt.in); out != tt.wanted { + t.Errorf("Deep(%v) => %#q, want %#q", tt.in, out, tt.wanted) } } } diff --git a/util/util.go b/util/util.go deleted file mode 100644 index 972d9696..00000000 --- a/util/util.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package util contains utility functions used by multiple packages of elvish. -package util