Skip to content

Commit

Permalink
apply pragmas to unmarshal printer (#176)
Browse files Browse the repository at this point in the history
* fix issue 174: apply pragmas to unmarshal printer

* fix build on tip; time.Time representation has changed
  • Loading branch information
philhofer authored May 10, 2017
1 parent 362bfb3 commit 1cce05a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
17 changes: 15 additions & 2 deletions _generated/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ func BenchmarkFastDecode(b *testing.B) {
}
}

func (a *TestType) Equal(b *TestType) bool {
// compare times, then zero out those
// fields, perform a DeepEqual, and restore them
ta, tb := a.Time, b.Time
if !ta.Equal(tb) {
return false
}
a.Time, b.Time = time.Time{}, time.Time{}
ok := reflect.DeepEqual(a, b)
a.Time, b.Time = ta, tb
return ok
}

// This covers the following cases:
// - Recursive types
// - Non-builtin identifiers (and recursive types)
Expand Down Expand Up @@ -97,7 +110,7 @@ func Test1EncodeDecode(t *testing.T) {
t.Error(err)
}

if !reflect.DeepEqual(tt, tnew) {
if !tt.Equal(tnew) {
t.Logf("in: %v", tt)
t.Logf("out: %v", tnew)
t.Fatal("objects not equal")
Expand All @@ -117,7 +130,7 @@ func Test1EncodeDecode(t *testing.T) {
t.Errorf("%d bytes left", len(left))
}

if !reflect.DeepEqual(tt, tanother) {
if !tt.Equal(tanother) {
t.Logf("in: %v", tt)
t.Logf("out: %v", tanother)
t.Fatal("objects not equal")
Expand Down
4 changes: 4 additions & 0 deletions gen/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (u *unmarshalGen) Execute(p Elem) error {
if !u.p.ok() {
return u.p.err
}
p = u.applyall(p)
if p == nil {
return nil
}
if !IsPrintable(p) {
return nil
}
Expand Down
13 changes: 7 additions & 6 deletions msgp/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ func TestReadIntf(t *testing.T) {
if err != nil {
t.Errorf("Test case: %d: %s", i, err)
}
if !reflect.DeepEqual(v, ts) {

/* for time, use time.Equal instead of reflect.DeepEqual */
if tm, ok := v.(time.Time); ok {
if !tm.Equal(v.(time.Time)) {
t.Errorf("%v != %v", ts, v)
}
} else if !reflect.DeepEqual(v, ts) {
t.Errorf("%v in; %v out", ts, v)
}
}
Expand Down Expand Up @@ -633,11 +639,6 @@ func TestTime(t *testing.T) {
if !now.Equal(out) {
t.Fatalf("%s in; %s out", now, out)
}

// check for time.Local zone
if now != out {
t.Error("returned time.Time not set to time.Local")
}
}

func BenchmarkReadTime(b *testing.B) {
Expand Down

0 comments on commit 1cce05a

Please sign in to comment.