Skip to content

Commit 9b149ed

Browse files
committed
add test
1 parent 1976b30 commit 9b149ed

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

encoder_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,22 @@ func TestEncoderNode2(t *testing.T) {
120120
}
121121
}
122122
}
123+
124+
// 0x01 (is a node, sequence id=1)
125+
// 0x04 (pvarint, node value length is 4 bytes)
126+
// 0x59, 0x6F, 0x4D, 0x6F (utf-8 string: "YoMo")
127+
func TestEncoderPrimitiveBinary(t *testing.T) {
128+
expected := []byte{0x01, 0x03, 0x01, 0x23, 0xFF}
129+
// 0x01 - SeqID=1
130+
var prim = NewPrimitivePacketEncoder(0x01)
131+
// Value = 0x0123FF
132+
prim.SetBytes([]byte{0x01, 0x23, 0xFF})
133+
134+
res := prim.Encode()
135+
136+
for i, p := range res {
137+
if p != expected[i] {
138+
t.Errorf("i=%v, expected=%v, actual=%v", i, expected[i], res[i])
139+
}
140+
}
141+
}

0 commit comments

Comments
 (0)