24 lines
492 B
Go
24 lines
492 B
Go
package packable
|
|
|
|
import "testing"
|
|
|
|
func TestPackableString(t *testing.T) {
|
|
raw := "hello"
|
|
s := NewString(raw)
|
|
if s.String() != raw {
|
|
t.Errorf("cannot convert string to String: %v vs %v", s, raw)
|
|
}
|
|
|
|
packed, err := s.Encode()
|
|
if err != nil {
|
|
t.Errorf("cannot encode String: %v", err)
|
|
}
|
|
|
|
x := NewString("")
|
|
if err := x.Decode(packed); err != nil {
|
|
t.Errorf("cannot decode string: %v", err)
|
|
} else if x.String() != raw {
|
|
t.Errorf("wrong decoded string: %v vs %v", x, raw)
|
|
}
|
|
}
|