1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
// Copyright (c) 2021-2022, Maxime Soulé
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
package types_test
import (
"encoding/json"
"errors"
"testing"
"github.com/maxatome/go-testdeep/internal/types"
)
var _ error = types.OperatorNotJSONMarshallableError("")
func TestOperatorNotJSONMarshallableError(t *testing.T) {
e := types.OperatorNotJSONMarshallableError("Pipo")
if e.Error() != "Pipo TestDeep operator cannot be json.Marshal'led" {
t.Errorf("unexpected %q", e.Error())
}
if e.Operator() != "Pipo" {
t.Errorf("unexpected %q", e.Operator())
}
t.Run("AsOperatorNotJSONMarshallableError", func(t *testing.T) {
ne, ok := types.AsOperatorNotJSONMarshallableError(e)
if !ok {
t.Error("AsOperatorNotJSONMarshallableError() returned false")
return
}
if ne != e {
t.Errorf("AsOperatorNotJSONMarshallableError(): %q ≠ %q",
ne.Error(), e.Error())
}
other := errors.New("Other error")
_, ok = types.AsOperatorNotJSONMarshallableError(other)
if ok {
t.Error("AsOperatorNotJSONMarshallableError() returned true")
return
}
je := &json.MarshalerError{Err: e}
ne, ok = types.AsOperatorNotJSONMarshallableError(je)
if !ok {
t.Error("AsOperatorNotJSONMarshallableError() returned false")
return
}
if ne != e {
t.Errorf("AsOperatorNotJSONMarshallableError(): %q ≠ %q",
ne.Error(), e.Error())
}
je.Err = other
_, ok = types.AsOperatorNotJSONMarshallableError(je)
if ok {
t.Error("AsOperatorNotJSONMarshallableError() returned true")
return
}
})
}
func TestRawString(t *testing.T) {
s := types.RawString("foo")
if str := s.String(); str != "foo" {
t.Errorf("Very weird, got %s", str)
}
}
func TestRawInt(t *testing.T) {
i := types.RawInt(42)
if str := i.String(); str != "42" {
t.Errorf("Very weird, got %s", str)
}
}
func TestRecvKind(t *testing.T) {
s := types.RecvNothing.String()
if s != "nothing received on channel" {
t.Errorf(`got: %q / expected: "nothing received on channel"`, s)
}
s = types.RecvClosed.String()
if s != "channel is closed" {
t.Errorf(`got: %q / expected: "channel is closed"`, s)
}
}
|