update unit test cases

This commit is contained in:
John
2019-03-12 23:45:44 +08:00
parent 782aaabd07
commit e71c837472
5 changed files with 79 additions and 44 deletions

View File

@ -24,8 +24,8 @@ test = "v=1"
host = "127.0.0.1"
port = "3306"
user = "root"
pass = ""
# pass = "12345678"
pass = "12345678"
# pass = ""
name = "test"
type = "mysql"
role = "master"
@ -35,8 +35,8 @@ test = "v=1"
host = "127.0.0.1"
port = "3306"
user = "root"
pass = ""
# pass = "12345678"
pass = "12345678"
# pass = ""
name = "test"
type = "mysql"
role = "master"

View File

@ -18,24 +18,24 @@ import (
func Test_View(t *testing.T) {
gtest.Case(t, func() {
gtest.AssertNE(gins.View(), nil)
b, e := gins.View().ParseContent(`{{"1540822968" | date "Y-m-d H:i:s"}}`, nil)
b, e := gins.View().ParseContent(`{{"我是中国人" | substr 2 -1}}`, nil)
gtest.Assert(e, nil)
gtest.Assert(string(b), "2018-10-29 22:22:48")
gtest.Assert(string(b), "中国人")
})
gtest.Case(t, func() {
tpl := "t.tpl"
err := gfile.PutContents(tpl, `{{"1540822968" | date "Y-m-d H:i:s"}}`)
err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`)
gtest.Assert(err, nil)
defer gfile.Remove(tpl)
b, e := gins.View().Parse("t.tpl", nil)
gtest.Assert(e, nil)
gtest.Assert(string(b), "2018-10-29 22:22:48")
gtest.Assert(string(b), "中国人")
})
gtest.Case(t, func() {
path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.Nanosecond())
tpl := fmt.Sprintf(`%s/%s`, path, "t.tpl")
err := gfile.PutContents(tpl, `{{"1540822968" | date "Y-m-d H:i:s"}}`)
err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`)
gtest.Assert(err, nil)
defer gfile.Remove(tpl)
err = gins.View().AddPath(path)
@ -43,7 +43,7 @@ func Test_View(t *testing.T) {
b, e := gins.View().Parse("t.tpl", nil)
gtest.Assert(e, nil)
gtest.Assert(string(b), "2018-10-29 22:22:48")
gtest.Assert(string(b), "中国人")
})
}

View File

@ -6,7 +6,7 @@ package fmtsort_test
import (
"fmt"
"internal/fmtsort"
"github.com/gogf/gf/g/os/gview/internal/fmtsort"
"math"
"reflect"
"strings"

View File

@ -235,39 +235,6 @@ func Test_Shuffle(t *testing.T) {
})
}
func Test_Trim(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.Trim(" 123456\n "), "123456")
gtest.Assert(gstr.Trim("#123456#;", "#;"), "123456")
})
}
func Test_TrimRight(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.TrimRight(" 123456\n "), " 123456")
gtest.Assert(gstr.TrimRight("#123456#;", "#;"), "#123456")
})
}
func Test_TrimRightStr(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.TrimRightStr("gogo我爱gogo", "go"), "gogo我爱")
})
}
func Test_TrimLeft(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.TrimLeft(" \r123456\n "), "123456\n ")
gtest.Assert(gstr.TrimLeft("#;123456#;", "#;"), "123456#;")
})
}
func Test_TrimLeftStr(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.TrimLeftStr("gogo我爱gogo", "go"), "我爱gogo")
})
}
func Test_Split(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.Split("1.2", "."), []string{"1", "2"})
@ -335,4 +302,24 @@ func Test_QuoteMeta(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.QuoteMeta(`.\+*?[^]($)`), `\.\\\+\*\?\[\^\]\(\$\)`)
})
}
func Test_Count(t *testing.T) {
gtest.Case(t, func() {
s := "abcdaAD"
gtest.Assert(gstr.Count(s, "0"), 0)
gtest.Assert(gstr.Count(s, "a"), 2)
gtest.Assert(gstr.Count(s, "b"), 1)
gtest.Assert(gstr.Count(s, "d"), 1)
})
}
func Test_CountI(t *testing.T) {
gtest.Case(t, func() {
s := "abcdaAD"
gtest.Assert(gstr.CountI(s, "0"), 0)
gtest.Assert(gstr.CountI(s, "a"), 3)
gtest.Assert(gstr.CountI(s, "b"), 1)
gtest.Assert(gstr.CountI(s, "d"), 2)
})
}

View File

@ -0,0 +1,48 @@
// 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.
// go test *.go -bench=".*"
package gstr_test
import (
"github.com/gogf/gf/g/test/gtest"
"github.com/gogf/gf/g/text/gstr"
"testing"
)
func Test_Trim(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.Trim(" 123456\n "), "123456")
gtest.Assert(gstr.Trim("#123456#;", "#;"), "123456")
})
}
func Test_TrimRight(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.TrimRight(" 123456\n "), " 123456")
gtest.Assert(gstr.TrimRight("#123456#;", "#;"), "#123456")
})
}
func Test_TrimRightStr(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.TrimRightStr("gogo我爱gogo", "go"), "gogo我爱")
})
}
func Test_TrimLeft(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.TrimLeft(" \r123456\n "), "123456\n ")
gtest.Assert(gstr.TrimLeft("#;123456#;", "#;"), "123456#;")
})
}
func Test_TrimLeftStr(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(gstr.TrimLeftStr("gogo我爱gogo", "go"), "我爱gogo")
})
}