mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 04:37:49 +08:00
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
|
// Copyright 2020 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
||
|
//
|
||
|
// This Source Code Form is subject to the terms of the MIT License.
|
||
|
// If a copy of the MIT was not distributed with this file,
|
||
|
// You can obtain one at https://github.com/gogf/gf.
|
||
|
|
||
|
package gvar_test
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"github.com/gogf/gf/container/gvar"
|
||
|
"github.com/gogf/gf/test/gtest"
|
||
|
"math"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func Test_Json(t *testing.T) {
|
||
|
// Marshal
|
||
|
gtest.C(t, func(t *gtest.T) {
|
||
|
s := "i love gf"
|
||
|
v := gvar.New(s)
|
||
|
b1, err1 := json.Marshal(v)
|
||
|
b2, err2 := json.Marshal(s)
|
||
|
t.Assert(err1, err2)
|
||
|
t.Assert(b1, b2)
|
||
|
})
|
||
|
|
||
|
gtest.C(t, func(t *gtest.T) {
|
||
|
s := int64(math.MaxInt64)
|
||
|
v := gvar.New(s)
|
||
|
b1, err1 := json.Marshal(v)
|
||
|
b2, err2 := json.Marshal(s)
|
||
|
t.Assert(err1, err2)
|
||
|
t.Assert(b1, b2)
|
||
|
})
|
||
|
|
||
|
// Unmarshal
|
||
|
gtest.C(t, func(t *gtest.T) {
|
||
|
s := "i love gf"
|
||
|
v := gvar.New(nil)
|
||
|
b, err := json.Marshal(s)
|
||
|
t.Assert(err, nil)
|
||
|
|
||
|
err = json.Unmarshal(b, v)
|
||
|
t.Assert(err, nil)
|
||
|
t.Assert(v.String(), s)
|
||
|
})
|
||
|
|
||
|
gtest.C(t, func(t *gtest.T) {
|
||
|
var v gvar.Var
|
||
|
s := "i love gf"
|
||
|
b, err := json.Marshal(s)
|
||
|
t.Assert(err, nil)
|
||
|
|
||
|
err = json.Unmarshal(b, &v)
|
||
|
t.Assert(err, nil)
|
||
|
t.Assert(v.String(), s)
|
||
|
})
|
||
|
}
|