remove deprecated functions and fix corresponding unit test cases

This commit is contained in:
John
2019-09-06 16:59:38 +08:00
parent 0d5dfe59b9
commit 13e528abb6
21 changed files with 57 additions and 57 deletions

View File

@ -9,7 +9,7 @@ import (
func main() {
err := gcompress.UnZipContent(
gfile.GetBinContents(`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg\encoding\gcompress\data.zip`),
gfile.GetBytes(`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg\encoding\gcompress\data.zip`),
`D:\Workspace\Go\GOPATH\src\github.com\gogf\gf\geg`,
)
fmt.Println(err)

View File

@ -11,7 +11,7 @@ func Upload(r *ghttp.Request) {
fname := gfile.Basename(h.Filename)
buffer := make([]byte, h.Size)
f.Read(buffer)
gfile.PutBinContents("/tmp/"+fname, buffer)
gfile.PutBytes("/tmp/"+fname, buffer)
r.Response.Write(fname + " uploaded successly")
} else {
r.Response.Write(e.Error())

View File

@ -13,7 +13,7 @@ func Upload(r *ghttp.Request) {
name := gfile.Basename(h.Filename)
buffer := make([]byte, h.Size)
f.Read(buffer)
gfile.PutBinContents("/tmp/"+name, buffer)
gfile.PutBytes("/tmp/"+name, buffer)
r.Response.Write(name + " uploaded successly")
} else {
r.Response.Write(e.Error())

View File

@ -34,7 +34,7 @@ func putContents() {
}
func putBinContents() {
fmt.Println(gfile.PutBinContents(filepath2, []byte("abc")))
fmt.Println(gfile.PutBytes(filepath2, []byte("abc")))
}
func main() {

View File

@ -14,8 +14,8 @@ func main() {
`
gfile.PutContents(path, content)
fmt.Println(gfile.Size(path))
fmt.Println(gfile.GetBinContentsTilCharByPath(path, '\n', 0))
fmt.Println(gfile.GetBinContentsTilCharByPath(path, '\n', 3))
fmt.Println(gfile.GetBinContentsTilCharByPath(path, '\n', 8))
fmt.Println(gfile.GetBinContentsTilCharByPath(path, '\n', 12))
fmt.Println(gfile.GetBytesTilCharByPath(path, '\n', 0))
fmt.Println(gfile.GetBytesTilCharByPath(path, '\n', 3))
fmt.Println(gfile.GetBytesTilCharByPath(path, '\n', 8))
fmt.Println(gfile.GetBytesTilCharByPath(path, '\n', 12))
}

View File

@ -153,7 +153,7 @@ func Upload(r *ghttp.Request) {
name := gfile.Basename(h.Filename)
buffer := make([]byte, h.Size)
f.Read(buffer)
gfile.PutBinContents("/tmp/" + name, buffer)
gfile.PutBytes("/tmp/" + name, buffer)
r.Response.Write(name + " uploaded successly")
} else {
r.Response.Write(e.Error())

View File

@ -294,7 +294,7 @@ func getConfigNodeByWeight(cg ConfigGroup) *ConfigNode {
}
}
// 不能取到末尾的边界点
r := grand.Rand(0, total)
r := grand.N(0, total)
if r > 0 {
r -= 1
}

View File

@ -104,7 +104,7 @@ func Test_ViolenceCheck(t *testing.T) {
})
}
func Test_GetToVar(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
@ -113,9 +113,9 @@ func Test_GetToVar(t *testing.T) {
j, err := gjson.DecodeToJson(data)
gtest.Assert(err, nil)
j.GetToVar("n", &n)
j.GetToVar("m", &m)
j.GetToVar("a", &a)
j.GetVar("n", &n)
j.GetVar("m", &m)
j.GetVar("a", &a)
gtest.Assert(n, "123456789")
gtest.Assert(m, g.Map{"k": "v"})
@ -340,8 +340,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.GetToVar("name1", &name) == nil, true)
gtest.Assert(j.GetToVar("name", &name) == nil, false)
gtest.Assert(j.GetVar("name1", &name) == nil, true)
gtest.Assert(j.GetVar("name", &name) == nil, 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")
@ -354,7 +354,7 @@ func Test_Convert2(t *testing.T) {
gtest.Assert(err, nil)
j = gjson.New(`{"person":{"name":"gf"}}`)
err = j.GetToStruct("person", &name)
err = j.GetStruct("person", &name)
gtest.Assert(err, nil)
gtest.Assert(name.Name, "gf")

View File

@ -30,7 +30,7 @@ func Test_Load_JSON(t *testing.T) {
// JSON
gtest.Case(t, func() {
path := "test.json"
gfile.PutBinContents(path, data)
gfile.PutBytes(path, data)
defer gfile.Remove(path)
j, err := gjson.Load(path)
gtest.Assert(err, nil)
@ -57,7 +57,7 @@ func Test_Load_XML(t *testing.T) {
// XML
gtest.Case(t, func() {
path := "test.xml"
gfile.PutBinContents(path, data)
gfile.PutBytes(path, data)
defer gfile.Remove(path)
j, err := gjson.Load(path)
gtest.Assert(err, nil)
@ -110,7 +110,7 @@ m:
// YAML
gtest.Case(t, func() {
path := "test.yaml"
gfile.PutBinContents(path, data)
gfile.PutBytes(path, data)
defer gfile.Remove(path)
j, err := gjson.Load(path)
gtest.Assert(err, nil)
@ -152,7 +152,7 @@ n = 123456789
// TOML
gtest.Case(t, func() {
path := "test.toml"
gfile.PutBinContents(path, data)
gfile.PutBytes(path, data)
defer gfile.Remove(path)
j, err := gjson.Load(path)
gtest.Assert(err, nil)

View File

@ -86,7 +86,7 @@ func Test_ViolenceCheck(t *testing.T) {
})
}
func Test_GetToVar(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
@ -95,9 +95,9 @@ func Test_GetToVar(t *testing.T) {
j := gparser.New(data)
gtest.AssertNE(j, nil)
j.GetToVar("n", &n)
j.GetToVar("m", &m)
j.GetToVar("a", &a)
j.GetVar("n", &n)
j.GetVar("m", &m)
j.GetVar("a", &a)
gtest.Assert(n, "123456789")
gtest.Assert(m, g.Map{"k": "v"})
@ -233,7 +233,7 @@ func Test_Convert(t *testing.T) {
name := struct {
Name string
}{}
err := p.GetToStruct("person", &name)
err := p.GetStruct("person", &name)
gtest.Assert(err, nil)
gtest.Assert(name.Name, "gf")
gtest.Assert(p.ToMap()["name"], "gf")

View File

@ -31,7 +31,7 @@ func Test_Load_JSON(t *testing.T) {
// JSON
gtest.Case(t, func() {
path := "test.json"
gfile.PutBinContents(path, data)
gfile.PutBytes(path, data)
defer gfile.Remove(path)
j, err := gparser.Load(path)
gtest.Assert(err, nil)
@ -58,7 +58,7 @@ func Test_Load_XML(t *testing.T) {
// XML
gtest.Case(t, func() {
path := "test.xml"
gfile.PutBinContents(path, data)
gfile.PutBytes(path, data)
defer gfile.Remove(path)
j, err := gparser.Load(path)
gtest.Assert(err, nil)
@ -111,7 +111,7 @@ m:
// YAML
gtest.Case(t, func() {
path := "test.yaml"
gfile.PutBinContents(path, data)
gfile.PutBytes(path, data)
defer gfile.Remove(path)
j, err := gparser.Load(path)
gtest.Assert(err, nil)
@ -153,7 +153,7 @@ n = "123456789"
// TOML
gtest.Case(t, func() {
path := "test.toml"
gfile.PutBinContents(path, data)
gfile.PutBytes(path, data)
defer gfile.Remove(path)
j, err := gparser.Load(path)
gtest.Assert(err, nil)

View File

@ -171,7 +171,7 @@ func (m *Manager) init() {
m.data[lang][k] = gconv.String(v)
}
} else {
glog.Errorf("load i18n file '%s' failed: %v", file, err)
glog.Errorf("load i18n file '%s' failed: %v", name, err)
}
}
}

View File

@ -1 +1 @@
hello = Привет
hello = "Привет"

View File

@ -1 +1 @@
world=мир
world = "мир"

View File

@ -1,2 +1,2 @@
hello = Привет
world = мир
hello = "Привет"
world = "мир"

View File

@ -43,7 +43,7 @@ func GetBinContents(path string, duration ...interface{}) []byte {
e = getSecondExpire(duration[0])
}
r := gcache.GetOrSetFuncLock(k, func() interface{} {
b := gfile.GetBinContents(path)
b := gfile.GetBytes(path)
if b != nil {
// Adding this <path> to gfsnotify,
// it will clear its cache if there's any changes of the file.

View File

@ -76,13 +76,13 @@ func Test_GetBinContents(t *testing.T) {
)
createTestFile(filepaths1, str1)
defer delTestFiles(filepaths1)
readcontent = gfile.GetBinContents(testpath() + filepaths1)
readcontent = gfile.GetBytes(testpath() + filepaths1)
gtest.Assert(readcontent, []byte(str1))
readcontent = gfile.GetBinContents(filepaths2)
readcontent = gfile.GetBytes(filepaths2)
gtest.Assert(string(readcontent), "")
gtest.Assert(string(gfile.GetBinContents(filepaths2)), "")
gtest.Assert(string(gfile.GetBytes(filepaths2)), "")
})
}
@ -174,7 +174,7 @@ func Test_PutBinContents(t *testing.T) {
createTestFile(filepaths, "a")
defer delTestFiles(filepaths)
err = gfile.PutBinContents(testpath()+filepaths, []byte("test!!"))
err = gfile.PutBytes(testpath()+filepaths, []byte("test!!"))
gtest.Assert(err, nil)
// 判断是否真正写入
@ -182,7 +182,7 @@ func Test_PutBinContents(t *testing.T) {
gtest.Assert(err, nil)
gtest.Assert(string(readcontent), "test!!")
err = gfile.PutBinContents("", []byte("test!!"))
err = gfile.PutBytes("", []byte("test!!"))
gtest.AssertNE(err, nil)
})
@ -197,7 +197,7 @@ func Test_PutBinContentsAppend(t *testing.T) {
)
createTestFile(filepaths, "test!!")
defer delTestFiles(filepaths)
err = gfile.PutBinContentsAppend(testpath()+filepaths, []byte("word"))
err = gfile.PutBytesAppend(testpath()+filepaths, []byte("word"))
gtest.Assert(err, nil)
// 判断是否真正写入
@ -205,7 +205,7 @@ func Test_PutBinContentsAppend(t *testing.T) {
gtest.Assert(err, nil)
gtest.Assert(string(readcontent), "test!!word")
err = gfile.PutBinContentsAppend("", []byte("word"))
err = gfile.PutBytesAppend("", []byte("word"))
gtest.AssertNE(err, nil)
})
@ -220,11 +220,11 @@ func Test_GetBinContentsByTwoOffsetsByPath(t *testing.T) {
createTestFile(filepaths, "abcdefghijk")
defer delTestFiles(filepaths)
readcontent = gfile.GetBinContentsByTwoOffsetsByPath(testpath()+filepaths, 2, 5)
readcontent = gfile.GetBytesByTwoOffsetsByPath(testpath()+filepaths, 2, 5)
gtest.Assert(string(readcontent), "cde")
readcontent = gfile.GetBinContentsByTwoOffsetsByPath("", 2, 5)
readcontent = gfile.GetBytesByTwoOffsetsByPath("", 2, 5)
gtest.Assert(len(readcontent), 0)
})
@ -271,10 +271,10 @@ func Test_GetBinContentsByTwoOffsets(t *testing.T) {
)
reader := strings.NewReader("helloword")
reads = gfile.GetBinContentsByTwoOffsets(reader, 1, 3)
reads = gfile.GetBytesByTwoOffsets(reader, 1, 3)
gtest.Assert(string(reads), "el")
reads = gfile.GetBinContentsByTwoOffsets(reader, 10, 30)
reads = gfile.GetBytesByTwoOffsets(reader, 10, 30)
gtest.Assert(string(reads), "")
})
@ -288,10 +288,10 @@ func Test_GetBinContentsTilChar(t *testing.T) {
)
reader := strings.NewReader("helloword")
reads, _ = gfile.GetBinContentsTilChar(reader, 'w', 2)
reads, _ = gfile.GetBytesTilChar(reader, 'w', 2)
gtest.Assert(string(reads), "llow")
_, indexs = gfile.GetBinContentsTilChar(reader, 'w', 20)
_, indexs = gfile.GetBytesTilChar(reader, 'w', 20)
gtest.Assert(indexs, -1)
})
@ -308,13 +308,13 @@ func Test_GetBinContentsTilCharByPath(t *testing.T) {
createTestFile(filepaths, "abcdefghijklmn")
defer delTestFiles(filepaths)
reads, _ = gfile.GetBinContentsTilCharByPath(testpath()+filepaths, 'c', 2)
reads, _ = gfile.GetBytesTilCharByPath(testpath()+filepaths, 'c', 2)
gtest.Assert(string(reads), "c")
reads, _ = gfile.GetBinContentsTilCharByPath(testpath()+filepaths, 'y', 1)
reads, _ = gfile.GetBytesTilCharByPath(testpath()+filepaths, 'y', 1)
gtest.Assert(string(reads), "")
_, indexs = gfile.GetBinContentsTilCharByPath(testpath()+filepaths, 'x', 1)
_, indexs = gfile.GetBytesTilCharByPath(testpath()+filepaths, 'x', 1)
gtest.Assert(indexs, -1)
})

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
hello = Привет
hello = "Привет"

View File

@ -1 +1 @@
world=мир
world = "мир"

View File

@ -1,2 +1,2 @@
hello = Привет
world = мир
hello = "Привет"
world = "мир"