go-xim/id_marshaltext_test.go

59 lines
1.3 KiB
Go
Raw Normal View History

2021-11-08 05:10:49 +00:00
package xim
2021-11-07 22:34:30 +00:00
import (
"testing"
)
2021-11-08 05:28:14 +00:00
func TestID_MarshalText(t *testing.T) {
2021-11-07 22:34:30 +00:00
for testNumber, test := range stdtests {
2021-11-08 05:28:14 +00:00
var id ID = something(test.Value)
2021-11-07 22:34:30 +00:00
var marshaled []byte
{
var err error
2021-11-08 05:28:14 +00:00
marshaled, err = id.MarshalText()
2021-11-07 22:34:30 +00:00
if nil != err {
t.Errorf("For test #%d, did not expect an error when mashaling, but actually got one.", testNumber)
t.Logf("VALUE: %064b", test.Value)
t.Logf("ERROR: (%T) %s", err, err)
continue
}
if nil == marshaled {
t.Errorf("For test #%d, the actual marshaled value is nil but that was not expected.", testNumber)
t.Logf("VALUE: %064b", test.Value)
t.Logf("MARSHALED: %s", marshaled)
continue
}
}
{
2021-11-08 05:28:14 +00:00
var newid ID
2021-11-07 22:34:30 +00:00
2021-11-08 05:28:14 +00:00
err := newid.UnmarshalText(marshaled)
2021-11-07 22:34:30 +00:00
if nil != err {
t.Errorf("For test #%d, did not expect an error when unmashaling, but actually got one.", testNumber)
t.Logf("VALUE: %064b", test.Value)
t.Logf("MARSHALED: %s", marshaled)
t.Logf("ERROR: (%T) %s", err, err)
continue
}
2021-11-08 05:28:14 +00:00
var expected ID = id
var actual ID = newid
2021-11-07 22:34:30 +00:00
if expected != actual {
t.Errorf("For test #%d, the actual unmarshaled marshaled value is not what was expected.", testNumber)
t.Logf("VALUE: %064b", test.Value)
t.Logf("EXPECTED: %s", expected)
t.Logf("ACTUAL: %s", actual)
continue
}
}
}
}