Skip to content

Commit

Permalink
gofix
Browse files Browse the repository at this point in the history
  • Loading branch information
kr committed Nov 18, 2011
1 parent a6f3cf4 commit 9c87471
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
11 changes: 1 addition & 10 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,33 @@ package pretty
import (
"fmt"
"io"
"os"
"reflect"
)


type sbuf []string


func (s *sbuf) Write(b []byte) (int, os.Error) {
func (s *sbuf) Write(b []byte) (int, error) {
*s = append(*s, string(b))
return len(b), nil
}


// Diff returns a slice where each element describes
// a difference between a and b.
func Diff(a, b interface{}) (desc []string) {
Fdiff((*sbuf)(&desc), a, b)
return desc
}


// Fdiff writes to w a description of the differences between a and b.
func Fdiff(w io.Writer, a, b interface{}) {
diffWriter{w: w}.diff(reflect.ValueOf(a), reflect.ValueOf(b))
}


type diffWriter struct {
w io.Writer
l string // label
}


func (w diffWriter) printf(f string, a ...interface{}) {
var l string
if w.l != "" {
Expand All @@ -45,7 +38,6 @@ func (w diffWriter) printf(f string, a ...interface{}) {
fmt.Fprintf(w.w, l+f, a...)
}


func (w diffWriter) diff(av, bv reflect.Value) {
if !av.IsValid() && bv.IsValid() {
w.printf("nil != %#v", bv.Interface())
Expand Down Expand Up @@ -103,7 +95,6 @@ func (w diffWriter) diff(av, bv reflect.Value) {
}
}


func (d diffWriter) relabel(name string) (d1 diffWriter) {
d1 = d
if d.l != "" {
Expand Down
12 changes: 3 additions & 9 deletions pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,32 @@ package pretty
import (
"fmt"
"io"
"os"
)


// Errorf is a convenience wrapper for fmt.Errorf.
//
// Calling Errorf(f, x, y) is equivalent to
// fmt.Errorf(f, Formatter(x), Formatter(y)).
func Errorf(format string, a ...interface{}) os.Error {
func Errorf(format string, a ...interface{}) error {
return fmt.Errorf(format, wrap(a)...)
}


// Fprintf is a convenience wrapper for fmt.Fprintf.
//
// Calling Fprintf(w, f, x, y) is equivalent to
// fmt.Fprintf(w, f, Formatter(x), Formatter(y)).
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, error os.Error) {
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, error error) {
return fmt.Fprintf(w, format, wrap(a)...)
}


// Printf is a convenience wrapper for fmt.Printf.
//
// Calling Printf(f, x, y) is equivalent to
// fmt.Printf(f, Formatter(x), Formatter(y)).
func Printf(format string, a ...interface{}) (n int, errno os.Error) {
func Printf(format string, a ...interface{}) (n int, errno error) {
return fmt.Printf(format, wrap(a)...)
}


// Sprintf is a convenience wrapper for fmt.Sprintf.
//
// Calling Sprintf(f, x, y) is equivalent to
Expand All @@ -58,7 +53,6 @@ func Sprintf(format string, a ...interface{}) string {
return fmt.Sprintf(format, wrap(a)...)
}


func wrap(a []interface{}) []interface{} {
w := make([]interface{}, len(a))
for i, x := range a {
Expand Down

0 comments on commit 9c87471

Please sign in to comment.