Skip to content

Commit 1cce05a

Browse files
authored
apply pragmas to unmarshal printer (#176)
* fix issue 174: apply pragmas to unmarshal printer * fix build on tip; time.Time representation has changed
1 parent 362bfb3 commit 1cce05a

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

_generated/gen_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ func BenchmarkFastDecode(b *testing.B) {
5656
}
5757
}
5858

59+
func (a *TestType) Equal(b *TestType) bool {
60+
// compare times, then zero out those
61+
// fields, perform a DeepEqual, and restore them
62+
ta, tb := a.Time, b.Time
63+
if !ta.Equal(tb) {
64+
return false
65+
}
66+
a.Time, b.Time = time.Time{}, time.Time{}
67+
ok := reflect.DeepEqual(a, b)
68+
a.Time, b.Time = ta, tb
69+
return ok
70+
}
71+
5972
// This covers the following cases:
6073
// - Recursive types
6174
// - Non-builtin identifiers (and recursive types)
@@ -97,7 +110,7 @@ func Test1EncodeDecode(t *testing.T) {
97110
t.Error(err)
98111
}
99112

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

120-
if !reflect.DeepEqual(tt, tanother) {
133+
if !tt.Equal(tanother) {
121134
t.Logf("in: %v", tt)
122135
t.Logf("out: %v", tanother)
123136
t.Fatal("objects not equal")

gen/unmarshal.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func (u *unmarshalGen) Execute(p Elem) error {
3232
if !u.p.ok() {
3333
return u.p.err
3434
}
35+
p = u.applyall(p)
36+
if p == nil {
37+
return nil
38+
}
3539
if !IsPrintable(p) {
3640
return nil
3741
}

msgp/read_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ func TestReadIntf(t *testing.T) {
5959
if err != nil {
6060
t.Errorf("Test case: %d: %s", i, err)
6161
}
62-
if !reflect.DeepEqual(v, ts) {
62+
63+
/* for time, use time.Equal instead of reflect.DeepEqual */
64+
if tm, ok := v.(time.Time); ok {
65+
if !tm.Equal(v.(time.Time)) {
66+
t.Errorf("%v != %v", ts, v)
67+
}
68+
} else if !reflect.DeepEqual(v, ts) {
6369
t.Errorf("%v in; %v out", ts, v)
6470
}
6571
}
@@ -633,11 +639,6 @@ func TestTime(t *testing.T) {
633639
if !now.Equal(out) {
634640
t.Fatalf("%s in; %s out", now, out)
635641
}
636-
637-
// check for time.Local zone
638-
if now != out {
639-
t.Error("returned time.Time not set to time.Local")
640-
}
641642
}
642643

643644
func BenchmarkReadTime(b *testing.B) {

0 commit comments

Comments
 (0)