@@ -16,11 +16,18 @@ func TestCustomTag(t *testing.T) {
16
16
ts := CustomTag {
17
17
Foo : "foostring13579" ,
18
18
Bar : 999_999 }
19
- encDecCustomTag (t , ts , "mytag" )
19
+ encDecCustomTag (t , ts , "mytag" , false )
20
+ })
21
+ t .Run ("Type Scope" , func (t * testing.T ) {
22
+ ts := CustomTag2 {
23
+ Foo : "foostring246810" ,
24
+ Bar : 777_777 }
25
+ encDecCustomTag (t , ts , "anothertag" , false )
26
+ encDecCustomTag (t , ts , "mytag" , true )
20
27
})
21
28
}
22
29
23
- func encDecCustomTag (t * testing.T , testStruct msgp.Encodable , tag string ) {
30
+ func encDecCustomTag (t * testing.T , testStruct msgp.Encodable , tag string , expectError bool ) {
24
31
var b bytes.Buffer
25
32
msgp .Encode (& b , testStruct )
26
33
@@ -46,6 +53,12 @@ func encDecCustomTag(t *testing.T, testStruct msgp.Encodable, tag string) {
46
53
// Check encoded field name
47
54
field := tsType .Field (i )
48
55
encodedValue , ok := encoded [field .Tag .Get (tag )]
56
+ if expectError {
57
+ if ok {
58
+ t .Error ("unexpected encoded field" , field .Name )
59
+ }
60
+ continue
61
+ }
49
62
if ! ok {
50
63
t .Error ("missing encoded value for field" , field .Name )
51
64
continue
0 commit comments