Coverage default.go #330

Merged
vtolstov merged 4 commits from :test_coverage into master 2024-09-20 17:55:25 +03:00
Showing only changes of commit 26e1267f6c - Show all commits

View File

@ -5,33 +5,32 @@ import (
"testing"
)
func TestMarshall(t *testing.T) {
a := "json"
res := []byte(a)
m := RawMessage(a)
func FuzzMarshall(f *testing.F) {
f.Fuzz(func(t *testing.T, ref []byte) {
rm := RawMessage(ref)
b, err := m.MarshalJSON()
if err != nil {
t.Errorf("Error %s", err)
}
if !reflect.DeepEqual(b, res) {
t.Errorf("Error %s", err)
}
b, err := rm.MarshalJSON()
if err != nil {
t.Errorf("Error MarshalJSON: %s", err)
}
if !reflect.DeepEqual(ref, b) {
t.Errorf("Error. Expected '%s', was '%s'", ref, b)
}
})
}
func TestUnmarshall(t *testing.T) {
strn := "json"
b := []byte(strn)
// exp := string(b)
m := RawMessage(b)
func FuzzUnmarshall(f *testing.F) {
f.Fuzz(func(t *testing.T, ref string) {
b := []byte(ref)
rm := RawMessage(b)
if err := m.UnmarshalJSON(b); err != nil {
t.Errorf("Error %s", m)
}
if err := rm.UnmarshalJSON(b); err != nil {
t.Errorf("Error UnmarshalJSON: %s", err)
}
if string(m) != strn {
t.Errorf("Error %s", m)
}
if ref != string(rm) {
t.Errorf("Error. Expected '%s', was '%s'", ref, rm)
}
})
}