2015-02-23 01:30:47 -07:00
|
|
|
// Copyright (C) 2015 The Protocol Authors.
|
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestCompressionMarshal(t *testing.T) {
|
|
|
|
uTestcases := []struct {
|
|
|
|
s string
|
|
|
|
c Compression
|
|
|
|
}{
|
2020-10-01 23:07:05 -07:00
|
|
|
{"true", CompressionMetadata},
|
|
|
|
{"false", CompressionNever},
|
|
|
|
{"never", CompressionNever},
|
|
|
|
{"metadata", CompressionMetadata},
|
|
|
|
{"always", CompressionAlways},
|
|
|
|
{"whatever", CompressionMetadata},
|
2015-02-23 01:30:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mTestcases := []struct {
|
|
|
|
s string
|
|
|
|
c Compression
|
|
|
|
}{
|
2020-10-01 23:07:05 -07:00
|
|
|
{"never", CompressionNever},
|
|
|
|
{"metadata", CompressionMetadata},
|
|
|
|
{"always", CompressionAlways},
|
2015-02-23 01:30:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var c Compression
|
|
|
|
for _, tc := range uTestcases {
|
|
|
|
err := c.UnmarshalText([]byte(tc.s))
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if c != tc.c {
|
|
|
|
t.Errorf("%s unmarshalled to %d, not %d", tc.s, c, tc.c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range mTestcases {
|
|
|
|
bs, err := tc.c.MarshalText()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
if s := string(bs); s != tc.s {
|
|
|
|
t.Errorf("%d marshalled to %q, not %q", tc.c, s, tc.s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|