mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
// Copyright GoFrame Author(https://goframe.org). 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 (
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/v2/container/gvar"
|
|
"github.com/gogf/gf/v2/internal/json"
|
|
"github.com/gogf/gf/v2/test/gtest"
|
|
)
|
|
|
|
func TestVar_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.AssertNil(err)
|
|
|
|
err = json.UnmarshalUseNumber(b, v)
|
|
t.AssertNil(err)
|
|
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.AssertNil(err)
|
|
|
|
err = json.UnmarshalUseNumber(b, &v)
|
|
t.AssertNil(err)
|
|
t.Assert(v.String(), s)
|
|
})
|
|
}
|