-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
# Conflicts: # gen/elem.go
- Loading branch information
Showing
24 changed files
with
706 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package _generated | ||
|
||
import ( | ||
"bytes" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/tinylib/msgp/msgp" | ||
) | ||
|
||
func TestAllownil(t *testing.T) { | ||
tt := &NamedStructAN{ | ||
A: []string{}, | ||
B: nil, | ||
} | ||
var buf bytes.Buffer | ||
|
||
err := msgp.Encode(&buf, tt) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
in := buf.Bytes() | ||
|
||
for _, tnew := range []*NamedStructAN{{}, {A: []string{}}, {B: []string{}}} { | ||
err = msgp.Decode(bytes.NewBuffer(in), tnew) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if !reflect.DeepEqual(tt, tnew) { | ||
t.Logf("in: %#v", tt) | ||
t.Logf("out: %#v", tnew) | ||
t.Fatal("objects not equal") | ||
} | ||
} | ||
|
||
in, err = tt.MarshalMsg(nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, tanother := range []*NamedStructAN{{}, {A: []string{}}, {B: []string{}}} { | ||
var left []byte | ||
left, err = tanother.UnmarshalMsg(in) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if len(left) > 0 { | ||
t.Errorf("%d bytes left", len(left)) | ||
} | ||
|
||
if !reflect.DeepEqual(tt, tanother) { | ||
t.Logf("in: %#v", tt) | ||
t.Logf("out: %#v", tanother) | ||
t.Fatal("objects not equal") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package _generated | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"testing" | ||
) | ||
|
||
// Issue 94: shims were not propogated recursively, | ||
// which caused shims that weren't at the top level | ||
// to be silently ignored. | ||
// | ||
// The following line will generate an error after | ||
// the code is generated if the generated code doesn't | ||
// have the right identifier in it. | ||
func TestIssue94(t *testing.T) { | ||
b, err := os.ReadFile("issue94_gen.go") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
const want = "timetostr" | ||
if !bytes.Contains(b, []byte(want)) { | ||
t.Errorf("generated code did not contain %q", want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package _generated | ||
|
||
import "time" | ||
|
||
//go:generate msgp | ||
|
||
// check some specific cases for omitzero | ||
|
||
type OmitZero0 struct { | ||
AStruct OmitZeroA `msg:"astruct,omitempty"` // leave this one omitempty | ||
BStruct OmitZeroA `msg:"bstruct,omitzero"` // and compare to this | ||
AStructPtr *OmitZeroA `msg:"astructptr,omitempty"` // a pointer case omitempty | ||
BStructPtr *OmitZeroA `msg:"bstructptr,omitzero"` // a pointer case omitzero | ||
AExt OmitZeroExt `msg:"aext,omitzero"` // external type case | ||
AExtPtr *OmitZeroExtPtr `msg:"aextptr,omitzero"` // external type pointer case | ||
|
||
// more | ||
APtrNamedStr *NamedStringOZ `msg:"aptrnamedstr,omitzero"` | ||
ANamedStruct NamedStructOZ `msg:"anamedstruct,omitzero"` | ||
APtrNamedStruct *NamedStructOZ `msg:"aptrnamedstruct,omitzero"` | ||
EmbeddableStruct `msg:",flatten,omitzero"` // embed flat | ||
EmbeddableStructOZ `msg:"embeddablestruct2,omitzero"` // embed non-flat | ||
ATime time.Time `msg:"atime,omitzero"` | ||
|
||
OmitZeroTuple OmitZeroTuple `msg:"ozt"` // the inside of a tuple should ignore both omitempty and omitzero | ||
} | ||
|
||
type OmitZeroA struct { | ||
A string `msg:"a,omitempty"` | ||
B NamedStringOZ `msg:"b,omitzero"` | ||
C NamedStringOZ `msg:"c,omitzero"` | ||
} | ||
|
||
func (o *OmitZeroA) IsZero() bool { | ||
if o == nil { | ||
return true | ||
} | ||
return *o == (OmitZeroA{}) | ||
} | ||
|
||
type NamedStructOZ struct { | ||
A string `msg:"a,omitempty"` | ||
B string `msg:"b,omitempty"` | ||
} | ||
|
||
func (ns *NamedStructOZ) IsZero() bool { | ||
if ns == nil { | ||
return true | ||
} | ||
return *ns == (NamedStructOZ{}) | ||
} | ||
|
||
type NamedStringOZ string | ||
|
||
func (ns *NamedStringOZ) IsZero() bool { | ||
if ns == nil { | ||
return true | ||
} | ||
return *ns == "" | ||
} | ||
|
||
type EmbeddableStructOZ struct { | ||
SomeEmbed string `msg:"someembed2,omitempty"` | ||
} | ||
|
||
func (es EmbeddableStructOZ) IsZero() bool { return es == (EmbeddableStructOZ{}) } | ||
|
||
type EmbeddableStructOZ2 struct { | ||
SomeEmbed2 string `msg:"someembed2,omitempty"` | ||
} | ||
|
||
func (es EmbeddableStructOZ2) IsZero() bool { return es == (EmbeddableStructOZ2{}) } | ||
|
||
//msgp:tuple OmitZeroTuple | ||
|
||
// OmitZeroTuple is flagged for tuple output, it should ignore all omitempty and omitzero functionality | ||
// since it's fundamentally incompatible. | ||
type OmitZeroTuple struct { | ||
FieldA string `msg:"fielda,omitempty"` | ||
FieldB NamedStringOZ `msg:"fieldb,omitzero"` | ||
FieldC NamedStringOZ `msg:"fieldc,omitzero"` | ||
} | ||
|
||
type OmitZero1 struct { | ||
T1 OmitZeroTuple `msg:"t1"` | ||
} |
Oops, something went wrong.