diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-01-29 14:17:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-29 14:17:40 -0800 |
commit | 961c04cae992eadb42d286d2f85f8a675bdc68c8 (patch) | |
tree | 3408f2d06f847e966c53485e2d54c692cdd037c1 /vendor/github.com/mailru/easyjson/tests/opt_test.go | |
parent | 8d66523ba7d9a77129844be476732ebfd5272d64 (diff) | |
download | chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.gz chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.bz2 chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.zip |
Upgrading server dependancies (#8154)
Diffstat (limited to 'vendor/github.com/mailru/easyjson/tests/opt_test.go')
-rw-r--r-- | vendor/github.com/mailru/easyjson/tests/opt_test.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/github.com/mailru/easyjson/tests/opt_test.go b/vendor/github.com/mailru/easyjson/tests/opt_test.go new file mode 100644 index 000000000..bdd32aa4a --- /dev/null +++ b/vendor/github.com/mailru/easyjson/tests/opt_test.go @@ -0,0 +1,70 @@ +package tests + +import ( + "math" + "reflect" + "testing" + + "encoding/json" + + "github.com/mailru/easyjson/opt" +) + +// This struct type must NOT have a generated marshaler +type OptsVanilla struct { + Int opt.Int + Uint opt.Uint + + Int8 opt.Int8 + Int16 opt.Int16 + Int32 opt.Int32 + Int64 opt.Int64 + + Uint8 opt.Uint8 + Uint16 opt.Uint16 + Uint32 opt.Uint32 + Uint64 opt.Uint64 + + Float32 opt.Float32 + Float64 opt.Float64 + + Bool opt.Bool + String opt.String +} + +var optsVanillaValue = OptsVanilla{ + Int: opt.OInt(-123), + Uint: opt.OUint(123), + + Int8: opt.OInt8(math.MaxInt8), + Int16: opt.OInt16(math.MaxInt16), + Int32: opt.OInt32(math.MaxInt32), + Int64: opt.OInt64(math.MaxInt64), + + Uint8: opt.OUint8(math.MaxUint8), + Uint16: opt.OUint16(math.MaxUint16), + Uint32: opt.OUint32(math.MaxUint32), + Uint64: opt.OUint64(math.MaxUint64), + + Float32: opt.OFloat32(math.MaxFloat32), + Float64: opt.OFloat64(math.MaxFloat64), + + Bool: opt.OBool(true), + String: opt.OString("foo"), +} + +func TestOptsVanilla(t *testing.T) { + data, err := json.Marshal(optsVanillaValue) + if err != nil { + t.Errorf("Failed to marshal vanilla opts: %v", err) + } + + var ov OptsVanilla + if err := json.Unmarshal(data, &ov); err != nil { + t.Errorf("Failed to unmarshal vanilla opts: %v", err) + } + + if !reflect.DeepEqual(optsVanillaValue, ov) { + t.Errorf("Vanilla opts unmarshal returned invalid value %+v, want %+v", ov, optsVanillaValue) + } +} |