mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
remove deprecated functions and fix corresponding unit test cases
This commit is contained in:
@ -1,21 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/net/ghttp"
|
||||
"github.com/gogf/gf/os/gres"
|
||||
_ "github.com/gogf/gf/os/gres/testdata"
|
||||
_ "github.com/gogf/gf/os/gres/testdata/data"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gres.Dump()
|
||||
|
||||
v := g.View()
|
||||
v.SetPath("files/template/layout1")
|
||||
v.SetPath("template/layout1")
|
||||
|
||||
s := g.Server()
|
||||
s.SetIndexFolder(true)
|
||||
s.SetServerRoot("files/root")
|
||||
s.SetServerRoot("root")
|
||||
s.BindHookHandler("/*", ghttp.HOOK_BEFORE_SERVE, func(r *ghttp.Request) {
|
||||
fmt.Println(r.URL.Path, r.IsFileRequest())
|
||||
})
|
||||
s.BindHandler("/template", func(r *ghttp.Request) {
|
||||
r.Response.WriteTpl("layout.html")
|
||||
})
|
||||
|
||||
@ -172,6 +172,16 @@ func (v *Var) Interfaces() []interface{} {
|
||||
return gconv.Interfaces(v.Val())
|
||||
}
|
||||
|
||||
// Slice is alias of Interfaces.
|
||||
func (v *Var) Slice() []interface{} {
|
||||
return v.Interfaces()
|
||||
}
|
||||
|
||||
// Array is alias of Interfaces.
|
||||
func (v *Var) Array() []interface{} {
|
||||
return v.Interfaces()
|
||||
}
|
||||
|
||||
// Vars converts and returns <v> as []*Var.
|
||||
func (v *Var) Vars() []*Var {
|
||||
array := gconv.Interfaces(v.Val())
|
||||
|
||||
@ -10,12 +10,15 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/frame/g"
|
||||
|
||||
"github.com/gogf/gf/container/gvar"
|
||||
"github.com/gogf/gf/test/gtest"
|
||||
)
|
||||
|
||||
func TestSet(t *testing.T) {
|
||||
func Test_Set(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
objOne := gvar.New("old", true)
|
||||
objOneOld, _ := objOne.Set("new").(string)
|
||||
@ -27,7 +30,7 @@ func TestSet(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestVal(t *testing.T) {
|
||||
func Test_Val(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
objOne := gvar.New(1, true)
|
||||
objOneOld, _ := objOne.Val().(int)
|
||||
@ -38,7 +41,7 @@ func TestVal(t *testing.T) {
|
||||
gtest.Assert(objTwoOld, 1)
|
||||
})
|
||||
}
|
||||
func TestInterface(t *testing.T) {
|
||||
func Test_Interface(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
objOne := gvar.New(1, true)
|
||||
objOneOld, _ := objOne.Interface().(int)
|
||||
@ -49,7 +52,7 @@ func TestInterface(t *testing.T) {
|
||||
gtest.Assert(objTwoOld, 1)
|
||||
})
|
||||
}
|
||||
func TestIsNil(t *testing.T) {
|
||||
func Test_IsNil(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
objOne := gvar.New(nil, true)
|
||||
gtest.Assert(objOne.IsNil(), true)
|
||||
@ -60,7 +63,7 @@ func TestIsNil(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestBytes(t *testing.T) {
|
||||
func Test_Bytes(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
x := int32(1)
|
||||
bytesBuffer := bytes.NewBuffer([]byte{})
|
||||
@ -77,7 +80,7 @@ func TestBytes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
func Test_String(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var str string = "hello"
|
||||
objOne := gvar.New(str, true)
|
||||
@ -85,7 +88,7 @@ func TestString(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
func TestBool(t *testing.T) {
|
||||
func Test_Bool(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var ok bool = true
|
||||
objOne := gvar.New(ok, true)
|
||||
@ -98,7 +101,7 @@ func TestBool(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInt(t *testing.T) {
|
||||
func Test_Int(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num int = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -107,7 +110,7 @@ func TestInt(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInt8(t *testing.T) {
|
||||
func Test_Int8(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num int8 = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -116,7 +119,7 @@ func TestInt8(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInt16(t *testing.T) {
|
||||
func Test_Int16(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num int16 = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -125,7 +128,7 @@ func TestInt16(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInt32(t *testing.T) {
|
||||
func Test_Int32(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num int32 = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -134,7 +137,7 @@ func TestInt32(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInt64(t *testing.T) {
|
||||
func Test_Int64(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num int64 = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -143,7 +146,7 @@ func TestInt64(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestUint(t *testing.T) {
|
||||
func Test_Uint(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num uint = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -152,7 +155,7 @@ func TestUint(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestUint8(t *testing.T) {
|
||||
func Test_Uint8(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num uint8 = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -161,7 +164,7 @@ func TestUint8(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestUint16(t *testing.T) {
|
||||
func Test_Uint16(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num uint16 = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -170,7 +173,7 @@ func TestUint16(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestUint32(t *testing.T) {
|
||||
func Test_Uint32(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num uint32 = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -179,7 +182,7 @@ func TestUint32(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestUint64(t *testing.T) {
|
||||
func Test_Uint64(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num uint64 = 1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -187,7 +190,7 @@ func TestUint64(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
func TestFloat32(t *testing.T) {
|
||||
func Test_Float32(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num float32 = 1.1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -196,7 +199,7 @@ func TestFloat32(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestFloat64(t *testing.T) {
|
||||
func Test_Float64(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var num float64 = 1.1
|
||||
objOne := gvar.New(num, true)
|
||||
@ -205,21 +208,21 @@ func TestFloat64(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestInts(t *testing.T) {
|
||||
func Test_Ints(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var arr = []int{1, 2, 3, 4, 5}
|
||||
objOne := gvar.New(arr, true)
|
||||
gtest.Assert(objOne.Ints()[0], arr[0])
|
||||
})
|
||||
}
|
||||
func TestFloats(t *testing.T) {
|
||||
func Test_Floats(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var arr = []float64{1, 2, 3, 4, 5}
|
||||
objOne := gvar.New(arr, true)
|
||||
gtest.Assert(objOne.Floats()[0], arr[0])
|
||||
})
|
||||
}
|
||||
func TestStrings(t *testing.T) {
|
||||
func Test_Strings(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var arr = []string{"hello", "world"}
|
||||
objOne := gvar.New(arr, true)
|
||||
@ -227,7 +230,41 @@ func TestStrings(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTime(t *testing.T) {
|
||||
func Test_Interfaces(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var arr = []int{1, 2, 3, 4, 5}
|
||||
objOne := gvar.New(arr, true)
|
||||
gtest.Assert(objOne.Interfaces(), arr)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Slice(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var arr = []int{1, 2, 3, 4, 5}
|
||||
objOne := gvar.New(arr, true)
|
||||
gtest.Assert(objOne.Slice(), arr)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Array(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var arr = []int{1, 2, 3, 4, 5}
|
||||
objOne := gvar.New(arr, false)
|
||||
gtest.Assert(objOne.Array(), arr)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Vars(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var arr = []int{1, 2, 3, 4, 5}
|
||||
objOne := gvar.New(arr, false)
|
||||
gtest.Assert(len(objOne.Vars()), 5)
|
||||
gtest.Assert(objOne.Vars()[0].Int(), 1)
|
||||
gtest.Assert(objOne.Vars()[4].Int(), 5)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Time(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var timeUnix int64 = 1556242660
|
||||
objOne := gvar.New(timeUnix, true)
|
||||
@ -235,11 +272,39 @@ func TestTime(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_GTime(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var timeUnix int64 = 1556242660
|
||||
objOne := gvar.New(timeUnix, true)
|
||||
gtest.Assert(objOne.GTime().Unix(), timeUnix)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Duration(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var timeUnix int64 = 1556242660
|
||||
objOne := gvar.New(timeUnix, true)
|
||||
gtest.Assert(objOne.Duration(), time.Duration(timeUnix))
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Map(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
m := g.Map{
|
||||
"k1": "v1",
|
||||
"k2": "v2",
|
||||
}
|
||||
objOne := gvar.New(m, true)
|
||||
gtest.Assert(objOne.Map()["k1"], m["k1"])
|
||||
gtest.Assert(objOne.Map()["k2"], m["k2"])
|
||||
})
|
||||
}
|
||||
|
||||
type StTest struct {
|
||||
Test int
|
||||
}
|
||||
|
||||
func TestStruct(t *testing.T) {
|
||||
func Test_Struct(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
Kv := make(map[string]int, 1)
|
||||
Kv["Test"] = 100
|
||||
|
||||
@ -16,17 +16,6 @@ import (
|
||||
"github.com/gogf/gf/test/gtest"
|
||||
)
|
||||
|
||||
func TestEncryptString(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s := "pibigstar"
|
||||
result := 693191136
|
||||
encrypt1 := gcrc32.EncryptString(s)
|
||||
encrypt2 := gcrc32.EncryptBytes([]byte(s))
|
||||
gtest.AssertEQ(int(encrypt1), result)
|
||||
gtest.AssertEQ(int(encrypt2), result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestEncrypt(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
s := "pibigstar"
|
||||
|
||||
@ -40,14 +40,6 @@ func TestEncrypt(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestEncryptString(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
result := "5b4c1c2a08ca85ddd031ef8627414f4cb2620b41"
|
||||
s := gsha1.EncryptString("pibigstar")
|
||||
gtest.AssertEQ(s, result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestEncryptFile(t *testing.T) {
|
||||
path := "test.text"
|
||||
errPath := "err.text"
|
||||
|
||||
@ -51,19 +51,6 @@ func Test_Do(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Send(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
redis := gredis.New(config)
|
||||
defer redis.Close()
|
||||
err := redis.Send("SET", "k", "v")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
r, err := redis.Do("GET", "k")
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(r, []byte("v"))
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Stats(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
redis := gredis.New(config)
|
||||
|
||||
@ -107,19 +107,13 @@ func Test_ViolenceCheck(t *testing.T) {
|
||||
func Test_GetVar(t *testing.T) {
|
||||
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
|
||||
gtest.Case(t, func() {
|
||||
var m map[string]string
|
||||
var n int
|
||||
var a []int
|
||||
j, err := gjson.DecodeToJson(data)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
j.GetVar("n", &n)
|
||||
j.GetVar("m", &m)
|
||||
j.GetVar("a", &a)
|
||||
|
||||
gtest.Assert(n, "123456789")
|
||||
gtest.Assert(m, g.Map{"k": "v"})
|
||||
gtest.Assert(a, g.Slice{1, 2, 3})
|
||||
gtest.Assert(j.GetVar("n").String(), "123456789")
|
||||
gtest.Assert(j.GetVar("m").Map(), g.Map{"k": "v"})
|
||||
gtest.Assert(j.GetVar("a").Interfaces(), g.Slice{1, 2, 3})
|
||||
gtest.Assert(j.GetVar("a").Slice(), g.Slice{1, 2, 3})
|
||||
gtest.Assert(j.GetVar("a").Array(), g.Slice{1, 2, 3})
|
||||
})
|
||||
}
|
||||
|
||||
@ -340,8 +334,8 @@ func Test_Convert2(t *testing.T) {
|
||||
gtest.Assert(j.GetJsons("name1"), nil)
|
||||
gtest.Assert(j.GetJsonMap("name1"), nil)
|
||||
gtest.Assert(j.Contains("name1"), false)
|
||||
gtest.Assert(j.GetVar("name1", &name) == nil, true)
|
||||
gtest.Assert(j.GetVar("name", &name) == nil, false)
|
||||
gtest.Assert(j.GetVar("name1").IsNil(), true)
|
||||
gtest.Assert(j.GetVar("name").IsNil(), false)
|
||||
gtest.Assert(j.Len("name1"), -1)
|
||||
gtest.Assert(j.GetTime("time").Format("2006-01-02"), "2019-06-12")
|
||||
gtest.Assert(j.GetGTime("time").Format("Y-m-d"), "2019-06-12")
|
||||
@ -350,7 +344,7 @@ func Test_Convert2(t *testing.T) {
|
||||
err := j.ToStruct(&name)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(name.Name, "gf")
|
||||
j.Dump()
|
||||
//j.Dump()
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
j = gjson.New(`{"person":{"name":"gf"}}`)
|
||||
@ -359,7 +353,7 @@ func Test_Convert2(t *testing.T) {
|
||||
gtest.Assert(name.Name, "gf")
|
||||
|
||||
j = gjson.New(`{"name":"gf""}`)
|
||||
j.Dump()
|
||||
//j.Dump()
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
j = gjson.New(`[1,2,3]`)
|
||||
|
||||
@ -89,19 +89,13 @@ func Test_ViolenceCheck(t *testing.T) {
|
||||
func Test_GetVar(t *testing.T) {
|
||||
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
|
||||
gtest.Case(t, func() {
|
||||
var m map[string]string
|
||||
var n int
|
||||
var a []int
|
||||
j := gparser.New(data)
|
||||
gtest.AssertNE(j, nil)
|
||||
|
||||
j.GetVar("n", &n)
|
||||
j.GetVar("m", &m)
|
||||
j.GetVar("a", &a)
|
||||
|
||||
gtest.Assert(n, "123456789")
|
||||
gtest.Assert(m, g.Map{"k": "v"})
|
||||
gtest.Assert(a, g.Slice{1, 2, 3})
|
||||
gtest.Assert(j.GetVar("n").String(), "123456789")
|
||||
gtest.Assert(j.GetVar("m").Map(), g.Map{"k": "v"})
|
||||
gtest.Assert(j.GetVar("a").Interfaces(), g.Slice{1, 2, 3})
|
||||
gtest.Assert(j.GetVar("a").Slice(), g.Slice{1, 2, 3})
|
||||
gtest.Assert(j.GetVar("a").Array(), g.Slice{1, 2, 3})
|
||||
})
|
||||
}
|
||||
|
||||
@ -240,7 +234,7 @@ func Test_Convert(t *testing.T) {
|
||||
err = p.ToStruct(&name)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(name.Name, "gf")
|
||||
p.Dump()
|
||||
//p.Dump()
|
||||
|
||||
p = gparser.New(`[0,1,2]`)
|
||||
gtest.Assert(p.ToArray()[0], 0)
|
||||
|
||||
@ -356,7 +356,7 @@ func TestCfg_FilePath(t *testing.T) {
|
||||
c := gcfg.New("config.yml")
|
||||
path := c.FilePath("tmp")
|
||||
gtest.Assert(path, "")
|
||||
path = c.GetFilePath("tmp")
|
||||
path = c.FilePath("tmp")
|
||||
gtest.Assert(path, "")
|
||||
})
|
||||
}
|
||||
@ -399,7 +399,7 @@ func TestCfg_Get(t *testing.T) {
|
||||
name := struct {
|
||||
Name string
|
||||
}{}
|
||||
gtest.Assert(c.GetToStruct("name", &name) == nil, false)
|
||||
gtest.Assert(c.GetStruct("name", &name) == nil, false)
|
||||
|
||||
c.Clear()
|
||||
|
||||
@ -409,7 +409,7 @@ func TestCfg_Get(t *testing.T) {
|
||||
gtest.Assert(c.GetGTime("time").Format("Y-m-d"), "2019-06-12")
|
||||
gtest.Assert(c.GetDuration("time").String(), "0s")
|
||||
//t.Log(c.GetString("person"))
|
||||
err := c.GetToStruct("person", &name)
|
||||
err := c.GetStruct("person", &name)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(name.Name, "gf")
|
||||
gtest.Assert(c.GetFloats("floats") == nil, false)
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright 2019 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 gfile_test
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright 2019 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 gfile_test
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright 2019 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 gfile_test
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright 2019 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 gfile_test
|
||||
|
||||
import (
|
||||
@ -40,7 +46,7 @@ func Test_MTimeMillisecond(t *testing.T) {
|
||||
fileobj, err = os.Stat(testpath() + file1)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
gtest.AssertGTE(gfile.MTimeMillisecond(testpath()+file1), fileobj.ModTime().Nanosecond()/1000000)
|
||||
gtest.AssertGE(gfile.MTimeMillisecond(testpath()+file1), fileobj.ModTime().Nanosecond()/1000000)
|
||||
gtest.Assert(gfile.MTimeMillisecond(""), 0)
|
||||
})
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ func Test_ToTime(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
timeTemp := gtime.Now()
|
||||
timeTemp1 := timeTemp.Time
|
||||
gtest.Assert(timeTemp.ToTime().UnixNano(), timeTemp1.UnixNano())
|
||||
gtest.Assert(timeTemp.Time.UnixNano(), timeTemp1.UnixNano())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ var buffer = make([]byte, 8)
|
||||
|
||||
func Benchmark_Rand(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
grand.Rand(0, 999999999)
|
||||
grand.N(0, 999999999)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,11 +20,11 @@ func Test_Intn(t *testing.T) {
|
||||
for i := 0; i < 1000000; i++ {
|
||||
n := grand.Intn(100)
|
||||
gtest.AssertLT(n, 100)
|
||||
gtest.AssertGTE(n, 0)
|
||||
gtest.AssertGE(n, 0)
|
||||
}
|
||||
for i := 0; i < 1000000; i++ {
|
||||
n := grand.Intn(-100)
|
||||
gtest.AssertLTE(n, 0)
|
||||
gtest.AssertLE(n, 0)
|
||||
gtest.AssertGT(n, -100)
|
||||
}
|
||||
})
|
||||
@ -75,16 +75,16 @@ func Test_N(t *testing.T) {
|
||||
func Test_Rand(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
for i := 0; i < 100; i++ {
|
||||
gtest.Assert(grand.Rand(1, 1), 1)
|
||||
gtest.Assert(grand.N(1, 1), 1)
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
gtest.Assert(grand.Rand(0, 0), 0)
|
||||
gtest.Assert(grand.N(0, 0), 0)
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
gtest.AssertIN(grand.Rand(1, 2), []int{1, 2})
|
||||
gtest.AssertIN(grand.N(1, 2), []int{1, 2})
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
gtest.AssertIN(grand.Rand(-1, 2), []int{-1, 0, 1, 2})
|
||||
gtest.AssertIN(grand.N(-1, 2), []int{-1, 0, 1, 2})
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -100,7 +100,7 @@ func Test_Str(t *testing.T) {
|
||||
func Test_RandStr(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
for i := 0; i < 100; i++ {
|
||||
gtest.Assert(len(grand.RandStr(5)), 5)
|
||||
gtest.Assert(len(grand.Str(5)), 5)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -116,7 +116,7 @@ func Test_Digits(t *testing.T) {
|
||||
func Test_RandDigits(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
for i := 0; i < 100; i++ {
|
||||
gtest.Assert(len(grand.RandDigits(5)), 5)
|
||||
gtest.Assert(len(grand.Digits(5)), 5)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -132,7 +132,7 @@ func Test_Letters(t *testing.T) {
|
||||
func Test_RandLetters(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
for i := 0; i < 100; i++ {
|
||||
gtest.Assert(len(grand.RandLetters(5)), 5)
|
||||
gtest.Assert(len(grand.Letters(5)), 5)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user