-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskip.fields_test.go
More file actions
51 lines (43 loc) · 1.14 KB
/
skip.fields_test.go
File metadata and controls
51 lines (43 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package binary
import (
"testing"
)
type skipStruct struct {
Public string
unexported string
SkippedJson string `json:"-"`
SkippedBin string `binary:"-"`
}
func TestFieldSkipping(t *testing.T) {
v := &skipStruct{
Public: "visible",
unexported: "hidden",
SkippedJson: "should-skip-json",
SkippedBin: "should-skip-bin",
}
var b []byte
err := Encode(v, &b)
if err != nil {
t.Fatalf("Marshal error: %v", err)
}
// The encoded data should ONLY contain "visible"
// If 1.75 etc was encoded in simple_test, we know string is just bytes with length prefix.
s := &skipStruct{}
err = Decode(b, s)
if err != nil {
t.Fatalf("Unmarshal error: %v", err)
}
if s.Public != "visible" {
t.Errorf("Expected Public='visible', got %q", s.Public)
}
// These should be empty because they should have been skipped during encoding or decoding
if s.unexported != "" {
t.Errorf("unexported field should be empty, got %q", s.unexported)
}
if s.SkippedJson != "" {
t.Errorf("SkippedJson field should be empty, got %q", s.SkippedJson)
}
if s.SkippedBin != "" {
t.Errorf("SkippedBin field should be empty, got %q", s.SkippedBin)
}
}