From 22540921b3b69ef566e5ad36f3f98809241d49a3 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 17 Mar 2020 22:23:29 +0800 Subject: [PATCH 1/9] improve codes typing for package package gvalid --- text/gregex/gregex_cache.go | 4 +++- util/gmode/gmode.go | 2 +- util/gvalid/gvalid_check.go | 16 +++++++++------- util/gvalid/gvalid_check_map.go | 5 ++++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/text/gregex/gregex_cache.go b/text/gregex/gregex_cache.go index 979ec19cd..1b4913782 100644 --- a/text/gregex/gregex_cache.go +++ b/text/gregex/gregex_cache.go @@ -14,7 +14,9 @@ import ( var ( regexMu = sync.RWMutex{} // Cache for regex object. - // Note that there's no expiring logic for this map. + // Note that: + // 1. It uses sync.RWMutex ensuring the concurrent safety. + // 2. There's no expiring logic for this map. regexMap = make(map[string]*regexp.Regexp) ) diff --git a/util/gmode/gmode.go b/util/gmode/gmode.go index c77b0dc63..ee8c104ff 100644 --- a/util/gmode/gmode.go +++ b/util/gmode/gmode.go @@ -6,7 +6,7 @@ // Package gmode provides release mode management for project. // -// It uses string to mark the mode instead of integer, which is easy for configuration. +// It uses string to mark the mode instead of integer, which is convenient for configuration. package gmode import "github.com/gogf/gf/os/gfile" diff --git a/util/gvalid/gvalid_check.go b/util/gvalid/gvalid_check.go index 0992ce8fc..334af1410 100644 --- a/util/gvalid/gvalid_check.go +++ b/util/gvalid/gvalid_check.go @@ -520,11 +520,14 @@ func checkRequired(value, ruleKey, ruleVal string, params map[string]string) boo return true } } + // 对字段值长度进行检测 func checkLength(value, ruleKey, ruleVal string, customMsgMap map[string]string) string { - msg := "" - runeArray := gconv.Runes(value) - valueLen := len(runeArray) + var ( + msg = "" + runeArray = gconv.Runes(value) + valueLen = len(runeArray) + ) switch ruleKey { // 长度范围 case "length": @@ -667,9 +670,9 @@ func checkIDNumber(value string) bool { return false } // 加权因子 - weightFactor := [...]int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2} + weightFactor := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2} // 校验码 - checkCode := [...]byte{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'} + checkCode := []byte{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'} last := value[17] num := 0 for i := 0; i < 17; i++ { @@ -679,8 +682,7 @@ func checkIDNumber(value string) bool { } num = num + tmp*weightFactor[i] } - resisue := num % 11 - if checkCode[resisue] != last { + if checkCode[num%11] != last { return false } diff --git a/util/gvalid/gvalid_check_map.go b/util/gvalid/gvalid_check_map.go index df82f65a3..fedd83f0a 100644 --- a/util/gvalid/gvalid_check_map.go +++ b/util/gvalid/gvalid_check_map.go @@ -19,7 +19,10 @@ func CheckMap(params interface{}, rules interface{}, msgs ...CustomMsg) *Error { // 将参数转换为 map[string]interface{}类型 data := gconv.Map(params) if data == nil { - return newErrorStr("invalid_params", "invalid params type: convert to map[string]interface{} failed") + return newErrorStr( + "invalid_params", + "invalid params type: convert to map[string]interface{} failed", + ) } // 真实校验规则数据结构 checkRules := make(map[string]string) From 55137b2aa3d9c08a917b16b0cca89775251d0436 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 17 Mar 2020 22:35:09 +0800 Subject: [PATCH 2/9] README, DONATOR updates --- DONATOR.MD | 4 +++- README.MD | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DONATOR.MD b/DONATOR.MD index acd6ba0e6..6a73fc3a9 100644 --- a/DONATOR.MD +++ b/DONATOR.MD @@ -63,9 +63,11 @@ We currently accept donation by Alipay/WechatPay, please note your github/gitee |[seny0929](https://gitee.com/seny0929)|wechat|¥99.90| |*华|wechat|¥6.66| 感谢郭强的热心 |[Playhi](https://github.com/Playhi)|alipay|¥10.00| -|北京京纬互动科技有限公司|alipay|¥200.00| +|北京京纬互动科技|alipay|¥200.00| |米司特包|wechat|¥99.99| |金毛|alipay|¥100.00| +|1*1x|wechat|¥100.00| +|[ywanbing](https://github.com/ywanbing)|wechat|¥66.66| diff --git a/README.MD b/README.MD index 63f9ebe5f..9a4aacc50 100644 --- a/README.MD +++ b/README.MD @@ -28,7 +28,7 @@ require github.com/gogf/gf latest # Limitation ``` -golang version >= 1.10 +golang version >= 1.11 ``` # Documentation From f01dca0895604e899241df6d46dda419e712d54b Mon Sep 17 00:00:00 2001 From: John Date: Tue, 17 Mar 2020 22:36:05 +0800 Subject: [PATCH 3/9] version updates --- version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.go b/version.go index 504db0668..beff1677c 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,4 @@ package gf -const VERSION = "v1.11.6" +const VERSION = "v1.11.7" const AUTHORS = "john" From 849e7370d109e7ceee70ac03c6cecf19b1c34095 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 19 Mar 2020 11:37:31 +0800 Subject: [PATCH 4/9] improve gutil.Dump, improve sqlite file searching when opening db file --- util/gutil/gutil_dump.go | 182 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 util/gutil/gutil_dump.go diff --git a/util/gutil/gutil_dump.go b/util/gutil/gutil_dump.go new file mode 100644 index 000000000..3b4fdc3d0 --- /dev/null +++ b/util/gutil/gutil_dump.go @@ -0,0 +1,182 @@ +// Copyright 2017 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 gutil provides utility functions. +package gutil + +import ( + "bytes" + "encoding/json" + "fmt" + "os" + "reflect" + "strings" + + "github.com/gogf/gf/internal/empty" + "github.com/gogf/gf/util/gconv" +) + +// Dump prints variables to stdout with more manually readable. +func Dump(i ...interface{}) { + s := Export(i...) + if s != "" { + fmt.Println(s) + } +} + +// Export returns variables as a string with more manually readable. +func Export(i ...interface{}) string { + buffer := bytes.NewBuffer(nil) + for _, v := range i { + if b, ok := v.([]byte); ok { + buffer.Write(b) + } else { + rv := reflect.ValueOf(value) + kind := rv.Kind() + // If it is a pointer, we should find its real data type. + if kind == reflect.Ptr { + rv = rv.Elem() + kind = rv.Kind() + } + switch kind { + // If is type of array, it converts the value of even number index as its key and + // the value of odd number index as its corresponding value. + // Eg: + // []string{"k1","v1","k2","v2"} => map[string]interface{}{"k1":"v1", "k2":"v2"} + // []string{"k1","v1","k2"} => map[string]interface{}{"k1":"v1", "k2":nil} + case reflect.Slice, reflect.Array: + length := rv.Len() + for i := 0; i < length; i += 2 { + if i+1 < length { + m[String(rv.Index(i).Interface())] = rv.Index(i + 1).Interface() + } else { + m[String(rv.Index(i).Interface())] = nil + } + } + case reflect.Map: + ks := rv.MapKeys() + for _, k := range ks { + m[String(k.Interface())] = rv.MapIndex(k).Interface() + } + case reflect.Struct: + // Map converting interface check. + if v, ok := value.(apiMapStrAny); ok { + return v.MapStrAny() + } + rt := rv.Type() + name := "" + tagArray := structTagPriority + switch len(tags) { + case 0: + // No need handle. + case 1: + tagArray = append(strings.Split(tags[0], ","), structTagPriority...) + default: + tagArray = append(tags, structTagPriority...) + } + var rtField reflect.StructField + var rvField reflect.Value + var rvKind reflect.Kind + for i := 0; i < rv.NumField(); i++ { + rtField = rt.Field(i) + rvField = rv.Field(i) + // Only convert the public attributes. + fieldName := rtField.Name + if !utils.IsLetterUpper(fieldName[0]) { + continue + } + name = "" + fieldTag := rtField.Tag + for _, tag := range tagArray { + if name = fieldTag.Get(tag); name != "" { + break + } + } + if name == "" { + name = strings.TrimSpace(fieldName) + } else { + // Support json tag feature: -, omitempty + name = strings.TrimSpace(name) + if name == "-" { + continue + } + array := strings.Split(name, ",") + if len(array) > 1 { + switch strings.TrimSpace(array[1]) { + case "omitempty": + if empty.IsEmpty(rvField.Interface()) { + continue + } else { + name = strings.TrimSpace(array[0]) + } + default: + name = strings.TrimSpace(array[0]) + } + } + } + if recursive { + rvKind = rvField.Kind() + if rvKind == reflect.Ptr { + rvField = rvField.Elem() + rvKind = rvField.Kind() + } + if rvKind == reflect.Struct { + for k, v := range doMapConvert(rvField.Interface(), recursive, tags...) { + m[k] = v + } + } else { + m[name] = rvField.Interface() + } + } else { + m[name] = rvField.Interface() + } + } + default: + return nil + } + if m := gconv.Map(v); m != nil && len(m) > 0 { + v = m + } + encoder := json.NewEncoder(buffer) + encoder.SetEscapeHTML(false) + encoder.SetIndent("", "\t") + if err := encoder.Encode(v); err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + } + } + } + return buffer.String() +} + +// Throw throws out an exception, which can be caught be TryCatch or recover. +func Throw(exception interface{}) { + panic(exception) +} + +// TryCatch implements try...catch... logistics. +func TryCatch(try func(), catch ...func(exception interface{})) { + if len(catch) > 0 { + // If is given, it's used to handle the exception. + defer func() { + if e := recover(); e != nil { + catch[0](e) + } + }() + } else { + // If no function passed, it filters the exception. + defer func() { + recover() + }() + } + try() +} + +// IsEmpty checks given empty or not. +// It returns false if is: integer(0), bool(false), slice/map(len=0), nil; +// or else returns true. +func IsEmpty(value interface{}) bool { + return empty.IsEmpty(value) +} From 36401a063dff888938cbda97853f2ec335ec38e7 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 19 Mar 2020 13:38:42 +0800 Subject: [PATCH 5/9] improve gutil.Dump, improve sqlite file searching when opening db file --- container/garray/garray_z_example_test.go | 54 ++++++--- database/gdb/gdb.go | 2 + database/gdb/gdb_driver_sqlite.go | 6 + net/ghttp/ghttp_client_request.go | 4 +- net/ghttp/ghttp_request_param_request.go | 139 +++++++++++----------- os/gmutex/gmutex_bench_test.go | 6 +- util/gconv/gconv.go | 1 - util/gutil/gutil.go | 35 ------ util/gutil/gutil_dump.go | 138 +-------------------- 9 files changed, 126 insertions(+), 259 deletions(-) diff --git a/container/garray/garray_z_example_test.go b/container/garray/garray_z_example_test.go index eace2f821..cca19b0da 100644 --- a/container/garray/garray_z_example_test.go +++ b/container/garray/garray_z_example_test.go @@ -8,51 +8,52 @@ package garray_test import ( "fmt" + "github.com/gogf/gf/frame/g" "github.com/gogf/gf/container/garray" ) -func Example_basic() { - // 创建普通的数组 +func Example_Basic() { + // A normal array. a := garray.New() - // 添加数据项 + // Adding items. for i := 0; i < 10; i++ { a.Append(i) } - // 获取当前数组长度 + // Print the array length. fmt.Println(a.Len()) - // 获取当前数据项列表 + // Print the array items. fmt.Println(a.Slice()) - // 获取指定索引项 + // Retrieve item by index. fmt.Println(a.Get(6)) - // 查找指定数据项是否存在 + // Check item existence. fmt.Println(a.Contains(6)) fmt.Println(a.Contains(100)) - // 在指定索引前插入数据项 + // Insert item before specified index. a.InsertAfter(9, 11) - // 在指定索引后插入数据项 + // Insert item after specified index. a.InsertBefore(10, 10) fmt.Println(a.Slice()) - // 修改指定索引的数据项 + // Modify item by index. a.Set(0, 100) fmt.Println(a.Slice()) - // 搜索数据项,返回搜索到的索引位置 + // Search item and return its index. fmt.Println(a.Search(5)) - // 删除指定索引的数据项 + // Remove item by index. a.Remove(0) fmt.Println(a.Slice()) - // 清空数组 + // Empty the array, removes all items of it. fmt.Println(a.Slice()) a.Clear() fmt.Println(a.Slice()) @@ -71,15 +72,23 @@ func Example_basic() { // [] } -func Example_rand() { +func Example_Rand() { array := garray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9}) - // 随机返回两个数据项(不删除) + + // Randomly retrieve and return 2 items from the array. + // It does not delete the items from array. fmt.Println(array.Rands(2)) + + // Randomly pick and return one item from the array. + // It deletes the picked up item from array. fmt.Println(array.PopRand()) } -func Example_pop() { +func Example_PopItem() { array := garray.NewFrom([]interface{}{1, 2, 3, 4, 5, 6, 7, 8, 9}) + + // Any Pop* functions pick, delete and return the item from array. + fmt.Println(array.PopLeft()) fmt.Println(array.PopLefts(2)) fmt.Println(array.PopRight()) @@ -92,7 +101,7 @@ func Example_pop() { // [7 8] } -func Example_merge() { +func Example_MergeArray() { array1 := garray.NewFrom([]interface{}{1, 2}) array2 := garray.NewFrom([]interface{}{3, 4}) slice1 := []interface{}{5, 6} @@ -110,3 +119,14 @@ func Example_merge() { // [1 2] // [1 2 1 2 3 4 5 6 7 8 9 0] } + +func Example_Filter() { + array1 := garray.NewFrom(g.Slice{0, 1, 2, nil, "", g.Slice{}, "john"}) + array2 := garray.NewFrom(g.Slice{0, 1, 2, nil, "", g.Slice{}, "john"}) + fmt.Printf("%#v\n", array1.FilterNil().Slice()) + fmt.Printf("%#v\n", array2.FilterEmpty().Slice()) + + // Output: + // []interface {}{0, 1, 2, "", []interface {}{}, "john"} + // []interface {}{1, 2, "john"} +} diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index 1c9936c96..fc5125530 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -11,6 +11,7 @@ import ( "database/sql" "errors" "fmt" + "github.com/gogf/gf/internal/intlog" "time" "github.com/gogf/gf/os/glog" @@ -370,6 +371,7 @@ func (c *Core) getSqlDb(master bool, schema ...string) (sqlDb *sql.DB, err error v := c.cache.GetOrSetFuncLock(node.String(), func() interface{} { sqlDb, err = c.DB.Open(node) if err != nil { + intlog.Printf("DB open failed: %v, %+v", err, node) return nil } if c.maxIdleConnCount > 0 { diff --git a/database/gdb/gdb_driver_sqlite.go b/database/gdb/gdb_driver_sqlite.go index a39335604..5a17fddeb 100644 --- a/database/gdb/gdb_driver_sqlite.go +++ b/database/gdb/gdb_driver_sqlite.go @@ -14,6 +14,7 @@ import ( "database/sql" "fmt" "github.com/gogf/gf/internal/intlog" + "github.com/gogf/gf/os/gfile" "github.com/gogf/gf/text/gstr" "strings" ) @@ -34,11 +35,16 @@ func (d *DriverSqlite) New(core *Core, node *ConfigNode) (DB, error) { // Open creates and returns a underlying sql.DB object for sqlite. func (d *DriverSqlite) Open(config *ConfigNode) (*sql.DB, error) { var source string + var err error if config.LinkInfo != "" { source = config.LinkInfo } else { source = config.Name } + source, err = gfile.Search(source) + if err != nil { + return nil, err + } intlog.Printf("Open: %s", source) if db, err := sql.Open("sqlite3", source); err == nil { return db, nil diff --git a/net/ghttp/ghttp_client_request.go b/net/ghttp/ghttp_client_request.go index a032c89f4..6b45fa6b9 100644 --- a/net/ghttp/ghttp_client_request.go +++ b/net/ghttp/ghttp_client_request.go @@ -24,8 +24,8 @@ import ( // Get send GET request and returns the response object. // Note that the response object MUST be closed if it'll be never used. -func (c *Client) Get(url string) (*ClientResponse, error) { - return c.DoRequest("GET", url) +func (c *Client) Get(url string, data ...interface{}) (*ClientResponse, error) { + return c.DoRequest("GET", url, data...) } // Put send PUT request and returns the response object. diff --git a/net/ghttp/ghttp_request_param_request.go b/net/ghttp/ghttp_request_param_request.go index ac11ef034..89d31e898 100644 --- a/net/ghttp/ghttp_request_param_request.go +++ b/net/ghttp/ghttp_request_param_request.go @@ -12,14 +12,14 @@ import ( "github.com/gogf/gf/util/gconv" ) -// GetRequest retrieves and returns the parameter named passed from client as interface{}, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequest retrieves and returns the parameter named passed from client and +// custom params as interface{}, no matter what HTTP method the client is using. The +// parameter specifies the default value if the does not exist. // // GetRequest is one of the most commonly used functions for retrieving parameters. // -// Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote -// in order of priority: router < query < body < form < custom. +// Note that if there're multiple parameters with the same name, the parameters are +// retrieved and overwrote in order of priority: router < query < body < form < custom. func (r *Request) GetRequest(key string, def ...interface{}) interface{} { value := r.GetParam(key) if value == nil { @@ -46,127 +46,127 @@ func (r *Request) GetRequest(key string, def ...interface{}) interface{} { return value } -// GetRequestVar retrieves and returns the parameter named passed from client as *gvar.Var, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestVar retrieves and returns the parameter named passed from client and +// custom params as *gvar.Var, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestVar(key string, def ...interface{}) *gvar.Var { return gvar.New(r.GetRequest(key, def...)) } -// GetRequestString retrieves and returns the parameter named passed from client as string, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestString retrieves and returns the parameter named passed from client and +// custom params as string, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestString(key string, def ...interface{}) string { return r.GetRequestVar(key, def...).String() } -// GetRequestBool retrieves and returns the parameter named passed from client as bool, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestBool retrieves and returns the parameter named passed from client and +// custom params as bool, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestBool(key string, def ...interface{}) bool { return r.GetRequestVar(key, def...).Bool() } -// GetRequestInt retrieves and returns the parameter named passed from client as int, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestInt retrieves and returns the parameter named passed from client and +// custom params as int, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestInt(key string, def ...interface{}) int { return r.GetRequestVar(key, def...).Int() } -// GetRequestInt32 retrieves and returns the parameter named passed from client as int32, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestInt32 retrieves and returns the parameter named passed from client and +// custom params as int32, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestInt32(key string, def ...interface{}) int32 { return r.GetRequestVar(key, def...).Int32() } -// GetRequestInt64 retrieves and returns the parameter named passed from client as int64, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestInt64 retrieves and returns the parameter named passed from client and +// custom params as int64, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestInt64(key string, def ...interface{}) int64 { return r.GetRequestVar(key, def...).Int64() } -// GetRequestInts retrieves and returns the parameter named passed from client as []int, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestInts retrieves and returns the parameter named passed from client and +// custom params as []int, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestInts(key string, def ...interface{}) []int { return r.GetRequestVar(key, def...).Ints() } -// GetRequestUint retrieves and returns the parameter named passed from client as uint, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestUint retrieves and returns the parameter named passed from client and +// custom params as uint, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestUint(key string, def ...interface{}) uint { return r.GetRequestVar(key, def...).Uint() } -// GetRequestUint32 retrieves and returns the parameter named passed from client as uint32, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestUint32 retrieves and returns the parameter named passed from client and +// custom params as uint32, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestUint32(key string, def ...interface{}) uint32 { return r.GetRequestVar(key, def...).Uint32() } -// GetRequestUint64 retrieves and returns the parameter named passed from client as uint64, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestUint64 retrieves and returns the parameter named passed from client and +// custom params as uint64, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestUint64(key string, def ...interface{}) uint64 { return r.GetRequestVar(key, def...).Uint64() } -// GetRequestFloat32 retrieves and returns the parameter named passed from client as float32, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestFloat32 retrieves and returns the parameter named passed from client and +// custom params as float32, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestFloat32(key string, def ...interface{}) float32 { return r.GetRequestVar(key, def...).Float32() } -// GetRequestFloat64 retrieves and returns the parameter named passed from client as float64, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestFloat64 retrieves and returns the parameter named passed from client and +// custom params as float64, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestFloat64(key string, def ...interface{}) float64 { return r.GetRequestVar(key, def...).Float64() } -// GetRequestFloats retrieves and returns the parameter named passed from client as []float64, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestFloats retrieves and returns the parameter named passed from client and +// custom params as []float64, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestFloats(key string, def ...interface{}) []float64 { return r.GetRequestVar(key, def...).Floats() } -// GetRequestArray retrieves and returns the parameter named passed from client as []string, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestArray retrieves and returns the parameter named passed from client and +// custom params as []string, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestArray(key string, def ...interface{}) []string { return r.GetRequestVar(key, def...).Strings() } -// GetRequestStrings retrieves and returns the parameter named passed from client as []string, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestStrings retrieves and returns the parameter named passed from client and +// custom params as []string, no matter what HTTP method the client is using. The parameter +// specifies the default value if the does not exist. func (r *Request) GetRequestStrings(key string, def ...interface{}) []string { return r.GetRequestVar(key, def...).Strings() } -// GetRequestInterfaces retrieves and returns the parameter named passed from client as []interface{}, -// no matter what HTTP method the client is using. The parameter specifies the default value -// if the does not exist. +// GetRequestInterfaces retrieves and returns the parameter named passed from client +// and custom params as []interface{}, no matter what HTTP method the client is using. The +// parameter specifies the default value if the does not exist. func (r *Request) GetRequestInterfaces(key string, def ...interface{}) []interface{} { return r.GetRequestVar(key, def...).Interfaces() } -// GetRequestMap retrieves and returns all parameters passed from client as map, -// no matter what HTTP method the client is using. The parameter specifies the keys -// retrieving from client parameters, the associated values are the default values if the client -// does not pass the according keys. +// GetRequestMap retrieves and returns all parameters passed from client and custom params +// as map, no matter what HTTP method the client is using. The parameter specifies +// the keys retrieving from client parameters, the associated values are the default values +// if the client does not pass the according keys. // // GetRequestMap is one of the most commonly used functions for retrieving parameters. // -// Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote -// in order of priority: router < query < body < form < custom. +// Note that if there're multiple parameters with the same name, the parameters are retrieved +// and overwrote in order of priority: router < query < body < form < custom. func (r *Request) GetRequestMap(kvMap ...map[string]interface{}) map[string]interface{} { r.parseQuery() r.parseForm() @@ -231,10 +231,10 @@ func (r *Request) GetRequestMap(kvMap ...map[string]interface{}) map[string]inte return m } -// GetRequestMapStrStr retrieves and returns all parameters passed from client as map[string]string, -// no matter what HTTP method the client is using. The parameter specifies the keys -// retrieving from client parameters, the associated values are the default values if the client -// does not pass. +// GetRequestMapStrStr retrieves and returns all parameters passed from client and custom +// params as map[string]string, no matter what HTTP method the client is using. The parameter +// specifies the keys retrieving from client parameters, the associated values are the +// default values if the client does not pass. func (r *Request) GetRequestMapStrStr(kvMap ...map[string]interface{}) map[string]string { requestMap := r.GetRequestMap(kvMap...) if len(requestMap) > 0 { @@ -247,10 +247,10 @@ func (r *Request) GetRequestMapStrStr(kvMap ...map[string]interface{}) map[strin return nil } -// GetRequestMapStrVar retrieves and returns all parameters passed from client as map[string]*gvar.Var, -// no matter what HTTP method the client is using. The parameter specifies the keys -// retrieving from client parameters, the associated values are the default values if the client -// does not pass. +// GetRequestMapStrVar retrieves and returns all parameters passed from client and custom +// params as map[string]*gvar.Var, no matter what HTTP method the client is using. The parameter +// specifies the keys retrieving from client parameters, the associated values are the +// default values if the client does not pass. func (r *Request) GetRequestMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var { requestMap := r.GetRequestMap(kvMap...) if len(requestMap) > 0 { @@ -263,8 +263,9 @@ func (r *Request) GetRequestMapStrVar(kvMap ...map[string]interface{}) map[strin return nil } -// GetRequestStruct retrieves all parameters passed from client no matter what HTTP method the client is using, -// and converts them to given struct object. Note that the parameter is a pointer to the struct object. +// GetRequestStruct retrieves all parameters passed from client and custom params no matter +// what HTTP method the client is using, and converts them to given struct object. Note that +// the parameter is a pointer to the struct object. // The optional parameter is used to specify the key to attribute mapping. func (r *Request) GetRequestStruct(pointer interface{}, mapping ...map[string]string) error { tagMap := structs.TagMapName(pointer, paramTagPriority, true) diff --git a/os/gmutex/gmutex_bench_test.go b/os/gmutex/gmutex_bench_test.go index 848b31c73..b54a7b5cf 100644 --- a/os/gmutex/gmutex_bench_test.go +++ b/os/gmutex/gmutex_bench_test.go @@ -59,7 +59,7 @@ func Benchmark_GMutex_TryLock(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { if gmu.TryLock() { - defer gmu.Unlock() + gmu.Unlock() } } }) @@ -77,7 +77,9 @@ func Benchmark_GMutex_RLockRUnlock(b *testing.B) { func Benchmark_GMutex_TryRLock(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { - gmu.TryRLock() + if gmu.TryRLock() { + gmu.RUnlock() + } } }) } diff --git a/util/gconv/gconv.go b/util/gconv/gconv.go index c34d0a569..e4449d49e 100644 --- a/util/gconv/gconv.go +++ b/util/gconv/gconv.go @@ -122,7 +122,6 @@ func Convert(i interface{}, t string, params ...interface{}) interface{} { case "Duration", "time.Duration": return Duration(i) default: - return i } } diff --git a/util/gutil/gutil.go b/util/gutil/gutil.go index 750d59554..32487fd6a 100644 --- a/util/gutil/gutil.go +++ b/util/gutil/gutil.go @@ -8,44 +8,9 @@ package gutil import ( - "bytes" - "encoding/json" - "fmt" - "os" - "github.com/gogf/gf/internal/empty" - "github.com/gogf/gf/util/gconv" ) -// Dump prints variables to stdout with more manually readable. -func Dump(i ...interface{}) { - s := Export(i...) - if s != "" { - fmt.Println(s) - } -} - -// Export returns variables as a string with more manually readable. -func Export(i ...interface{}) string { - buffer := bytes.NewBuffer(nil) - for _, v := range i { - if b, ok := v.([]byte); ok { - buffer.Write(b) - } else { - if m := gconv.Map(v); m != nil && len(m) > 0 { - v = m - } - encoder := json.NewEncoder(buffer) - encoder.SetEscapeHTML(false) - encoder.SetIndent("", "\t") - if err := encoder.Encode(v); err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - } - } - } - return buffer.String() -} - // Throw throws out an exception, which can be caught be TryCatch or recover. func Throw(exception interface{}) { panic(exception) diff --git a/util/gutil/gutil_dump.go b/util/gutil/gutil_dump.go index 3b4fdc3d0..708cd5c32 100644 --- a/util/gutil/gutil_dump.go +++ b/util/gutil/gutil_dump.go @@ -4,19 +4,15 @@ // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. -// Package gutil provides utility functions. package gutil import ( "bytes" "encoding/json" "fmt" + "github.com/gogf/gf/util/gconv" "os" "reflect" - "strings" - - "github.com/gogf/gf/internal/empty" - "github.com/gogf/gf/util/gconv" ) // Dump prints variables to stdout with more manually readable. @@ -34,111 +30,17 @@ func Export(i ...interface{}) string { if b, ok := v.([]byte); ok { buffer.Write(b) } else { - rv := reflect.ValueOf(value) + rv := reflect.ValueOf(v) kind := rv.Kind() - // If it is a pointer, we should find its real data type. if kind == reflect.Ptr { rv = rv.Elem() kind = rv.Kind() } switch kind { - // If is type of array, it converts the value of even number index as its key and - // the value of odd number index as its corresponding value. - // Eg: - // []string{"k1","v1","k2","v2"} => map[string]interface{}{"k1":"v1", "k2":"v2"} - // []string{"k1","v1","k2"} => map[string]interface{}{"k1":"v1", "k2":nil} case reflect.Slice, reflect.Array: - length := rv.Len() - for i := 0; i < length; i += 2 { - if i+1 < length { - m[String(rv.Index(i).Interface())] = rv.Index(i + 1).Interface() - } else { - m[String(rv.Index(i).Interface())] = nil - } - } - case reflect.Map: - ks := rv.MapKeys() - for _, k := range ks { - m[String(k.Interface())] = rv.MapIndex(k).Interface() - } - case reflect.Struct: - // Map converting interface check. - if v, ok := value.(apiMapStrAny); ok { - return v.MapStrAny() - } - rt := rv.Type() - name := "" - tagArray := structTagPriority - switch len(tags) { - case 0: - // No need handle. - case 1: - tagArray = append(strings.Split(tags[0], ","), structTagPriority...) - default: - tagArray = append(tags, structTagPriority...) - } - var rtField reflect.StructField - var rvField reflect.Value - var rvKind reflect.Kind - for i := 0; i < rv.NumField(); i++ { - rtField = rt.Field(i) - rvField = rv.Field(i) - // Only convert the public attributes. - fieldName := rtField.Name - if !utils.IsLetterUpper(fieldName[0]) { - continue - } - name = "" - fieldTag := rtField.Tag - for _, tag := range tagArray { - if name = fieldTag.Get(tag); name != "" { - break - } - } - if name == "" { - name = strings.TrimSpace(fieldName) - } else { - // Support json tag feature: -, omitempty - name = strings.TrimSpace(name) - if name == "-" { - continue - } - array := strings.Split(name, ",") - if len(array) > 1 { - switch strings.TrimSpace(array[1]) { - case "omitempty": - if empty.IsEmpty(rvField.Interface()) { - continue - } else { - name = strings.TrimSpace(array[0]) - } - default: - name = strings.TrimSpace(array[0]) - } - } - } - if recursive { - rvKind = rvField.Kind() - if rvKind == reflect.Ptr { - rvField = rvField.Elem() - rvKind = rvField.Kind() - } - if rvKind == reflect.Struct { - for k, v := range doMapConvert(rvField.Interface(), recursive, tags...) { - m[k] = v - } - } else { - m[name] = rvField.Interface() - } - } else { - m[name] = rvField.Interface() - } - } - default: - return nil - } - if m := gconv.Map(v); m != nil && len(m) > 0 { - v = m + v = gconv.Interfaces(v) + case reflect.Map, reflect.Struct: + v = gconv.Map(v) } encoder := json.NewEncoder(buffer) encoder.SetEscapeHTML(false) @@ -150,33 +52,3 @@ func Export(i ...interface{}) string { } return buffer.String() } - -// Throw throws out an exception, which can be caught be TryCatch or recover. -func Throw(exception interface{}) { - panic(exception) -} - -// TryCatch implements try...catch... logistics. -func TryCatch(try func(), catch ...func(exception interface{})) { - if len(catch) > 0 { - // If is given, it's used to handle the exception. - defer func() { - if e := recover(); e != nil { - catch[0](e) - } - }() - } else { - // If no function passed, it filters the exception. - defer func() { - recover() - }() - } - try() -} - -// IsEmpty checks given empty or not. -// It returns false if is: integer(0), bool(false), slice/map(len=0), nil; -// or else returns true. -func IsEmpty(value interface{}) bool { - return empty.IsEmpty(value) -} From 0b6d04485e30ae0f359c81b9536746248582b5ab Mon Sep 17 00:00:00 2001 From: John Date: Thu, 19 Mar 2020 22:56:12 +0800 Subject: [PATCH 6/9] improve unit testing cases --- .example/other/test.go | 57 +- .../garray/garray_z_unit_all_basic_test.go | 32 +- .../garray_z_unit_normal_any_array_test.go | 382 ++--- .../garray_z_unit_normal_int_array_test.go | 396 ++--- .../garray_z_unit_normal_str_array_test.go | 412 ++--- .../garray_z_unit_sorted_any_array_test.go | 390 ++--- .../garray_z_unit_sorted_int_array_test.go | 360 ++-- .../garray_z_unit_sorted_str_array_test.go | 378 ++--- container/gchan/gchan_z_unit_test.go | 20 +- container/glist/glist_z_unit_test.go | 102 +- container/gmap/gmap_z_basic_test.go | 64 +- container/gmap/gmap_z_unit_any_any_test.go | 190 +-- container/gmap/gmap_z_unit_int_any_test.go | 180 +- container/gmap/gmap_z_unit_int_int_test.go | 180 +- container/gmap/gmap_z_unit_int_str_test.go | 180 +- container/gmap/gmap_z_unit_list_map_test.go | 162 +- container/gmap/gmap_z_unit_str_any_test.go | 190 +-- container/gmap/gmap_z_unit_str_int_test.go | 190 +-- container/gmap/gmap_z_unit_str_str_test.go | 190 +-- container/gmap/gmap_z_unit_tree_map_test.go | 108 +- container/gpool/gpool_z_unit_test.go | 46 +- container/gqueue/gqueue_unit_test.go | 12 +- container/gring/gring_unit_test.go | 72 +- container/gset/gset_z_unit_any_test.go | 286 ++-- container/gset/gset_z_unit_int_test.go | 256 +-- container/gset/gset_z_unit_str_test.go | 290 ++-- container/gtree/gtree_z_avl_tree_test.go | 178 +- container/gtree/gtree_z_b_tree_test.go | 144 +- container/gtree/gtree_z_redblack_tree_test.go | 178 +- container/gtype/z_unit_bool_test.go | 86 +- container/gtype/z_unit_byte_test.go | 32 +- container/gtype/z_unit_bytes_test.go | 28 +- container/gtype/z_unit_float32_test.go | 28 +- container/gtype/z_unit_float64_test.go | 28 +- container/gtype/z_unit_int32_test.go | 30 +- container/gtype/z_unit_int64_test.go | 30 +- container/gtype/z_unit_int_test.go | 30 +- container/gtype/z_unit_interface_test.go | 28 +- container/gtype/z_unit_string_test.go | 28 +- container/gtype/z_unit_uint32_test.go | 30 +- container/gtype/z_unit_uint64_test.go | 30 +- container/gtype/z_unit_uint_test.go | 30 +- container/gvar/gvar_z_unit_test.go | 192 +-- crypto/gaes/gaes_test.go | 82 +- crypto/gcrc32/gcrc32_test.go | 8 +- crypto/gdes/gdes_test.go | 172 +- crypto/gmd5/gmd5_test.go | 22 +- crypto/gsha1/gsha1_test.go | 16 +- database/gdb/gdb_unit_init_test.go | 8 +- database/gdb/gdb_unit_z_driver_test.go | 10 +- database/gdb/gdb_unit_z_func_test.go | 32 +- database/gdb/gdb_unit_z_mysql_basic_test.go | 10 +- database/gdb/gdb_unit_z_mysql_method_test.go | 574 +++---- database/gdb/gdb_unit_z_mysql_model_test.go | 1460 ++++++++--------- database/gdb/gdb_unit_z_mysql_struct_test.go | 30 +- .../gdb/gdb_unit_z_mysql_transaction_test.go | 162 +- database/gdb/gdb_unit_z_mysql_types_test.go | 28 +- database/gredis/gredis_unit_test.go | 126 +- encoding/gbase64/gbase64_test.go | 38 +- encoding/gbinary/gbinary_z_be_test.go | 60 +- encoding/gbinary/gbinary_z_le_test.go | 60 +- encoding/gbinary/gbinary_z_test.go | 66 +- encoding/gcharset/gcharset_test.go | 20 +- .../gcompress/gcompress_z_unit_gzip_test.go | 20 +- .../gcompress/gcompress_z_unit_zip_test.go | 72 +- .../gcompress/gcompress_z_unit_zlib_test.go | 12 +- encoding/ghash/ghash_z_unit_basic_test.go | 64 +- encoding/ghtml/ghtml_test.go | 10 +- encoding/gini/gini_test.go | 36 +- encoding/gjson/gjson_api_new_load.go | 5 +- encoding/gjson/gjson_z_unit_basic_test.go | 402 ++--- .../gjson/gjson_z_unit_implements_test.go | 46 +- encoding/gjson/gjson_z_unit_json_test.go | 48 + encoding/gjson/gjson_z_unit_load_test.go | 178 +- encoding/gjson/gjson_z_unit_new_test.go | 32 +- encoding/gjson/gjson_z_unit_struct_test.go | 26 +- encoding/gparser/gparser_unit_basic_test.go | 272 +-- encoding/gparser/gparser_unit_load_test.go | 140 +- encoding/gparser/gparser_unit_new_test.go | 32 +- encoding/gtoml/gtoml_test.go | 20 +- encoding/gurl/url_test.go | 20 +- encoding/gxml/gxml_test.go | 24 +- encoding/gyaml/gyaml_test.go | 26 +- errors/gerror/gerror_test.go | 74 +- frame/gins/gins_z_unit_basic_test.go | 34 +- frame/gins/gins_z_unit_config_test.go | 122 +- frame/gins/gins_z_unit_database_test.go | 20 +- frame/gins/gins_z_unit_redis_test.go | 28 +- frame/gins/gins_z_unit_view_test.go | 82 +- i18n/gi18n/gi18n_unit_test.go | 76 +- internal/cmdenv/cmdenv_test.go | 10 +- internal/empty/empty_test.go | 94 +- internal/mutex/mutex_z_unit_test.go | 34 +- internal/rwmutex/rwmutex_z_unit_test.go | 44 +- internal/structs/structs_test.go | 22 +- net/ghttp/ghttp_client_request.go | 4 +- net/ghttp/ghttp_client_response.go | 22 +- net/ghttp/ghttp_unit_client_test.go | 62 +- net/ghttp/ghttp_unit_config_test.go | 18 +- net/ghttp/ghttp_unit_context_test.go | 4 +- net/ghttp/ghttp_unit_cookie_test.go | 24 +- net/ghttp/ghttp_unit_log_test.go | 16 +- net/ghttp/ghttp_unit_mess_test.go | 4 +- net/ghttp/ghttp_unit_middleware_basic_test.go | 184 +-- net/ghttp/ghttp_unit_middleware_cors_test.go | 86 +- net/ghttp/ghttp_unit_param_file_test.go | 62 +- net/ghttp/ghttp_unit_param_json_test.go | 52 +- net/ghttp/ghttp_unit_param_page_test.go | 10 +- net/ghttp/ghttp_unit_param_struct_test.go | 20 +- net/ghttp/ghttp_unit_param_test.go | 194 +-- net/ghttp/ghttp_unit_param_xml_test.go | 14 +- net/ghttp/ghttp_unit_pprof_test.go | 2 +- net/ghttp/ghttp_unit_router_basic_test.go | 86 +- .../ghttp_unit_router_controller_rest_test.go | 28 +- .../ghttp_unit_router_controller_test.go | 62 +- .../ghttp_unit_router_domain_basic_test.go | 186 +-- ...unit_router_domain_controller_rest_test.go | 60 +- ...http_unit_router_domain_controller_test.go | 162 +- ...ttp_unit_router_domain_object_rest_test.go | 60 +- .../ghttp_unit_router_domain_object_test.go | 160 +- net/ghttp/ghttp_unit_router_exit_test.go | 18 +- .../ghttp_unit_router_group_group_test.go | 30 +- .../ghttp_unit_router_group_hook_test.go | 26 +- .../ghttp_unit_router_group_rest_test.go | 70 +- net/ghttp/ghttp_unit_router_group_test.go | 88 +- net/ghttp/ghttp_unit_router_hook_test.go | 34 +- net/ghttp/ghttp_unit_router_names_test.go | 32 +- .../ghttp_unit_router_object_rest1_test.go | 36 +- .../ghttp_unit_router_object_rest2_test.go | 10 +- net/ghttp/ghttp_unit_router_object_test.go | 62 +- net/ghttp/ghttp_unit_session_test.go | 72 +- net/ghttp/ghttp_unit_static_test.go | 102 +- net/ghttp/ghttp_unit_template_test.go | 34 +- net/ghttp/ghttp_unit_websocket_test.go | 12 +- net/gtcp/gtcp_unit_pkg_test.go | 78 +- net/gtcp/gtcp_unit_pool_pkg_test.go | 78 +- net/gtcp/gtcp_unit_pool_test.go | 18 +- net/gudp/gudp_unit_basic_test.go | 36 +- os/gcache/gcache_z_unit_1_test.go | 156 +- os/gcfg/gcfg_z_unit_test.go | 408 ++--- os/gcmd/gcmd_z_unit_default_test.go | 26 +- os/gcmd/gcmd_z_unit_parser_test.go | 114 +- os/gcron/gcron_unit_1_test.go | 124 +- os/gcron/gcron_unit_2_test.go | 34 +- os/genv/genv_test.go | 44 +- os/gfcache/gfcache_z_unit_test.go | 8 +- os/gfile/gfile_z_contents_test.go | 110 +- os/gfile/gfile_z_copy_test.go | 60 +- os/gfile/gfile_z_readline_test.go | 16 +- os/gfile/gfile_z_scan_test.go | 40 +- os/gfile/gfile_z_search_test.go | 16 +- os/gfile/gfile_z_size_test.go | 28 +- os/gfile/gfile_z_test.go | 208 +-- os/gfile/gfile_z_time_test.go | 16 +- os/gfpool/gfpool_z_unit_test.go | 44 +- os/gfsnotify/gfsnotify_z_unit_test.go | 70 +- os/glog/glog_z_unit_basic_test.go | 36 +- os/glog/glog_z_unit_chaining_test.go | 128 +- os/glog/glog_z_unit_config_test.go | 10 +- os/glog/glog_z_unit_level_test.go | 40 +- os/glog/glog_z_unit_rotate_test.go | 14 +- os/gmlock/gmlock_unit_lock_test.go | 38 +- os/gmlock/gmlock_unit_rlock_test.go | 60 +- os/gmutex/gmutex_unit_test.go | 84 +- os/gres/gres_unit_1_test.go | 34 +- os/gres/gres_unit_2_test.go | 114 +- os/grpool/grpool_unit_test.go | 36 +- .../gsession_unit_storage_file_test.go | 56 +- .../gsession_unit_storage_memory_test.go | 56 +- ...ssion_unit_storage_redis_hashtable_test.go | 116 +- .../gsession_unit_storage_redis_test.go | 116 +- os/gsession/gsession_unit_test.go | 6 +- os/gspath/gspath_unit_test.go | 90 +- os/gtime/gtime_z_unit_basic_test.go | 62 +- os/gtime/gtime_z_unit_format_test.go | 46 +- os/gtime/gtime_z_unit_json_test.go | 42 +- os/gtime/gtime_z_unit_time_test.go | 114 +- os/gtimer/gtimer_z_unit_0_test.go | 50 +- os/gtimer/gtimer_z_unit_1_test.go | 92 +- os/gtimer/gtimer_z_unit_2_test.go | 22 +- os/gview/gview_unit_basic_test.go | 188 +-- os/gview/gview_unit_config_test.go | 24 +- os/gview/gview_unit_i18n_test.go | 28 +- test/gtest/gtest.go | 310 ---- test/gtest/gtest_t.go | 83 + test/gtest/gtest_util.go | 331 ++++ .../{gtest_test.go => gtest_z_unit_test.go} | 21 +- text/gregex/gregex_z_unit_test.go | 128 +- text/gstr/gstr_z_unit_basic_test.go | 350 ++-- text/gstr/gstr_z_unit_convert_test.go | 4 +- text/gstr/gstr_z_unit_domain_test.go | 68 +- text/gstr/gstr_z_unit_parse_test.go | 48 +- text/gstr/gstr_z_unit_pos_test.go | 50 +- text/gstr/gstr_z_unit_trim_test.go | 50 +- util/gconv/gconv_z_all_test.go | 1150 ++++++------- util/gconv/gconv_z_unit_basic_test.go | 38 +- util/gconv/gconv_z_unit_bool_test.go | 38 +- util/gconv/gconv_z_unit_map_test.go | 328 ++-- util/gconv/gconv_z_unit_slice_test.go | 52 +- util/gconv/gconv_z_unit_string_test.go | 58 +- util/gconv/gconv_z_unit_struct_slice_test.go | 48 +- util/gconv/gconv_z_unit_struct_test.go | 204 +-- util/gconv/gconv_z_unit_time_test.go | 8 +- util/gconv/gconv_z_unit_unsafe_test.go | 8 +- util/gpage/gpage_unit_test.go | 102 +- util/grand/grand_z_unit_test.go | 98 +- util/gutil/gutil_z_comparator_z_unit_test.go | 128 +- util/gutil/gutil_z_unit_test.go | 20 +- util/guuid/guuid_z_unit_test.go | 16 +- util/gvalid/gvalid_unit_basic_all_test.go | 406 ++--- util/gvalid/gvalid_unit_checkmap_test.go | 24 +- util/gvalid/gvalid_unit_checkstruct_test.go | 100 +- util/gvalid/gvalid_unit_customerror_test.go | 4 +- 213 files changed, 10757 insertions(+), 10522 deletions(-) create mode 100644 encoding/gjson/gjson_z_unit_json_test.go create mode 100644 test/gtest/gtest_t.go create mode 100644 test/gtest/gtest_util.go rename test/gtest/{gtest_test.go => gtest_z_unit_test.go} (50%) diff --git a/.example/other/test.go b/.example/other/test.go index 84f83a83d..59f4e6281 100644 --- a/.example/other/test.go +++ b/.example/other/test.go @@ -1,35 +1,38 @@ package main import ( - "github.com/gogf/gf/frame/g" - "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/os/gtime" - "github.com/gogf/gf/os/gtimer" - "time" + "encoding/json" + "fmt" + "github.com/gogf/gf/encoding/gjson" ) -func GetList() { -START: - for { - res, err := g.Redis().DoVar("RPOP", "mill") - if err != nil { - glog.Debug("Rpop:", err) - break - } - glog.Debug(res) - if res.IsEmpty() { - glog.Debug("nil") - continue START - } - interval := 50 * time.Second - gtimer.AddOnce(interval, func() { - glog.Debug("end------:", res, gtime.Now().Format("Y-m-d H:i:s")) - }) - } +type ModifyFieldInfoType struct { + Id int64 `json:"id"` + New string `json:"new"` +} +type ModifyFieldInfosType struct { + Duration ModifyFieldInfoType `json:"duration"` + OMLevel ModifyFieldInfoType `json:"om_level"` } -func main() { - g.Redis().SetMaxActive(2) - //g.Redis().SetMaxIdle(100) - GetList() +type MediaRequestModifyInfo struct { + Modify ModifyFieldInfosType `json:"modifyFieldInfos"` + Field ModifyFieldInfosType `json:"fieldInfos"` + FeedID string `json:"feed_id"` + Vid string `json:"id"` +} + +var processQueue chan MediaRequestModifyInfo + +func main() { + + jsonContent := `{"dataSetId":2001,"fieldInfos":{"duration":{"id":80079,"value":"59"},"om_level":{"id":2409,"value":"4"}},"id":"g0936lt1u0f","modifyFieldInfos":{"om_level":{"id":2409,"new":"4","old":""}},"timeStamp":1584599734}` + var t MediaRequestModifyInfo + err := gjson.DecodeTo(jsonContent, &t) + fmt.Println(err) + fmt.Printf("%+v\n", t) + fmt.Println(gjson.New(t).MustToJsonString()) + + b, _ := json.Marshal(t) + fmt.Println(string(b)) } diff --git a/container/garray/garray_z_unit_all_basic_test.go b/container/garray/garray_z_unit_all_basic_test.go index 2b6b26a9d..af6e56837 100644 --- a/container/garray/garray_z_unit_all_basic_test.go +++ b/container/garray/garray_z_unit_all_basic_test.go @@ -22,7 +22,7 @@ func Test_IntArray_Unique(t *testing.T) { array := garray.NewIntArray() array.Append(1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6) array.Unique() - gtest.Assert(array.Slice(), expect) + t.Assert(array.Slice(), expect) } func Test_SortedIntArray1(t *testing.T) { @@ -31,8 +31,8 @@ func Test_SortedIntArray1(t *testing.T) { for i := 10; i > -1; i-- { array.Add(i) } - gtest.Assert(array.Slice(), expect) - gtest.Assert(array.Add().Slice(), expect) + t.Assert(array.Slice(), expect) + t.Assert(array.Add().Slice(), expect) } func Test_SortedIntArray2(t *testing.T) { @@ -41,7 +41,7 @@ func Test_SortedIntArray2(t *testing.T) { for i := 0; i <= 10; i++ { array.Add(i) } - gtest.Assert(array.Slice(), expect) + t.Assert(array.Slice(), expect) } func Test_SortedStrArray1(t *testing.T) { @@ -52,8 +52,8 @@ func Test_SortedStrArray1(t *testing.T) { array1.Add(gconv.String(i)) array2.Add(gconv.String(i)) } - gtest.Assert(array1.Slice(), expect) - gtest.Assert(array2.Slice(), expect) + t.Assert(array1.Slice(), expect) + t.Assert(array2.Slice(), expect) } @@ -63,9 +63,9 @@ func Test_SortedStrArray2(t *testing.T) { for i := 0; i <= 10; i++ { array.Add(gconv.String(i)) } - gtest.Assert(array.Slice(), expect) + t.Assert(array.Slice(), expect) array.Add() - gtest.Assert(array.Slice(), expect) + t.Assert(array.Slice(), expect) } func Test_SortedArray1(t *testing.T) { @@ -76,7 +76,7 @@ func Test_SortedArray1(t *testing.T) { for i := 10; i > -1; i-- { array.Add(gconv.String(i)) } - gtest.Assert(array.Slice(), expect) + t.Assert(array.Slice(), expect) } func Test_SortedArray2(t *testing.T) { @@ -90,17 +90,17 @@ func Test_SortedArray2(t *testing.T) { array.Add(gconv.String(i)) array2.Add(gconv.String(i)) } - gtest.Assert(array.Slice(), expect) - gtest.Assert(array.Add().Slice(), expect) - gtest.Assert(array2.Slice(), expect) + t.Assert(array.Slice(), expect) + t.Assert(array.Add().Slice(), expect) + t.Assert(array2.Slice(), expect) } func TestNewFromCopy(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"100", "200", "300", "400", "500", "600"} array1 := garray.NewFromCopy(a1) - gtest.AssertIN(array1.PopRands(2), a1) - gtest.Assert(len(array1.PopRands(1)), 1) - gtest.Assert(len(array1.PopRands(9)), 3) + t.AssertIN(array1.PopRands(2), a1) + t.Assert(len(array1.PopRands(1)), 1) + t.Assert(len(array1.PopRands(9)), 3) }) } diff --git a/container/garray/garray_z_unit_normal_any_array_test.go b/container/garray/garray_z_unit_normal_any_array_test.go index 6fda1f5ea..b656ad4fb 100644 --- a/container/garray/garray_z_unit_normal_any_array_test.go +++ b/container/garray/garray_z_unit_normal_any_array_test.go @@ -20,41 +20,41 @@ import ( ) func Test_Array_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []interface{}{0, 1, 2, 3} array := garray.NewArrayFrom(expect) array2 := garray.NewArrayFrom(expect) array3 := garray.NewArrayFrom([]interface{}{}) - gtest.Assert(array.Slice(), expect) - gtest.Assert(array.Interfaces(), expect) + t.Assert(array.Slice(), expect) + t.Assert(array.Interfaces(), expect) array.Set(0, 100) - gtest.Assert(array.Get(0), 100) - gtest.Assert(array.Get(1), 1) - gtest.Assert(array.Search(100), 0) - gtest.Assert(array3.Search(100), -1) - gtest.Assert(array.Contains(100), true) - gtest.Assert(array.Remove(0), 100) - gtest.Assert(array.Remove(-1), nil) - gtest.Assert(array.Remove(100000), nil) + t.Assert(array.Get(0), 100) + t.Assert(array.Get(1), 1) + t.Assert(array.Search(100), 0) + t.Assert(array3.Search(100), -1) + t.Assert(array.Contains(100), true) + t.Assert(array.Remove(0), 100) + t.Assert(array.Remove(-1), nil) + t.Assert(array.Remove(100000), nil) - gtest.Assert(array2.Remove(3), 3) - gtest.Assert(array2.Remove(1), 1) + t.Assert(array2.Remove(3), 3) + t.Assert(array2.Remove(1), 1) - gtest.Assert(array.Contains(100), false) + t.Assert(array.Contains(100), false) array.Append(4) - gtest.Assert(array.Len(), 4) + t.Assert(array.Len(), 4) array.InsertBefore(0, 100) array.InsertAfter(0, 200) - gtest.Assert(array.Slice(), []interface{}{100, 200, 2, 2, 3, 4}) + t.Assert(array.Slice(), []interface{}{100, 200, 2, 2, 3, 4}) array.InsertBefore(5, 300) array.InsertAfter(6, 400) - gtest.Assert(array.Slice(), []interface{}{100, 200, 2, 2, 3, 300, 4, 400}) - gtest.Assert(array.Clear().Len(), 0) + t.Assert(array.Slice(), []interface{}{100, 200, 2, 2, 3, 300, 4, 400}) + t.Assert(array.Clear().Len(), 0) }) } func TestArray_Sort(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect1 := []interface{}{0, 1, 2, 3} expect2 := []interface{}{3, 2, 1, 0} array := garray.NewArray() @@ -64,78 +64,78 @@ func TestArray_Sort(t *testing.T) { array.SortFunc(func(v1, v2 interface{}) bool { return v1.(int) < v2.(int) }) - gtest.Assert(array.Slice(), expect1) + t.Assert(array.Slice(), expect1) array.SortFunc(func(v1, v2 interface{}) bool { return v1.(int) > v2.(int) }) - gtest.Assert(array.Slice(), expect2) + t.Assert(array.Slice(), expect2) }) } func TestArray_Unique(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []interface{}{1, 1, 2, 3} array := garray.NewArrayFrom(expect) - gtest.Assert(array.Unique().Slice(), []interface{}{1, 2, 3}) + t.Assert(array.Unique().Slice(), []interface{}{1, 2, 3}) }) } func TestArray_PushAndPop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []interface{}{0, 1, 2, 3} array := garray.NewArrayFrom(expect) - gtest.Assert(array.Slice(), expect) - gtest.Assert(array.PopLeft(), 0) - gtest.Assert(array.PopRight(), 3) - gtest.AssertIN(array.PopRand(), []interface{}{1, 2}) - gtest.AssertIN(array.PopRand(), []interface{}{1, 2}) - gtest.Assert(array.Len(), 0) + t.Assert(array.Slice(), expect) + t.Assert(array.PopLeft(), 0) + t.Assert(array.PopRight(), 3) + t.AssertIN(array.PopRand(), []interface{}{1, 2}) + t.AssertIN(array.PopRand(), []interface{}{1, 2}) + t.Assert(array.Len(), 0) array.PushLeft(1).PushRight(2) - gtest.Assert(array.Slice(), []interface{}{1, 2}) + t.Assert(array.Slice(), []interface{}{1, 2}) }) } func TestArray_PopRands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{100, 200, 300, 400, 500, 600} array := garray.NewFromCopy(a1) - gtest.AssertIN(array.PopRands(2), []interface{}{100, 200, 300, 400, 500, 600}) + t.AssertIN(array.PopRands(2), []interface{}{100, 200, 300, 400, 500, 600}) }) } func TestArray_PopLeftsAndPopRights(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value1 := []interface{}{0, 1, 2, 3, 4, 5, 6} value2 := []interface{}{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(value1) array2 := garray.NewArrayFrom(value2) - gtest.Assert(array1.PopLefts(2), []interface{}{0, 1}) - gtest.Assert(array1.Slice(), []interface{}{2, 3, 4, 5, 6}) - gtest.Assert(array1.PopRights(2), []interface{}{5, 6}) - gtest.Assert(array1.Slice(), []interface{}{2, 3, 4}) - gtest.Assert(array1.PopRights(20), []interface{}{2, 3, 4}) - gtest.Assert(array1.Slice(), []interface{}{}) - gtest.Assert(array2.PopLefts(20), []interface{}{0, 1, 2, 3, 4, 5, 6}) - gtest.Assert(array2.Slice(), []interface{}{}) + t.Assert(array1.PopLefts(2), []interface{}{0, 1}) + t.Assert(array1.Slice(), []interface{}{2, 3, 4, 5, 6}) + t.Assert(array1.PopRights(2), []interface{}{5, 6}) + t.Assert(array1.Slice(), []interface{}{2, 3, 4}) + t.Assert(array1.PopRights(20), []interface{}{2, 3, 4}) + t.Assert(array1.Slice(), []interface{}{}) + t.Assert(array2.PopLefts(20), []interface{}{0, 1, 2, 3, 4, 5, 6}) + t.Assert(array2.Slice(), []interface{}{}) }) } func TestArray_Range(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value1 := []interface{}{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(value1) array2 := garray.NewArrayFrom(value1, true) - gtest.Assert(array1.Range(0, 1), []interface{}{0}) - gtest.Assert(array1.Range(1, 2), []interface{}{1}) - gtest.Assert(array1.Range(0, 2), []interface{}{0, 1}) - gtest.Assert(array1.Range(-1, 10), value1) - gtest.Assert(array1.Range(10, 2), nil) - gtest.Assert(array2.Range(1, 3), []interface{}{1, 2}) + t.Assert(array1.Range(0, 1), []interface{}{0}) + t.Assert(array1.Range(1, 2), []interface{}{1}) + t.Assert(array1.Range(0, 2), []interface{}{0, 1}) + t.Assert(array1.Range(-1, 10), value1) + t.Assert(array1.Range(10, 2), nil) + t.Assert(array2.Range(1, 3), []interface{}{1, 2}) }) } func TestArray_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { func1 := func(v1, v2 interface{}) int { if gconv.Int(v1) < gconv.Int(v2) { return 0 @@ -147,7 +147,7 @@ func TestArray_Merge(t *testing.T) { i2 := []interface{}{4, 5, 6, 7} array1 := garray.NewArrayFrom(i1) array2 := garray.NewArrayFrom(i2) - gtest.Assert(array1.Merge(array2).Slice(), []interface{}{0, 1, 2, 3, 4, 5, 6, 7}) + t.Assert(array1.Merge(array2).Slice(), []interface{}{0, 1, 2, 3, 4, 5, 6, 7}) //s1 := []string{"a", "b", "c", "d"} s2 := []string{"e", "f"} @@ -159,185 +159,185 @@ func TestArray_Merge(t *testing.T) { s6 := garray.NewSortedIntArrayFrom([]int{1, 2, 3}) a1 := garray.NewArrayFrom(i1) - gtest.Assert(a1.Merge(s2).Len(), 6) - gtest.Assert(a1.Merge(i3).Len(), 9) - gtest.Assert(a1.Merge(i4).Len(), 10) - gtest.Assert(a1.Merge(s3).Len(), 12) - gtest.Assert(a1.Merge(s4).Len(), 14) - gtest.Assert(a1.Merge(s5).Len(), 16) - gtest.Assert(a1.Merge(s6).Len(), 19) + t.Assert(a1.Merge(s2).Len(), 6) + t.Assert(a1.Merge(i3).Len(), 9) + t.Assert(a1.Merge(i4).Len(), 10) + t.Assert(a1.Merge(s3).Len(), 12) + t.Assert(a1.Merge(s4).Len(), 14) + t.Assert(a1.Merge(s5).Len(), 16) + t.Assert(a1.Merge(s6).Len(), 19) }) } func TestArray_Fill(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0} a2 := []interface{}{0} array1 := garray.NewArrayFrom(a1) array2 := garray.NewArrayFrom(a2, true) - gtest.Assert(array1.Fill(1, 2, 100).Slice(), []interface{}{0, 100, 100}) - gtest.Assert(array2.Fill(0, 2, 100).Slice(), []interface{}{100, 100}) - gtest.Assert(array2.Fill(-1, 2, 100).Slice(), []interface{}{100, 100}) + t.Assert(array1.Fill(1, 2, 100).Slice(), []interface{}{0, 100, 100}) + t.Assert(array2.Fill(0, 2, 100).Slice(), []interface{}{100, 100}) + t.Assert(array2.Fill(-1, 2, 100).Slice(), []interface{}{100, 100}) }) } func TestArray_Chunk(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{1, 2, 3, 4, 5} array1 := garray.NewArrayFrom(a1) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []interface{}{1, 2}) - gtest.Assert(chunks[1], []interface{}{3, 4}) - gtest.Assert(chunks[2], []interface{}{5}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []interface{}{1, 2}) + t.Assert(chunks[1], []interface{}{3, 4}) + t.Assert(chunks[2], []interface{}{5}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{1, 2, 3, 4, 5} array1 := garray.NewArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []interface{}{1, 2, 3}) - gtest.Assert(chunks[1], []interface{}{4, 5}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []interface{}{1, 2, 3}) + t.Assert(chunks[1], []interface{}{4, 5}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(a1) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []interface{}{1, 2}) - gtest.Assert(chunks[1], []interface{}{3, 4}) - gtest.Assert(chunks[2], []interface{}{5, 6}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []interface{}{1, 2}) + t.Assert(chunks[1], []interface{}{3, 4}) + t.Assert(chunks[2], []interface{}{5, 6}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []interface{}{1, 2, 3}) - gtest.Assert(chunks[1], []interface{}{4, 5, 6}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []interface{}{1, 2, 3}) + t.Assert(chunks[1], []interface{}{4, 5, 6}) + t.Assert(array1.Chunk(0), nil) }) } func TestArray_Pad(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0} array1 := garray.NewArrayFrom(a1) - gtest.Assert(array1.Pad(3, 1).Slice(), []interface{}{0, 1, 1}) - gtest.Assert(array1.Pad(-4, 1).Slice(), []interface{}{1, 0, 1, 1}) - gtest.Assert(array1.Pad(3, 1).Slice(), []interface{}{1, 0, 1, 1}) + t.Assert(array1.Pad(3, 1).Slice(), []interface{}{0, 1, 1}) + t.Assert(array1.Pad(-4, 1).Slice(), []interface{}{1, 0, 1, 1}) + t.Assert(array1.Pad(3, 1).Slice(), []interface{}{1, 0, 1, 1}) }) } func TestArray_SubSlice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(a1) array2 := garray.NewArrayFrom(a1, true) - gtest.Assert(array1.SubSlice(0, 2), []interface{}{0, 1}) - gtest.Assert(array1.SubSlice(2, 2), []interface{}{2, 3}) - gtest.Assert(array1.SubSlice(5, 8), []interface{}{5, 6}) - gtest.Assert(array1.SubSlice(9, 1), nil) - gtest.Assert(array1.SubSlice(-2, 2), []interface{}{5, 6}) - gtest.Assert(array1.SubSlice(-9, 2), nil) - gtest.Assert(array1.SubSlice(1, -2), nil) - gtest.Assert(array2.SubSlice(0, 2), []interface{}{0, 1}) + t.Assert(array1.SubSlice(0, 2), []interface{}{0, 1}) + t.Assert(array1.SubSlice(2, 2), []interface{}{2, 3}) + t.Assert(array1.SubSlice(5, 8), []interface{}{5, 6}) + t.Assert(array1.SubSlice(9, 1), nil) + t.Assert(array1.SubSlice(-2, 2), []interface{}{5, 6}) + t.Assert(array1.SubSlice(-9, 2), nil) + t.Assert(array1.SubSlice(1, -2), nil) + t.Assert(array2.SubSlice(0, 2), []interface{}{0, 1}) }) } func TestArray_Rand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(a1) - gtest.Assert(len(array1.Rands(2)), 2) - gtest.Assert(len(array1.Rands(10)), 7) - gtest.AssertIN(array1.Rands(1)[0], a1) + t.Assert(len(array1.Rands(2)), 2) + t.Assert(len(array1.Rands(10)), 7) + t.AssertIN(array1.Rands(1)[0], a1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []interface{}{"a", "b", "c", "d"} a1 := garray.NewArrayFrom(s1) i1 := a1.Rand() - gtest.Assert(a1.Contains(i1), true) - gtest.Assert(a1.Len(), 4) + t.Assert(a1.Contains(i1), true) + t.Assert(a1.Len(), 4) }) } func TestArray_Shuffle(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(a1) - gtest.Assert(array1.Shuffle().Len(), 7) + t.Assert(array1.Shuffle().Len(), 7) }) } func TestArray_Reverse(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(a1) - gtest.Assert(array1.Reverse().Slice(), []interface{}{6, 5, 4, 3, 2, 1, 0}) + t.Assert(array1.Reverse().Slice(), []interface{}{6, 5, 4, 3, 2, 1, 0}) }) } func TestArray_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(a1) - gtest.Assert(array1.Join("."), `0.1.2.3.4.5.6`) + t.Assert(array1.Join("."), `0.1.2.3.4.5.6`) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, `"a"`, `\a`} array1 := garray.NewArrayFrom(a1) - gtest.Assert(array1.Join("."), `0.1."a".\a`) + t.Assert(array1.Join("."), `0.1."a".\a`) }) } func TestArray_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewArrayFrom(a1) - gtest.Assert(array1.String(), `[0,1,2,3,4,5,6]`) + t.Assert(array1.String(), `[0,1,2,3,4,5,6]`) }) } func TestArray_Replace(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3, 4, 5, 6} a2 := []interface{}{"a", "b", "c"} a3 := []interface{}{"m", "n", "p", "z", "x", "y", "d", "u"} array1 := garray.NewArrayFrom(a1) array2 := array1.Replace(a2) - gtest.Assert(array2.Len(), 7) - gtest.Assert(array2.Contains("b"), true) - gtest.Assert(array2.Contains(4), true) - gtest.Assert(array2.Contains("v"), false) + t.Assert(array2.Len(), 7) + t.Assert(array2.Contains("b"), true) + t.Assert(array2.Contains(4), true) + t.Assert(array2.Contains("v"), false) array3 := array1.Replace(a3) - gtest.Assert(array3.Len(), 7) - gtest.Assert(array3.Contains(4), false) - gtest.Assert(array3.Contains("p"), true) - gtest.Assert(array3.Contains("u"), false) + t.Assert(array3.Len(), 7) + t.Assert(array3.Contains(4), false) + t.Assert(array3.Contains("p"), true) + t.Assert(array3.Contains("u"), false) }) } func TestArray_SetArray(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3, 4, 5, 6} a2 := []interface{}{"a", "b", "c"} array1 := garray.NewArrayFrom(a1) array1 = array1.SetArray(a2) - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1.Contains("b"), true) - gtest.Assert(array1.Contains("5"), false) + t.Assert(array1.Len(), 3) + t.Assert(array1.Contains("b"), true) + t.Assert(array1.Contains("5"), false) }) } func TestArray_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3} a2 := []interface{}{"a", "b", "c"} a3 := []interface{}{"a", "1", "2"} @@ -346,39 +346,39 @@ func TestArray_Sum(t *testing.T) { array2 := garray.NewArrayFrom(a2) array3 := garray.NewArrayFrom(a3) - gtest.Assert(array1.Sum(), 6) - gtest.Assert(array2.Sum(), 0) - gtest.Assert(array3.Sum(), 3) + t.Assert(array1.Sum(), 6) + t.Assert(array2.Sum(), 0) + t.Assert(array3.Sum(), 3) }) } func TestArray_Clone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, 2, 3} array1 := garray.NewArrayFrom(a1) array2 := array1.Clone() - gtest.Assert(array1.Len(), 4) - gtest.Assert(array2.Sum(), 6) - gtest.AssertEQ(array1, array2) + t.Assert(array1.Len(), 4) + t.Assert(array2.Sum(), 6) + t.AssertEQ(array1, array2) }) } func TestArray_CountValues(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "b", "c", "d", "e", "d"} array1 := garray.NewArrayFrom(a1) array2 := array1.CountValues() - gtest.Assert(len(array2), 5) - gtest.Assert(array2["b"], 1) - gtest.Assert(array2["d"], 2) + t.Assert(len(array2), 5) + t.Assert(array2["b"], 1) + t.Assert(array2["d"], 2) }) } func TestArray_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []interface{}{"a", "b", "c", "d"} a1 := garray.NewArrayFrom(s1, true) @@ -404,13 +404,13 @@ func TestArray_LockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 - gtest.Assert(a1.Contains("g"), true) + t.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 + t.Assert(a1.Contains("g"), true) }) } func TestArray_RLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []interface{}{"a", "b", "c", "d"} a1 := garray.NewArrayFrom(s1, true) @@ -436,32 +436,32 @@ func TestArray_RLockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 - gtest.Assert(a1.Contains("g"), true) + t.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 + t.Assert(a1.Contains("g"), true) }) } func TestArray_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []interface{}{"a", "b", "d", "c"} a1 := garray.NewArrayFrom(s1) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(b1, b2) - gtest.Assert(err1, err2) + t.Assert(b1, b2) + t.Assert(err1, err2) a2 := garray.New() err2 = json.Unmarshal(b2, &a2) - gtest.Assert(err2, nil) - gtest.Assert(a2.Slice(), s1) + t.Assert(err2, nil) + t.Assert(a2.Slice(), s1) var a3 garray.Array err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a3.Slice(), s1) + t.Assert(err, nil) + t.Assert(a3.Slice(), s1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Name string Scores *garray.Array @@ -471,72 +471,72 @@ func TestArray_Json(t *testing.T) { "Scores": []int{99, 100, 98}, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) user := new(User) err = json.Unmarshal(b, user) - gtest.Assert(err, nil) - gtest.Assert(user.Name, data["Name"]) - gtest.Assert(user.Scores, data["Scores"]) + t.Assert(err, nil) + t.Assert(user.Name, data["Name"]) + t.Assert(user.Scores, data["Scores"]) }) } func TestArray_Iterator(t *testing.T) { slice := g.Slice{"a", "b", "d", "c"} array := garray.NewArrayFrom(slice) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.Iterator(func(k int, v interface{}) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorAsc(func(k int, v interface{}) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorDesc(func(k int, v interface{}) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.Iterator(func(k int, v interface{}) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorAsc(func(k int, v interface{}) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorDesc(func(k int, v interface{}) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) } func TestArray_RemoveValue(t *testing.T) { slice := g.Slice{"a", "b", "d", "c"} array := garray.NewArrayFrom(slice) - gtest.Case(t, func() { - gtest.Assert(array.RemoveValue("e"), false) - gtest.Assert(array.RemoveValue("b"), true) - gtest.Assert(array.RemoveValue("a"), true) - gtest.Assert(array.RemoveValue("c"), true) - gtest.Assert(array.RemoveValue("f"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(array.RemoveValue("e"), false) + t.Assert(array.RemoveValue("b"), true) + t.Assert(array.RemoveValue("a"), true) + t.Assert(array.RemoveValue("c"), true) + t.Assert(array.RemoveValue("f"), false) }) } @@ -546,48 +546,48 @@ func TestArray_UnmarshalValue(t *testing.T) { Array *garray.Array } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`[1,2,3]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": g.Slice{1, 2, 3}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) }) } func TestArray_FilterNil(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { values := g.Slice{0, 1, 2, 3, 4, "", g.Slice{}} array := garray.NewArrayFromCopy(values) - gtest.Assert(array.FilterNil().Slice(), values) + t.Assert(array.FilterNil().Slice(), values) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewArrayFromCopy(g.Slice{nil, 1, 2, 3, 4, nil}) - gtest.Assert(array.FilterNil(), g.Slice{1, 2, 3, 4}) + t.Assert(array.FilterNil(), g.Slice{1, 2, 3, 4}) }) } func TestArray_FilterEmpty(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewArrayFrom(g.Slice{0, 1, 2, 3, 4, "", g.Slice{}}) - gtest.Assert(array.FilterEmpty(), g.Slice{1, 2, 3, 4}) + t.Assert(array.FilterEmpty(), g.Slice{1, 2, 3, 4}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewArrayFrom(g.Slice{1, 2, 3, 4}) - gtest.Assert(array.FilterEmpty(), g.Slice{1, 2, 3, 4}) + t.Assert(array.FilterEmpty(), g.Slice{1, 2, 3, 4}) }) } diff --git a/container/garray/garray_z_unit_normal_int_array_test.go b/container/garray/garray_z_unit_normal_int_array_test.go index 2cf7285a7..db9bff224 100644 --- a/container/garray/garray_z_unit_normal_int_array_test.go +++ b/container/garray/garray_z_unit_normal_int_array_test.go @@ -21,37 +21,37 @@ import ( ) func Test_IntArray_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []int{0, 1, 2, 3} expect2 := []int{} array := garray.NewIntArrayFrom(expect) array2 := garray.NewIntArrayFrom(expect2) - gtest.Assert(array.Slice(), expect) - gtest.Assert(array.Interfaces(), expect) + t.Assert(array.Slice(), expect) + t.Assert(array.Interfaces(), expect) array.Set(0, 100) - gtest.Assert(array.Get(0), 100) - gtest.Assert(array.Get(1), 1) - gtest.Assert(array.Search(100), 0) - gtest.Assert(array2.Search(100), -1) - gtest.Assert(array.Contains(100), true) - gtest.Assert(array.Remove(0), 100) - gtest.Assert(array.Remove(-1), 0) - gtest.Assert(array.Remove(100000), 0) - gtest.Assert(array.Contains(100), false) + t.Assert(array.Get(0), 100) + t.Assert(array.Get(1), 1) + t.Assert(array.Search(100), 0) + t.Assert(array2.Search(100), -1) + t.Assert(array.Contains(100), true) + t.Assert(array.Remove(0), 100) + t.Assert(array.Remove(-1), 0) + t.Assert(array.Remove(100000), 0) + t.Assert(array.Contains(100), false) array.Append(4) - gtest.Assert(array.Len(), 4) + t.Assert(array.Len(), 4) array.InsertBefore(0, 100) array.InsertAfter(0, 200) - gtest.Assert(array.Slice(), []int{100, 200, 1, 2, 3, 4}) + t.Assert(array.Slice(), []int{100, 200, 1, 2, 3, 4}) array.InsertBefore(5, 300) array.InsertAfter(6, 400) - gtest.Assert(array.Slice(), []int{100, 200, 1, 2, 3, 300, 4, 400}) - gtest.Assert(array.Clear().Len(), 0) + t.Assert(array.Slice(), []int{100, 200, 1, 2, 3, 300, 4, 400}) + t.Assert(array.Clear().Len(), 0) }) } func TestIntArray_Sort(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect1 := []int{0, 1, 2, 3} expect2 := []int{3, 2, 1, 0} array := garray.NewIntArray() @@ -61,69 +61,69 @@ func TestIntArray_Sort(t *testing.T) { array2.Append(i) } array.Sort() - gtest.Assert(array.Slice(), expect1) + t.Assert(array.Slice(), expect1) array.Sort(true) - gtest.Assert(array.Slice(), expect2) - gtest.Assert(array2.Slice(), expect2) + t.Assert(array.Slice(), expect2) + t.Assert(array2.Slice(), expect2) }) } func TestIntArray_Unique(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []int{1, 1, 2, 3} array := garray.NewIntArrayFrom(expect) - gtest.Assert(array.Unique().Slice(), []int{1, 2, 3}) + t.Assert(array.Unique().Slice(), []int{1, 2, 3}) }) } func TestIntArray_PushAndPop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []int{0, 1, 2, 3} array := garray.NewIntArrayFrom(expect) - gtest.Assert(array.Slice(), expect) - gtest.Assert(array.PopLeft(), 0) - gtest.Assert(array.PopRight(), 3) - gtest.AssertIN(array.PopRand(), []int{1, 2}) - gtest.AssertIN(array.PopRand(), []int{1, 2}) - gtest.Assert(array.Len(), 0) + t.Assert(array.Slice(), expect) + t.Assert(array.PopLeft(), 0) + t.Assert(array.PopRight(), 3) + t.AssertIN(array.PopRand(), []int{1, 2}) + t.AssertIN(array.PopRand(), []int{1, 2}) + t.Assert(array.Len(), 0) array.PushLeft(1).PushRight(2) - gtest.Assert(array.Slice(), []int{1, 2}) + t.Assert(array.Slice(), []int{1, 2}) }) } func TestIntArray_PopLeftsAndPopRights(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value1 := []int{0, 1, 2, 3, 4, 5, 6} value2 := []int{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(value1) array2 := garray.NewIntArrayFrom(value2) - gtest.Assert(array1.PopLefts(2), []int{0, 1}) - gtest.Assert(array1.Slice(), []int{2, 3, 4, 5, 6}) - gtest.Assert(array1.PopRights(2), []int{5, 6}) - gtest.Assert(array1.Slice(), []int{2, 3, 4}) - gtest.Assert(array1.PopRights(20), []int{2, 3, 4}) - gtest.Assert(array1.Slice(), []int{}) - gtest.Assert(array2.PopLefts(20), []int{0, 1, 2, 3, 4, 5, 6}) - gtest.Assert(array2.Slice(), []int{}) + t.Assert(array1.PopLefts(2), []int{0, 1}) + t.Assert(array1.Slice(), []int{2, 3, 4, 5, 6}) + t.Assert(array1.PopRights(2), []int{5, 6}) + t.Assert(array1.Slice(), []int{2, 3, 4}) + t.Assert(array1.PopRights(20), []int{2, 3, 4}) + t.Assert(array1.Slice(), []int{}) + t.Assert(array2.PopLefts(20), []int{0, 1, 2, 3, 4, 5, 6}) + t.Assert(array2.Slice(), []int{}) }) } func TestIntArray_Range(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value1 := []int{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(value1) array2 := garray.NewIntArrayFrom(value1, true) - gtest.Assert(array1.Range(0, 1), []int{0}) - gtest.Assert(array1.Range(1, 2), []int{1}) - gtest.Assert(array1.Range(0, 2), []int{0, 1}) - gtest.Assert(array1.Range(10, 2), nil) - gtest.Assert(array1.Range(-1, 10), value1) - gtest.Assert(array2.Range(1, 2), []int{1}) + t.Assert(array1.Range(0, 1), []int{0}) + t.Assert(array1.Range(1, 2), []int{1}) + t.Assert(array1.Range(0, 2), []int{0, 1}) + t.Assert(array1.Range(10, 2), nil) + t.Assert(array1.Range(-1, 10), value1) + t.Assert(array2.Range(1, 2), []int{1}) }) } func TestIntArray_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { func1 := func(v1, v2 interface{}) int { if gconv.Int(v1) < gconv.Int(v2) { return 0 @@ -147,260 +147,260 @@ func TestIntArray_Merge(t *testing.T) { a7 := garray.NewSortedStrArrayFrom(s1) a8 := garray.NewSortedArrayFrom([]interface{}{4, 5}, func1) - gtest.Assert(a1.Merge(a2).Slice(), []int{0, 1, 2, 3, 4, 5, 6, 7}) - gtest.Assert(a1.Merge(a3).Len(), 10) - gtest.Assert(a1.Merge(a4).Len(), 13) - gtest.Assert(a1.Merge(a5).Len(), 15) - gtest.Assert(a1.Merge(a6).Len(), 18) - gtest.Assert(a1.Merge(a7).Len(), 21) - gtest.Assert(a1.Merge(a8).Len(), 23) + t.Assert(a1.Merge(a2).Slice(), []int{0, 1, 2, 3, 4, 5, 6, 7}) + t.Assert(a1.Merge(a3).Len(), 10) + t.Assert(a1.Merge(a4).Len(), 13) + t.Assert(a1.Merge(a5).Len(), 15) + t.Assert(a1.Merge(a6).Len(), 18) + t.Assert(a1.Merge(a7).Len(), 21) + t.Assert(a1.Merge(a8).Len(), 23) }) } func TestIntArray_Fill(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0} a2 := []int{0} array1 := garray.NewIntArrayFrom(a1) array2 := garray.NewIntArrayFrom(a2) - gtest.Assert(array1.Fill(1, 2, 100).Slice(), []int{0, 100, 100}) - gtest.Assert(array2.Fill(0, 2, 100).Slice(), []int{100, 100}) - gtest.Assert(array2.Fill(-1, 2, 100).Slice(), []int{100, 100}) + t.Assert(array1.Fill(1, 2, 100).Slice(), []int{0, 100, 100}) + t.Assert(array2.Fill(0, 2, 100).Slice(), []int{100, 100}) + t.Assert(array2.Fill(-1, 2, 100).Slice(), []int{100, 100}) }) } func TestIntArray_Chunk(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5} array1 := garray.NewIntArrayFrom(a1) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []int{1, 2}) - gtest.Assert(chunks[1], []int{3, 4}) - gtest.Assert(chunks[2], []int{5}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []int{1, 2}) + t.Assert(chunks[1], []int{3, 4}) + t.Assert(chunks[2], []int{5}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5} array1 := garray.NewIntArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []int{1, 2, 3}) - gtest.Assert(chunks[1], []int{4, 5}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []int{1, 2, 3}) + t.Assert(chunks[1], []int{4, 5}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(a1) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []int{1, 2}) - gtest.Assert(chunks[1], []int{3, 4}) - gtest.Assert(chunks[2], []int{5, 6}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []int{1, 2}) + t.Assert(chunks[1], []int{3, 4}) + t.Assert(chunks[2], []int{5, 6}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []int{1, 2, 3}) - gtest.Assert(chunks[1], []int{4, 5, 6}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []int{1, 2, 3}) + t.Assert(chunks[1], []int{4, 5, 6}) + t.Assert(array1.Chunk(0), nil) }) } func TestIntArray_Pad(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0} array1 := garray.NewIntArrayFrom(a1) - gtest.Assert(array1.Pad(3, 1).Slice(), []int{0, 1, 1}) - gtest.Assert(array1.Pad(-4, 1).Slice(), []int{1, 0, 1, 1}) - gtest.Assert(array1.Pad(3, 1).Slice(), []int{1, 0, 1, 1}) + t.Assert(array1.Pad(3, 1).Slice(), []int{0, 1, 1}) + t.Assert(array1.Pad(-4, 1).Slice(), []int{1, 0, 1, 1}) + t.Assert(array1.Pad(3, 1).Slice(), []int{1, 0, 1, 1}) }) } func TestIntArray_SubSlice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(a1) array2 := garray.NewIntArrayFrom(a1, true) - gtest.Assert(array1.SubSlice(6), []int{6}) - gtest.Assert(array1.SubSlice(5), []int{5, 6}) - gtest.Assert(array1.SubSlice(8), nil) - gtest.Assert(array1.SubSlice(0, 2), []int{0, 1}) - gtest.Assert(array1.SubSlice(2, 2), []int{2, 3}) - gtest.Assert(array1.SubSlice(5, 8), []int{5, 6}) - gtest.Assert(array1.SubSlice(-1, 1), []int{6}) - gtest.Assert(array1.SubSlice(-1, 9), []int{6}) - gtest.Assert(array1.SubSlice(-2, 3), []int{5, 6}) - gtest.Assert(array1.SubSlice(-7, 3), []int{0, 1, 2}) - gtest.Assert(array1.SubSlice(-8, 3), nil) - gtest.Assert(array1.SubSlice(-1, -3), []int{3, 4, 5}) - gtest.Assert(array1.SubSlice(-9, 3), nil) - gtest.Assert(array1.SubSlice(1, -1), []int{0}) - gtest.Assert(array1.SubSlice(1, -3), nil) - gtest.Assert(array2.SubSlice(0, 2), []int{0, 1}) + t.Assert(array1.SubSlice(6), []int{6}) + t.Assert(array1.SubSlice(5), []int{5, 6}) + t.Assert(array1.SubSlice(8), nil) + t.Assert(array1.SubSlice(0, 2), []int{0, 1}) + t.Assert(array1.SubSlice(2, 2), []int{2, 3}) + t.Assert(array1.SubSlice(5, 8), []int{5, 6}) + t.Assert(array1.SubSlice(-1, 1), []int{6}) + t.Assert(array1.SubSlice(-1, 9), []int{6}) + t.Assert(array1.SubSlice(-2, 3), []int{5, 6}) + t.Assert(array1.SubSlice(-7, 3), []int{0, 1, 2}) + t.Assert(array1.SubSlice(-8, 3), nil) + t.Assert(array1.SubSlice(-1, -3), []int{3, 4, 5}) + t.Assert(array1.SubSlice(-9, 3), nil) + t.Assert(array1.SubSlice(1, -1), []int{0}) + t.Assert(array1.SubSlice(1, -3), nil) + t.Assert(array2.SubSlice(0, 2), []int{0, 1}) }) } func TestIntArray_Rand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(a1) - gtest.Assert(len(array1.Rands(2)), 2) - gtest.Assert(len(array1.Rands(10)), 7) - gtest.AssertIN(array1.Rands(1)[0], a1) - gtest.AssertIN(array1.Rand(), a1) + t.Assert(len(array1.Rands(2)), 2) + t.Assert(len(array1.Rands(10)), 7) + t.AssertIN(array1.Rands(1)[0], a1) + t.AssertIN(array1.Rand(), a1) }) } func TestIntArray_PopRands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{100, 200, 300, 400, 500, 600} array := garray.NewIntArrayFrom(a1) ns1 := array.PopRands(2) - gtest.AssertIN(ns1, []int{100, 200, 300, 400, 500, 600}) - gtest.Assert(len(ns1), 2) + t.AssertIN(ns1, []int{100, 200, 300, 400, 500, 600}) + t.Assert(len(ns1), 2) ns2 := array.PopRands(7) - gtest.Assert(len(ns2), 4) - gtest.AssertIN(ns2, []int{100, 200, 300, 400, 500, 600}) + t.Assert(len(ns2), 4) + t.AssertIN(ns2, []int{100, 200, 300, 400, 500, 600}) }) } func TestIntArray_Shuffle(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(a1) - gtest.Assert(array1.Shuffle().Len(), 7) + t.Assert(array1.Shuffle().Len(), 7) }) } func TestIntArray_Reverse(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(a1) - gtest.Assert(array1.Reverse().Slice(), []int{6, 5, 4, 3, 2, 1, 0}) + t.Assert(array1.Reverse().Slice(), []int{6, 5, 4, 3, 2, 1, 0}) }) } func TestIntArray_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(a1) - gtest.Assert(array1.Join("."), "0.1.2.3.4.5.6") + t.Assert(array1.Join("."), "0.1.2.3.4.5.6") }) } func TestIntArray_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 1, 2, 3, 4, 5, 6} array1 := garray.NewIntArrayFrom(a1) - gtest.Assert(array1.String(), "[0,1,2,3,4,5,6]") + t.Assert(array1.String(), "[0,1,2,3,4,5,6]") }) } func TestIntArray_SetArray(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5} a2 := []int{6, 7} array1 := garray.NewIntArrayFrom(a1) array1.SetArray(a2) - gtest.Assert(array1.Len(), 2) - gtest.Assert(array1, []int{6, 7}) + t.Assert(array1.Len(), 2) + t.Assert(array1, []int{6, 7}) }) } func TestIntArray_Replace(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5} a2 := []int{6, 7} a3 := []int{9, 10, 11, 12, 13} array1 := garray.NewIntArrayFrom(a1) array1.Replace(a2) - gtest.Assert(array1, []int{6, 7, 3, 5}) + t.Assert(array1, []int{6, 7, 3, 5}) array1.Replace(a3) - gtest.Assert(array1, []int{9, 10, 11, 12}) + t.Assert(array1, []int{9, 10, 11, 12}) }) } func TestIntArray_Clear(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5} array1 := garray.NewIntArrayFrom(a1) array1.Clear() - gtest.Assert(array1.Len(), 0) + t.Assert(array1.Len(), 0) }) } func TestIntArray_Clone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5} array1 := garray.NewIntArrayFrom(a1) array2 := array1.Clone() - gtest.Assert(array1, array2) + t.Assert(array1, array2) }) } func TestArray_Get(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5} array1 := garray.NewIntArrayFrom(a1) - gtest.Assert(array1.Get(2), 3) - gtest.Assert(array1.Len(), 4) + t.Assert(array1.Get(2), 3) + t.Assert(array1.Len(), 4) }) } func TestIntArray_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5} array1 := garray.NewIntArrayFrom(a1) - gtest.Assert(array1.Sum(), 11) + t.Assert(array1.Sum(), 11) }) } func TestIntArray_CountValues(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5, 3} array1 := garray.NewIntArrayFrom(a1) m1 := array1.CountValues() - gtest.Assert(len(m1), 4) - gtest.Assert(m1[1], 1) - gtest.Assert(m1[3], 2) + t.Assert(len(m1), 4) + t.Assert(m1[1], 1) + t.Assert(m1[3], 2) }) } func TestNewIntArrayFromCopy(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5, 3} array1 := garray.NewIntArrayFromCopy(a1) - gtest.Assert(array1.Len(), 5) - gtest.Assert(array1, a1) + t.Assert(array1.Len(), 5) + t.Assert(array1, a1) }) } func TestIntArray_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 5, 4} array1 := garray.NewIntArrayFrom(a1) n1 := array1.Remove(1) - gtest.Assert(n1, 2) - gtest.Assert(array1.Len(), 4) + t.Assert(n1, 2) + t.Assert(array1.Len(), 4) n1 = array1.Remove(0) - gtest.Assert(n1, 1) - gtest.Assert(array1.Len(), 3) + t.Assert(n1, 1) + t.Assert(array1.Len(), 3) n1 = array1.Remove(2) - gtest.Assert(n1, 4) - gtest.Assert(array1.Len(), 2) + t.Assert(n1, 4) + t.Assert(array1.Len(), 2) }) } func TestIntArray_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []int{1, 2, 3, 4} a1 := garray.NewIntArrayFrom(s1, true) @@ -426,26 +426,26 @@ func TestIntArray_LockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 - gtest.Assert(a1.Contains(6), true) + t.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 + t.Assert(a1.Contains(6), true) }) } func TestIntArray_SortFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []int{1, 4, 3, 2} a1 := garray.NewIntArrayFrom(s1) func1 := func(v1, v2 int) bool { return v1 < v2 } a11 := a1.SortFunc(func1) - gtest.Assert(a11, []int{1, 2, 3, 4}) + t.Assert(a11, []int{1, 2, 3, 4}) }) } func TestIntArray_RLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []int{1, 2, 3, 4} a1 := garray.NewIntArrayFrom(s1, true) @@ -471,31 +471,31 @@ func TestIntArray_RLockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 - gtest.Assert(a1.Contains(6), true) + t.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 + t.Assert(a1.Contains(6), true) }) } func TestIntArray_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []int{1, 4, 3, 2} a1 := garray.NewIntArrayFrom(s1) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(b1, b2) - gtest.Assert(err1, err2) + t.Assert(b1, b2) + t.Assert(err1, err2) a2 := garray.NewIntArray() err1 = json.Unmarshal(b2, &a2) - gtest.Assert(a2.Slice(), s1) + t.Assert(a2.Slice(), s1) var a3 garray.IntArray err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a3.Slice(), s1) + t.Assert(err, nil) + t.Assert(a3.Slice(), s1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Name string Scores *garray.IntArray @@ -505,73 +505,73 @@ func TestIntArray_Json(t *testing.T) { "Scores": []int{99, 100, 98}, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) user := new(User) err = json.Unmarshal(b, user) - gtest.Assert(err, nil) - gtest.Assert(user.Name, data["Name"]) - gtest.Assert(user.Scores, data["Scores"]) + t.Assert(err, nil) + t.Assert(user.Name, data["Name"]) + t.Assert(user.Scores, data["Scores"]) }) } func TestIntArray_Iterator(t *testing.T) { slice := g.SliceInt{10, 20, 30, 40} array := garray.NewIntArrayFrom(slice) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.Iterator(func(k int, v int) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorAsc(func(k int, v int) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorDesc(func(k int, v int) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.Iterator(func(k int, v int) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorAsc(func(k int, v int) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorDesc(func(k int, v int) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) } func TestIntArray_RemoveValue(t *testing.T) { slice := g.SliceInt{10, 20, 30, 40} array := garray.NewIntArrayFrom(slice) - gtest.Case(t, func() { - gtest.Assert(array.RemoveValue(99), false) - gtest.Assert(array.RemoveValue(20), true) - gtest.Assert(array.RemoveValue(10), true) - gtest.Assert(array.RemoveValue(20), false) - gtest.Assert(array.RemoveValue(88), false) - gtest.Assert(array.Len(), 2) + gtest.C(t, func(t *gtest.T) { + t.Assert(array.RemoveValue(99), false) + t.Assert(array.RemoveValue(20), true) + t.Assert(array.RemoveValue(10), true) + t.Assert(array.RemoveValue(20), false) + t.Assert(array.RemoveValue(88), false) + t.Assert(array.Len(), 2) }) } @@ -581,36 +581,36 @@ func TestIntArray_UnmarshalValue(t *testing.T) { Array *garray.IntArray } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`[1,2,3]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": g.Slice{1, 2, 3}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) }) } func TestIntArray_FilterEmpty(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewIntArrayFrom(g.SliceInt{0, 1, 2, 3, 4, 0}) - gtest.Assert(array.FilterEmpty(), g.SliceInt{1, 2, 3, 4}) + t.Assert(array.FilterEmpty(), g.SliceInt{1, 2, 3, 4}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewIntArrayFrom(g.SliceInt{1, 2, 3, 4}) - gtest.Assert(array.FilterEmpty(), g.SliceInt{1, 2, 3, 4}) + t.Assert(array.FilterEmpty(), g.SliceInt{1, 2, 3, 4}) }) } diff --git a/container/garray/garray_z_unit_normal_str_array_test.go b/container/garray/garray_z_unit_normal_str_array_test.go index 1d11fdc46..f1e1b8a6d 100644 --- a/container/garray/garray_z_unit_normal_str_array_test.go +++ b/container/garray/garray_z_unit_normal_str_array_test.go @@ -21,38 +21,38 @@ import ( ) func Test_StrArray_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []string{"0", "1", "2", "3"} array := garray.NewStrArrayFrom(expect) array2 := garray.NewStrArrayFrom(expect, true) array3 := garray.NewStrArrayFrom([]string{}) - gtest.Assert(array.Slice(), expect) - gtest.Assert(array.Interfaces(), expect) + t.Assert(array.Slice(), expect) + t.Assert(array.Interfaces(), expect) array.Set(0, "100") - gtest.Assert(array.Get(0), 100) - gtest.Assert(array.Get(1), 1) - gtest.Assert(array.Search("100"), 0) - gtest.Assert(array.Contains("100"), true) - gtest.Assert(array.Remove(0), 100) - gtest.Assert(array.Remove(-1), "") - gtest.Assert(array.Remove(100000), "") - gtest.Assert(array.Contains("100"), false) + t.Assert(array.Get(0), 100) + t.Assert(array.Get(1), 1) + t.Assert(array.Search("100"), 0) + t.Assert(array.Contains("100"), true) + t.Assert(array.Remove(0), 100) + t.Assert(array.Remove(-1), "") + t.Assert(array.Remove(100000), "") + t.Assert(array.Contains("100"), false) array.Append("4") - gtest.Assert(array.Len(), 4) + t.Assert(array.Len(), 4) array.InsertBefore(0, "100") array.InsertAfter(0, "200") - gtest.Assert(array.Slice(), []string{"100", "200", "1", "2", "3", "4"}) + t.Assert(array.Slice(), []string{"100", "200", "1", "2", "3", "4"}) array.InsertBefore(5, "300") array.InsertAfter(6, "400") - gtest.Assert(array.Slice(), []string{"100", "200", "1", "2", "3", "300", "4", "400"}) - gtest.Assert(array.Clear().Len(), 0) - gtest.Assert(array2.Slice(), expect) - gtest.Assert(array3.Search("100"), -1) + t.Assert(array.Slice(), []string{"100", "200", "1", "2", "3", "300", "4", "400"}) + t.Assert(array.Clear().Len(), 0) + t.Assert(array2.Slice(), expect) + t.Assert(array3.Search("100"), -1) }) } func TestStrArray_Sort(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect1 := []string{"0", "1", "2", "3"} expect2 := []string{"3", "2", "1", "0"} array := garray.NewStrArray() @@ -60,73 +60,73 @@ func TestStrArray_Sort(t *testing.T) { array.Append(gconv.String(i)) } array.Sort() - gtest.Assert(array.Slice(), expect1) + t.Assert(array.Slice(), expect1) array.Sort(true) - gtest.Assert(array.Slice(), expect2) + t.Assert(array.Slice(), expect2) }) } func TestStrArray_Unique(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []string{"1", "1", "2", "3"} array := garray.NewStrArrayFrom(expect) - gtest.Assert(array.Unique().Slice(), []string{"1", "2", "3"}) + t.Assert(array.Unique().Slice(), []string{"1", "2", "3"}) }) } func TestStrArray_PushAndPop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expect := []string{"0", "1", "2", "3"} array := garray.NewStrArrayFrom(expect) - gtest.Assert(array.Slice(), expect) - gtest.Assert(array.PopLeft(), "0") - gtest.Assert(array.PopRight(), "3") - gtest.AssertIN(array.PopRand(), []string{"1", "2"}) - gtest.AssertIN(array.PopRand(), []string{"1", "2"}) - gtest.Assert(array.Len(), 0) + t.Assert(array.Slice(), expect) + t.Assert(array.PopLeft(), "0") + t.Assert(array.PopRight(), "3") + t.AssertIN(array.PopRand(), []string{"1", "2"}) + t.AssertIN(array.PopRand(), []string{"1", "2"}) + t.Assert(array.Len(), 0) array.PushLeft("1").PushRight("2") - gtest.Assert(array.Slice(), []string{"1", "2"}) + t.Assert(array.Slice(), []string{"1", "2"}) }) } func TestStrArray_PopLeftsAndPopRights(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value1 := []string{"0", "1", "2", "3", "4", "5", "6"} value2 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(value1) array2 := garray.NewStrArrayFrom(value2) - gtest.Assert(array1.PopLefts(2), []interface{}{"0", "1"}) - gtest.Assert(array1.Slice(), []interface{}{"2", "3", "4", "5", "6"}) - gtest.Assert(array1.PopRights(2), []interface{}{"5", "6"}) - gtest.Assert(array1.Slice(), []interface{}{"2", "3", "4"}) - gtest.Assert(array1.PopRights(20), []interface{}{"2", "3", "4"}) - gtest.Assert(array1.Slice(), []interface{}{}) - gtest.Assert(array2.PopLefts(20), []interface{}{"0", "1", "2", "3", "4", "5", "6"}) - gtest.Assert(array2.Slice(), []interface{}{}) + t.Assert(array1.PopLefts(2), []interface{}{"0", "1"}) + t.Assert(array1.Slice(), []interface{}{"2", "3", "4", "5", "6"}) + t.Assert(array1.PopRights(2), []interface{}{"5", "6"}) + t.Assert(array1.Slice(), []interface{}{"2", "3", "4"}) + t.Assert(array1.PopRights(20), []interface{}{"2", "3", "4"}) + t.Assert(array1.Slice(), []interface{}{}) + t.Assert(array2.PopLefts(20), []interface{}{"0", "1", "2", "3", "4", "5", "6"}) + t.Assert(array2.Slice(), []interface{}{}) }) } func TestString_Range(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(value1) array2 := garray.NewStrArrayFrom(value1, true) - gtest.Assert(array1.Range(0, 1), []interface{}{"0"}) - gtest.Assert(array1.Range(1, 2), []interface{}{"1"}) - gtest.Assert(array1.Range(0, 2), []interface{}{"0", "1"}) - gtest.Assert(array1.Range(-1, 10), value1) - gtest.Assert(array1.Range(10, 1), nil) - gtest.Assert(array2.Range(0, 1), []interface{}{"0"}) + t.Assert(array1.Range(0, 1), []interface{}{"0"}) + t.Assert(array1.Range(1, 2), []interface{}{"1"}) + t.Assert(array1.Range(0, 2), []interface{}{"0", "1"}) + t.Assert(array1.Range(-1, 10), value1) + t.Assert(array1.Range(10, 1), nil) + t.Assert(array2.Range(0, 1), []interface{}{"0"}) }) } func TestStrArray_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a11 := []string{"0", "1", "2", "3"} a21 := []string{"4", "5", "6", "7"} array1 := garray.NewStrArrayFrom(a11) array2 := garray.NewStrArrayFrom(a21) - gtest.Assert(array1.Merge(array2).Slice(), []string{"0", "1", "2", "3", "4", "5", "6", "7"}) + t.Assert(array1.Merge(array2).Slice(), []string{"0", "1", "2", "3", "4", "5", "6", "7"}) func1 := func(v1, v2 interface{}) int { if gconv.Int(v1) < gconv.Int(v2) { @@ -145,267 +145,267 @@ func TestStrArray_Merge(t *testing.T) { s6 := garray.NewSortedIntArrayFrom([]int{1, 2, 3}) a1 := garray.NewStrArrayFrom(s1) - gtest.Assert(a1.Merge(s2).Len(), 6) - gtest.Assert(a1.Merge(i1).Len(), 9) - gtest.Assert(a1.Merge(i2).Len(), 10) - gtest.Assert(a1.Merge(s3).Len(), 12) - gtest.Assert(a1.Merge(s4).Len(), 14) - gtest.Assert(a1.Merge(s5).Len(), 16) - gtest.Assert(a1.Merge(s6).Len(), 19) + t.Assert(a1.Merge(s2).Len(), 6) + t.Assert(a1.Merge(i1).Len(), 9) + t.Assert(a1.Merge(i2).Len(), 10) + t.Assert(a1.Merge(s3).Len(), 12) + t.Assert(a1.Merge(s4).Len(), 14) + t.Assert(a1.Merge(s5).Len(), 16) + t.Assert(a1.Merge(s6).Len(), 19) }) } func TestStrArray_Fill(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0"} a2 := []string{"0"} array1 := garray.NewStrArrayFrom(a1) array2 := garray.NewStrArrayFrom(a2) - gtest.Assert(array1.Fill(1, 2, "100").Slice(), []string{"0", "100", "100"}) - gtest.Assert(array2.Fill(0, 2, "100").Slice(), []string{"100", "100"}) + t.Assert(array1.Fill(1, 2, "100").Slice(), []string{"0", "100", "100"}) + t.Assert(array2.Fill(0, 2, "100").Slice(), []string{"100", "100"}) s1 := array2.Fill(-1, 2, "100") - gtest.Assert(s1.Len(), 2) + t.Assert(s1.Len(), 2) }) } func TestStrArray_Chunk(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"1", "2", "3", "4", "5"} array1 := garray.NewStrArrayFrom(a1) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []string{"1", "2"}) - gtest.Assert(chunks[1], []string{"3", "4"}) - gtest.Assert(chunks[2], []string{"5"}) - gtest.Assert(len(array1.Chunk(0)), 0) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []string{"1", "2"}) + t.Assert(chunks[1], []string{"3", "4"}) + t.Assert(chunks[2], []string{"5"}) + t.Assert(len(array1.Chunk(0)), 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"1", "2", "3", "4", "5"} array1 := garray.NewStrArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []string{"1", "2", "3"}) - gtest.Assert(chunks[1], []string{"4", "5"}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []string{"1", "2", "3"}) + t.Assert(chunks[1], []string{"4", "5"}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []string{"1", "2"}) - gtest.Assert(chunks[1], []string{"3", "4"}) - gtest.Assert(chunks[2], []string{"5", "6"}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []string{"1", "2"}) + t.Assert(chunks[1], []string{"3", "4"}) + t.Assert(chunks[2], []string{"5", "6"}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []string{"1", "2", "3"}) - gtest.Assert(chunks[1], []string{"4", "5", "6"}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []string{"1", "2", "3"}) + t.Assert(chunks[1], []string{"4", "5", "6"}) + t.Assert(array1.Chunk(0), nil) }) } func TestStrArray_Pad(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0"} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(array1.Pad(3, "1").Slice(), []string{"0", "1", "1"}) - gtest.Assert(array1.Pad(-4, "1").Slice(), []string{"1", "0", "1", "1"}) - gtest.Assert(array1.Pad(3, "1").Slice(), []string{"1", "0", "1", "1"}) + t.Assert(array1.Pad(3, "1").Slice(), []string{"0", "1", "1"}) + t.Assert(array1.Pad(-4, "1").Slice(), []string{"1", "0", "1", "1"}) + t.Assert(array1.Pad(3, "1").Slice(), []string{"1", "0", "1", "1"}) }) } func TestStrArray_SubSlice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) array2 := garray.NewStrArrayFrom(a1, true) - gtest.Assert(array1.SubSlice(0, 2), []string{"0", "1"}) - gtest.Assert(array1.SubSlice(2, 2), []string{"2", "3"}) - gtest.Assert(array1.SubSlice(5, 8), []string{"5", "6"}) - gtest.Assert(array1.SubSlice(8, 2), nil) - gtest.Assert(array1.SubSlice(1, -2), nil) - gtest.Assert(array1.SubSlice(-5, 2), []string{"2", "3"}) - gtest.Assert(array1.SubSlice(-10, 1), nil) - gtest.Assert(array2.SubSlice(0, 2), []string{"0", "1"}) + t.Assert(array1.SubSlice(0, 2), []string{"0", "1"}) + t.Assert(array1.SubSlice(2, 2), []string{"2", "3"}) + t.Assert(array1.SubSlice(5, 8), []string{"5", "6"}) + t.Assert(array1.SubSlice(8, 2), nil) + t.Assert(array1.SubSlice(1, -2), nil) + t.Assert(array1.SubSlice(-5, 2), []string{"2", "3"}) + t.Assert(array1.SubSlice(-10, 1), nil) + t.Assert(array2.SubSlice(0, 2), []string{"0", "1"}) }) } func TestStrArray_Rand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(len(array1.Rands(2)), "2") - gtest.Assert(len(array1.Rands(10)), "7") - gtest.AssertIN(array1.Rands(1)[0], a1) - gtest.Assert(len(array1.Rand()), 1) - gtest.AssertIN(array1.Rand(), a1) + t.Assert(len(array1.Rands(2)), "2") + t.Assert(len(array1.Rands(10)), "7") + t.AssertIN(array1.Rands(1)[0], a1) + t.Assert(len(array1.Rand()), 1) + t.AssertIN(array1.Rand(), a1) }) } func TestStrArray_PopRands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"a", "b", "c", "d", "e", "f", "g"} array1 := garray.NewStrArrayFrom(a1) - gtest.AssertIN(array1.PopRands(1), []string{"a", "b", "c", "d", "e", "f", "g"}) - gtest.AssertIN(array1.PopRands(1), []string{"a", "b", "c", "d", "e", "f", "g"}) - gtest.AssertNI(array1.PopRands(1), array1.Slice()) - gtest.AssertNI(array1.PopRands(1), array1.Slice()) - gtest.Assert(len(array1.PopRands(10)), 3) + t.AssertIN(array1.PopRands(1), []string{"a", "b", "c", "d", "e", "f", "g"}) + t.AssertIN(array1.PopRands(1), []string{"a", "b", "c", "d", "e", "f", "g"}) + t.AssertNI(array1.PopRands(1), array1.Slice()) + t.AssertNI(array1.PopRands(1), array1.Slice()) + t.Assert(len(array1.PopRands(10)), 3) }) } func TestStrArray_Shuffle(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(array1.Shuffle().Len(), 7) + t.Assert(array1.Shuffle().Len(), 7) }) } func TestStrArray_Reverse(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(array1.Reverse().Slice(), []string{"6", "5", "4", "3", "2", "1", "0"}) + t.Assert(array1.Reverse().Slice(), []string{"6", "5", "4", "3", "2", "1", "0"}) }) } func TestStrArray_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(array1.Join("."), `0.1.2.3.4.5.6`) + t.Assert(array1.Join("."), `0.1.2.3.4.5.6`) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", `"a"`, `\a`} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(array1.Join("."), `0.1."a".\a`) + t.Assert(array1.Join("."), `0.1."a".\a`) }) } func TestStrArray_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(array1.String(), `["0","1","2","3","4","5","6"]`) + t.Assert(array1.String(), `["0","1","2","3","4","5","6"]`) }) } func TestNewStrArrayFromCopy(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} a2 := garray.NewStrArrayFromCopy(a1) a3 := garray.NewStrArrayFromCopy(a1, true) - gtest.Assert(a2.Contains("1"), true) - gtest.Assert(a2.Len(), 7) - gtest.Assert(a2, a3) + t.Assert(a2.Contains("1"), true) + t.Assert(a2.Len(), 7) + t.Assert(a2, a3) }) } func TestStrArray_SetArray(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} a2 := []string{"a", "b", "c", "d"} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(array1.Contains("2"), true) - gtest.Assert(array1.Len(), 7) + t.Assert(array1.Contains("2"), true) + t.Assert(array1.Len(), 7) array1 = array1.SetArray(a2) - gtest.Assert(array1.Contains("2"), false) - gtest.Assert(array1.Contains("c"), true) - gtest.Assert(array1.Len(), 4) + t.Assert(array1.Contains("2"), false) + t.Assert(array1.Contains("c"), true) + t.Assert(array1.Len(), 4) }) } func TestStrArray_Replace(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} a2 := []string{"a", "b", "c", "d"} a3 := []string{"o", "p", "q", "x", "y", "z", "w", "r", "v"} array1 := garray.NewStrArrayFrom(a1) - gtest.Assert(array1.Contains("2"), true) - gtest.Assert(array1.Len(), 7) + t.Assert(array1.Contains("2"), true) + t.Assert(array1.Len(), 7) array1 = array1.Replace(a2) - gtest.Assert(array1.Contains("2"), false) - gtest.Assert(array1.Contains("c"), true) - gtest.Assert(array1.Contains("5"), true) - gtest.Assert(array1.Len(), 7) + t.Assert(array1.Contains("2"), false) + t.Assert(array1.Contains("c"), true) + t.Assert(array1.Contains("5"), true) + t.Assert(array1.Len(), 7) array1 = array1.Replace(a3) - gtest.Assert(array1.Contains("2"), false) - gtest.Assert(array1.Contains("c"), false) - gtest.Assert(array1.Contains("5"), false) - gtest.Assert(array1.Contains("p"), true) - gtest.Assert(array1.Contains("r"), false) - gtest.Assert(array1.Len(), 7) + t.Assert(array1.Contains("2"), false) + t.Assert(array1.Contains("c"), false) + t.Assert(array1.Contains("5"), false) + t.Assert(array1.Contains("p"), true) + t.Assert(array1.Contains("r"), false) + t.Assert(array1.Len(), 7) }) } func TestStrArray_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} a2 := []string{"0", "a", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) array2 := garray.NewStrArrayFrom(a2) - gtest.Assert(array1.Sum(), 21) - gtest.Assert(array2.Sum(), 18) + t.Assert(array1.Sum(), 21) + t.Assert(array2.Sum(), 18) }) } func TestStrArray_PopRand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) str1 := array1.PopRand() - gtest.Assert(strings.Contains("0,1,2,3,4,5,6", str1), true) - gtest.Assert(array1.Len(), 6) + t.Assert(strings.Contains("0,1,2,3,4,5,6", str1), true) + t.Assert(array1.Len(), 6) }) } func TestStrArray_Clone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "5", "6"} array1 := garray.NewStrArrayFrom(a1) array2 := array1.Clone() - gtest.Assert(array2, array1) - gtest.Assert(array2.Len(), 7) + t.Assert(array2, array1) + t.Assert(array2.Len(), 7) }) } func TestStrArray_CountValues(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"0", "1", "2", "3", "4", "4", "6"} array1 := garray.NewStrArrayFrom(a1) m1 := array1.CountValues() - gtest.Assert(len(m1), 6) - gtest.Assert(m1["2"], 1) - gtest.Assert(m1["4"], 2) + t.Assert(len(m1), 6) + t.Assert(m1["2"], 1) + t.Assert(m1["4"], 2) }) } func TestStrArray_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "a", "c"} array1 := garray.NewStrArrayFrom(a1) s1 := array1.Remove(1) - gtest.Assert(s1, "a") - gtest.Assert(array1.Len(), 4) + t.Assert(s1, "a") + t.Assert(array1.Len(), 4) s1 = array1.Remove(3) - gtest.Assert(s1, "c") - gtest.Assert(array1.Len(), 3) + t.Assert(s1, "c") + t.Assert(array1.Len(), 3) }) } func TestStrArray_RLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []string{"a", "b", "c", "d"} a1 := garray.NewStrArrayFrom(s1, true) @@ -431,25 +431,25 @@ func TestStrArray_RLockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 - gtest.Assert(a1.Contains("g"), true) + t.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 + t.Assert(a1.Contains("g"), true) }) } func TestStrArray_SortFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []string{"a", "d", "c", "b"} a1 := garray.NewStrArrayFrom(s1) func1 := func(v1, v2 string) bool { return v1 < v2 } a11 := a1.SortFunc(func1) - gtest.Assert(a11, []string{"a", "b", "c", "d"}) + t.Assert(a11, []string{"a", "b", "c", "d"}) }) } func TestStrArray_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []string{"a", "b", "c", "d"} a1 := garray.NewStrArrayFrom(s1, true) @@ -475,31 +475,31 @@ func TestStrArray_LockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 - gtest.Assert(a1.Contains("g"), true) + t.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 + t.Assert(a1.Contains("g"), true) }) } func TestStrArray_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []string{"a", "b", "d", "c"} a1 := garray.NewStrArrayFrom(s1) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(b1, b2) - gtest.Assert(err1, err2) + t.Assert(b1, b2) + t.Assert(err1, err2) a2 := garray.NewStrArray() err1 = json.Unmarshal(b2, &a2) - gtest.Assert(a2.Slice(), s1) + t.Assert(a2.Slice(), s1) var a3 garray.StrArray err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a3.Slice(), s1) + t.Assert(err, nil) + t.Assert(a3.Slice(), s1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Name string Scores *garray.StrArray @@ -509,72 +509,72 @@ func TestStrArray_Json(t *testing.T) { "Scores": []string{"A+", "A", "A"}, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) user := new(User) err = json.Unmarshal(b, user) - gtest.Assert(err, nil) - gtest.Assert(user.Name, data["Name"]) - gtest.Assert(user.Scores, data["Scores"]) + t.Assert(err, nil) + t.Assert(user.Name, data["Name"]) + t.Assert(user.Scores, data["Scores"]) }) } func TestStrArray_Iterator(t *testing.T) { slice := g.SliceStr{"a", "b", "d", "c"} array := garray.NewStrArrayFrom(slice) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.Iterator(func(k int, v string) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorAsc(func(k int, v string) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorDesc(func(k int, v string) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.Iterator(func(k int, v string) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorAsc(func(k int, v string) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorDesc(func(k int, v string) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) } func TestStrArray_RemoveValue(t *testing.T) { slice := g.SliceStr{"a", "b", "d", "c"} array := garray.NewStrArrayFrom(slice) - gtest.Case(t, func() { - gtest.Assert(array.RemoveValue("e"), false) - gtest.Assert(array.RemoveValue("b"), true) - gtest.Assert(array.RemoveValue("a"), true) - gtest.Assert(array.RemoveValue("c"), true) - gtest.Assert(array.RemoveValue("f"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(array.RemoveValue("e"), false) + t.Assert(array.RemoveValue("b"), true) + t.Assert(array.RemoveValue("a"), true) + t.Assert(array.RemoveValue("c"), true) + t.Assert(array.RemoveValue("f"), false) }) } @@ -584,36 +584,36 @@ func TestStrArray_UnmarshalValue(t *testing.T) { Array *garray.StrArray } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`["1","2","3"]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": g.SliceStr{"1", "2", "3"}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) }) } func TestStrArray_FilterEmpty(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewStrArrayFrom(g.SliceStr{"", "1", "2", "0"}) - gtest.Assert(array.FilterEmpty(), g.SliceStr{"1", "2", "0"}) + t.Assert(array.FilterEmpty(), g.SliceStr{"1", "2", "0"}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewStrArrayFrom(g.SliceStr{"1", "2"}) - gtest.Assert(array.FilterEmpty(), g.SliceStr{"1", "2"}) + t.Assert(array.FilterEmpty(), g.SliceStr{"1", "2"}) }) } diff --git a/container/garray/garray_z_unit_sorted_any_array_test.go b/container/garray/garray_z_unit_sorted_any_array_test.go index 7ec8d01d4..2946ca5ad 100644 --- a/container/garray/garray_z_unit_sorted_any_array_test.go +++ b/container/garray/garray_z_unit_sorted_any_array_test.go @@ -22,7 +22,7 @@ import ( ) func TestSortedArray_NewSortedArrayFrom(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "f", "c"} a2 := []interface{}{"h", "j", "i", "k"} func1 := func(v1, v2 interface{}) int { @@ -34,16 +34,16 @@ func TestSortedArray_NewSortedArrayFrom(t *testing.T) { array1 := garray.NewSortedArrayFrom(a1, func1) array2 := garray.NewSortedArrayFrom(a2, func2) - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1, []interface{}{"a", "c", "f"}) + t.Assert(array1.Len(), 3) + t.Assert(array1, []interface{}{"a", "c", "f"}) - gtest.Assert(array2.Len(), 4) - gtest.Assert(array2, []interface{}{"k", "i", "j", "h"}) + t.Assert(array2.Len(), 4) + t.Assert(array2, []interface{}{"k", "i", "j", "h"}) }) } func TestNewSortedArrayFromCopy(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "f", "c"} func1 := func(v1, v2 interface{}) int { @@ -54,15 +54,15 @@ func TestNewSortedArrayFromCopy(t *testing.T) { } array1 := garray.NewSortedArrayFromCopy(a1, func1) array2 := garray.NewSortedArrayFromCopy(a1, func2) - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1, []interface{}{"a", "c", "f"}) - gtest.Assert(array1.Len(), 3) - gtest.Assert(array2, []interface{}{"c", "f", "a"}) + t.Assert(array1.Len(), 3) + t.Assert(array1, []interface{}{"a", "c", "f"}) + t.Assert(array1.Len(), 3) + t.Assert(array2, []interface{}{"c", "f", "a"}) }) } func TestSortedArray_SetArray(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "f", "c"} a2 := []interface{}{"e", "h", "g", "k"} @@ -72,171 +72,171 @@ func TestSortedArray_SetArray(t *testing.T) { array1 := garray.NewSortedArrayFrom(a1, func1) array1.SetArray(a2) - gtest.Assert(array1.Len(), 4) - gtest.Assert(array1, []interface{}{"e", "g", "h", "k"}) + t.Assert(array1.Len(), 4) + t.Assert(array1, []interface{}{"e", "g", "h", "k"}) }) } func TestSortedArray_Sort(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "f", "c"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) array1.Sort() - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1, []interface{}{"a", "c", "f"}) + t.Assert(array1.Len(), 3) + t.Assert(array1, []interface{}{"a", "c", "f"}) }) } func TestSortedArray_Get(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "f", "c"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) - gtest.Assert(array1.Get(2), "f") - gtest.Assert(array1.Get(1), "c") + t.Assert(array1.Get(2), "f") + t.Assert(array1.Get(1), "c") }) } func TestSortedArray_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.Remove(1) - gtest.Assert(gconv.String(i1), "b") - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1.Contains("b"), false) + t.Assert(gconv.String(i1), "b") + t.Assert(array1.Len(), 3) + t.Assert(array1.Contains("b"), false) - gtest.Assert(array1.Remove(-1), nil) - gtest.Assert(array1.Remove(100000), nil) + t.Assert(array1.Remove(-1), nil) + t.Assert(array1.Remove(100000), nil) i2 := array1.Remove(0) - gtest.Assert(gconv.String(i2), "a") - gtest.Assert(array1.Len(), 2) - gtest.Assert(array1.Contains("a"), false) + t.Assert(gconv.String(i2), "a") + t.Assert(array1.Len(), 2) + t.Assert(array1.Contains("a"), false) i3 := array1.Remove(1) - gtest.Assert(gconv.String(i3), "d") - gtest.Assert(array1.Len(), 1) - gtest.Assert(array1.Contains("d"), false) + t.Assert(gconv.String(i3), "d") + t.Assert(array1.Len(), 1) + t.Assert(array1.Contains("d"), false) }) } func TestSortedArray_PopLeft(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.PopLeft() - gtest.Assert(gconv.String(i1), "a") - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1, []interface{}{"b", "c", "d"}) + t.Assert(gconv.String(i1), "a") + t.Assert(array1.Len(), 3) + t.Assert(array1, []interface{}{"b", "c", "d"}) }) } func TestSortedArray_PopRight(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.PopRight() - gtest.Assert(gconv.String(i1), "d") - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1, []interface{}{"a", "b", "c"}) + t.Assert(gconv.String(i1), "d") + t.Assert(array1.Len(), 3) + t.Assert(array1, []interface{}{"a", "b", "c"}) }) } func TestSortedArray_PopRand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.PopRand() - gtest.AssertIN(i1, []interface{}{"a", "d", "c", "b"}) - gtest.Assert(array1.Len(), 3) + t.AssertIN(i1, []interface{}{"a", "d", "c", "b"}) + t.Assert(array1.Len(), 3) }) } func TestSortedArray_PopRands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.PopRands(2) - gtest.Assert(len(i1), 2) - gtest.AssertIN(i1, []interface{}{"a", "d", "c", "b"}) - gtest.Assert(array1.Len(), 2) + t.Assert(len(i1), 2) + t.AssertIN(i1, []interface{}{"a", "d", "c", "b"}) + t.Assert(array1.Len(), 2) i2 := array1.PopRands(3) - gtest.Assert(len(i1), 2) - gtest.AssertIN(i2, []interface{}{"a", "d", "c", "b"}) - gtest.Assert(array1.Len(), 0) + t.Assert(len(i1), 2) + t.AssertIN(i2, []interface{}{"a", "d", "c", "b"}) + t.Assert(array1.Len(), 0) }) } func TestSortedArray_PopLefts(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b", "e", "f"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.PopLefts(2) - gtest.Assert(len(i1), 2) - gtest.AssertIN(i1, []interface{}{"a", "d", "c", "b", "e", "f"}) - gtest.Assert(array1.Len(), 4) + t.Assert(len(i1), 2) + t.AssertIN(i1, []interface{}{"a", "d", "c", "b", "e", "f"}) + t.Assert(array1.Len(), 4) i2 := array1.PopLefts(5) - gtest.Assert(len(i2), 4) - gtest.AssertIN(i1, []interface{}{"a", "d", "c", "b", "e", "f"}) - gtest.Assert(array1.Len(), 0) + t.Assert(len(i2), 4) + t.AssertIN(i1, []interface{}{"a", "d", "c", "b", "e", "f"}) + t.Assert(array1.Len(), 0) }) } func TestSortedArray_PopRights(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b", "e", "f"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.PopRights(2) - gtest.Assert(len(i1), 2) - gtest.Assert(i1, []interface{}{"e", "f"}) - gtest.Assert(array1.Len(), 4) + t.Assert(len(i1), 2) + t.Assert(i1, []interface{}{"e", "f"}) + t.Assert(array1.Len(), 4) i2 := array1.PopRights(10) - gtest.Assert(len(i2), 4) + t.Assert(len(i2), 4) }) } func TestSortedArray_Range(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b", "e", "f"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) @@ -244,25 +244,25 @@ func TestSortedArray_Range(t *testing.T) { array1 := garray.NewSortedArrayFrom(a1, func1) array2 := garray.NewSortedArrayFrom(a1, func1, true) i1 := array1.Range(2, 5) - gtest.Assert(i1, []interface{}{"c", "d", "e"}) - gtest.Assert(array1.Len(), 6) + t.Assert(i1, []interface{}{"c", "d", "e"}) + t.Assert(array1.Len(), 6) i2 := array1.Range(7, 5) - gtest.Assert(len(i2), 0) + t.Assert(len(i2), 0) i2 = array1.Range(-1, 2) - gtest.Assert(i2, []interface{}{"a", "b"}) + t.Assert(i2, []interface{}{"a", "b"}) i2 = array1.Range(4, 10) - gtest.Assert(len(i2), 2) - gtest.Assert(i2, []interface{}{"e", "f"}) + t.Assert(len(i2), 2) + t.Assert(i2, []interface{}{"e", "f"}) - gtest.Assert(array2.Range(1, 3), []interface{}{"b", "c"}) + t.Assert(array2.Range(1, 3), []interface{}{"b", "c"}) }) } func TestSortedArray_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b", "e", "f"} a2 := []interface{}{"1", "2", "3", "b", "e", "f"} a3 := []interface{}{"4", "5", "6"} @@ -272,15 +272,15 @@ func TestSortedArray_Sum(t *testing.T) { array1 := garray.NewSortedArrayFrom(a1, func1) array2 := garray.NewSortedArrayFrom(a2, func1) array3 := garray.NewSortedArrayFrom(a3, func1) - gtest.Assert(array1.Sum(), 0) - gtest.Assert(array2.Sum(), 6) - gtest.Assert(array3.Sum(), 15) + t.Assert(array1.Sum(), 0) + t.Assert(array2.Sum(), 6) + t.Assert(array3.Sum(), 15) }) } func TestSortedArray_Clone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b", "e", "f"} func1 := func(v1, v2 interface{}) int { @@ -288,30 +288,30 @@ func TestSortedArray_Clone(t *testing.T) { } array1 := garray.NewSortedArrayFrom(a1, func1) array2 := array1.Clone() - gtest.Assert(array1, array2) + t.Assert(array1, array2) array1.Remove(1) - gtest.AssertNE(array1, array2) + t.AssertNE(array1, array2) }) } func TestSortedArray_Clear(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b", "e", "f"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) - gtest.Assert(array1.Len(), 6) + t.Assert(array1.Len(), 6) array1.Clear() - gtest.Assert(array1.Len(), 0) + t.Assert(array1.Len(), 0) }) } func TestSortedArray_Chunk(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b", "e"} func1 := func(v1, v2 interface{}) int { @@ -319,45 +319,45 @@ func TestSortedArray_Chunk(t *testing.T) { } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.Chunk(2) - gtest.Assert(len(i1), 3) - gtest.Assert(i1[0], []interface{}{"a", "b"}) - gtest.Assert(i1[2], []interface{}{"e"}) + t.Assert(len(i1), 3) + t.Assert(i1[0], []interface{}{"a", "b"}) + t.Assert(i1[2], []interface{}{"e"}) i1 = array1.Chunk(0) - gtest.Assert(len(i1), 0) + t.Assert(len(i1), 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{1, 2, 3, 4, 5} array1 := garray.NewSortedArrayFrom(a1, gutil.ComparatorInt) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []interface{}{1, 2, 3}) - gtest.Assert(chunks[1], []interface{}{4, 5}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []interface{}{1, 2, 3}) + t.Assert(chunks[1], []interface{}{4, 5}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{1, 2, 3, 4, 5, 6} array1 := garray.NewSortedArrayFrom(a1, gutil.ComparatorInt) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []interface{}{1, 2}) - gtest.Assert(chunks[1], []interface{}{3, 4}) - gtest.Assert(chunks[2], []interface{}{5, 6}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []interface{}{1, 2}) + t.Assert(chunks[1], []interface{}{3, 4}) + t.Assert(chunks[2], []interface{}{5, 6}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{1, 2, 3, 4, 5, 6} array1 := garray.NewSortedArrayFrom(a1, gutil.ComparatorInt) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []interface{}{1, 2, 3}) - gtest.Assert(chunks[1], []interface{}{4, 5, 6}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []interface{}{1, 2, 3}) + t.Assert(chunks[1], []interface{}{4, 5, 6}) + t.Assert(array1.Chunk(0), nil) }) } func TestSortedArray_SubSlice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "b", "e"} func1 := func(v1, v2 interface{}) int { @@ -366,28 +366,28 @@ func TestSortedArray_SubSlice(t *testing.T) { array1 := garray.NewSortedArrayFrom(a1, func1) array2 := garray.NewSortedArrayFrom(a1, func1, true) i1 := array1.SubSlice(2, 3) - gtest.Assert(len(i1), 3) - gtest.Assert(i1, []interface{}{"c", "d", "e"}) + t.Assert(len(i1), 3) + t.Assert(i1, []interface{}{"c", "d", "e"}) i1 = array1.SubSlice(2, 6) - gtest.Assert(len(i1), 3) - gtest.Assert(i1, []interface{}{"c", "d", "e"}) + t.Assert(len(i1), 3) + t.Assert(i1, []interface{}{"c", "d", "e"}) i1 = array1.SubSlice(7, 2) - gtest.Assert(len(i1), 0) + t.Assert(len(i1), 0) s1 := array1.SubSlice(1, -2) - gtest.Assert(s1, nil) + t.Assert(s1, nil) s1 = array1.SubSlice(-9, 2) - gtest.Assert(s1, nil) - gtest.Assert(array2.SubSlice(1, 3), []interface{}{"b", "c", "d"}) + t.Assert(s1, nil) + t.Assert(array2.SubSlice(1, 3), []interface{}{"b", "c", "d"}) }) } func TestSortedArray_Rand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c"} func1 := func(v1, v2 interface{}) int { @@ -395,13 +395,13 @@ func TestSortedArray_Rand(t *testing.T) { } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.Rand() - gtest.AssertIN(i1, []interface{}{"a", "d", "c"}) - gtest.Assert(array1.Len(), 3) + t.AssertIN(i1, []interface{}{"a", "d", "c"}) + t.Assert(array1.Len(), 3) }) } func TestSortedArray_Rands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c"} func1 := func(v1, v2 interface{}) int { @@ -409,43 +409,43 @@ func TestSortedArray_Rands(t *testing.T) { } array1 := garray.NewSortedArrayFrom(a1, func1) i1 := array1.Rands(2) - gtest.AssertIN(i1, []interface{}{"a", "d", "c"}) - gtest.Assert(len(i1), 2) - gtest.Assert(array1.Len(), 3) + t.AssertIN(i1, []interface{}{"a", "d", "c"}) + t.Assert(len(i1), 2) + t.Assert(array1.Len(), 3) i1 = array1.Rands(4) - gtest.Assert(len(i1), 3) + t.Assert(len(i1), 3) }) } func TestSortedArray_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c"} func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } array1 := garray.NewSortedArrayFrom(a1, func1) - gtest.Assert(array1.Join(","), `a,c,d`) - gtest.Assert(array1.Join("."), `a.c.d`) + t.Assert(array1.Join(","), `a,c,d`) + t.Assert(array1.Join("."), `a.c.d`) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, `"a"`, `\a`} array1 := garray.NewSortedArrayFrom(a1, gutil.ComparatorString) - gtest.Assert(array1.Join("."), `"a".0.1.\a`) + t.Assert(array1.Join("."), `"a".0.1.\a`) }) } func TestSortedArray_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{0, 1, "a", "b"} array1 := garray.NewSortedArrayFrom(a1, gutil.ComparatorString) - gtest.Assert(array1.String(), `[0,1,"a","b"]`) + t.Assert(array1.String(), `[0,1,"a","b"]`) }) } func TestSortedArray_CountValues(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "c"} func1 := func(v1, v2 interface{}) int { @@ -453,15 +453,15 @@ func TestSortedArray_CountValues(t *testing.T) { } array1 := garray.NewSortedArrayFrom(a1, func1) m1 := array1.CountValues() - gtest.Assert(len(m1), 3) - gtest.Assert(m1["c"], 2) - gtest.Assert(m1["a"], 1) + t.Assert(len(m1), 3) + t.Assert(m1["c"], 2) + t.Assert(m1["a"], 1) }) } func TestSortedArray_SetUnique(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []interface{}{"a", "d", "c", "c"} func1 := func(v1, v2 interface{}) int { @@ -469,13 +469,13 @@ func TestSortedArray_SetUnique(t *testing.T) { } array1 := garray.NewSortedArrayFrom(a1, func1) array1.SetUnique(true) - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1, []interface{}{"a", "c", "d"}) + t.Assert(array1.Len(), 3) + t.Assert(array1, []interface{}{"a", "c", "d"}) }) } func TestSortedArray_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } @@ -504,13 +504,13 @@ func TestSortedArray_LockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 - gtest.Assert(a1.Contains("g"), true) + t.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 + t.Assert(a1.Contains("g"), true) }) } func TestSortedArray_RLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { func1 := func(v1, v2 interface{}) int { return strings.Compare(gconv.String(v1), gconv.String(v2)) } @@ -539,13 +539,13 @@ func TestSortedArray_RLockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候不会被阻塞。 - gtest.Assert(a1.Contains("g"), true) + t.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候不会被阻塞。 + t.Assert(a1.Contains("g"), true) }) } func TestSortedArray_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { func1 := func(v1, v2 interface{}) int { if gconv.Int(v1) < gconv.Int(v2) { return 0 @@ -564,38 +564,38 @@ func TestSortedArray_Merge(t *testing.T) { a1 := garray.NewSortedArrayFrom(s1, func1) - gtest.Assert(a1.Merge(s2).Len(), 6) - gtest.Assert(a1.Merge(i1).Len(), 9) - gtest.Assert(a1.Merge(i2).Len(), 10) - gtest.Assert(a1.Merge(s3).Len(), 12) - gtest.Assert(a1.Merge(s4).Len(), 14) - gtest.Assert(a1.Merge(s5).Len(), 16) - gtest.Assert(a1.Merge(s6).Len(), 19) + t.Assert(a1.Merge(s2).Len(), 6) + t.Assert(a1.Merge(i1).Len(), 9) + t.Assert(a1.Merge(i2).Len(), 10) + t.Assert(a1.Merge(s3).Len(), 12) + t.Assert(a1.Merge(s4).Len(), 14) + t.Assert(a1.Merge(s5).Len(), 16) + t.Assert(a1.Merge(s6).Len(), 19) }) } func TestSortedArray_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []interface{}{"a", "b", "d", "c"} s2 := []interface{}{"a", "b", "c", "d"} a1 := garray.NewSortedArrayFrom(s1, gutil.ComparatorString) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(b1, b2) - gtest.Assert(err1, err2) + t.Assert(b1, b2) + t.Assert(err1, err2) a2 := garray.NewSortedArray(gutil.ComparatorString) err1 = json.Unmarshal(b2, &a2) - gtest.Assert(a2.Slice(), s2) + t.Assert(a2.Slice(), s2) var a3 garray.SortedArray err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a3.Slice(), s1) - gtest.Assert(a3.Interfaces(), s1) + t.Assert(err, nil) + t.Assert(a3.Slice(), s1) + t.Assert(a3.Interfaces(), s1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Name string Scores *garray.SortedArray @@ -605,76 +605,76 @@ func TestSortedArray_Json(t *testing.T) { "Scores": []int{99, 100, 98}, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) user := new(User) err = json.Unmarshal(b, user) - gtest.Assert(err, nil) - gtest.Assert(user.Name, data["Name"]) - gtest.AssertNE(user.Scores, nil) - gtest.Assert(user.Scores.Len(), 3) - gtest.AssertIN(user.Scores.PopLeft(), data["Scores"]) - gtest.AssertIN(user.Scores.PopLeft(), data["Scores"]) - gtest.AssertIN(user.Scores.PopLeft(), data["Scores"]) + t.Assert(err, nil) + t.Assert(user.Name, data["Name"]) + t.AssertNE(user.Scores, nil) + t.Assert(user.Scores.Len(), 3) + t.AssertIN(user.Scores.PopLeft(), data["Scores"]) + t.AssertIN(user.Scores.PopLeft(), data["Scores"]) + t.AssertIN(user.Scores.PopLeft(), data["Scores"]) }) } func TestSortedArray_Iterator(t *testing.T) { slice := g.Slice{"a", "b", "d", "c"} array := garray.NewSortedArrayFrom(slice, gutil.ComparatorString) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.Iterator(func(k int, v interface{}) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorAsc(func(k int, v interface{}) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorDesc(func(k int, v interface{}) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.Iterator(func(k int, v interface{}) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorAsc(func(k int, v interface{}) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorDesc(func(k int, v interface{}) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) } func TestSortedArray_RemoveValue(t *testing.T) { slice := g.Slice{"a", "b", "d", "c"} array := garray.NewSortedArrayFrom(slice, gutil.ComparatorString) - gtest.Case(t, func() { - gtest.Assert(array.RemoveValue("e"), false) - gtest.Assert(array.RemoveValue("b"), true) - gtest.Assert(array.RemoveValue("a"), true) - gtest.Assert(array.RemoveValue("c"), true) - gtest.Assert(array.RemoveValue("f"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(array.RemoveValue("e"), false) + t.Assert(array.RemoveValue("b"), true) + t.Assert(array.RemoveValue("a"), true) + t.Assert(array.RemoveValue("c"), true) + t.Assert(array.RemoveValue("f"), false) }) } @@ -684,48 +684,48 @@ func TestSortedArray_UnmarshalValue(t *testing.T) { Array *garray.SortedArray } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`[2,3,1]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": g.Slice{2, 3, 1}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) }) } func TestSortedArray_FilterNil(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { values := g.Slice{0, 1, 2, 3, 4, "", g.Slice{}} array := garray.NewSortedArrayFromCopy(values, gutil.ComparatorInt) - gtest.Assert(array.FilterNil().Slice(), g.Slice{0, "", g.Slice{}, 1, 2, 3, 4}) + t.Assert(array.FilterNil().Slice(), g.Slice{0, "", g.Slice{}, 1, 2, 3, 4}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewSortedArrayFromCopy(g.Slice{nil, 1, 2, 3, 4, nil}, gutil.ComparatorInt) - gtest.Assert(array.FilterNil(), g.Slice{1, 2, 3, 4}) + t.Assert(array.FilterNil(), g.Slice{1, 2, 3, 4}) }) } func TestSortedArray_FilterEmpty(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewSortedArrayFrom(g.Slice{0, 1, 2, 3, 4, "", g.Slice{}}, gutil.ComparatorInt) - gtest.Assert(array.FilterEmpty(), g.Slice{1, 2, 3, 4}) + t.Assert(array.FilterEmpty(), g.Slice{1, 2, 3, 4}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewSortedArrayFrom(g.Slice{1, 2, 3, 4}, gutil.ComparatorInt) - gtest.Assert(array.FilterEmpty(), g.Slice{1, 2, 3, 4}) + t.Assert(array.FilterEmpty(), g.Slice{1, 2, 3, 4}) }) } diff --git a/container/garray/garray_z_unit_sorted_int_array_test.go b/container/garray/garray_z_unit_sorted_int_array_test.go index e7aeae3ca..26542fff4 100644 --- a/container/garray/garray_z_unit_sorted_int_array_test.go +++ b/container/garray/garray_z_unit_sorted_int_array_test.go @@ -21,355 +21,355 @@ import ( ) func TestNewSortedIntArrayFrom(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 3, 2, 1, 4, 5, 6} array1 := garray.NewSortedIntArrayFrom(a1, true) - gtest.Assert(array1.Join("."), "0.1.2.3.4.5.6") - gtest.Assert(array1.Slice(), a1) - gtest.Assert(array1.Interfaces(), a1) + t.Assert(array1.Join("."), "0.1.2.3.4.5.6") + t.Assert(array1.Slice(), a1) + t.Assert(array1.Interfaces(), a1) }) } func TestNewSortedIntArrayFromCopy(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 5, 2, 1, 4, 3, 6} array1 := garray.NewSortedIntArrayFromCopy(a1, false) - gtest.Assert(array1.Join("."), "0.1.2.3.4.5.6") + t.Assert(array1.Join("."), "0.1.2.3.4.5.6") }) } func TestSortedIntArray_SetArray(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 1, 2, 3} a2 := []int{4, 5, 6} array1 := garray.NewSortedIntArrayFrom(a1) array2 := array1.SetArray(a2) - gtest.Assert(array2.Len(), 3) - gtest.Assert(array2.Search(3), -1) - gtest.Assert(array2.Search(5), 1) - gtest.Assert(array2.Search(6), 2) + t.Assert(array2.Len(), 3) + t.Assert(array2.Search(3), -1) + t.Assert(array2.Search(5), 1) + t.Assert(array2.Search(6), 2) }) } func TestSortedIntArray_Sort(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{0, 3, 2, 1} array1 := garray.NewSortedIntArrayFrom(a1) array2 := array1.Sort() - gtest.Assert(array2.Len(), 4) - gtest.Assert(array2, []int{0, 1, 2, 3}) + t.Assert(array2.Len(), 4) + t.Assert(array2, []int{0, 1, 2, 3}) }) } func TestSortedIntArray_Get(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 0} array1 := garray.NewSortedIntArrayFrom(a1) - gtest.Assert(array1.Get(0), 0) - gtest.Assert(array1.Get(1), 1) - gtest.Assert(array1.Get(3), 5) + t.Assert(array1.Get(0), 0) + t.Assert(array1.Get(1), 1) + t.Assert(array1.Get(3), 5) }) } func TestSortedIntArray_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 0} array1 := garray.NewSortedIntArrayFrom(a1) - gtest.Assert(array1.Remove(-1), 0) - gtest.Assert(array1.Remove(100000), 0) + t.Assert(array1.Remove(-1), 0) + t.Assert(array1.Remove(100000), 0) i1 := array1.Remove(2) - gtest.Assert(i1, 3) - gtest.Assert(array1.Search(5), 2) + t.Assert(i1, 3) + t.Assert(array1.Search(5), 2) // 再次删除剩下的数组中的第一个 i2 := array1.Remove(0) - gtest.Assert(i2, 0) - gtest.Assert(array1.Search(5), 1) + t.Assert(i2, 0) + t.Assert(array1.Search(5), 1) a2 := []int{1, 3, 4} array2 := garray.NewSortedIntArrayFrom(a2) i3 := array2.Remove(1) - gtest.Assert(array2.Search(1), 0) - gtest.Assert(i3, 3) + t.Assert(array2.Search(1), 0) + t.Assert(i3, 3) i3 = array2.Remove(1) - gtest.Assert(array2.Search(4), -1) - gtest.Assert(i3, 4) + t.Assert(array2.Search(4), -1) + t.Assert(i3, 4) }) } func TestSortedIntArray_PopLeft(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 2} array1 := garray.NewSortedIntArrayFrom(a1) i1 := array1.PopLeft() - gtest.Assert(i1, 1) - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1.Search(1), -1) + t.Assert(i1, 1) + t.Assert(array1.Len(), 3) + t.Assert(array1.Search(1), -1) }) } func TestSortedIntArray_PopRight(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 2} array1 := garray.NewSortedIntArrayFrom(a1) i1 := array1.PopRight() - gtest.Assert(i1, 5) - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1.Search(5), -1) + t.Assert(i1, 5) + t.Assert(array1.Len(), 3) + t.Assert(array1.Search(5), -1) }) } func TestSortedIntArray_PopRand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 2} array1 := garray.NewSortedIntArrayFrom(a1) i1 := array1.PopRand() - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1.Search(i1), -1) - gtest.AssertIN(i1, []int{1, 3, 5, 2}) + t.Assert(array1.Len(), 3) + t.Assert(array1.Search(i1), -1) + t.AssertIN(i1, []int{1, 3, 5, 2}) }) } func TestSortedIntArray_PopRands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 2} array1 := garray.NewSortedIntArrayFrom(a1) ns1 := array1.PopRands(2) - gtest.Assert(array1.Len(), 2) - gtest.AssertIN(ns1, []int{1, 3, 5, 2}) + t.Assert(array1.Len(), 2) + t.AssertIN(ns1, []int{1, 3, 5, 2}) a2 := []int{1, 3, 5, 2} array2 := garray.NewSortedIntArrayFrom(a2) ns2 := array2.PopRands(5) - gtest.Assert(array2.Len(), 0) - gtest.Assert(len(ns2), 4) - gtest.AssertIN(ns2, []int{1, 3, 5, 2}) + t.Assert(array2.Len(), 0) + t.Assert(len(ns2), 4) + t.AssertIN(ns2, []int{1, 3, 5, 2}) }) } func TestSortedIntArray_PopLefts(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 2} array1 := garray.NewSortedIntArrayFrom(a1) ns1 := array1.PopLefts(2) - gtest.Assert(array1.Len(), 2) - gtest.Assert(ns1, []int{1, 2}) + t.Assert(array1.Len(), 2) + t.Assert(ns1, []int{1, 2}) a2 := []int{1, 3, 5, 2} array2 := garray.NewSortedIntArrayFrom(a2) ns2 := array2.PopLefts(5) - gtest.Assert(array2.Len(), 0) - gtest.AssertIN(ns2, []int{1, 3, 5, 2}) + t.Assert(array2.Len(), 0) + t.AssertIN(ns2, []int{1, 3, 5, 2}) }) } func TestSortedIntArray_PopRights(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 2} array1 := garray.NewSortedIntArrayFrom(a1) ns1 := array1.PopRights(2) - gtest.Assert(array1.Len(), 2) - gtest.Assert(ns1, []int{3, 5}) + t.Assert(array1.Len(), 2) + t.Assert(ns1, []int{3, 5}) a2 := []int{1, 3, 5, 2} array2 := garray.NewSortedIntArrayFrom(a2) ns2 := array2.PopRights(5) - gtest.Assert(array2.Len(), 0) - gtest.AssertIN(ns2, []int{1, 3, 5, 2}) + t.Assert(array2.Len(), 0) + t.AssertIN(ns2, []int{1, 3, 5, 2}) }) } func TestSortedIntArray_Range(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5, 2, 6, 7} array1 := garray.NewSortedIntArrayFrom(a1) array2 := garray.NewSortedIntArrayFrom(a1, true) ns1 := array1.Range(1, 4) - gtest.Assert(len(ns1), 3) - gtest.Assert(ns1, []int{2, 3, 5}) + t.Assert(len(ns1), 3) + t.Assert(ns1, []int{2, 3, 5}) ns2 := array1.Range(5, 4) - gtest.Assert(len(ns2), 0) + t.Assert(len(ns2), 0) ns3 := array1.Range(-1, 4) - gtest.Assert(len(ns3), 4) + t.Assert(len(ns3), 4) nsl := array1.Range(5, 8) - gtest.Assert(len(nsl), 1) - gtest.Assert(array2.Range(1, 2), []int{2}) + t.Assert(len(nsl), 1) + t.Assert(array2.Range(1, 2), []int{2}) }) } func TestSortedIntArray_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5} array1 := garray.NewSortedIntArrayFrom(a1) n1 := array1.Sum() - gtest.Assert(n1, 9) + t.Assert(n1, 9) }) } func TestSortedIntArray_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5} array1 := garray.NewSortedIntArrayFrom(a1) - gtest.Assert(array1.Join("."), `1.3.5`) + t.Assert(array1.Join("."), `1.3.5`) }) } func TestSortedIntArray_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5} array1 := garray.NewSortedIntArrayFrom(a1) - gtest.Assert(array1.String(), `[1,3,5]`) + t.Assert(array1.String(), `[1,3,5]`) }) } func TestSortedIntArray_Contains(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5} array1 := garray.NewSortedIntArrayFrom(a1) - gtest.Assert(array1.Contains(4), false) + t.Assert(array1.Contains(4), false) }) } func TestSortedIntArray_Clone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5} array1 := garray.NewSortedIntArrayFrom(a1) array2 := array1.Clone() - gtest.Assert(array2.Len(), 3) - gtest.Assert(array2, array1) + t.Assert(array2.Len(), 3) + t.Assert(array2, array1) }) } func TestSortedIntArray_Clear(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 3, 5} array1 := garray.NewSortedIntArrayFrom(a1) array1.Clear() - gtest.Assert(array1.Len(), 0) + t.Assert(array1.Len(), 0) }) } func TestSortedIntArray_Chunk(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5} array1 := garray.NewSortedIntArrayFrom(a1) ns1 := array1.Chunk(2) //按每几个元素切成一个数组 ns2 := array1.Chunk(-1) - gtest.Assert(len(ns1), 3) - gtest.Assert(ns1[0], []int{1, 2}) - gtest.Assert(ns1[2], []int{5}) - gtest.Assert(len(ns2), 0) + t.Assert(len(ns1), 3) + t.Assert(ns1[0], []int{1, 2}) + t.Assert(ns1[2], []int{5}) + t.Assert(len(ns2), 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5} array1 := garray.NewSortedIntArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []int{1, 2, 3}) - gtest.Assert(chunks[1], []int{4, 5}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []int{1, 2, 3}) + t.Assert(chunks[1], []int{4, 5}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5, 6} array1 := garray.NewSortedIntArrayFrom(a1) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []int{1, 2}) - gtest.Assert(chunks[1], []int{3, 4}) - gtest.Assert(chunks[2], []int{5, 6}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []int{1, 2}) + t.Assert(chunks[1], []int{3, 4}) + t.Assert(chunks[2], []int{5, 6}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5, 6} array1 := garray.NewSortedIntArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []int{1, 2, 3}) - gtest.Assert(chunks[1], []int{4, 5, 6}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []int{1, 2, 3}) + t.Assert(chunks[1], []int{4, 5, 6}) + t.Assert(array1.Chunk(0), nil) }) } func TestSortedIntArray_SubSlice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5} array1 := garray.NewSortedIntArrayFrom(a1) array2 := garray.NewSortedIntArrayFrom(a1, true) ns1 := array1.SubSlice(1, 2) - gtest.Assert(len(ns1), 2) - gtest.Assert(ns1, []int{2, 3}) + t.Assert(len(ns1), 2) + t.Assert(ns1, []int{2, 3}) ns2 := array1.SubSlice(7, 2) - gtest.Assert(len(ns2), 0) + t.Assert(len(ns2), 0) ns3 := array1.SubSlice(3, 5) - gtest.Assert(len(ns3), 2) - gtest.Assert(ns3, []int{4, 5}) + t.Assert(len(ns3), 2) + t.Assert(ns3, []int{4, 5}) ns4 := array1.SubSlice(3, 1) - gtest.Assert(len(ns4), 1) - gtest.Assert(ns4, []int{4}) - gtest.Assert(array1.SubSlice(-1, 1), []int{5}) - gtest.Assert(array1.SubSlice(-9, 1), nil) - gtest.Assert(array1.SubSlice(1, -9), nil) - gtest.Assert(array2.SubSlice(1, 2), []int{2, 3}) + t.Assert(len(ns4), 1) + t.Assert(ns4, []int{4}) + t.Assert(array1.SubSlice(-1, 1), []int{5}) + t.Assert(array1.SubSlice(-9, 1), nil) + t.Assert(array1.SubSlice(1, -9), nil) + t.Assert(array2.SubSlice(1, 2), []int{2, 3}) }) } func TestSortedIntArray_Rand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5} array1 := garray.NewSortedIntArrayFrom(a1) ns1 := array1.Rand() //按每几个元素切成一个数组 - gtest.AssertIN(ns1, a1) + t.AssertIN(ns1, a1) }) } func TestSortedIntArray_Rands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5} array1 := garray.NewSortedIntArrayFrom(a1) ns1 := array1.Rands(2) //按每几个元素切成一个数组 - gtest.AssertIN(ns1, a1) - gtest.Assert(len(ns1), 2) + t.AssertIN(ns1, a1) + t.Assert(len(ns1), 2) ns2 := array1.Rands(6) //按每几个元素切成一个数组 - gtest.AssertIN(ns2, a1) - gtest.Assert(len(ns2), 5) + t.AssertIN(ns2, a1) + t.Assert(len(ns2), 5) }) } func TestSortedIntArray_CountValues(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5, 3} array1 := garray.NewSortedIntArrayFrom(a1) ns1 := array1.CountValues() //按每几个元素切成一个数组 - gtest.Assert(len(ns1), 5) - gtest.Assert(ns1[2], 1) - gtest.Assert(ns1[3], 2) + t.Assert(len(ns1), 5) + t.Assert(ns1[2], 1) + t.Assert(ns1[3], 2) }) } func TestSortedIntArray_SetUnique(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []int{1, 2, 3, 4, 5, 3} array1 := garray.NewSortedIntArrayFrom(a1) array1.SetUnique(true) - gtest.Assert(array1.Len(), 5) - gtest.Assert(array1, []int{1, 2, 3, 4, 5}) + t.Assert(array1.Len(), 5) + t.Assert(array1, []int{1, 2, 3, 4, 5}) }) } func TestSortedIntArray_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []int{1, 2, 3, 4} a1 := garray.NewSortedIntArrayFrom(s1, true) ch1 := make(chan int64, 3) @@ -394,13 +394,13 @@ func TestSortedIntArray_LockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 - gtest.Assert(a1.Contains(6), true) + t.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 + t.Assert(a1.Contains(6), true) }) } func TestSortedIntArray_RLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []int{1, 2, 3, 4} a1 := garray.NewSortedIntArrayFrom(s1, true) @@ -426,13 +426,13 @@ func TestSortedIntArray_RLockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 - gtest.Assert(a1.Contains(6), true) + t.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 + t.Assert(a1.Contains(6), true) }) } func TestSortedIntArray_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { func1 := func(v1, v2 interface{}) int { if gconv.Int(v1) < gconv.Int(v2) { return 0 @@ -449,37 +449,37 @@ func TestSortedIntArray_Merge(t *testing.T) { s6 := garray.NewSortedIntArrayFrom([]int{1, 2, 3}) a1 := garray.NewSortedIntArrayFrom(i0) - gtest.Assert(a1.Merge(s2).Len(), 6) - gtest.Assert(a1.Merge(i1).Len(), 9) - gtest.Assert(a1.Merge(i2).Len(), 10) - gtest.Assert(a1.Merge(s3).Len(), 12) - gtest.Assert(a1.Merge(s4).Len(), 14) - gtest.Assert(a1.Merge(s5).Len(), 16) - gtest.Assert(a1.Merge(s6).Len(), 19) + t.Assert(a1.Merge(s2).Len(), 6) + t.Assert(a1.Merge(i1).Len(), 9) + t.Assert(a1.Merge(i2).Len(), 10) + t.Assert(a1.Merge(s3).Len(), 12) + t.Assert(a1.Merge(s4).Len(), 14) + t.Assert(a1.Merge(s5).Len(), 16) + t.Assert(a1.Merge(s6).Len(), 19) }) } func TestSortedIntArray_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []int{1, 4, 3, 2} s2 := []int{1, 2, 3, 4} a1 := garray.NewSortedIntArrayFrom(s1) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(b1, b2) - gtest.Assert(err1, err2) + t.Assert(b1, b2) + t.Assert(err1, err2) a2 := garray.NewSortedIntArray() err1 = json.Unmarshal(b2, &a2) - gtest.Assert(a2.Slice(), s2) + t.Assert(a2.Slice(), s2) var a3 garray.SortedIntArray err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a3.Slice(), s1) + t.Assert(err, nil) + t.Assert(a3.Slice(), s1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Name string Scores *garray.SortedIntArray @@ -489,73 +489,73 @@ func TestSortedIntArray_Json(t *testing.T) { "Scores": []int{99, 100, 98}, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) user := new(User) err = json.Unmarshal(b, user) - gtest.Assert(err, nil) - gtest.Assert(user.Name, data["Name"]) - gtest.Assert(user.Scores, []int{98, 99, 100}) + t.Assert(err, nil) + t.Assert(user.Name, data["Name"]) + t.Assert(user.Scores, []int{98, 99, 100}) }) } func TestSortedIntArray_Iterator(t *testing.T) { slice := g.SliceInt{10, 20, 30, 40} array := garray.NewSortedIntArrayFrom(slice) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.Iterator(func(k int, v int) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorAsc(func(k int, v int) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorDesc(func(k int, v int) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.Iterator(func(k int, v int) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorAsc(func(k int, v int) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorDesc(func(k int, v int) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) } func TestSortedIntArray_RemoveValue(t *testing.T) { slice := g.SliceInt{10, 20, 30, 40} array := garray.NewSortedIntArrayFrom(slice) - gtest.Case(t, func() { - gtest.Assert(array.RemoveValue(99), false) - gtest.Assert(array.RemoveValue(20), true) - gtest.Assert(array.RemoveValue(10), true) - gtest.Assert(array.RemoveValue(20), false) - gtest.Assert(array.RemoveValue(88), false) - gtest.Assert(array.Len(), 2) + gtest.C(t, func(t *gtest.T) { + t.Assert(array.RemoveValue(99), false) + t.Assert(array.RemoveValue(20), true) + t.Assert(array.RemoveValue(10), true) + t.Assert(array.RemoveValue(20), false) + t.Assert(array.RemoveValue(88), false) + t.Assert(array.Len(), 2) }) } @@ -565,36 +565,36 @@ func TestSortedIntArray_UnmarshalValue(t *testing.T) { Array *garray.SortedIntArray } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`[2,3,1]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": g.Slice{2, 3, 1}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) }) } func TestSortedIntArray_FilterEmpty(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewSortedIntArrayFrom(g.SliceInt{0, 1, 2, 3, 4, 0}) - gtest.Assert(array.FilterEmpty(), g.SliceInt{1, 2, 3, 4}) + t.Assert(array.FilterEmpty(), g.SliceInt{1, 2, 3, 4}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewSortedIntArrayFrom(g.SliceInt{1, 2, 3, 4}) - gtest.Assert(array.FilterEmpty(), g.SliceInt{1, 2, 3, 4}) + t.Assert(array.FilterEmpty(), g.SliceInt{1, 2, 3, 4}) }) } diff --git a/container/garray/garray_z_unit_sorted_str_array_test.go b/container/garray/garray_z_unit_sorted_str_array_test.go index 24cd2f4dd..fd1e75cbe 100644 --- a/container/garray/garray_z_unit_sorted_str_array_test.go +++ b/container/garray/garray_z_unit_sorted_str_array_test.go @@ -20,362 +20,362 @@ import ( ) func TestNewSortedStrArrayFrom(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"a", "d", "c", "b"} s1 := garray.NewSortedStrArrayFrom(a1, true) - gtest.Assert(s1, []string{"a", "b", "c", "d"}) + t.Assert(s1, []string{"a", "b", "c", "d"}) s2 := garray.NewSortedStrArrayFrom(a1, false) - gtest.Assert(s2, []string{"a", "b", "c", "d"}) + t.Assert(s2, []string{"a", "b", "c", "d"}) }) } func TestNewSortedStrArrayFromCopy(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"a", "d", "c", "b"} s1 := garray.NewSortedStrArrayFromCopy(a1, true) - gtest.Assert(s1.Len(), 4) - gtest.Assert(s1, []string{"a", "b", "c", "d"}) + t.Assert(s1.Len(), 4) + t.Assert(s1, []string{"a", "b", "c", "d"}) }) } func TestSortedStrArray_SetArray(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"a", "d", "c", "b"} a2 := []string{"f", "g", "h"} array1 := garray.NewSortedStrArrayFrom(a1) array1.SetArray(a2) - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1.Contains("d"), false) - gtest.Assert(array1.Contains("b"), false) - gtest.Assert(array1.Contains("g"), true) + t.Assert(array1.Len(), 3) + t.Assert(array1.Contains("d"), false) + t.Assert(array1.Contains("b"), false) + t.Assert(array1.Contains("g"), true) }) } func TestSortedStrArray_Sort(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"a", "d", "c", "b"} array1 := garray.NewSortedStrArrayFrom(a1) - gtest.Assert(array1, []string{"a", "b", "c", "d"}) + t.Assert(array1, []string{"a", "b", "c", "d"}) array1.Sort() - gtest.Assert(array1.Len(), 4) - gtest.Assert(array1.Contains("c"), true) - gtest.Assert(array1, []string{"a", "b", "c", "d"}) + t.Assert(array1.Len(), 4) + t.Assert(array1.Contains("c"), true) + t.Assert(array1, []string{"a", "b", "c", "d"}) }) } func TestSortedStrArray_Get(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"a", "d", "c", "b"} array1 := garray.NewSortedStrArrayFrom(a1) - gtest.Assert(array1.Get(2), "c") - gtest.Assert(array1.Get(0), "a") + t.Assert(array1.Get(2), "c") + t.Assert(array1.Get(0), "a") }) } func TestSortedStrArray_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"a", "d", "c", "b"} array1 := garray.NewSortedStrArrayFrom(a1) - gtest.Assert(array1.Remove(-1), "") - gtest.Assert(array1.Remove(100000), "") + t.Assert(array1.Remove(-1), "") + t.Assert(array1.Remove(100000), "") - gtest.Assert(array1.Remove(2), "c") - gtest.Assert(array1.Get(2), "d") - gtest.Assert(array1.Len(), 3) - gtest.Assert(array1.Contains("c"), false) + t.Assert(array1.Remove(2), "c") + t.Assert(array1.Get(2), "d") + t.Assert(array1.Len(), 3) + t.Assert(array1.Contains("c"), false) - gtest.Assert(array1.Remove(0), "a") - gtest.Assert(array1.Len(), 2) - gtest.Assert(array1.Contains("a"), false) + t.Assert(array1.Remove(0), "a") + t.Assert(array1.Len(), 2) + t.Assert(array1.Contains("a"), false) // 此时array1里的元素只剩下2个 - gtest.Assert(array1.Remove(1), "d") - gtest.Assert(array1.Len(), 1) + t.Assert(array1.Remove(1), "d") + t.Assert(array1.Len(), 1) }) } func TestSortedStrArray_PopLeft(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b"} array1 := garray.NewSortedStrArrayFrom(a1) s1 := array1.PopLeft() - gtest.Assert(s1, "a") - gtest.Assert(array1.Len(), 4) - gtest.Assert(array1.Contains("a"), false) + t.Assert(s1, "a") + t.Assert(array1.Len(), 4) + t.Assert(array1.Contains("a"), false) }) } func TestSortedStrArray_PopRight(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b"} array1 := garray.NewSortedStrArrayFrom(a1) s1 := array1.PopRight() - gtest.Assert(s1, "e") - gtest.Assert(array1.Len(), 4) - gtest.Assert(array1.Contains("e"), false) + t.Assert(s1, "e") + t.Assert(array1.Len(), 4) + t.Assert(array1.Contains("e"), false) }) } func TestSortedStrArray_PopRand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b"} array1 := garray.NewSortedStrArrayFrom(a1) s1 := array1.PopRand() - gtest.AssertIN(s1, []string{"e", "a", "d", "c", "b"}) - gtest.Assert(array1.Len(), 4) - gtest.Assert(array1.Contains(s1), false) + t.AssertIN(s1, []string{"e", "a", "d", "c", "b"}) + t.Assert(array1.Len(), 4) + t.Assert(array1.Contains(s1), false) }) } func TestSortedStrArray_PopRands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b"} array1 := garray.NewSortedStrArrayFrom(a1) s1 := array1.PopRands(2) - gtest.AssertIN(s1, []string{"e", "a", "d", "c", "b"}) - gtest.Assert(array1.Len(), 3) - gtest.Assert(len(s1), 2) + t.AssertIN(s1, []string{"e", "a", "d", "c", "b"}) + t.Assert(array1.Len(), 3) + t.Assert(len(s1), 2) s1 = array1.PopRands(4) - gtest.Assert(len(s1), 3) - gtest.AssertIN(s1, []string{"e", "a", "d", "c", "b"}) + t.Assert(len(s1), 3) + t.AssertIN(s1, []string{"e", "a", "d", "c", "b"}) }) } func TestSortedStrArray_PopLefts(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b"} array1 := garray.NewSortedStrArrayFrom(a1) s1 := array1.PopLefts(2) - gtest.Assert(s1, []string{"a", "b"}) - gtest.Assert(array1.Len(), 3) - gtest.Assert(len(s1), 2) + t.Assert(s1, []string{"a", "b"}) + t.Assert(array1.Len(), 3) + t.Assert(len(s1), 2) s1 = array1.PopLefts(4) - gtest.Assert(len(s1), 3) - gtest.Assert(s1, []string{"c", "d", "e"}) + t.Assert(len(s1), 3) + t.Assert(s1, []string{"c", "d", "e"}) }) } func TestSortedStrArray_PopRights(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b", "f", "g"} array1 := garray.NewSortedStrArrayFrom(a1) s1 := array1.PopRights(2) - gtest.Assert(s1, []string{"f", "g"}) - gtest.Assert(array1.Len(), 5) - gtest.Assert(len(s1), 2) + t.Assert(s1, []string{"f", "g"}) + t.Assert(array1.Len(), 5) + t.Assert(len(s1), 2) s1 = array1.PopRights(6) - gtest.Assert(len(s1), 5) - gtest.Assert(s1, []string{"a", "b", "c", "d", "e"}) - gtest.Assert(array1.Len(), 0) + t.Assert(len(s1), 5) + t.Assert(s1, []string{"a", "b", "c", "d", "e"}) + t.Assert(array1.Len(), 0) }) } func TestSortedStrArray_Range(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b", "f", "g"} array1 := garray.NewSortedStrArrayFrom(a1) array2 := garray.NewSortedStrArrayFrom(a1, true) s1 := array1.Range(2, 4) - gtest.Assert(len(s1), 2) - gtest.Assert(s1, []string{"c", "d"}) + t.Assert(len(s1), 2) + t.Assert(s1, []string{"c", "d"}) s1 = array1.Range(-1, 2) - gtest.Assert(len(s1), 2) - gtest.Assert(s1, []string{"a", "b"}) + t.Assert(len(s1), 2) + t.Assert(s1, []string{"a", "b"}) s1 = array1.Range(4, 8) - gtest.Assert(len(s1), 3) - gtest.Assert(s1, []string{"e", "f", "g"}) - gtest.Assert(array1.Range(10, 2), nil) + t.Assert(len(s1), 3) + t.Assert(s1, []string{"e", "f", "g"}) + t.Assert(array1.Range(10, 2), nil) s2 := array2.Range(2, 4) - gtest.Assert(s2, []string{"c", "d"}) + t.Assert(s2, []string{"c", "d"}) }) } func TestSortedStrArray_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b", "f", "g"} a2 := []string{"1", "2", "3", "4", "a"} array1 := garray.NewSortedStrArrayFrom(a1) array2 := garray.NewSortedStrArrayFrom(a2) - gtest.Assert(array1.Sum(), 0) - gtest.Assert(array2.Sum(), 10) + t.Assert(array1.Sum(), 0) + t.Assert(array2.Sum(), 10) }) } func TestSortedStrArray_Clone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b", "f", "g"} array1 := garray.NewSortedStrArrayFrom(a1) array2 := array1.Clone() - gtest.Assert(array1, array2) + t.Assert(array1, array2) array1.Remove(1) - gtest.Assert(array2.Len(), 7) + t.Assert(array2.Len(), 7) }) } func TestSortedStrArray_Clear(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b", "f", "g"} array1 := garray.NewSortedStrArrayFrom(a1) array1.Clear() - gtest.Assert(array1.Len(), 0) + t.Assert(array1.Len(), 0) }) } func TestSortedStrArray_SubSlice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b", "f", "g"} array1 := garray.NewSortedStrArrayFrom(a1) array2 := garray.NewSortedStrArrayFrom(a1, true) s1 := array1.SubSlice(1, 3) - gtest.Assert(len(s1), 3) - gtest.Assert(s1, []string{"b", "c", "d"}) - gtest.Assert(array1.Len(), 7) + t.Assert(len(s1), 3) + t.Assert(s1, []string{"b", "c", "d"}) + t.Assert(array1.Len(), 7) s2 := array1.SubSlice(1, 10) - gtest.Assert(len(s2), 6) + t.Assert(len(s2), 6) s3 := array1.SubSlice(10, 2) - gtest.Assert(len(s3), 0) + t.Assert(len(s3), 0) s3 = array1.SubSlice(-5, 2) - gtest.Assert(s3, []string{"c", "d"}) + t.Assert(s3, []string{"c", "d"}) s3 = array1.SubSlice(-10, 2) - gtest.Assert(s3, nil) + t.Assert(s3, nil) s3 = array1.SubSlice(1, -2) - gtest.Assert(s3, nil) + t.Assert(s3, nil) - gtest.Assert(array2.SubSlice(1, 3), []string{"b", "c", "d"}) + t.Assert(array2.SubSlice(1, 3), []string{"b", "c", "d"}) }) } func TestSortedStrArray_Len(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "c", "b", "f", "g"} array1 := garray.NewSortedStrArrayFrom(a1) - gtest.Assert(array1.Len(), 7) + t.Assert(array1.Len(), 7) }) } func TestSortedStrArray_Rand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d"} array1 := garray.NewSortedStrArrayFrom(a1) - gtest.AssertIN(array1.Rand(), []string{"e", "a", "d"}) + t.AssertIN(array1.Rand(), []string{"e", "a", "d"}) }) } func TestSortedStrArray_Rands(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d"} array1 := garray.NewSortedStrArrayFrom(a1) s1 := array1.Rands(2) - gtest.AssertIN(s1, []string{"e", "a", "d"}) - gtest.Assert(len(s1), 2) + t.AssertIN(s1, []string{"e", "a", "d"}) + t.Assert(len(s1), 2) s1 = array1.Rands(4) - gtest.AssertIN(s1, []string{"e", "a", "d"}) - gtest.Assert(len(s1), 3) + t.AssertIN(s1, []string{"e", "a", "d"}) + t.Assert(len(s1), 3) }) } func TestSortedStrArray_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d"} array1 := garray.NewSortedStrArrayFrom(a1) - gtest.Assert(array1.Join(","), `a,d,e`) - gtest.Assert(array1.Join("."), `a.d.e`) + t.Assert(array1.Join(","), `a,d,e`) + t.Assert(array1.Join("."), `a.d.e`) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"a", `"b"`, `\c`} array1 := garray.NewSortedStrArrayFrom(a1) - gtest.Assert(array1.Join("."), `"b".\c.a`) + t.Assert(array1.Join("."), `"b".\c.a`) }) } func TestSortedStrArray_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d"} array1 := garray.NewSortedStrArrayFrom(a1) - gtest.Assert(array1.String(), `["a","d","e"]`) + t.Assert(array1.String(), `["a","d","e"]`) }) } func TestSortedStrArray_CountValues(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "a", "c"} array1 := garray.NewSortedStrArrayFrom(a1) m1 := array1.CountValues() - gtest.Assert(m1["a"], 2) - gtest.Assert(m1["d"], 1) + t.Assert(m1["a"], 2) + t.Assert(m1["d"], 1) }) } func TestSortedStrArray_Chunk(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "a", "c"} array1 := garray.NewSortedStrArrayFrom(a1) array2 := array1.Chunk(2) - gtest.Assert(len(array2), 3) - gtest.Assert(len(array2[0]), 2) - gtest.Assert(array2[1], []string{"c", "d"}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(array2), 3) + t.Assert(len(array2[0]), 2) + t.Assert(array2[1], []string{"c", "d"}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"1", "2", "3", "4", "5"} array1 := garray.NewSortedStrArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []string{"1", "2", "3"}) - gtest.Assert(chunks[1], []string{"4", "5"}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []string{"1", "2", "3"}) + t.Assert(chunks[1], []string{"4", "5"}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"1", "2", "3", "4", "5", "6"} array1 := garray.NewSortedStrArrayFrom(a1) chunks := array1.Chunk(2) - gtest.Assert(len(chunks), 3) - gtest.Assert(chunks[0], []string{"1", "2"}) - gtest.Assert(chunks[1], []string{"3", "4"}) - gtest.Assert(chunks[2], []string{"5", "6"}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 3) + t.Assert(chunks[0], []string{"1", "2"}) + t.Assert(chunks[1], []string{"3", "4"}) + t.Assert(chunks[2], []string{"5", "6"}) + t.Assert(array1.Chunk(0), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"1", "2", "3", "4", "5", "6"} array1 := garray.NewSortedStrArrayFrom(a1) chunks := array1.Chunk(3) - gtest.Assert(len(chunks), 2) - gtest.Assert(chunks[0], []string{"1", "2", "3"}) - gtest.Assert(chunks[1], []string{"4", "5", "6"}) - gtest.Assert(array1.Chunk(0), nil) + t.Assert(len(chunks), 2) + t.Assert(chunks[0], []string{"1", "2", "3"}) + t.Assert(chunks[1], []string{"4", "5", "6"}) + t.Assert(array1.Chunk(0), nil) }) } func TestSortedStrArray_SetUnique(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a1 := []string{"e", "a", "d", "a", "c"} array1 := garray.NewSortedStrArrayFrom(a1) array2 := array1.SetUnique(true) - gtest.Assert(array2.Len(), 4) - gtest.Assert(array2, []string{"a", "c", "d", "e"}) + t.Assert(array2.Len(), 4) + t.Assert(array2, []string{"a", "c", "d", "e"}) }) } func TestSortedStrArray_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []string{"a", "b", "c", "d"} a1 := garray.NewSortedStrArrayFrom(s1, true) @@ -401,13 +401,13 @@ func TestSortedStrArray_LockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 - gtest.Assert(a1.Contains("g"), true) + t.AssertGT(t2-t1, 20) //go1加的读写互斥锁,所go2读的时候被阻塞。 + t.Assert(a1.Contains("g"), true) }) } func TestSortedStrArray_RLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []string{"a", "b", "c", "d"} a1 := garray.NewSortedStrArrayFrom(s1, true) @@ -433,13 +433,13 @@ func TestSortedStrArray_RLockFunc(t *testing.T) { <-ch2 //等待go1完成 // 防止ci抖动,以豪秒为单位 - gtest.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 - gtest.Assert(a1.Contains("g"), true) + t.AssertLT(t2-t1, 20) //go1加的读锁,所go2读的时候,并没有阻塞。 + t.Assert(a1.Contains("g"), true) }) } func TestSortedStrArray_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { func1 := func(v1, v2 interface{}) int { if gconv.Int(v1) < gconv.Int(v2) { return 0 @@ -457,39 +457,39 @@ func TestSortedStrArray_Merge(t *testing.T) { s6 := garray.NewSortedIntArrayFrom([]int{1, 2, 3}) a1 := garray.NewSortedStrArrayFrom(s1) - gtest.Assert(a1.Merge(s2).Len(), 6) - gtest.Assert(a1.Merge(i1).Len(), 9) - gtest.Assert(a1.Merge(i2).Len(), 10) - gtest.Assert(a1.Merge(s3).Len(), 12) - gtest.Assert(a1.Merge(s4).Len(), 14) - gtest.Assert(a1.Merge(s5).Len(), 16) - gtest.Assert(a1.Merge(s6).Len(), 19) + t.Assert(a1.Merge(s2).Len(), 6) + t.Assert(a1.Merge(i1).Len(), 9) + t.Assert(a1.Merge(i2).Len(), 10) + t.Assert(a1.Merge(s3).Len(), 12) + t.Assert(a1.Merge(s4).Len(), 14) + t.Assert(a1.Merge(s5).Len(), 16) + t.Assert(a1.Merge(s6).Len(), 19) }) } func TestSortedStrArray_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []string{"a", "b", "d", "c"} s2 := []string{"a", "b", "c", "d"} a1 := garray.NewSortedStrArrayFrom(s1) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(b1, b2) - gtest.Assert(err1, err2) + t.Assert(b1, b2) + t.Assert(err1, err2) a2 := garray.NewSortedStrArray() err1 = json.Unmarshal(b2, &a2) - gtest.Assert(a2.Slice(), s2) - gtest.Assert(a2.Interfaces(), s2) + t.Assert(a2.Slice(), s2) + t.Assert(a2.Interfaces(), s2) var a3 garray.SortedStrArray err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a3.Slice(), s1) - gtest.Assert(a3.Interfaces(), s1) + t.Assert(err, nil) + t.Assert(a3.Slice(), s1) + t.Assert(a3.Interfaces(), s1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Name string Scores *garray.SortedStrArray @@ -499,72 +499,72 @@ func TestSortedStrArray_Json(t *testing.T) { "Scores": []string{"A+", "A", "A"}, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) user := new(User) err = json.Unmarshal(b, user) - gtest.Assert(err, nil) - gtest.Assert(user.Name, data["Name"]) - gtest.Assert(user.Scores, []string{"A", "A", "A+"}) + t.Assert(err, nil) + t.Assert(user.Name, data["Name"]) + t.Assert(user.Scores, []string{"A", "A", "A+"}) }) } func TestSortedStrArray_Iterator(t *testing.T) { slice := g.SliceStr{"a", "b", "d", "c"} array := garray.NewSortedStrArrayFrom(slice) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.Iterator(func(k int, v string) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorAsc(func(k int, v string) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array.IteratorDesc(func(k int, v string) bool { - gtest.Assert(v, slice[k]) + t.Assert(v, slice[k]) return true }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.Iterator(func(k int, v string) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorAsc(func(k int, v string) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { index := 0 array.IteratorDesc(func(k int, v string) bool { index++ return false }) - gtest.Assert(index, 1) + t.Assert(index, 1) }) } func TestSortedStrArray_RemoveValue(t *testing.T) { slice := g.SliceStr{"a", "b", "d", "c"} array := garray.NewSortedStrArrayFrom(slice) - gtest.Case(t, func() { - gtest.Assert(array.RemoveValue("e"), false) - gtest.Assert(array.RemoveValue("b"), true) - gtest.Assert(array.RemoveValue("a"), true) - gtest.Assert(array.RemoveValue("c"), true) - gtest.Assert(array.RemoveValue("f"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(array.RemoveValue("e"), false) + t.Assert(array.RemoveValue("b"), true) + t.Assert(array.RemoveValue("a"), true) + t.Assert(array.RemoveValue("c"), true) + t.Assert(array.RemoveValue("f"), false) }) } @@ -574,36 +574,36 @@ func TestSortedStrArray_UnmarshalValue(t *testing.T) { Array *garray.SortedStrArray } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`["1","3","2"]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "array": g.SliceStr{"1", "3", "2"}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) }) } func TestSortedStrArray_FilterEmpty(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewSortedStrArrayFrom(g.SliceStr{"", "1", "2", "0"}) - gtest.Assert(array.FilterEmpty(), g.SliceStr{"0", "1", "2"}) + t.Assert(array.FilterEmpty(), g.SliceStr{"0", "1", "2"}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewSortedStrArrayFrom(g.SliceStr{"1", "2"}) - gtest.Assert(array.FilterEmpty(), g.SliceStr{"1", "2"}) + t.Assert(array.FilterEmpty(), g.SliceStr{"1", "2"}) }) } diff --git a/container/gchan/gchan_z_unit_test.go b/container/gchan/gchan_z_unit_test.go index ed60f15ca..cb3d07e46 100644 --- a/container/gchan/gchan_z_unit_test.go +++ b/container/gchan/gchan_z_unit_test.go @@ -9,18 +9,18 @@ import ( ) func Test_Gchan(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { ch := gchan.New(10) - gtest.Assert(ch.Cap(), 10) - gtest.Assert(ch.Push(1), nil) - gtest.Assert(ch.Len(), 1) - gtest.Assert(ch.Size(), 1) + t.Assert(ch.Cap(), 10) + t.Assert(ch.Push(1), nil) + t.Assert(ch.Len(), 1) + t.Assert(ch.Size(), 1) ch.Pop() - gtest.Assert(ch.Len(), 0) - gtest.Assert(ch.Size(), 0) + t.Assert(ch.Len(), 0) + t.Assert(ch.Size(), 0) ch.Close() - gtest.Assert(ch.Push(1), errors.New("channel is closed")) + t.Assert(ch.Push(1), errors.New("channel is closed")) ch = gchan.New(0) ch1 := gchan.New(0) @@ -32,7 +32,7 @@ func Test_Gchan(t *testing.T) { ch1.Push(i) break } - gtest.Assert(v, i) + t.Assert(v, i) i++ } }() @@ -41,7 +41,7 @@ func Test_Gchan(t *testing.T) { ch.Push(index) } ch.Close() - gtest.Assert(ch1.Pop(), 10) + t.Assert(ch1.Pop(), 10) ch1.Close() }) } diff --git a/container/glist/glist_z_unit_test.go b/container/glist/glist_z_unit_test.go index 81fdeef08..49a249b2a 100644 --- a/container/glist/glist_z_unit_test.go +++ b/container/glist/glist_z_unit_test.go @@ -408,17 +408,17 @@ func TestList_PushBacks(t *testing.T) { } func TestList_PopBacks(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { l := New() a1 := []interface{}{1, 2, 3, 4} a2 := []interface{}{"a", "c", "b", "e"} l.PushFronts(a1) i1 := l.PopBacks(2) - gtest.Assert(i1, []interface{}{1, 2}) + t.Assert(i1, []interface{}{1, 2}) l.PushBacks(a2) //4.3,a,c,b,e i1 = l.PopBacks(3) - gtest.Assert(i1, []interface{}{"e", "b", "c"}) + t.Assert(i1, []interface{}{"e", "b", "c"}) }) } @@ -427,8 +427,8 @@ func TestList_PopFronts(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) i1 := l.PopFronts(2) - gtest.Assert(i1, []interface{}{4, 3}) - gtest.Assert(l.Len(), 2) + t.Assert(i1, []interface{}{4, 3}) + t.Assert(l.Len(), 2) } func TestList_PopBackAll(t *testing.T) { @@ -436,8 +436,8 @@ func TestList_PopBackAll(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) i1 := l.PopBackAll() - gtest.Assert(i1, []interface{}{1, 2, 3, 4}) - gtest.Assert(l.Len(), 0) + t.Assert(i1, []interface{}{1, 2, 3, 4}) + t.Assert(l.Len(), 0) } @@ -446,8 +446,8 @@ func TestList_PopFrontAll(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) i1 := l.PopFrontAll() - gtest.Assert(i1, []interface{}{4, 3, 2, 1}) - gtest.Assert(l.Len(), 0) + t.Assert(i1, []interface{}{4, 3, 2, 1}) + t.Assert(l.Len(), 0) } func TestList_FrontAll(t *testing.T) { @@ -455,8 +455,8 @@ func TestList_FrontAll(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) i1 := l.FrontAll() - gtest.Assert(i1, []interface{}{4, 3, 2, 1}) - gtest.Assert(l.Len(), 4) + t.Assert(i1, []interface{}{4, 3, 2, 1}) + t.Assert(l.Len(), 4) } func TestList_BackAll(t *testing.T) { @@ -464,8 +464,8 @@ func TestList_BackAll(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) i1 := l.BackAll() - gtest.Assert(i1, []interface{}{1, 2, 3, 4}) - gtest.Assert(l.Len(), 4) + t.Assert(i1, []interface{}{1, 2, 3, 4}) + t.Assert(l.Len(), 4) } func TestList_FrontValue(t *testing.T) { @@ -474,11 +474,11 @@ func TestList_FrontValue(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) i1 := l.FrontValue() - gtest.Assert(gconv.Int(i1), 4) - gtest.Assert(l.Len(), 4) + t.Assert(gconv.Int(i1), 4) + t.Assert(l.Len(), 4) i1 = l2.FrontValue() - gtest.Assert(i1, nil) + t.Assert(i1, nil) } func TestList_BackValue(t *testing.T) { @@ -487,11 +487,11 @@ func TestList_BackValue(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) i1 := l.BackValue() - gtest.Assert(gconv.Int(i1), 1) - gtest.Assert(l.Len(), 4) + t.Assert(gconv.Int(i1), 1) + t.Assert(l.Len(), 4) i1 = l2.FrontValue() - gtest.Assert(i1, nil) + t.Assert(i1, nil) } @@ -500,17 +500,17 @@ func TestList_Back(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) e1 := l.Back() - gtest.Assert(e1.Value, 1) - gtest.Assert(l.Len(), 4) + t.Assert(e1.Value, 1) + t.Assert(l.Len(), 4) } func TestList_Size(t *testing.T) { l := New() a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) - gtest.Assert(l.Size(), 4) + t.Assert(l.Size(), 4) l.PopFront() - gtest.Assert(l.Size(), 3) + t.Assert(l.Size(), 3) } func TestList_Removes(t *testing.T) { @@ -519,11 +519,11 @@ func TestList_Removes(t *testing.T) { l.PushFronts(a1) e1 := l.Back() l.Removes([]*Element{e1}) - gtest.Assert(l.Len(), 3) + t.Assert(l.Len(), 3) e2 := l.Back() l.Removes([]*Element{e2}) - gtest.Assert(l.Len(), 2) + t.Assert(l.Len(), 2) checkList(t, l, []interface{}{4, 3}) } @@ -533,7 +533,7 @@ func TestList_Clear(t *testing.T) { a1 := []interface{}{1, 2, 3, 4} l.PushFronts(a1) l.Clear() - gtest.Assert(l.Len(), 0) + t.Assert(l.Len(), 0) } func TestList_IteratorAsc(t *testing.T) { @@ -564,7 +564,7 @@ func TestList_IteratorDesc(t *testing.T) { return false } l.IteratorDesc(fun1) - gtest.Assert(l.Len(), 4) + t.Assert(l.Len(), 4) checkList(t, l, []interface{}{4, 3, 2, 1}) } @@ -585,51 +585,51 @@ func TestList_Iterator(t *testing.T) { } func TestList_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { l := NewFrom([]interface{}{1, 2, "a", `"b"`, `\c`}) - gtest.Assert(l.Join(","), `1,2,"a","\"b\"","\\c"`) - gtest.Assert(l.Join("."), `1.2."a"."\"b\""."\\c"`) + t.Assert(l.Join(","), `1,2,"a","\"b\"","\\c"`) + t.Assert(l.Join("."), `1.2."a"."\"b\""."\\c"`) }) } func TestList_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { l := NewFrom([]interface{}{1, 2, "a", `"b"`, `\c`}) - gtest.Assert(l.String(), `[1,2,"a","\"b\"","\\c"]`) + t.Assert(l.String(), `[1,2,"a","\"b\"","\\c"]`) }) } func TestList_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a := []interface{}{"a", "b", "c"} l := New() l.PushBacks(a) b1, err1 := json.Marshal(l) b2, err2 := json.Marshal(a) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a := []interface{}{"a", "b", "c"} l := New() b, err := json.Marshal(a) - gtest.Assert(err, nil) + t.Assert(err, nil) err = json.Unmarshal(b, l) - gtest.Assert(err, nil) - gtest.Assert(l.FrontAll(), a) + t.Assert(err, nil) + t.Assert(l.FrontAll(), a) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var l List a := []interface{}{"a", "b", "c"} b, err := json.Marshal(a) - gtest.Assert(err, nil) + t.Assert(err, nil) err = json.Unmarshal(b, &l) - gtest.Assert(err, nil) - gtest.Assert(l.FrontAll(), a) + t.Assert(err, nil) + t.Assert(l.FrontAll(), a) }) } @@ -639,25 +639,25 @@ func TestList_UnmarshalValue(t *testing.T) { List *List } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "list": []byte(`[1,2,3]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.List.FrontAll(), []interface{}{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.List.FrontAll(), []interface{}{1, 2, 3}) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "list": []interface{}{1, 2, 3}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.List.FrontAll(), []interface{}{1, 2, 3}) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.List.FrontAll(), []interface{}{1, 2, 3}) }) } diff --git a/container/gmap/gmap_z_basic_test.go b/container/gmap/gmap_z_basic_test.go index 0502916bc..b847e2809 100644 --- a/container/gmap/gmap_z_basic_test.go +++ b/container/gmap/gmap_z_basic_test.go @@ -18,63 +18,63 @@ func getValue() interface{} { } func Test_Map_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.New() m.Set("key1", "val1") - gtest.Assert(m.Keys(), []interface{}{"key1"}) + t.Assert(m.Keys(), []interface{}{"key1"}) - gtest.Assert(m.Get("key1"), "val1") - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("key1"), "val1") + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("key2", "val2"), "val2") - gtest.Assert(m.SetIfNotExist("key2", "val2"), false) + t.Assert(m.GetOrSet("key2", "val2"), "val2") + t.Assert(m.SetIfNotExist("key2", "val2"), false) - gtest.Assert(m.SetIfNotExist("key3", "val3"), true) + t.Assert(m.SetIfNotExist("key3", "val3"), true) - gtest.Assert(m.Remove("key2"), "val2") - gtest.Assert(m.Contains("key2"), false) + t.Assert(m.Remove("key2"), "val2") + t.Assert(m.Contains("key2"), false) - gtest.AssertIN("key3", m.Keys()) - gtest.AssertIN("key1", m.Keys()) - gtest.AssertIN("val3", m.Values()) - gtest.AssertIN("val1", m.Values()) + t.AssertIN("key3", m.Keys()) + t.AssertIN("key1", m.Keys()) + t.AssertIN("val3", m.Values()) + t.AssertIN("val1", m.Values()) m.Flip() - gtest.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) + t.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewFrom(map[interface{}]interface{}{1: 1, "key1": "val1"}) - gtest.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) + t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) }) } func Test_Map_Set_Fun(t *testing.T) { m := gmap.New() m.GetOrSetFunc("fun", getValue) m.GetOrSetFuncLock("funlock", getValue) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) m.GetOrSetFunc("fun", getValue) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), false) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) } func Test_Map_Batch(t *testing.T) { m := gmap.New() m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) m.Removes([]interface{}{"key1", 1}) - gtest.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) } func Test_Map_Iterator(t *testing.T) { expect := map[interface{}]interface{}{1: 1, "key1": "val1"} m := gmap.NewFrom(expect) m.Iterator(func(k interface{}, v interface{}) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -88,8 +88,8 @@ func Test_Map_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, 2) - gtest.Assert(j, 1) + t.Assert(i, 2) + t.Assert(j, 1) } func Test_Map_Lock(t *testing.T) { @@ -97,10 +97,10 @@ func Test_Map_Lock(t *testing.T) { m := gmap.NewFrom(expect) m.LockFunc(func(m map[interface{}]interface{}) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) m.RLockFunc(func(m map[interface{}]interface{}) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) } @@ -110,11 +110,11 @@ func Test_Map_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove("key1") //修改clone map,原 map 不影响 - gtest.AssertIN("key1", m.Keys()) + t.AssertIN("key1", m.Keys()) } func Test_Map_Basic_Merge(t *testing.T) { m1 := gmap.New() @@ -122,5 +122,5 @@ func Test_Map_Basic_Merge(t *testing.T) { m1.Set("key1", "val1") m2.Set("key2", "val2") m1.Merge(m2) - gtest.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"}) + t.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"}) } diff --git a/container/gmap/gmap_z_unit_any_any_test.go b/container/gmap/gmap_z_unit_any_any_test.go index 31f6162d7..ba6e2bf58 100644 --- a/container/gmap/gmap_z_unit_any_any_test.go +++ b/container/gmap/gmap_z_unit_any_any_test.go @@ -22,35 +22,35 @@ func anyAnyCallBack(int, interface{}) bool { } func Test_AnyAnyMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewAnyAnyMap() m.Set(1, 1) - gtest.Assert(m.Get(1), 1) - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get(1), 1) + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet(2, "2"), "2") - gtest.Assert(m.SetIfNotExist(2, "2"), false) + t.Assert(m.GetOrSet(2, "2"), "2") + t.Assert(m.SetIfNotExist(2, "2"), false) - gtest.Assert(m.SetIfNotExist(3, 3), true) + t.Assert(m.SetIfNotExist(3, 3), true) - gtest.Assert(m.Remove(2), "2") - gtest.Assert(m.Contains(2), false) + t.Assert(m.Remove(2), "2") + t.Assert(m.Contains(2), false) - gtest.AssertIN(3, m.Keys()) - gtest.AssertIN(1, m.Keys()) - gtest.AssertIN(3, m.Values()) - gtest.AssertIN(1, m.Values()) + t.AssertIN(3, m.Keys()) + t.AssertIN(1, m.Keys()) + t.AssertIN(3, m.Values()) + t.AssertIN(1, m.Values()) m.Flip() - gtest.Assert(m.Map(), map[interface{}]int{1: 1, 3: 3}) + t.Assert(m.Map(), map[interface{}]int{1: 1, 3: 3}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewAnyAnyMapFrom(map[interface{}]interface{}{1: 1, 2: "2"}) - gtest.Assert(m2.Map(), map[interface{}]interface{}{1: 1, 2: "2"}) + t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, 2: "2"}) }) } @@ -59,14 +59,14 @@ func Test_AnyAnyMap_Set_Fun(t *testing.T) { m.GetOrSetFunc(1, getAny) m.GetOrSetFuncLock(2, getAny) - gtest.Assert(m.Get(1), 123) - gtest.Assert(m.Get(2), 123) + t.Assert(m.Get(1), 123) + t.Assert(m.Get(2), 123) - gtest.Assert(m.SetIfNotExistFunc(1, getAny), false) - gtest.Assert(m.SetIfNotExistFunc(3, getAny), true) + t.Assert(m.SetIfNotExistFunc(1, getAny), false) + t.Assert(m.SetIfNotExistFunc(3, getAny), true) - gtest.Assert(m.SetIfNotExistFuncLock(2, getAny), false) - gtest.Assert(m.SetIfNotExistFuncLock(4, getAny), true) + t.Assert(m.SetIfNotExistFuncLock(2, getAny), false) + t.Assert(m.SetIfNotExistFuncLock(4, getAny), true) } @@ -74,16 +74,16 @@ func Test_AnyAnyMap_Batch(t *testing.T) { m := gmap.NewAnyAnyMap() m.Sets(map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) - gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) m.Removes([]interface{}{1, 2}) - gtest.Assert(m.Map(), map[interface{}]interface{}{3: 3}) + t.Assert(m.Map(), map[interface{}]interface{}{3: 3}) } func Test_AnyAnyMap_Iterator(t *testing.T) { expect := map[interface{}]interface{}{1: 1, 2: "2"} m := gmap.NewAnyAnyMapFrom(expect) m.Iterator(func(k interface{}, v interface{}) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -97,8 +97,8 @@ func Test_AnyAnyMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, "2") - gtest.Assert(j, 1) + t.Assert(i, "2") + t.Assert(j, 1) } @@ -106,26 +106,26 @@ func Test_AnyAnyMap_Lock(t *testing.T) { expect := map[interface{}]interface{}{1: 1, 2: "2"} m := gmap.NewAnyAnyMapFrom(expect) m.LockFunc(func(m map[interface{}]interface{}) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) m.RLockFunc(func(m map[interface{}]interface{}) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) } func Test_AnyAnyMap_Clone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //clone 方法是深克隆 m := gmap.NewAnyAnyMapFrom(map[interface{}]interface{}{1: 1, 2: "2"}) m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove(2) //修改clone map,原 map 不影响 - gtest.AssertIN(2, m.Keys()) + t.AssertIN(2, m.Keys()) }) } @@ -135,53 +135,53 @@ func Test_AnyAnyMap_Merge(t *testing.T) { m1.Set(1, 1) m2.Set(2, "2") m1.Merge(m2) - gtest.Assert(m1.Map(), map[interface{}]interface{}{1: 1, 2: "2"}) + t.Assert(m1.Map(), map[interface{}]interface{}{1: 1, 2: "2"}) } func Test_AnyAnyMap_Map(t *testing.T) { m := gmap.NewAnyAnyMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) data := m.Map() - gtest.Assert(data[1], 0) - gtest.Assert(data[2], 2) + t.Assert(data[1], 0) + t.Assert(data[2], 2) data[3] = 3 - gtest.Assert(m.Get(3), 3) + t.Assert(m.Get(3), 3) m.Set(4, 4) - gtest.Assert(data[4], 4) + t.Assert(data[4], 4) } func Test_AnyAnyMap_MapCopy(t *testing.T) { m := gmap.NewAnyAnyMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) data := m.MapCopy() - gtest.Assert(data[1], 0) - gtest.Assert(data[2], 2) + t.Assert(data[1], 0) + t.Assert(data[2], 2) data[3] = 3 - gtest.Assert(m.Get(3), nil) + t.Assert(m.Get(3), nil) m.Set(4, 4) - gtest.Assert(data[4], nil) + t.Assert(data[4], nil) } func Test_AnyAnyMap_FilterEmpty(t *testing.T) { m := gmap.NewAnyAnyMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) m.FilterEmpty() - gtest.Assert(m.Get(1), nil) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Get(1), nil) + t.Assert(m.Get(2), 2) } func Test_AnyAnyMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", @@ -189,90 +189,90 @@ func Test_AnyAnyMap_Json(t *testing.T) { m1 := gmap.NewAnyAnyMapFrom(data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(gconv.Map(data)) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(gconv.Map(data)) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.New() err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(gconv.Map(data)) - gtest.Assert(err, nil) + t.Assert(err, nil) var m gmap.Map err = json.Unmarshal(b, &m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) } func Test_AnyAnyMap_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewAnyAnyMapFrom(g.MapAnyAny{ "k1": "v1", "k2": "v2", }) - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) k1, v1 := m.Pop() - gtest.AssertIN(k1, g.Slice{"k1", "k2"}) - gtest.AssertIN(v1, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 1) + t.AssertIN(k1, g.Slice{"k1", "k2"}) + t.AssertIN(v1, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 1) k2, v2 := m.Pop() - gtest.AssertIN(k2, g.Slice{"k1", "k2"}) - gtest.AssertIN(v2, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 0) + t.AssertIN(k2, g.Slice{"k1", "k2"}) + t.AssertIN(v2, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 0) - gtest.AssertNE(k1, k2) - gtest.AssertNE(v1, v2) + t.AssertNE(k1, k2) + t.AssertNE(v1, v2) }) } func Test_AnyAnyMap_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewAnyAnyMapFrom(g.MapAnyAny{ "k1": "v1", "k2": "v2", "k3": "v3", }) - gtest.Assert(m.Size(), 3) + t.Assert(m.Size(), 3) kArray := garray.New() vArray := garray.New() for k, v := range m.Pops(1) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) for k, v := range m.Pops(2) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 0) + t.Assert(m.Size(), 0) - gtest.Assert(kArray.Unique().Len(), 3) - gtest.Assert(vArray.Unique().Len(), 3) + t.Assert(kArray.Unique().Len(), 3) + t.Assert(vArray.Unique().Len(), 3) }) } @@ -282,20 +282,20 @@ func TestAnyAnyMap_UnmarshalValue(t *testing.T) { Map *gmap.Map } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":"v1","k2":"v2"}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), "v1") - gtest.Assert(t.Map.Get("k2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), "v1") + t.Assert(t.Map.Get("k2"), "v2") }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -304,10 +304,10 @@ func TestAnyAnyMap_UnmarshalValue(t *testing.T) { "k2": "v2", }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), "v1") - gtest.Assert(t.Map.Get("k2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), "v1") + t.Assert(t.Map.Get("k2"), "v2") }) } diff --git a/container/gmap/gmap_z_unit_int_any_test.go b/container/gmap/gmap_z_unit_int_any_test.go index 4d0438422..4c8efb98a 100644 --- a/container/gmap/gmap_z_unit_int_any_test.go +++ b/container/gmap/gmap_z_unit_int_any_test.go @@ -24,35 +24,35 @@ func intAnyCallBack(int, interface{}) bool { return true } func Test_IntAnyMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntAnyMap() m.Set(1, 1) - gtest.Assert(m.Get(1), 1) - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get(1), 1) + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet(2, "2"), "2") - gtest.Assert(m.SetIfNotExist(2, "2"), false) + t.Assert(m.GetOrSet(2, "2"), "2") + t.Assert(m.SetIfNotExist(2, "2"), false) - gtest.Assert(m.SetIfNotExist(3, 3), true) + t.Assert(m.SetIfNotExist(3, 3), true) - gtest.Assert(m.Remove(2), "2") - gtest.Assert(m.Contains(2), false) + t.Assert(m.Remove(2), "2") + t.Assert(m.Contains(2), false) - gtest.AssertIN(3, m.Keys()) - gtest.AssertIN(1, m.Keys()) - gtest.AssertIN(3, m.Values()) - gtest.AssertIN(1, m.Values()) + t.AssertIN(3, m.Keys()) + t.AssertIN(1, m.Keys()) + t.AssertIN(3, m.Values()) + t.AssertIN(1, m.Values()) m.Flip() - gtest.Assert(m.Map(), map[interface{}]int{1: 1, 3: 3}) + t.Assert(m.Map(), map[interface{}]int{1: 1, 3: 3}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewIntAnyMapFrom(map[int]interface{}{1: 1, 2: "2"}) - gtest.Assert(m2.Map(), map[int]interface{}{1: 1, 2: "2"}) + t.Assert(m2.Map(), map[int]interface{}{1: 1, 2: "2"}) }) } func Test_IntAnyMap_Set_Fun(t *testing.T) { @@ -60,14 +60,14 @@ func Test_IntAnyMap_Set_Fun(t *testing.T) { m.GetOrSetFunc(1, getAny) m.GetOrSetFuncLock(2, getAny) - gtest.Assert(m.Get(1), 123) - gtest.Assert(m.Get(2), 123) + t.Assert(m.Get(1), 123) + t.Assert(m.Get(2), 123) - gtest.Assert(m.SetIfNotExistFunc(1, getAny), false) - gtest.Assert(m.SetIfNotExistFunc(3, getAny), true) + t.Assert(m.SetIfNotExistFunc(1, getAny), false) + t.Assert(m.SetIfNotExistFunc(3, getAny), true) - gtest.Assert(m.SetIfNotExistFuncLock(2, getAny), false) - gtest.Assert(m.SetIfNotExistFuncLock(4, getAny), true) + t.Assert(m.SetIfNotExistFuncLock(2, getAny), false) + t.Assert(m.SetIfNotExistFuncLock(4, getAny), true) } @@ -75,15 +75,15 @@ func Test_IntAnyMap_Batch(t *testing.T) { m := gmap.NewIntAnyMap() m.Sets(map[int]interface{}{1: 1, 2: "2", 3: 3}) - gtest.Assert(m.Map(), map[int]interface{}{1: 1, 2: "2", 3: 3}) + t.Assert(m.Map(), map[int]interface{}{1: 1, 2: "2", 3: 3}) m.Removes([]int{1, 2}) - gtest.Assert(m.Map(), map[int]interface{}{3: 3}) + t.Assert(m.Map(), map[int]interface{}{3: 3}) } func Test_IntAnyMap_Iterator(t *testing.T) { expect := map[int]interface{}{1: 1, 2: "2"} m := gmap.NewIntAnyMapFrom(expect) m.Iterator(func(k int, v interface{}) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -97,8 +97,8 @@ func Test_IntAnyMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, "2") - gtest.Assert(j, 1) + t.Assert(i, "2") + t.Assert(j, 1) } @@ -106,10 +106,10 @@ func Test_IntAnyMap_Lock(t *testing.T) { expect := map[int]interface{}{1: 1, 2: "2"} m := gmap.NewIntAnyMapFrom(expect) m.LockFunc(func(m map[int]interface{}) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) m.RLockFunc(func(m map[int]interface{}) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) } func Test_IntAnyMap_Clone(t *testing.T) { @@ -119,11 +119,11 @@ func Test_IntAnyMap_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove(2) //修改clone map,原 map 不影响 - gtest.AssertIN(2, m.Keys()) + t.AssertIN(2, m.Keys()) } func Test_IntAnyMap_Merge(t *testing.T) { m1 := gmap.NewIntAnyMap() @@ -131,54 +131,54 @@ func Test_IntAnyMap_Merge(t *testing.T) { m1.Set(1, 1) m2.Set(2, "2") m1.Merge(m2) - gtest.Assert(m1.Map(), map[int]interface{}{1: 1, 2: "2"}) + t.Assert(m1.Map(), map[int]interface{}{1: 1, 2: "2"}) } func Test_IntAnyMap_Map(t *testing.T) { m := gmap.NewIntAnyMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) data := m.Map() - gtest.Assert(data[1], 0) - gtest.Assert(data[2], 2) + t.Assert(data[1], 0) + t.Assert(data[2], 2) data[3] = 3 - gtest.Assert(m.Get(3), 3) + t.Assert(m.Get(3), 3) m.Set(4, 4) - gtest.Assert(data[4], 4) + t.Assert(data[4], 4) } func Test_IntAnyMap_MapCopy(t *testing.T) { m := gmap.NewIntAnyMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) data := m.MapCopy() - gtest.Assert(data[1], 0) - gtest.Assert(data[2], 2) + t.Assert(data[1], 0) + t.Assert(data[2], 2) data[3] = 3 - gtest.Assert(m.Get(3), nil) + t.Assert(m.Get(3), nil) m.Set(4, 4) - gtest.Assert(data[4], nil) + t.Assert(data[4], nil) } func Test_IntAnyMap_FilterEmpty(t *testing.T) { m := gmap.NewIntAnyMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Size(), 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Size(), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) m.FilterEmpty() - gtest.Assert(m.Size(), 1) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Size(), 1) + t.Assert(m.Get(2), 2) } func Test_IntAnyMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapIntAny{ 1: "v1", 2: "v2", @@ -186,76 +186,76 @@ func Test_IntAnyMap_Json(t *testing.T) { m1 := gmap.NewIntAnyMapFrom(data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(data) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapIntAny{ 1: "v1", 2: "v2", } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.NewIntAnyMap() err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get(1), data[1]) - gtest.Assert(m.Get(2), data[2]) + t.Assert(err, nil) + t.Assert(m.Get(1), data[1]) + t.Assert(m.Get(2), data[2]) }) } func Test_IntAnyMap_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntAnyMapFrom(g.MapIntAny{ 1: "v1", 2: "v2", }) - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) k1, v1 := m.Pop() - gtest.AssertIN(k1, g.Slice{1, 2}) - gtest.AssertIN(v1, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 1) + t.AssertIN(k1, g.Slice{1, 2}) + t.AssertIN(v1, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 1) k2, v2 := m.Pop() - gtest.AssertIN(k2, g.Slice{1, 2}) - gtest.AssertIN(v2, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 0) + t.AssertIN(k2, g.Slice{1, 2}) + t.AssertIN(v2, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 0) - gtest.AssertNE(k1, k2) - gtest.AssertNE(v1, v2) + t.AssertNE(k1, k2) + t.AssertNE(v1, v2) }) } func Test_IntAnyMap_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntAnyMapFrom(g.MapIntAny{ 1: "v1", 2: "v2", 3: "v3", }) - gtest.Assert(m.Size(), 3) + t.Assert(m.Size(), 3) kArray := garray.New() vArray := garray.New() for k, v := range m.Pops(1) { - gtest.AssertIN(k, g.Slice{1, 2, 3}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{1, 2, 3}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) for k, v := range m.Pops(2) { - gtest.AssertIN(k, g.Slice{1, 2, 3}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{1, 2, 3}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 0) + t.Assert(m.Size(), 0) - gtest.Assert(kArray.Unique().Len(), 3) - gtest.Assert(vArray.Unique().Len(), 3) + t.Assert(kArray.Unique().Len(), 3) + t.Assert(vArray.Unique().Len(), 3) }) } @@ -265,20 +265,20 @@ func TestIntAnyMap_UnmarshalValue(t *testing.T) { Map *gmap.IntAnyMap } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"1":"v1","2":"v2"}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get(1), "v1") - gtest.Assert(t.Map.Get(2), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get(1), "v1") + t.Assert(t.Map.Get(2), "v2") }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -287,10 +287,10 @@ func TestIntAnyMap_UnmarshalValue(t *testing.T) { 2: "v2", }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get(1), "v1") - gtest.Assert(t.Map.Get(2), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get(1), "v1") + t.Assert(t.Map.Get(2), "v2") }) } diff --git a/container/gmap/gmap_z_unit_int_int_test.go b/container/gmap/gmap_z_unit_int_int_test.go index b6214d58f..719916107 100644 --- a/container/gmap/gmap_z_unit_int_int_test.go +++ b/container/gmap/gmap_z_unit_int_int_test.go @@ -24,35 +24,35 @@ func intIntCallBack(int, int) bool { return true } func Test_IntIntMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntIntMap() m.Set(1, 1) - gtest.Assert(m.Get(1), 1) - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get(1), 1) + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet(2, 2), 2) - gtest.Assert(m.SetIfNotExist(2, 2), false) + t.Assert(m.GetOrSet(2, 2), 2) + t.Assert(m.SetIfNotExist(2, 2), false) - gtest.Assert(m.SetIfNotExist(3, 3), true) + t.Assert(m.SetIfNotExist(3, 3), true) - gtest.Assert(m.Remove(2), 2) - gtest.Assert(m.Contains(2), false) + t.Assert(m.Remove(2), 2) + t.Assert(m.Contains(2), false) - gtest.AssertIN(3, m.Keys()) - gtest.AssertIN(1, m.Keys()) - gtest.AssertIN(3, m.Values()) - gtest.AssertIN(1, m.Values()) + t.AssertIN(3, m.Keys()) + t.AssertIN(1, m.Keys()) + t.AssertIN(3, m.Values()) + t.AssertIN(1, m.Values()) m.Flip() - gtest.Assert(m.Map(), map[int]int{1: 1, 3: 3}) + t.Assert(m.Map(), map[int]int{1: 1, 3: 3}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewIntIntMapFrom(map[int]int{1: 1, 2: 2}) - gtest.Assert(m2.Map(), map[int]int{1: 1, 2: 2}) + t.Assert(m2.Map(), map[int]int{1: 1, 2: 2}) }) } func Test_IntIntMap_Set_Fun(t *testing.T) { @@ -60,13 +60,13 @@ func Test_IntIntMap_Set_Fun(t *testing.T) { m.GetOrSetFunc(1, getInt) m.GetOrSetFuncLock(2, getInt) - gtest.Assert(m.Get(1), 123) - gtest.Assert(m.Get(2), 123) - gtest.Assert(m.SetIfNotExistFunc(1, getInt), false) - gtest.Assert(m.SetIfNotExistFunc(3, getInt), true) + t.Assert(m.Get(1), 123) + t.Assert(m.Get(2), 123) + t.Assert(m.SetIfNotExistFunc(1, getInt), false) + t.Assert(m.SetIfNotExistFunc(3, getInt), true) - gtest.Assert(m.SetIfNotExistFuncLock(2, getInt), false) - gtest.Assert(m.SetIfNotExistFuncLock(4, getInt), true) + t.Assert(m.SetIfNotExistFuncLock(2, getInt), false) + t.Assert(m.SetIfNotExistFuncLock(4, getInt), true) } @@ -75,16 +75,16 @@ func Test_IntIntMap_Batch(t *testing.T) { m.Sets(map[int]int{1: 1, 2: 2, 3: 3}) m.Iterator(intIntCallBack) - gtest.Assert(m.Map(), map[int]int{1: 1, 2: 2, 3: 3}) + t.Assert(m.Map(), map[int]int{1: 1, 2: 2, 3: 3}) m.Removes([]int{1, 2}) - gtest.Assert(m.Map(), map[int]int{3: 3}) + t.Assert(m.Map(), map[int]int{3: 3}) } func Test_IntIntMap_Iterator(t *testing.T) { expect := map[int]int{1: 1, 2: 2} m := gmap.NewIntIntMapFrom(expect) m.Iterator(func(k int, v int) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -98,18 +98,18 @@ func Test_IntIntMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, 2) - gtest.Assert(j, 1) + t.Assert(i, 2) + t.Assert(j, 1) } func Test_IntIntMap_Lock(t *testing.T) { expect := map[int]int{1: 1, 2: 2} m := gmap.NewIntIntMapFrom(expect) m.LockFunc(func(m map[int]int) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) m.RLockFunc(func(m map[int]int) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) } @@ -121,11 +121,11 @@ func Test_IntIntMap_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove(2) //修改clone map,原 map 不影响 - gtest.AssertIN(2, m.Keys()) + t.AssertIN(2, m.Keys()) } func Test_IntIntMap_Merge(t *testing.T) { @@ -134,54 +134,54 @@ func Test_IntIntMap_Merge(t *testing.T) { m1.Set(1, 1) m2.Set(2, 2) m1.Merge(m2) - gtest.Assert(m1.Map(), map[int]int{1: 1, 2: 2}) + t.Assert(m1.Map(), map[int]int{1: 1, 2: 2}) } func Test_IntIntMap_Map(t *testing.T) { m := gmap.NewIntIntMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) data := m.Map() - gtest.Assert(data[1], 0) - gtest.Assert(data[2], 2) + t.Assert(data[1], 0) + t.Assert(data[2], 2) data[3] = 3 - gtest.Assert(m.Get(3), 3) + t.Assert(m.Get(3), 3) m.Set(4, 4) - gtest.Assert(data[4], 4) + t.Assert(data[4], 4) } func Test_IntIntMap_MapCopy(t *testing.T) { m := gmap.NewIntIntMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) data := m.MapCopy() - gtest.Assert(data[1], 0) - gtest.Assert(data[2], 2) + t.Assert(data[1], 0) + t.Assert(data[2], 2) data[3] = 3 - gtest.Assert(m.Get(3), 0) + t.Assert(m.Get(3), 0) m.Set(4, 4) - gtest.Assert(data[4], 0) + t.Assert(data[4], 0) } func Test_IntIntMap_FilterEmpty(t *testing.T) { m := gmap.NewIntIntMap() m.Set(1, 0) m.Set(2, 2) - gtest.Assert(m.Size(), 2) - gtest.Assert(m.Get(1), 0) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Size(), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) m.FilterEmpty() - gtest.Assert(m.Size(), 1) - gtest.Assert(m.Get(2), 2) + t.Assert(m.Size(), 1) + t.Assert(m.Get(2), 2) } func Test_IntIntMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapIntInt{ 1: 10, 2: 20, @@ -189,76 +189,76 @@ func Test_IntIntMap_Json(t *testing.T) { m1 := gmap.NewIntIntMapFrom(data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(data) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapIntInt{ 1: 10, 2: 20, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.NewIntIntMap() err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get(1), data[1]) - gtest.Assert(m.Get(2), data[2]) + t.Assert(err, nil) + t.Assert(m.Get(1), data[1]) + t.Assert(m.Get(2), data[2]) }) } func Test_IntIntMap_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntIntMapFrom(g.MapIntInt{ 1: 11, 2: 22, }) - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) k1, v1 := m.Pop() - gtest.AssertIN(k1, g.Slice{1, 2}) - gtest.AssertIN(v1, g.Slice{11, 22}) - gtest.Assert(m.Size(), 1) + t.AssertIN(k1, g.Slice{1, 2}) + t.AssertIN(v1, g.Slice{11, 22}) + t.Assert(m.Size(), 1) k2, v2 := m.Pop() - gtest.AssertIN(k2, g.Slice{1, 2}) - gtest.AssertIN(v2, g.Slice{11, 22}) - gtest.Assert(m.Size(), 0) + t.AssertIN(k2, g.Slice{1, 2}) + t.AssertIN(v2, g.Slice{11, 22}) + t.Assert(m.Size(), 0) - gtest.AssertNE(k1, k2) - gtest.AssertNE(v1, v2) + t.AssertNE(k1, k2) + t.AssertNE(v1, v2) }) } func Test_IntIntMap_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntIntMapFrom(g.MapIntInt{ 1: 11, 2: 22, 3: 33, }) - gtest.Assert(m.Size(), 3) + t.Assert(m.Size(), 3) kArray := garray.New() vArray := garray.New() for k, v := range m.Pops(1) { - gtest.AssertIN(k, g.Slice{1, 2, 3}) - gtest.AssertIN(v, g.Slice{11, 22, 33}) + t.AssertIN(k, g.Slice{1, 2, 3}) + t.AssertIN(v, g.Slice{11, 22, 33}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) for k, v := range m.Pops(2) { - gtest.AssertIN(k, g.Slice{1, 2, 3}) - gtest.AssertIN(v, g.Slice{11, 22, 33}) + t.AssertIN(k, g.Slice{1, 2, 3}) + t.AssertIN(v, g.Slice{11, 22, 33}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 0) + t.Assert(m.Size(), 0) - gtest.Assert(kArray.Unique().Len(), 3) - gtest.Assert(vArray.Unique().Len(), 3) + t.Assert(kArray.Unique().Len(), 3) + t.Assert(vArray.Unique().Len(), 3) }) } @@ -268,20 +268,20 @@ func TestIntIntMap_UnmarshalValue(t *testing.T) { Map *gmap.IntIntMap } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"1":1,"2":2}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get(1), "1") - gtest.Assert(t.Map.Get(2), "2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get(1), "1") + t.Assert(t.Map.Get(2), "2") }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -290,10 +290,10 @@ func TestIntIntMap_UnmarshalValue(t *testing.T) { 2: 2, }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get(1), "1") - gtest.Assert(t.Map.Get(2), "2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get(1), "1") + t.Assert(t.Map.Get(2), "2") }) } diff --git a/container/gmap/gmap_z_unit_int_str_test.go b/container/gmap/gmap_z_unit_int_str_test.go index f36c576f0..489ed525f 100644 --- a/container/gmap/gmap_z_unit_int_str_test.go +++ b/container/gmap/gmap_z_unit_int_str_test.go @@ -24,40 +24,40 @@ func intStrCallBack(int, string) bool { return true } func Test_IntStrMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntStrMap() m.Set(1, "a") - gtest.Assert(m.Get(1), "a") - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get(1), "a") + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet(2, "b"), "b") - gtest.Assert(m.SetIfNotExist(2, "b"), false) + t.Assert(m.GetOrSet(2, "b"), "b") + t.Assert(m.SetIfNotExist(2, "b"), false) - gtest.Assert(m.SetIfNotExist(3, "c"), true) + t.Assert(m.SetIfNotExist(3, "c"), true) - gtest.Assert(m.Remove(2), "b") - gtest.Assert(m.Contains(2), false) + t.Assert(m.Remove(2), "b") + t.Assert(m.Contains(2), false) - gtest.AssertIN(3, m.Keys()) - gtest.AssertIN(1, m.Keys()) - gtest.AssertIN("a", m.Values()) - gtest.AssertIN("c", m.Values()) + t.AssertIN(3, m.Keys()) + t.AssertIN(1, m.Keys()) + t.AssertIN("a", m.Values()) + t.AssertIN("c", m.Values()) //反转之后不成为以下 map,flip 操作只是翻转原 map - //gtest.Assert(m.Map(), map[string]int{"a": 1, "c": 3}) + //t.Assert(m.Map(), map[string]int{"a": 1, "c": 3}) m_f := gmap.NewIntStrMap() m_f.Set(1, "2") m_f.Flip() - gtest.Assert(m_f.Map(), map[int]string{2: "1"}) + t.Assert(m_f.Map(), map[int]string{2: "1"}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewIntStrMapFrom(map[int]string{1: "a", 2: "b"}) - gtest.Assert(m2.Map(), map[int]string{1: "a", 2: "b"}) + t.Assert(m2.Map(), map[int]string{1: "a", 2: "b"}) }) } func Test_IntStrMap_Set_Fun(t *testing.T) { @@ -65,13 +65,13 @@ func Test_IntStrMap_Set_Fun(t *testing.T) { m.GetOrSetFunc(1, getStr) m.GetOrSetFuncLock(2, getStr) - gtest.Assert(m.Get(1), "z") - gtest.Assert(m.Get(2), "z") - gtest.Assert(m.SetIfNotExistFunc(1, getStr), false) - gtest.Assert(m.SetIfNotExistFunc(3, getStr), true) + t.Assert(m.Get(1), "z") + t.Assert(m.Get(2), "z") + t.Assert(m.SetIfNotExistFunc(1, getStr), false) + t.Assert(m.SetIfNotExistFunc(3, getStr), true) - gtest.Assert(m.SetIfNotExistFuncLock(2, getStr), false) - gtest.Assert(m.SetIfNotExistFuncLock(4, getStr), true) + t.Assert(m.SetIfNotExistFuncLock(2, getStr), false) + t.Assert(m.SetIfNotExistFuncLock(4, getStr), true) } @@ -79,15 +79,15 @@ func Test_IntStrMap_Batch(t *testing.T) { m := gmap.NewIntStrMap() m.Sets(map[int]string{1: "a", 2: "b", 3: "c"}) - gtest.Assert(m.Map(), map[int]string{1: "a", 2: "b", 3: "c"}) + t.Assert(m.Map(), map[int]string{1: "a", 2: "b", 3: "c"}) m.Removes([]int{1, 2}) - gtest.Assert(m.Map(), map[int]interface{}{3: "c"}) + t.Assert(m.Map(), map[int]interface{}{3: "c"}) } func Test_IntStrMap_Iterator(t *testing.T) { expect := map[int]string{1: "a", 2: "b"} m := gmap.NewIntStrMapFrom(expect) m.Iterator(func(k int, v string) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -101,8 +101,8 @@ func Test_IntStrMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, 2) - gtest.Assert(j, 1) + t.Assert(i, 2) + t.Assert(j, 1) } func Test_IntStrMap_Lock(t *testing.T) { @@ -110,10 +110,10 @@ func Test_IntStrMap_Lock(t *testing.T) { expect := map[int]string{1: "a", 2: "b", 3: "c"} m := gmap.NewIntStrMapFrom(expect) m.LockFunc(func(m map[int]string) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) m.RLockFunc(func(m map[int]string) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) } @@ -124,11 +124,11 @@ func Test_IntStrMap_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove(2) //修改clone map,原 map 不影响 - gtest.AssertIN(2, m.Keys()) + t.AssertIN(2, m.Keys()) } func Test_IntStrMap_Merge(t *testing.T) { m1 := gmap.NewIntStrMap() @@ -136,53 +136,53 @@ func Test_IntStrMap_Merge(t *testing.T) { m1.Set(1, "a") m2.Set(2, "b") m1.Merge(m2) - gtest.Assert(m1.Map(), map[int]string{1: "a", 2: "b"}) + t.Assert(m1.Map(), map[int]string{1: "a", 2: "b"}) } func Test_IntStrMap_Map(t *testing.T) { m := gmap.NewIntStrMap() m.Set(1, "0") m.Set(2, "2") - gtest.Assert(m.Get(1), "0") - gtest.Assert(m.Get(2), "2") + t.Assert(m.Get(1), "0") + t.Assert(m.Get(2), "2") data := m.Map() - gtest.Assert(data[1], "0") - gtest.Assert(data[2], "2") + t.Assert(data[1], "0") + t.Assert(data[2], "2") data[3] = "3" - gtest.Assert(m.Get(3), "3") + t.Assert(m.Get(3), "3") m.Set(4, "4") - gtest.Assert(data[4], "4") + t.Assert(data[4], "4") } func Test_IntStrMap_MapCopy(t *testing.T) { m := gmap.NewIntStrMap() m.Set(1, "0") m.Set(2, "2") - gtest.Assert(m.Get(1), "0") - gtest.Assert(m.Get(2), "2") + t.Assert(m.Get(1), "0") + t.Assert(m.Get(2), "2") data := m.MapCopy() - gtest.Assert(data[1], "0") - gtest.Assert(data[2], "2") + t.Assert(data[1], "0") + t.Assert(data[2], "2") data[3] = "3" - gtest.Assert(m.Get(3), "") + t.Assert(m.Get(3), "") m.Set(4, "4") - gtest.Assert(data[4], "") + t.Assert(data[4], "") } func Test_IntStrMap_FilterEmpty(t *testing.T) { m := gmap.NewIntStrMap() m.Set(1, "") m.Set(2, "2") - gtest.Assert(m.Size(), 2) - gtest.Assert(m.Get(2), "2") + t.Assert(m.Size(), 2) + t.Assert(m.Get(2), "2") m.FilterEmpty() - gtest.Assert(m.Size(), 1) - gtest.Assert(m.Get(2), "2") + t.Assert(m.Size(), 1) + t.Assert(m.Get(2), "2") } func Test_IntStrMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapIntStr{ 1: "v1", 2: "v2", @@ -190,76 +190,76 @@ func Test_IntStrMap_Json(t *testing.T) { m1 := gmap.NewIntStrMapFrom(data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(data) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapIntStr{ 1: "v1", 2: "v2", } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.NewIntStrMap() err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get(1), data[1]) - gtest.Assert(m.Get(2), data[2]) + t.Assert(err, nil) + t.Assert(m.Get(1), data[1]) + t.Assert(m.Get(2), data[2]) }) } func Test_IntStrMap_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntStrMapFrom(g.MapIntStr{ 1: "v1", 2: "v2", }) - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) k1, v1 := m.Pop() - gtest.AssertIN(k1, g.Slice{1, 2}) - gtest.AssertIN(v1, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 1) + t.AssertIN(k1, g.Slice{1, 2}) + t.AssertIN(v1, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 1) k2, v2 := m.Pop() - gtest.AssertIN(k2, g.Slice{1, 2}) - gtest.AssertIN(v2, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 0) + t.AssertIN(k2, g.Slice{1, 2}) + t.AssertIN(v2, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 0) - gtest.AssertNE(k1, k2) - gtest.AssertNE(v1, v2) + t.AssertNE(k1, k2) + t.AssertNE(v1, v2) }) } func Test_IntStrMap_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewIntStrMapFrom(g.MapIntStr{ 1: "v1", 2: "v2", 3: "v3", }) - gtest.Assert(m.Size(), 3) + t.Assert(m.Size(), 3) kArray := garray.New() vArray := garray.New() for k, v := range m.Pops(1) { - gtest.AssertIN(k, g.Slice{1, 2, 3}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{1, 2, 3}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) for k, v := range m.Pops(2) { - gtest.AssertIN(k, g.Slice{1, 2, 3}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{1, 2, 3}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 0) + t.Assert(m.Size(), 0) - gtest.Assert(kArray.Unique().Len(), 3) - gtest.Assert(vArray.Unique().Len(), 3) + t.Assert(kArray.Unique().Len(), 3) + t.Assert(vArray.Unique().Len(), 3) }) } @@ -269,20 +269,20 @@ func TestIntStrMap_UnmarshalValue(t *testing.T) { Map *gmap.IntStrMap } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"1":"v1","2":"v2"}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get(1), "v1") - gtest.Assert(t.Map.Get(2), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get(1), "v1") + t.Assert(t.Map.Get(2), "v2") }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -291,10 +291,10 @@ func TestIntStrMap_UnmarshalValue(t *testing.T) { 2: "v2", }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get(1), "v1") - gtest.Assert(t.Map.Get(2), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get(1), "v1") + t.Assert(t.Map.Get(2), "v2") }) } diff --git a/container/gmap/gmap_z_unit_list_map_test.go b/container/gmap/gmap_z_unit_list_map_test.go index 7829bf16d..bc3ea2b59 100644 --- a/container/gmap/gmap_z_unit_list_map_test.go +++ b/container/gmap/gmap_z_unit_list_map_test.go @@ -18,63 +18,63 @@ import ( ) func Test_ListMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewListMap() m.Set("key1", "val1") - gtest.Assert(m.Keys(), []interface{}{"key1"}) + t.Assert(m.Keys(), []interface{}{"key1"}) - gtest.Assert(m.Get("key1"), "val1") - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("key1"), "val1") + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("key2", "val2"), "val2") - gtest.Assert(m.SetIfNotExist("key2", "val2"), false) + t.Assert(m.GetOrSet("key2", "val2"), "val2") + t.Assert(m.SetIfNotExist("key2", "val2"), false) - gtest.Assert(m.SetIfNotExist("key3", "val3"), true) - gtest.Assert(m.Remove("key2"), "val2") - gtest.Assert(m.Contains("key2"), false) + t.Assert(m.SetIfNotExist("key3", "val3"), true) + t.Assert(m.Remove("key2"), "val2") + t.Assert(m.Contains("key2"), false) - gtest.AssertIN("key3", m.Keys()) - gtest.AssertIN("key1", m.Keys()) - gtest.AssertIN("val3", m.Values()) - gtest.AssertIN("val1", m.Values()) + t.AssertIN("key3", m.Keys()) + t.AssertIN("key1", m.Keys()) + t.AssertIN("val3", m.Values()) + t.AssertIN("val1", m.Values()) m.Flip() - gtest.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) + t.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewListMapFrom(map[interface{}]interface{}{1: 1, "key1": "val1"}) - gtest.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) + t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) }) } func Test_ListMap_Set_Fun(t *testing.T) { m := gmap.NewListMap() m.GetOrSetFunc("fun", getValue) m.GetOrSetFuncLock("funlock", getValue) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) m.GetOrSetFunc("fun", getValue) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), false) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) } func Test_ListMap_Batch(t *testing.T) { m := gmap.NewListMap() m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) m.Removes([]interface{}{"key1", 1}) - gtest.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) } func Test_ListMap_Iterator(t *testing.T) { expect := map[interface{}]interface{}{1: 1, "key1": "val1"} m := gmap.NewListMapFrom(expect) m.Iterator(func(k interface{}, v interface{}) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -88,8 +88,8 @@ func Test_ListMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, 2) - gtest.Assert(j, 1) + t.Assert(i, 2) + t.Assert(j, 1) } func Test_ListMap_Clone(t *testing.T) { @@ -98,11 +98,11 @@ func Test_ListMap_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove("key1") //修改clone map,原 map 不影响 - gtest.AssertIN("key1", m.Keys()) + t.AssertIN("key1", m.Keys()) } func Test_ListMap_Basic_Merge(t *testing.T) { @@ -111,7 +111,7 @@ func Test_ListMap_Basic_Merge(t *testing.T) { m1.Set("key1", "val1") m2.Set("key2", "val2") m1.Merge(m2) - gtest.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"}) + t.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"}) } func Test_ListMap_Order(t *testing.T) { @@ -119,24 +119,24 @@ func Test_ListMap_Order(t *testing.T) { m.Set("k1", "v1") m.Set("k2", "v2") m.Set("k3", "v3") - gtest.Assert(m.Keys(), g.Slice{"k1", "k2", "k3"}) - gtest.Assert(m.Values(), g.Slice{"v1", "v2", "v3"}) + t.Assert(m.Keys(), g.Slice{"k1", "k2", "k3"}) + t.Assert(m.Values(), g.Slice{"v1", "v2", "v3"}) } func Test_ListMap_FilterEmpty(t *testing.T) { m := gmap.NewListMap() m.Set(1, "") m.Set(2, "2") - gtest.Assert(m.Size(), 2) - gtest.Assert(m.Get(2), "2") + t.Assert(m.Size(), 2) + t.Assert(m.Get(2), "2") m.FilterEmpty() - gtest.Assert(m.Size(), 1) - gtest.Assert(m.Get(2), "2") + t.Assert(m.Size(), 1) + t.Assert(m.Get(2), "2") } func Test_ListMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", @@ -144,91 +144,91 @@ func Test_ListMap_Json(t *testing.T) { m1 := gmap.NewListMapFrom(data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(gconv.Map(data)) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(gconv.Map(data)) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.NewListMap() err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(gconv.Map(data)) - gtest.Assert(err, nil) + t.Assert(err, nil) var m gmap.ListMap err = json.Unmarshal(b, &m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) } func Test_ListMap_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewListMapFrom(g.MapAnyAny{ "k1": "v1", "k2": "v2", }) - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) k1, v1 := m.Pop() - gtest.AssertIN(k1, g.Slice{"k1", "k2"}) - gtest.AssertIN(v1, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 1) + t.AssertIN(k1, g.Slice{"k1", "k2"}) + t.AssertIN(v1, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 1) k2, v2 := m.Pop() - gtest.AssertIN(k2, g.Slice{"k1", "k2"}) - gtest.AssertIN(v2, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 0) + t.AssertIN(k2, g.Slice{"k1", "k2"}) + t.AssertIN(v2, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 0) - gtest.AssertNE(k1, k2) - gtest.AssertNE(v1, v2) + t.AssertNE(k1, k2) + t.AssertNE(v1, v2) }) } func Test_ListMap_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewListMapFrom(g.MapAnyAny{ "k1": "v1", "k2": "v2", "k3": "v3", }) - gtest.Assert(m.Size(), 3) + t.Assert(m.Size(), 3) kArray := garray.New() vArray := garray.New() for k, v := range m.Pops(1) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) for k, v := range m.Pops(2) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 0) + t.Assert(m.Size(), 0) - gtest.Assert(kArray.Unique().Len(), 3) - gtest.Assert(vArray.Unique().Len(), 3) + t.Assert(kArray.Unique().Len(), 3) + t.Assert(vArray.Unique().Len(), 3) }) } @@ -238,20 +238,20 @@ func TestListMap_UnmarshalValue(t *testing.T) { Map *gmap.ListMap } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"1":"v1","2":"v2"}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("1"), "v1") - gtest.Assert(t.Map.Get("2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("1"), "v1") + t.Assert(t.Map.Get("2"), "v2") }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -260,10 +260,10 @@ func TestListMap_UnmarshalValue(t *testing.T) { 2: "v2", }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("1"), "v1") - gtest.Assert(t.Map.Get("2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("1"), "v1") + t.Assert(t.Map.Get("2"), "v2") }) } diff --git a/container/gmap/gmap_z_unit_str_any_test.go b/container/gmap/gmap_z_unit_str_any_test.go index d47f31413..f8b5468d0 100644 --- a/container/gmap/gmap_z_unit_str_any_test.go +++ b/container/gmap/gmap_z_unit_str_any_test.go @@ -21,36 +21,36 @@ func stringAnyCallBack(string, interface{}) bool { return true } func Test_StrAnyMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrAnyMap() m.Set("a", 1) - gtest.Assert(m.Get("a"), 1) - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("a"), 1) + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("b", "2"), "2") - gtest.Assert(m.SetIfNotExist("b", "2"), false) + t.Assert(m.GetOrSet("b", "2"), "2") + t.Assert(m.SetIfNotExist("b", "2"), false) - gtest.Assert(m.SetIfNotExist("c", 3), true) + t.Assert(m.SetIfNotExist("c", 3), true) - gtest.Assert(m.Remove("b"), "2") - gtest.Assert(m.Contains("b"), false) + t.Assert(m.Remove("b"), "2") + t.Assert(m.Contains("b"), false) - gtest.AssertIN("c", m.Keys()) - gtest.AssertIN("a", m.Keys()) - gtest.AssertIN(3, m.Values()) - gtest.AssertIN(1, m.Values()) + t.AssertIN("c", m.Keys()) + t.AssertIN("a", m.Keys()) + t.AssertIN(3, m.Values()) + t.AssertIN(1, m.Values()) m.Flip() - gtest.Assert(m.Map(), map[string]interface{}{"1": "a", "3": "c"}) + t.Assert(m.Map(), map[string]interface{}{"1": "a", "3": "c"}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewStrAnyMapFrom(map[string]interface{}{"a": 1, "b": "2"}) - gtest.Assert(m2.Map(), map[string]interface{}{"a": 1, "b": "2"}) + t.Assert(m2.Map(), map[string]interface{}{"a": 1, "b": "2"}) }) } func Test_StrAnyMap_Set_Fun(t *testing.T) { @@ -58,13 +58,13 @@ func Test_StrAnyMap_Set_Fun(t *testing.T) { m.GetOrSetFunc("a", getAny) m.GetOrSetFuncLock("b", getAny) - gtest.Assert(m.Get("a"), 123) - gtest.Assert(m.Get("b"), 123) - gtest.Assert(m.SetIfNotExistFunc("a", getAny), false) - gtest.Assert(m.SetIfNotExistFunc("c", getAny), true) + t.Assert(m.Get("a"), 123) + t.Assert(m.Get("b"), 123) + t.Assert(m.SetIfNotExistFunc("a", getAny), false) + t.Assert(m.SetIfNotExistFunc("c", getAny), true) - gtest.Assert(m.SetIfNotExistFuncLock("b", getAny), false) - gtest.Assert(m.SetIfNotExistFuncLock("d", getAny), true) + t.Assert(m.SetIfNotExistFuncLock("b", getAny), false) + t.Assert(m.SetIfNotExistFuncLock("d", getAny), true) } @@ -72,16 +72,16 @@ func Test_StrAnyMap_Batch(t *testing.T) { m := gmap.NewStrAnyMap() m.Sets(map[string]interface{}{"a": 1, "b": "2", "c": 3}) - gtest.Assert(m.Map(), map[string]interface{}{"a": 1, "b": "2", "c": 3}) + t.Assert(m.Map(), map[string]interface{}{"a": 1, "b": "2", "c": 3}) m.Removes([]string{"a", "b"}) - gtest.Assert(m.Map(), map[string]interface{}{"c": 3}) + t.Assert(m.Map(), map[string]interface{}{"c": 3}) } func Test_StrAnyMap_Iterator(t *testing.T) { expect := map[string]interface{}{"a": true, "b": false} m := gmap.NewStrAnyMapFrom(expect) m.Iterator(func(k string, v interface{}) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -95,8 +95,8 @@ func Test_StrAnyMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, 2) - gtest.Assert(j, 1) + t.Assert(i, 2) + t.Assert(j, 1) } func Test_StrAnyMap_Lock(t *testing.T) { @@ -104,10 +104,10 @@ func Test_StrAnyMap_Lock(t *testing.T) { m := gmap.NewStrAnyMapFrom(expect) m.LockFunc(func(m map[string]interface{}) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) m.RLockFunc(func(m map[string]interface{}) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) } func Test_StrAnyMap_Clone(t *testing.T) { @@ -117,11 +117,11 @@ func Test_StrAnyMap_Clone(t *testing.T) { m_clone := m.Clone() m.Remove("a") //修改原 map,clone 后的 map 不影响 - gtest.AssertIN("a", m_clone.Keys()) + t.AssertIN("a", m_clone.Keys()) m_clone.Remove("b") //修改clone map,原 map 不影响 - gtest.AssertIN("b", m.Keys()) + t.AssertIN("b", m.Keys()) } func Test_StrAnyMap_Merge(t *testing.T) { m1 := gmap.NewStrAnyMap() @@ -129,54 +129,54 @@ func Test_StrAnyMap_Merge(t *testing.T) { m1.Set("a", 1) m2.Set("b", "2") m1.Merge(m2) - gtest.Assert(m1.Map(), map[string]interface{}{"a": 1, "b": "2"}) + t.Assert(m1.Map(), map[string]interface{}{"a": 1, "b": "2"}) } func Test_StrAnyMap_Map(t *testing.T) { m := gmap.NewStrAnyMap() m.Set("1", 1) m.Set("2", 2) - gtest.Assert(m.Get("1"), 1) - gtest.Assert(m.Get("2"), 2) + t.Assert(m.Get("1"), 1) + t.Assert(m.Get("2"), 2) data := m.Map() - gtest.Assert(data["1"], 1) - gtest.Assert(data["2"], 2) + t.Assert(data["1"], 1) + t.Assert(data["2"], 2) data["3"] = 3 - gtest.Assert(m.Get("3"), 3) + t.Assert(m.Get("3"), 3) m.Set("4", 4) - gtest.Assert(data["4"], 4) + t.Assert(data["4"], 4) } func Test_StrAnyMap_MapCopy(t *testing.T) { m := gmap.NewStrAnyMap() m.Set("1", 1) m.Set("2", 2) - gtest.Assert(m.Get("1"), 1) - gtest.Assert(m.Get("2"), 2) + t.Assert(m.Get("1"), 1) + t.Assert(m.Get("2"), 2) data := m.MapCopy() - gtest.Assert(data["1"], 1) - gtest.Assert(data["2"], 2) + t.Assert(data["1"], 1) + t.Assert(data["2"], 2) data["3"] = 3 - gtest.Assert(m.Get("3"), nil) + t.Assert(m.Get("3"), nil) m.Set("4", 4) - gtest.Assert(data["4"], nil) + t.Assert(data["4"], nil) } func Test_StrAnyMap_FilterEmpty(t *testing.T) { m := gmap.NewStrAnyMap() m.Set("1", 0) m.Set("2", 2) - gtest.Assert(m.Size(), 2) - gtest.Assert(m.Get("1"), 0) - gtest.Assert(m.Get("2"), 2) + t.Assert(m.Size(), 2) + t.Assert(m.Get("1"), 0) + t.Assert(m.Get("2"), 2) m.FilterEmpty() - gtest.Assert(m.Size(), 1) - gtest.Assert(m.Get("2"), 2) + t.Assert(m.Size(), 1) + t.Assert(m.Get("2"), 2) } func Test_StrAnyMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrAny{ "k1": "v1", "k2": "v2", @@ -184,90 +184,90 @@ func Test_StrAnyMap_Json(t *testing.T) { m1 := gmap.NewStrAnyMapFrom(data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(data) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrAny{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.NewStrAnyMap() err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrAny{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) var m gmap.StrAnyMap err = json.Unmarshal(b, &m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) } func Test_StrAnyMap_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrAnyMapFrom(g.MapStrAny{ "k1": "v1", "k2": "v2", }) - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) k1, v1 := m.Pop() - gtest.AssertIN(k1, g.Slice{"k1", "k2"}) - gtest.AssertIN(v1, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 1) + t.AssertIN(k1, g.Slice{"k1", "k2"}) + t.AssertIN(v1, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 1) k2, v2 := m.Pop() - gtest.AssertIN(k2, g.Slice{"k1", "k2"}) - gtest.AssertIN(v2, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 0) + t.AssertIN(k2, g.Slice{"k1", "k2"}) + t.AssertIN(v2, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 0) - gtest.AssertNE(k1, k2) - gtest.AssertNE(v1, v2) + t.AssertNE(k1, k2) + t.AssertNE(v1, v2) }) } func Test_StrAnyMap_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrAnyMapFrom(g.MapStrAny{ "k1": "v1", "k2": "v2", "k3": "v3", }) - gtest.Assert(m.Size(), 3) + t.Assert(m.Size(), 3) kArray := garray.New() vArray := garray.New() for k, v := range m.Pops(1) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) for k, v := range m.Pops(2) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 0) + t.Assert(m.Size(), 0) - gtest.Assert(kArray.Unique().Len(), 3) - gtest.Assert(vArray.Unique().Len(), 3) + t.Assert(kArray.Unique().Len(), 3) + t.Assert(vArray.Unique().Len(), 3) }) } @@ -277,20 +277,20 @@ func TestStrAnyMap_UnmarshalValue(t *testing.T) { Map *gmap.StrAnyMap } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":"v1","k2":"v2"}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), "v1") - gtest.Assert(t.Map.Get("k2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), "v1") + t.Assert(t.Map.Get("k2"), "v2") }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -299,10 +299,10 @@ func TestStrAnyMap_UnmarshalValue(t *testing.T) { "k2": "v2", }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), "v1") - gtest.Assert(t.Map.Get("k2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), "v1") + t.Assert(t.Map.Get("k2"), "v2") }) } diff --git a/container/gmap/gmap_z_unit_str_int_test.go b/container/gmap/gmap_z_unit_str_int_test.go index c7f6ab407..fc713aa1a 100644 --- a/container/gmap/gmap_z_unit_str_int_test.go +++ b/container/gmap/gmap_z_unit_str_int_test.go @@ -21,38 +21,38 @@ func stringIntCallBack(string, int) bool { return true } func Test_StrIntMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrIntMap() m.Set("a", 1) - gtest.Assert(m.Get("a"), 1) - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("a"), 1) + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("b", 2), 2) - gtest.Assert(m.SetIfNotExist("b", 2), false) + t.Assert(m.GetOrSet("b", 2), 2) + t.Assert(m.SetIfNotExist("b", 2), false) - gtest.Assert(m.SetIfNotExist("c", 3), true) + t.Assert(m.SetIfNotExist("c", 3), true) - gtest.Assert(m.Remove("b"), 2) - gtest.Assert(m.Contains("b"), false) + t.Assert(m.Remove("b"), 2) + t.Assert(m.Contains("b"), false) - gtest.AssertIN("c", m.Keys()) - gtest.AssertIN("a", m.Keys()) - gtest.AssertIN(3, m.Values()) - gtest.AssertIN(1, m.Values()) + t.AssertIN("c", m.Keys()) + t.AssertIN("a", m.Keys()) + t.AssertIN(3, m.Values()) + t.AssertIN(1, m.Values()) m_f := gmap.NewStrIntMap() m_f.Set("1", 2) m_f.Flip() - gtest.Assert(m_f.Map(), map[string]int{"2": 1}) + t.Assert(m_f.Map(), map[string]int{"2": 1}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewStrIntMapFrom(map[string]int{"a": 1, "b": 2}) - gtest.Assert(m2.Map(), map[string]int{"a": 1, "b": 2}) + t.Assert(m2.Map(), map[string]int{"a": 1, "b": 2}) }) } func Test_StrIntMap_Set_Fun(t *testing.T) { @@ -60,13 +60,13 @@ func Test_StrIntMap_Set_Fun(t *testing.T) { m.GetOrSetFunc("a", getInt) m.GetOrSetFuncLock("b", getInt) - gtest.Assert(m.Get("a"), 123) - gtest.Assert(m.Get("b"), 123) - gtest.Assert(m.SetIfNotExistFunc("a", getInt), false) - gtest.Assert(m.SetIfNotExistFunc("c", getInt), true) + t.Assert(m.Get("a"), 123) + t.Assert(m.Get("b"), 123) + t.Assert(m.SetIfNotExistFunc("a", getInt), false) + t.Assert(m.SetIfNotExistFunc("c", getInt), true) - gtest.Assert(m.SetIfNotExistFuncLock("b", getInt), false) - gtest.Assert(m.SetIfNotExistFuncLock("d", getInt), true) + t.Assert(m.SetIfNotExistFuncLock("b", getInt), false) + t.Assert(m.SetIfNotExistFuncLock("d", getInt), true) } @@ -74,15 +74,15 @@ func Test_StrIntMap_Batch(t *testing.T) { m := gmap.NewStrIntMap() m.Sets(map[string]int{"a": 1, "b": 2, "c": 3}) - gtest.Assert(m.Map(), map[string]int{"a": 1, "b": 2, "c": 3}) + t.Assert(m.Map(), map[string]int{"a": 1, "b": 2, "c": 3}) m.Removes([]string{"a", "b"}) - gtest.Assert(m.Map(), map[string]int{"c": 3}) + t.Assert(m.Map(), map[string]int{"c": 3}) } func Test_StrIntMap_Iterator(t *testing.T) { expect := map[string]int{"a": 1, "b": 2} m := gmap.NewStrIntMapFrom(expect) m.Iterator(func(k string, v int) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -96,8 +96,8 @@ func Test_StrIntMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, 2) - gtest.Assert(j, 1) + t.Assert(i, 2) + t.Assert(j, 1) } @@ -106,10 +106,10 @@ func Test_StrIntMap_Lock(t *testing.T) { m := gmap.NewStrIntMapFrom(expect) m.LockFunc(func(m map[string]int) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) m.RLockFunc(func(m map[string]int) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) } @@ -120,11 +120,11 @@ func Test_StrIntMap_Clone(t *testing.T) { m_clone := m.Clone() m.Remove("a") //修改原 map,clone 后的 map 不影响 - gtest.AssertIN("a", m_clone.Keys()) + t.AssertIN("a", m_clone.Keys()) m_clone.Remove("b") //修改clone map,原 map 不影响 - gtest.AssertIN("b", m.Keys()) + t.AssertIN("b", m.Keys()) } func Test_StrIntMap_Merge(t *testing.T) { m1 := gmap.NewStrIntMap() @@ -132,54 +132,54 @@ func Test_StrIntMap_Merge(t *testing.T) { m1.Set("a", 1) m2.Set("b", 2) m1.Merge(m2) - gtest.Assert(m1.Map(), map[string]int{"a": 1, "b": 2}) + t.Assert(m1.Map(), map[string]int{"a": 1, "b": 2}) } func Test_StrIntMap_Map(t *testing.T) { m := gmap.NewStrIntMap() m.Set("1", 1) m.Set("2", 2) - gtest.Assert(m.Get("1"), 1) - gtest.Assert(m.Get("2"), 2) + t.Assert(m.Get("1"), 1) + t.Assert(m.Get("2"), 2) data := m.Map() - gtest.Assert(data["1"], 1) - gtest.Assert(data["2"], 2) + t.Assert(data["1"], 1) + t.Assert(data["2"], 2) data["3"] = 3 - gtest.Assert(m.Get("3"), 3) + t.Assert(m.Get("3"), 3) m.Set("4", 4) - gtest.Assert(data["4"], 4) + t.Assert(data["4"], 4) } func Test_StrIntMap_MapCopy(t *testing.T) { m := gmap.NewStrIntMap() m.Set("1", 1) m.Set("2", 2) - gtest.Assert(m.Get("1"), 1) - gtest.Assert(m.Get("2"), 2) + t.Assert(m.Get("1"), 1) + t.Assert(m.Get("2"), 2) data := m.MapCopy() - gtest.Assert(data["1"], 1) - gtest.Assert(data["2"], 2) + t.Assert(data["1"], 1) + t.Assert(data["2"], 2) data["3"] = 3 - gtest.Assert(m.Get("3"), 0) + t.Assert(m.Get("3"), 0) m.Set("4", 4) - gtest.Assert(data["4"], 0) + t.Assert(data["4"], 0) } func Test_StrIntMap_FilterEmpty(t *testing.T) { m := gmap.NewStrIntMap() m.Set("1", 0) m.Set("2", 2) - gtest.Assert(m.Size(), 2) - gtest.Assert(m.Get("1"), 0) - gtest.Assert(m.Get("2"), 2) + t.Assert(m.Size(), 2) + t.Assert(m.Get("1"), 0) + t.Assert(m.Get("2"), 2) m.FilterEmpty() - gtest.Assert(m.Size(), 1) - gtest.Assert(m.Get("2"), 2) + t.Assert(m.Size(), 1) + t.Assert(m.Get("2"), 2) } func Test_StrIntMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrInt{ "k1": 1, "k2": 2, @@ -187,90 +187,90 @@ func Test_StrIntMap_Json(t *testing.T) { m1 := gmap.NewStrIntMapFrom(data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(data) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrInt{ "k1": 1, "k2": 2, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.NewStrIntMap() err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrInt{ "k1": 1, "k2": 2, } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) var m gmap.StrIntMap err = json.Unmarshal(b, &m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) } func Test_StrIntMap_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrIntMapFrom(g.MapStrInt{ "k1": 11, "k2": 22, }) - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) k1, v1 := m.Pop() - gtest.AssertIN(k1, g.Slice{"k1", "k2"}) - gtest.AssertIN(v1, g.Slice{11, 22}) - gtest.Assert(m.Size(), 1) + t.AssertIN(k1, g.Slice{"k1", "k2"}) + t.AssertIN(v1, g.Slice{11, 22}) + t.Assert(m.Size(), 1) k2, v2 := m.Pop() - gtest.AssertIN(k2, g.Slice{"k1", "k2"}) - gtest.AssertIN(v2, g.Slice{11, 22}) - gtest.Assert(m.Size(), 0) + t.AssertIN(k2, g.Slice{"k1", "k2"}) + t.AssertIN(v2, g.Slice{11, 22}) + t.Assert(m.Size(), 0) - gtest.AssertNE(k1, k2) - gtest.AssertNE(v1, v2) + t.AssertNE(k1, k2) + t.AssertNE(v1, v2) }) } func Test_StrIntMap_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrIntMapFrom(g.MapStrInt{ "k1": 11, "k2": 22, "k3": 33, }) - gtest.Assert(m.Size(), 3) + t.Assert(m.Size(), 3) kArray := garray.New() vArray := garray.New() for k, v := range m.Pops(1) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{11, 22, 33}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{11, 22, 33}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) for k, v := range m.Pops(2) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{11, 22, 33}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{11, 22, 33}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 0) + t.Assert(m.Size(), 0) - gtest.Assert(kArray.Unique().Len(), 3) - gtest.Assert(vArray.Unique().Len(), 3) + t.Assert(kArray.Unique().Len(), 3) + t.Assert(vArray.Unique().Len(), 3) }) } @@ -280,20 +280,20 @@ func TestStrIntMap_UnmarshalValue(t *testing.T) { Map *gmap.StrIntMap } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":1,"k2":2}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), 1) - gtest.Assert(t.Map.Get("k2"), 2) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), 1) + t.Assert(t.Map.Get("k2"), 2) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -302,10 +302,10 @@ func TestStrIntMap_UnmarshalValue(t *testing.T) { "k2": 2, }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), 1) - gtest.Assert(t.Map.Get("k2"), 2) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), 1) + t.Assert(t.Map.Get("k2"), 2) }) } diff --git a/container/gmap/gmap_z_unit_str_str_test.go b/container/gmap/gmap_z_unit_str_str_test.go index 6906818a3..1a3ca665b 100644 --- a/container/gmap/gmap_z_unit_str_str_test.go +++ b/container/gmap/gmap_z_unit_str_str_test.go @@ -21,37 +21,37 @@ func stringStrCallBack(string, string) bool { return true } func Test_StrStrMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrStrMap() m.Set("a", "a") - gtest.Assert(m.Get("a"), "a") - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("a"), "a") + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("b", "b"), "b") - gtest.Assert(m.SetIfNotExist("b", "b"), false) + t.Assert(m.GetOrSet("b", "b"), "b") + t.Assert(m.SetIfNotExist("b", "b"), false) - gtest.Assert(m.SetIfNotExist("c", "c"), true) + t.Assert(m.SetIfNotExist("c", "c"), true) - gtest.Assert(m.Remove("b"), "b") - gtest.Assert(m.Contains("b"), false) + t.Assert(m.Remove("b"), "b") + t.Assert(m.Contains("b"), false) - gtest.AssertIN("c", m.Keys()) - gtest.AssertIN("a", m.Keys()) - gtest.AssertIN("a", m.Values()) - gtest.AssertIN("c", m.Values()) + t.AssertIN("c", m.Keys()) + t.AssertIN("a", m.Keys()) + t.AssertIN("a", m.Values()) + t.AssertIN("c", m.Values()) m.Flip() - gtest.Assert(m.Map(), map[string]string{"a": "a", "c": "c"}) + t.Assert(m.Map(), map[string]string{"a": "a", "c": "c"}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewStrStrMapFrom(map[string]string{"a": "a", "b": "b"}) - gtest.Assert(m2.Map(), map[string]string{"a": "a", "b": "b"}) + t.Assert(m2.Map(), map[string]string{"a": "a", "b": "b"}) }) } func Test_StrStrMap_Set_Fun(t *testing.T) { @@ -59,13 +59,13 @@ func Test_StrStrMap_Set_Fun(t *testing.T) { m.GetOrSetFunc("a", getStr) m.GetOrSetFuncLock("b", getStr) - gtest.Assert(m.Get("a"), "z") - gtest.Assert(m.Get("b"), "z") - gtest.Assert(m.SetIfNotExistFunc("a", getStr), false) - gtest.Assert(m.SetIfNotExistFunc("c", getStr), true) + t.Assert(m.Get("a"), "z") + t.Assert(m.Get("b"), "z") + t.Assert(m.SetIfNotExistFunc("a", getStr), false) + t.Assert(m.SetIfNotExistFunc("c", getStr), true) - gtest.Assert(m.SetIfNotExistFuncLock("b", getStr), false) - gtest.Assert(m.SetIfNotExistFuncLock("d", getStr), true) + t.Assert(m.SetIfNotExistFuncLock("b", getStr), false) + t.Assert(m.SetIfNotExistFuncLock("d", getStr), true) } @@ -73,15 +73,15 @@ func Test_StrStrMap_Batch(t *testing.T) { m := gmap.NewStrStrMap() m.Sets(map[string]string{"a": "a", "b": "b", "c": "c"}) - gtest.Assert(m.Map(), map[string]string{"a": "a", "b": "b", "c": "c"}) + t.Assert(m.Map(), map[string]string{"a": "a", "b": "b", "c": "c"}) m.Removes([]string{"a", "b"}) - gtest.Assert(m.Map(), map[string]string{"c": "c"}) + t.Assert(m.Map(), map[string]string{"c": "c"}) } func Test_StrStrMap_Iterator(t *testing.T) { expect := map[string]string{"a": "a", "b": "b"} m := gmap.NewStrStrMapFrom(expect) m.Iterator(func(k string, v string) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -95,8 +95,8 @@ func Test_StrStrMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, 2) - gtest.Assert(j, 1) + t.Assert(i, 2) + t.Assert(j, 1) } func Test_StrStrMap_Lock(t *testing.T) { @@ -104,10 +104,10 @@ func Test_StrStrMap_Lock(t *testing.T) { m := gmap.NewStrStrMapFrom(expect) m.LockFunc(func(m map[string]string) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) m.RLockFunc(func(m map[string]string) { - gtest.Assert(m, expect) + t.Assert(m, expect) }) } func Test_StrStrMap_Clone(t *testing.T) { @@ -117,11 +117,11 @@ func Test_StrStrMap_Clone(t *testing.T) { m_clone := m.Clone() m.Remove("a") //修改原 map,clone 后的 map 不影响 - gtest.AssertIN("a", m_clone.Keys()) + t.AssertIN("a", m_clone.Keys()) m_clone.Remove("b") //修改clone map,原 map 不影响 - gtest.AssertIN("b", m.Keys()) + t.AssertIN("b", m.Keys()) } func Test_StrStrMap_Merge(t *testing.T) { m1 := gmap.NewStrStrMap() @@ -129,54 +129,54 @@ func Test_StrStrMap_Merge(t *testing.T) { m1.Set("a", "a") m2.Set("b", "b") m1.Merge(m2) - gtest.Assert(m1.Map(), map[string]string{"a": "a", "b": "b"}) + t.Assert(m1.Map(), map[string]string{"a": "a", "b": "b"}) } func Test_StrStrMap_Map(t *testing.T) { m := gmap.NewStrStrMap() m.Set("1", "1") m.Set("2", "2") - gtest.Assert(m.Get("1"), "1") - gtest.Assert(m.Get("2"), "2") + t.Assert(m.Get("1"), "1") + t.Assert(m.Get("2"), "2") data := m.Map() - gtest.Assert(data["1"], "1") - gtest.Assert(data["2"], "2") + t.Assert(data["1"], "1") + t.Assert(data["2"], "2") data["3"] = "3" - gtest.Assert(m.Get("3"), "3") + t.Assert(m.Get("3"), "3") m.Set("4", "4") - gtest.Assert(data["4"], "4") + t.Assert(data["4"], "4") } func Test_StrStrMap_MapCopy(t *testing.T) { m := gmap.NewStrStrMap() m.Set("1", "1") m.Set("2", "2") - gtest.Assert(m.Get("1"), "1") - gtest.Assert(m.Get("2"), "2") + t.Assert(m.Get("1"), "1") + t.Assert(m.Get("2"), "2") data := m.MapCopy() - gtest.Assert(data["1"], "1") - gtest.Assert(data["2"], "2") + t.Assert(data["1"], "1") + t.Assert(data["2"], "2") data["3"] = "3" - gtest.Assert(m.Get("3"), "") + t.Assert(m.Get("3"), "") m.Set("4", "4") - gtest.Assert(data["4"], "") + t.Assert(data["4"], "") } func Test_StrStrMap_FilterEmpty(t *testing.T) { m := gmap.NewStrStrMap() m.Set("1", "") m.Set("2", "2") - gtest.Assert(m.Size(), 2) - gtest.Assert(m.Get("1"), "") - gtest.Assert(m.Get("2"), "2") + t.Assert(m.Size(), 2) + t.Assert(m.Get("1"), "") + t.Assert(m.Get("2"), "2") m.FilterEmpty() - gtest.Assert(m.Size(), 1) - gtest.Assert(m.Get("2"), "2") + t.Assert(m.Size(), 1) + t.Assert(m.Get("2"), "2") } func Test_StrStrMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrStr{ "k1": "v1", "k2": "v2", @@ -184,90 +184,90 @@ func Test_StrStrMap_Json(t *testing.T) { m1 := gmap.NewStrStrMapFrom(data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(data) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrStr{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.NewStrStrMap() err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapStrStr{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(data) - gtest.Assert(err, nil) + t.Assert(err, nil) var m gmap.StrStrMap err = json.Unmarshal(b, &m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) } func Test_StrStrMap_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrStrMapFrom(g.MapStrStr{ "k1": "v1", "k2": "v2", }) - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) k1, v1 := m.Pop() - gtest.AssertIN(k1, g.Slice{"k1", "k2"}) - gtest.AssertIN(v1, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 1) + t.AssertIN(k1, g.Slice{"k1", "k2"}) + t.AssertIN(v1, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 1) k2, v2 := m.Pop() - gtest.AssertIN(k2, g.Slice{"k1", "k2"}) - gtest.AssertIN(v2, g.Slice{"v1", "v2"}) - gtest.Assert(m.Size(), 0) + t.AssertIN(k2, g.Slice{"k1", "k2"}) + t.AssertIN(v2, g.Slice{"v1", "v2"}) + t.Assert(m.Size(), 0) - gtest.AssertNE(k1, k2) - gtest.AssertNE(v1, v2) + t.AssertNE(k1, k2) + t.AssertNE(v1, v2) }) } func Test_StrStrMap_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewStrStrMapFrom(g.MapStrStr{ "k1": "v1", "k2": "v2", "k3": "v3", }) - gtest.Assert(m.Size(), 3) + t.Assert(m.Size(), 3) kArray := garray.New() vArray := garray.New() for k, v := range m.Pops(1) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 2) + t.Assert(m.Size(), 2) for k, v := range m.Pops(2) { - gtest.AssertIN(k, g.Slice{"k1", "k2", "k3"}) - gtest.AssertIN(v, g.Slice{"v1", "v2", "v3"}) + t.AssertIN(k, g.Slice{"k1", "k2", "k3"}) + t.AssertIN(v, g.Slice{"v1", "v2", "v3"}) kArray.Append(k) vArray.Append(v) } - gtest.Assert(m.Size(), 0) + t.Assert(m.Size(), 0) - gtest.Assert(kArray.Unique().Len(), 3) - gtest.Assert(vArray.Unique().Len(), 3) + t.Assert(kArray.Unique().Len(), 3) + t.Assert(vArray.Unique().Len(), 3) }) } @@ -277,20 +277,20 @@ func TestStrStrMap_UnmarshalValue(t *testing.T) { Map *gmap.StrStrMap } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":"v1","k2":"v2"}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), "v1") - gtest.Assert(t.Map.Get("k2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), "v1") + t.Assert(t.Map.Get("k2"), "v2") }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -299,10 +299,10 @@ func TestStrStrMap_UnmarshalValue(t *testing.T) { "k2": "v2", }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), "v1") - gtest.Assert(t.Map.Get("k2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), "v1") + t.Assert(t.Map.Get("k2"), "v2") }) } diff --git a/container/gmap/gmap_z_unit_tree_map_test.go b/container/gmap/gmap_z_unit_tree_map_test.go index 1578142ec..a1658c174 100644 --- a/container/gmap/gmap_z_unit_tree_map_test.go +++ b/container/gmap/gmap_z_unit_tree_map_test.go @@ -18,63 +18,63 @@ import ( ) func Test_TreeMap_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewTreeMap(gutil.ComparatorString) m.Set("key1", "val1") - gtest.Assert(m.Keys(), []interface{}{"key1"}) + t.Assert(m.Keys(), []interface{}{"key1"}) - gtest.Assert(m.Get("key1"), "val1") - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("key1"), "val1") + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("key2", "val2"), "val2") - gtest.Assert(m.SetIfNotExist("key2", "val2"), false) + t.Assert(m.GetOrSet("key2", "val2"), "val2") + t.Assert(m.SetIfNotExist("key2", "val2"), false) - gtest.Assert(m.SetIfNotExist("key3", "val3"), true) + t.Assert(m.SetIfNotExist("key3", "val3"), true) - gtest.Assert(m.Remove("key2"), "val2") - gtest.Assert(m.Contains("key2"), false) + t.Assert(m.Remove("key2"), "val2") + t.Assert(m.Contains("key2"), false) - gtest.AssertIN("key3", m.Keys()) - gtest.AssertIN("key1", m.Keys()) - gtest.AssertIN("val3", m.Values()) - gtest.AssertIN("val1", m.Values()) + t.AssertIN("key3", m.Keys()) + t.AssertIN("key1", m.Keys()) + t.AssertIN("val3", m.Values()) + t.AssertIN("val1", m.Values()) m.Flip() - gtest.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) + t.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gmap.NewTreeMapFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) - gtest.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) + t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) }) } func Test_TreeMap_Set_Fun(t *testing.T) { m := gmap.NewTreeMap(gutil.ComparatorString) m.GetOrSetFunc("fun", getValue) m.GetOrSetFuncLock("funlock", getValue) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) m.GetOrSetFunc("fun", getValue) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), false) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) } func Test_TreeMap_Batch(t *testing.T) { m := gmap.NewTreeMap(gutil.ComparatorString) m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) m.Removes([]interface{}{"key1", 1}) - gtest.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) } func Test_TreeMap_Iterator(t *testing.T) { expect := map[interface{}]interface{}{1: 1, "key1": "val1"} m := gmap.NewTreeMapFrom(gutil.ComparatorString, expect) m.Iterator(func(k interface{}, v interface{}) bool { - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) // 断言返回值对遍历控制 @@ -88,8 +88,8 @@ func Test_TreeMap_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, 2) - gtest.Assert(j, 1) + t.Assert(i, 2) + t.Assert(j, 1) } func Test_TreeMap_Clone(t *testing.T) { @@ -98,16 +98,16 @@ func Test_TreeMap_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove("key1") //修改clone map,原 map 不影响 - gtest.AssertIN("key1", m.Keys()) + t.AssertIN("key1", m.Keys()) } func Test_TreeMap_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", @@ -115,37 +115,37 @@ func Test_TreeMap_Json(t *testing.T) { m1 := gmap.NewTreeMapFrom(gutil.ComparatorString, data) b1, err1 := json.Marshal(m1) b2, err2 := json.Marshal(gconv.Map(data)) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(gconv.Map(data)) - gtest.Assert(err, nil) + t.Assert(err, nil) m := gmap.NewTreeMap(gutil.ComparatorString) err = json.Unmarshal(b, m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data := g.MapAnyAny{ "k1": "v1", "k2": "v2", } b, err := json.Marshal(gconv.Map(data)) - gtest.Assert(err, nil) + t.Assert(err, nil) var m gmap.TreeMap err = json.Unmarshal(b, &m) - gtest.Assert(err, nil) - gtest.Assert(m.Get("k1"), data["k1"]) - gtest.Assert(m.Get("k2"), data["k2"]) + t.Assert(err, nil) + t.Assert(m.Get("k1"), data["k1"]) + t.Assert(m.Get("k2"), data["k2"]) }) } @@ -155,20 +155,20 @@ func TestTreeMap_UnmarshalValue(t *testing.T) { Map *gmap.TreeMap } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":"v1","k2":"v2"}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), "v1") - gtest.Assert(t.Map.Get("k2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), "v1") + t.Assert(t.Map.Get("k2"), "v2") }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", @@ -177,10 +177,10 @@ func TestTreeMap_UnmarshalValue(t *testing.T) { "k2": "v2", }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Map.Size(), 2) - gtest.Assert(t.Map.Get("k1"), "v1") - gtest.Assert(t.Map.Get("k2"), "v2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Map.Size(), 2) + t.Assert(t.Map.Get("k1"), "v1") + t.Assert(t.Map.Get("k2"), "v2") }) } diff --git a/container/gpool/gpool_z_unit_test.go b/container/gpool/gpool_z_unit_test.go index c27487c2c..c3bdbdf03 100644 --- a/container/gpool/gpool_z_unit_test.go +++ b/container/gpool/gpool_z_unit_test.go @@ -24,11 +24,11 @@ var nf gpool.NewFunc = func() (i interface{}, e error) { var assertIndex int = 0 var ef gpool.ExpireFunc = func(i interface{}) { assertIndex++ - gtest.Assert(i, assertIndex) + t.Assert(i, assertIndex) } func Test_Gpool(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // //expire = 0 p1 := gpool.New(0, nf) @@ -37,63 +37,63 @@ func Test_Gpool(t *testing.T) { time.Sleep(1 * time.Second) //test won't be timeout v1, err1 := p1.Get() - gtest.Assert(err1, nil) - gtest.AssertIN(v1, g.Slice{1, 2}) + t.Assert(err1, nil) + t.AssertIN(v1, g.Slice{1, 2}) //test clear p1.Clear() - gtest.Assert(p1.Size(), 0) + t.Assert(p1.Size(), 0) //test newFunc v1, err1 = p1.Get() - gtest.Assert(err1, nil) - gtest.Assert(v1, "hello") + t.Assert(err1, nil) + t.Assert(v1, "hello") //put data again p1.Put(3) p1.Put(4) v1, err1 = p1.Get() - gtest.Assert(err1, nil) - gtest.AssertIN(v1, g.Slice{3, 4}) + t.Assert(err1, nil) + t.AssertIN(v1, g.Slice{3, 4}) //test close p1.Close() v1, err1 = p1.Get() - gtest.Assert(err1, nil) - gtest.Assert(v1, "hello") + t.Assert(err1, nil) + t.Assert(v1, "hello") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // //expire > 0 p2 := gpool.New(2*time.Second, nil, ef) for index := 0; index < 10; index++ { p2.Put(index) } - gtest.Assert(p2.Size(), 10) + t.Assert(p2.Size(), 10) v2, err2 := p2.Get() - gtest.Assert(err2, nil) - gtest.Assert(v2, 0) + t.Assert(err2, nil) + t.Assert(v2, 0) //test timeout expireFunc time.Sleep(3 * time.Second) v2, err2 = p2.Get() - gtest.Assert(err2, errors.New("pool is empty")) - gtest.Assert(v2, nil) + t.Assert(err2, errors.New("pool is empty")) + t.Assert(v2, nil) //test close expireFunc for index := 0; index < 10; index++ { p2.Put(index) } - gtest.Assert(p2.Size(), 10) + t.Assert(p2.Size(), 10) v2, err2 = p2.Get() - gtest.Assert(err2, nil) - gtest.Assert(v2, 0) + t.Assert(err2, nil) + t.Assert(v2, 0) assertIndex = 0 p2.Close() time.Sleep(3 * time.Second) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // //expire < 0 p3 := gpool.New(-1, nil) v3, err3 := p3.Get() - gtest.Assert(err3, errors.New("pool is empty")) - gtest.Assert(v3, nil) + t.Assert(err3, errors.New("pool is empty")) + t.Assert(v3, nil) }) } diff --git a/container/gqueue/gqueue_unit_test.go b/container/gqueue/gqueue_unit_test.go index 25cbcff6c..854008b3a 100644 --- a/container/gqueue/gqueue_unit_test.go +++ b/container/gqueue/gqueue_unit_test.go @@ -23,8 +23,8 @@ func TestQueue_Len(t *testing.T) { for i := 0; i < max; i++ { q1.Push(i) } - gtest.Assert(q1.Len(), max) - gtest.Assert(q1.Size(), max) + t.Assert(q1.Len(), max) + t.Assert(q1.Size(), max) } } @@ -33,8 +33,8 @@ func TestQueue_Basic(t *testing.T) { for i := 0; i < 100; i++ { q.Push(i) } - gtest.Assert(q.Pop(), 0) - gtest.Assert(q.Pop(), 1) + t.Assert(q.Pop(), 0) + t.Assert(q.Pop(), 1) } func TestQueue_Pop(t *testing.T) { @@ -44,7 +44,7 @@ func TestQueue_Pop(t *testing.T) { q1.Push(3) q1.Push(4) i1 := q1.Pop() - gtest.Assert(i1, 1) + t.Assert(i1, 1) } func TestQueue_Close(t *testing.T) { @@ -52,6 +52,6 @@ func TestQueue_Close(t *testing.T) { q1.Push(1) q1.Push(2) time.Sleep(time.Millisecond) - gtest.Assert(q1.Len(), 2) + t.Assert(q1.Len(), 2) q1.Close() } diff --git a/container/gring/gring_unit_test.go b/container/gring/gring_unit_test.go index 6f735e8f3..9032d9222 100644 --- a/container/gring/gring_unit_test.go +++ b/container/gring/gring_unit_test.go @@ -16,7 +16,7 @@ type Student struct { } func TestRing_Val(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //定义cap 为3的ring类型数据 r := gring.New(3, true) //分别给3个元素初始化赋值 @@ -25,46 +25,46 @@ func TestRing_Val(t *testing.T) { r.Put(&Student{3, "alon", false}) //元素取值并判断和预设值是否相等 - gtest.Assert(r.Val().(*Student).name, "jimmy") + t.Assert(r.Val().(*Student).name, "jimmy") //从当前位置往后移两个元素 r.Move(2) - gtest.Assert(r.Val().(*Student).name, "alon") + t.Assert(r.Val().(*Student).name, "alon") //更新元素值 //测试 value == nil r.Set(nil) - gtest.Assert(r.Val(), nil) + t.Assert(r.Val(), nil) //测试value != nil r.Set(&Student{3, "jack", true}) }) } func TestRing_CapLen(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r := gring.New(10) r.Put("goframe") //cap长度 10 - gtest.Assert(r.Cap(), 10) + t.Assert(r.Cap(), 10) //已有数据项 1 - gtest.Assert(r.Len(), 1) + t.Assert(r.Len(), 1) }) } func TestRing_Position(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r := gring.New(2) r.Put(1) r.Put(2) //往后移动1个元素 r.Next() - gtest.Assert(r.Val(), 2) + t.Assert(r.Val(), 2) //往前移动1个元素 r.Prev() - gtest.Assert(r.Val(), 1) + t.Assert(r.Val(), 1) }) } func TestRing_Link(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r := gring.New(3) r.Put(1) r.Put(2) @@ -74,13 +74,13 @@ func TestRing_Link(t *testing.T) { s.Put("b") rs := r.Link(s) - gtest.Assert(rs.Move(2).Val(), "b") + t.Assert(rs.Move(2).Val(), "b") }) } func TestRing_Unlink(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r := gring.New(5) for i := 0; i < 5; i++ { r.Put(i + 1) @@ -89,13 +89,13 @@ func TestRing_Unlink(t *testing.T) { // 删除当前位置往后的2个数据,返回被删除的数据 // 重新计算s len s := r.Unlink(2) // 2 3 - gtest.Assert(s.Val(), 2) - gtest.Assert(s.Len(), 1) + t.Assert(s.Val(), 2) + t.Assert(s.Len(), 1) }) } func TestRing_Slice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { ringLen := 5 r := gring.New(ringLen) for i := 0; i < ringLen; i++ { @@ -103,49 +103,49 @@ func TestRing_Slice(t *testing.T) { } r.Move(2) // 3 array := r.SliceNext() // [3 4 5 1 2] - gtest.Assert(array[0], 3) - gtest.Assert(len(array), 5) + t.Assert(array[0], 3) + t.Assert(len(array), 5) //判断array是否等于[3 4 5 1 2] ra := []int{3, 4, 5, 1, 2} - gtest.Assert(ra, array) + t.Assert(ra, array) //第3个元素设为nil r.Set(nil) array2 := r.SliceNext() //[4 5 1 2] //返回当前位置往后不为空的元素数组,长度为4 - gtest.Assert(array2, g.Slice{4, 5, 1, 2}) + t.Assert(array2, g.Slice{4, 5, 1, 2}) array3 := r.SlicePrev() //[2 1 5 4] - gtest.Assert(array3, g.Slice{2, 1, 5, 4}) + t.Assert(array3, g.Slice{2, 1, 5, 4}) s := gring.New(ringLen) for i := 0; i < ringLen; i++ { s.Put(i + 1) } array4 := s.SlicePrev() // [] - gtest.Assert(array4, g.Slice{1, 5, 4, 3, 2}) + t.Assert(array4, g.Slice{1, 5, 4, 3, 2}) }) } func TestRing_RLockIterator(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { ringLen := 5 r := gring.New(ringLen) //ring不存在有值元素 r.RLockIteratorNext(func(v interface{}) bool { - gtest.Assert(v, nil) + t.Assert(v, nil) return false }) r.RLockIteratorNext(func(v interface{}) bool { - gtest.Assert(v, nil) + t.Assert(v, nil) return true }) r.RLockIteratorPrev(func(v interface{}) bool { - gtest.Assert(v, nil) + t.Assert(v, nil) return true }) @@ -156,14 +156,14 @@ func TestRing_RLockIterator(t *testing.T) { //回调函数返回true,RLockIteratorNext遍历5次,期望值分别是1、2、3、4、5 i := 0 r.RLockIteratorNext(func(v interface{}) bool { - gtest.Assert(v, i+1) + t.Assert(v, i+1) i++ return true }) //RLockIteratorPrev遍历1次返回 false,退出遍历 r.RLockIteratorPrev(func(v interface{}) bool { - gtest.Assert(v, 1) + t.Assert(v, 1) return false }) @@ -171,30 +171,30 @@ func TestRing_RLockIterator(t *testing.T) { } func TestRing_LockIterator(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { ringLen := 5 r := gring.New(ringLen) //不存在有值元素 r.LockIteratorNext(func(item *ring.Ring) bool { - gtest.Assert(item.Value, nil) + t.Assert(item.Value, nil) return false }) r.LockIteratorNext(func(item *ring.Ring) bool { - gtest.Assert(item.Value, nil) + t.Assert(item.Value, nil) return false }) r.LockIteratorNext(func(item *ring.Ring) bool { - gtest.Assert(item.Value, nil) + t.Assert(item.Value, nil) return true }) r.LockIteratorPrev(func(item *ring.Ring) bool { - gtest.Assert(item.Value, nil) + t.Assert(item.Value, nil) return false }) r.LockIteratorPrev(func(item *ring.Ring) bool { - gtest.Assert(item.Value, nil) + t.Assert(item.Value, nil) return true }) @@ -208,7 +208,7 @@ func TestRing_LockIterator(t *testing.T) { ii := 0 r.LockIteratorNext(func(item *ring.Ring) bool { //校验每一次遍历取值是否是期望值 - gtest.Assert(item.Value, array1[ii]) + t.Assert(item.Value, array1[ii]) ii++ return true }) @@ -221,7 +221,7 @@ func TestRing_LockIterator(t *testing.T) { if i > 2 { return false } - gtest.Assert(item.Value, a[i]) + t.Assert(item.Value, a[i]) i++ return true }) diff --git a/container/gset/gset_z_unit_any_test.go b/container/gset/gset_z_unit_any_test.go index ac9a80e66..a42751232 100644 --- a/container/gset/gset_z_unit_any_test.go +++ b/container/gset/gset_z_unit_any_test.go @@ -22,50 +22,50 @@ import ( ) func TestSet_New(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.New() s.Add(1).Add(1).Add(2) s.Add([]interface{}{3, 4}...) - gtest.Assert(s.Size(), 4) - gtest.AssertIN(1, s.Slice()) - gtest.AssertIN(2, s.Slice()) - gtest.AssertIN(3, s.Slice()) - gtest.AssertIN(4, s.Slice()) - gtest.AssertNI(0, s.Slice()) - gtest.Assert(s.Contains(4), true) - gtest.Assert(s.Contains(5), false) + t.Assert(s.Size(), 4) + t.AssertIN(1, s.Slice()) + t.AssertIN(2, s.Slice()) + t.AssertIN(3, s.Slice()) + t.AssertIN(4, s.Slice()) + t.AssertNI(0, s.Slice()) + t.Assert(s.Contains(4), true) + t.Assert(s.Contains(5), false) s.Remove(1) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) s.Clear() - gtest.Assert(s.Size(), 0) + t.Assert(s.Size(), 0) }) } func TestSet_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewSet() s.Add(1).Add(1).Add(2) s.Add([]interface{}{3, 4}...) - gtest.Assert(s.Size(), 4) - gtest.AssertIN(1, s.Slice()) - gtest.AssertIN(2, s.Slice()) - gtest.AssertIN(3, s.Slice()) - gtest.AssertIN(4, s.Slice()) - gtest.AssertNI(0, s.Slice()) - gtest.Assert(s.Contains(4), true) - gtest.Assert(s.Contains(5), false) + t.Assert(s.Size(), 4) + t.AssertIN(1, s.Slice()) + t.AssertIN(2, s.Slice()) + t.AssertIN(3, s.Slice()) + t.AssertIN(4, s.Slice()) + t.AssertNI(0, s.Slice()) + t.Assert(s.Contains(4), true) + t.Assert(s.Contains(5), false) s.Remove(1) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) s.Clear() - gtest.Assert(s.Size(), 0) + t.Assert(s.Size(), 0) }) } func TestSet_Iterator(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewSet() s.Add(1).Add(2).Add(3) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) a1 := garray.New(true) a2 := garray.New(true) @@ -77,22 +77,22 @@ func TestSet_Iterator(t *testing.T) { a2.Append(1) return true }) - gtest.Assert(a1.Len(), 1) - gtest.Assert(a2.Len(), 3) + t.Assert(a1.Len(), 1) + t.Assert(a2.Len(), 3) }) } func TestSet_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewSet() s.Add(1).Add(2).Add(3) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) s.LockFunc(func(m map[interface{}]struct{}) { delete(m, 1) }) - gtest.Assert(s.Size(), 2) + t.Assert(s.Size(), 2) s.RLockFunc(func(m map[interface{}]struct{}) { - gtest.Assert(m, map[interface{}]struct{}{ + t.Assert(m, map[interface{}]struct{}{ 3: struct{}{}, 2: struct{}{}, }) @@ -101,266 +101,266 @@ func TestSet_LockFunc(t *testing.T) { } func TestSet_Equal(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewSet() s2 := gset.NewSet() s3 := gset.NewSet() s1.Add(1).Add(2).Add(3) s2.Add(1).Add(2).Add(3) s3.Add(1).Add(2).Add(3).Add(4) - gtest.Assert(s1.Equal(s2), true) - gtest.Assert(s1.Equal(s3), false) + t.Assert(s1.Equal(s2), true) + t.Assert(s1.Equal(s3), false) }) } func TestSet_IsSubsetOf(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewSet() s2 := gset.NewSet() s3 := gset.NewSet() s1.Add(1).Add(2) s2.Add(1).Add(2).Add(3) s3.Add(1).Add(2).Add(3).Add(4) - gtest.Assert(s1.IsSubsetOf(s2), true) - gtest.Assert(s2.IsSubsetOf(s3), true) - gtest.Assert(s1.IsSubsetOf(s3), true) - gtest.Assert(s2.IsSubsetOf(s1), false) - gtest.Assert(s3.IsSubsetOf(s2), false) + t.Assert(s1.IsSubsetOf(s2), true) + t.Assert(s2.IsSubsetOf(s3), true) + t.Assert(s1.IsSubsetOf(s3), true) + t.Assert(s2.IsSubsetOf(s1), false) + t.Assert(s3.IsSubsetOf(s2), false) }) } func TestSet_Union(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewSet() s2 := gset.NewSet() s1.Add(1).Add(2) s2.Add(3).Add(4) s3 := s1.Union(s2) - gtest.Assert(s3.Contains(1), true) - gtest.Assert(s3.Contains(2), true) - gtest.Assert(s3.Contains(3), true) - gtest.Assert(s3.Contains(4), true) + t.Assert(s3.Contains(1), true) + t.Assert(s3.Contains(2), true) + t.Assert(s3.Contains(3), true) + t.Assert(s3.Contains(4), true) }) } func TestSet_Diff(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewSet() s2 := gset.NewSet() s1.Add(1).Add(2).Add(3) s2.Add(3).Add(4).Add(5) s3 := s1.Diff(s2) - gtest.Assert(s3.Contains(1), true) - gtest.Assert(s3.Contains(2), true) - gtest.Assert(s3.Contains(3), false) - gtest.Assert(s3.Contains(4), false) + t.Assert(s3.Contains(1), true) + t.Assert(s3.Contains(2), true) + t.Assert(s3.Contains(3), false) + t.Assert(s3.Contains(4), false) }) } func TestSet_Intersect(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewSet() s2 := gset.NewSet() s1.Add(1).Add(2).Add(3) s2.Add(3).Add(4).Add(5) s3 := s1.Intersect(s2) - gtest.Assert(s3.Contains(1), false) - gtest.Assert(s3.Contains(2), false) - gtest.Assert(s3.Contains(3), true) - gtest.Assert(s3.Contains(4), false) + t.Assert(s3.Contains(1), false) + t.Assert(s3.Contains(2), false) + t.Assert(s3.Contains(3), true) + t.Assert(s3.Contains(4), false) }) } func TestSet_Complement(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewSet() s2 := gset.NewSet() s1.Add(1).Add(2).Add(3) s2.Add(3).Add(4).Add(5) s3 := s1.Complement(s2) - gtest.Assert(s3.Contains(1), false) - gtest.Assert(s3.Contains(2), false) - gtest.Assert(s3.Contains(4), true) - gtest.Assert(s3.Contains(5), true) + t.Assert(s3.Contains(1), false) + t.Assert(s3.Contains(2), false) + t.Assert(s3.Contains(4), true) + t.Assert(s3.Contains(5), true) }) } func TestNewFrom(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewFrom("a") s2 := gset.NewFrom("b", false) s3 := gset.NewFrom(3, true) s4 := gset.NewFrom([]string{"s1", "s2"}, true) - gtest.Assert(s1.Contains("a"), true) - gtest.Assert(s2.Contains("b"), true) - gtest.Assert(s3.Contains(3), true) - gtest.Assert(s4.Contains("s1"), true) - gtest.Assert(s4.Contains("s3"), false) + t.Assert(s1.Contains("a"), true) + t.Assert(s2.Contains("b"), true) + t.Assert(s3.Contains(3), true) + t.Assert(s4.Contains("s1"), true) + t.Assert(s4.Contains("s3"), false) }) } func TestNew(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.New() s1.Add("a").Add(2) s2 := gset.New(true) s2.Add("b").Add(3) - gtest.Assert(s1.Contains("a"), true) + t.Assert(s1.Contains("a"), true) }) } func TestSet_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.New(true) s1.Add("a").Add("a1").Add("b").Add("c") str1 := s1.Join(",") - gtest.Assert(strings.Contains(str1, "a1"), true) + t.Assert(strings.Contains(str1, "a1"), true) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.New(true) s1.Add("a").Add(`"b"`).Add(`\c`) str1 := s1.Join(",") - gtest.Assert(strings.Contains(str1, `"b"`), true) - gtest.Assert(strings.Contains(str1, `\c`), true) - gtest.Assert(strings.Contains(str1, `a`), true) + t.Assert(strings.Contains(str1, `"b"`), true) + t.Assert(strings.Contains(str1, `\c`), true) + t.Assert(strings.Contains(str1, `a`), true) }) } func TestSet_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.New(true) s1.Add("a").Add("a2").Add("b").Add("c") str1 := s1.String() - gtest.Assert(strings.Contains(str1, "["), true) - gtest.Assert(strings.Contains(str1, "]"), true) - gtest.Assert(strings.Contains(str1, "a2"), true) + t.Assert(strings.Contains(str1, "["), true) + t.Assert(strings.Contains(str1, "]"), true) + t.Assert(strings.Contains(str1, "a2"), true) }) } func TestSet_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.New(true) s2 := gset.New(true) s1.Add("a").Add("a2").Add("b").Add("c") s2.Add("b").Add("b1").Add("e").Add("f") ss := s1.Merge(s2) - gtest.Assert(ss.Contains("a2"), true) - gtest.Assert(ss.Contains("b1"), true) + t.Assert(ss.Contains("a2"), true) + t.Assert(ss.Contains("b1"), true) }) } func TestSet_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.New(true) s1.Add(1).Add(2).Add(3).Add(4) - gtest.Assert(s1.Sum(), int(10)) + t.Assert(s1.Sum(), int(10)) }) } func TestSet_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.New(true) s.Add(1).Add(2).Add(3).Add(4) - gtest.Assert(s.Size(), 4) - gtest.AssertIN(s.Pop(), []int{1, 2, 3, 4}) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 4) + t.AssertIN(s.Pop(), []int{1, 2, 3, 4}) + t.Assert(s.Size(), 3) }) } func TestSet_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.New(true) s.Add(1).Add(2).Add(3).Add(4) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Pops(0), nil) - gtest.AssertIN(s.Pops(1), []int{1, 2, 3, 4}) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 4) + t.Assert(s.Pops(0), nil) + t.AssertIN(s.Pops(1), []int{1, 2, 3, 4}) + t.Assert(s.Size(), 3) a := s.Pops(6) - gtest.Assert(len(a), 3) - gtest.AssertIN(a, []int{1, 2, 3, 4}) - gtest.Assert(s.Size(), 0) + t.Assert(len(a), 3) + t.AssertIN(a, []int{1, 2, 3, 4}) + t.Assert(s.Size(), 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.New(true) a := []interface{}{1, 2, 3, 4} s.Add(a...) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Pops(-2), nil) - gtest.AssertIN(s.Pops(-1), a) + t.Assert(s.Size(), 4) + t.Assert(s.Pops(-2), nil) + t.AssertIN(s.Pops(-1), a) }) } func TestSet_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []interface{}{"a", "b", "d", "c"} a1 := gset.NewFrom(s1) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(len(b1), len(b2)) - gtest.Assert(err1, err2) + t.Assert(len(b1), len(b2)) + t.Assert(err1, err2) a2 := gset.New() err2 = json.Unmarshal(b2, &a2) - gtest.Assert(err2, nil) - gtest.Assert(a2.Contains("a"), true) - gtest.Assert(a2.Contains("b"), true) - gtest.Assert(a2.Contains("c"), true) - gtest.Assert(a2.Contains("d"), true) - gtest.Assert(a2.Contains("e"), false) + t.Assert(err2, nil) + t.Assert(a2.Contains("a"), true) + t.Assert(a2.Contains("b"), true) + t.Assert(a2.Contains("c"), true) + t.Assert(a2.Contains("d"), true) + t.Assert(a2.Contains("e"), false) var a3 gset.Set err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a3.Contains("a"), true) - gtest.Assert(a3.Contains("b"), true) - gtest.Assert(a3.Contains("c"), true) - gtest.Assert(a3.Contains("d"), true) - gtest.Assert(a3.Contains("e"), false) + t.Assert(err, nil) + t.Assert(a3.Contains("a"), true) + t.Assert(a3.Contains("b"), true) + t.Assert(a3.Contains("c"), true) + t.Assert(a3.Contains("d"), true) + t.Assert(a3.Contains("e"), false) }) } func TestSet_AddIfNotExistFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.New(true) s.Add(1) - gtest.Assert(s.Contains(1), true) - gtest.Assert(s.Contains(2), false) + t.Assert(s.Contains(1), true) + t.Assert(s.Contains(2), false) s.AddIfNotExistFunc(2, func() interface{} { return 3 }) - gtest.Assert(s.Contains(2), false) - gtest.Assert(s.Contains(3), true) + t.Assert(s.Contains(2), false) + t.Assert(s.Contains(3), true) s.AddIfNotExistFunc(3, func() interface{} { return 4 }) - gtest.Assert(s.Contains(3), true) - gtest.Assert(s.Contains(4), false) + t.Assert(s.Contains(3), true) + t.Assert(s.Contains(4), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.New(true) s.Add(1) - gtest.Assert(s.Contains(1), true) - gtest.Assert(s.Contains(2), false) + t.Assert(s.Contains(1), true) + t.Assert(s.Contains(2), false) s.AddIfNotExistFuncLock(2, func() interface{} { return 3 }) - gtest.Assert(s.Contains(2), false) - gtest.Assert(s.Contains(3), true) + t.Assert(s.Contains(2), false) + t.Assert(s.Contains(3), true) s.AddIfNotExistFuncLock(3, func() interface{} { return 4 }) - gtest.Assert(s.Contains(3), true) - gtest.Assert(s.Contains(4), false) + t.Assert(s.Contains(3), true) + t.Assert(s.Contains(4), false) }) } @@ -370,33 +370,33 @@ func TestSet_UnmarshalValue(t *testing.T) { Set *gset.Set } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "set": []byte(`["k1","k2","k3"]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Set.Size(), 3) - gtest.Assert(t.Set.Contains("k1"), true) - gtest.Assert(t.Set.Contains("k2"), true) - gtest.Assert(t.Set.Contains("k3"), true) - gtest.Assert(t.Set.Contains("k4"), false) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Set.Size(), 3) + t.Assert(t.Set.Contains("k1"), true) + t.Assert(t.Set.Contains("k2"), true) + t.Assert(t.Set.Contains("k3"), true) + t.Assert(t.Set.Contains("k4"), false) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "set": g.Slice{"k1", "k2", "k3"}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Set.Size(), 3) - gtest.Assert(t.Set.Contains("k1"), true) - gtest.Assert(t.Set.Contains("k2"), true) - gtest.Assert(t.Set.Contains("k3"), true) - gtest.Assert(t.Set.Contains("k4"), false) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Set.Size(), 3) + t.Assert(t.Set.Contains("k1"), true) + t.Assert(t.Set.Contains("k2"), true) + t.Assert(t.Set.Contains("k3"), true) + t.Assert(t.Set.Contains("k4"), false) }) } diff --git a/container/gset/gset_z_unit_int_test.go b/container/gset/gset_z_unit_int_test.go index f24491454..8e5e17bd8 100644 --- a/container/gset/gset_z_unit_int_test.go +++ b/container/gset/gset_z_unit_int_test.go @@ -21,30 +21,30 @@ import ( ) func TestIntSet_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewIntSet() s.Add(1).Add(1).Add(2) s.Add([]int{3, 4}...) - gtest.Assert(s.Size(), 4) - gtest.AssertIN(1, s.Slice()) - gtest.AssertIN(2, s.Slice()) - gtest.AssertIN(3, s.Slice()) - gtest.AssertIN(4, s.Slice()) - gtest.AssertNI(0, s.Slice()) - gtest.Assert(s.Contains(4), true) - gtest.Assert(s.Contains(5), false) + t.Assert(s.Size(), 4) + t.AssertIN(1, s.Slice()) + t.AssertIN(2, s.Slice()) + t.AssertIN(3, s.Slice()) + t.AssertIN(4, s.Slice()) + t.AssertNI(0, s.Slice()) + t.Assert(s.Contains(4), true) + t.Assert(s.Contains(5), false) s.Remove(1) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) s.Clear() - gtest.Assert(s.Size(), 0) + t.Assert(s.Size(), 0) }) } func TestIntSet_Iterator(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewIntSet() s.Add(1).Add(2).Add(3) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) a1 := garray.New(true) a2 := garray.New(true) @@ -56,22 +56,22 @@ func TestIntSet_Iterator(t *testing.T) { a2.Append(1) return true }) - gtest.Assert(a1.Len(), 1) - gtest.Assert(a2.Len(), 3) + t.Assert(a1.Len(), 1) + t.Assert(a2.Len(), 3) }) } func TestIntSet_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewIntSet() s.Add(1).Add(2).Add(3) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) s.LockFunc(func(m map[int]struct{}) { delete(m, 1) }) - gtest.Assert(s.Size(), 2) + t.Assert(s.Size(), 2) s.RLockFunc(func(m map[int]struct{}) { - gtest.Assert(m, map[int]struct{}{ + t.Assert(m, map[int]struct{}{ 3: struct{}{}, 2: struct{}{}, }) @@ -80,250 +80,250 @@ func TestIntSet_LockFunc(t *testing.T) { } func TestIntSet_Equal(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s2 := gset.NewIntSet() s3 := gset.NewIntSet() s1.Add(1).Add(2).Add(3) s2.Add(1).Add(2).Add(3) s3.Add(1).Add(2).Add(3).Add(4) - gtest.Assert(s1.Equal(s2), true) - gtest.Assert(s1.Equal(s3), false) + t.Assert(s1.Equal(s2), true) + t.Assert(s1.Equal(s3), false) }) } func TestIntSet_IsSubsetOf(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s2 := gset.NewIntSet() s3 := gset.NewIntSet() s1.Add(1).Add(2) s2.Add(1).Add(2).Add(3) s3.Add(1).Add(2).Add(3).Add(4) - gtest.Assert(s1.IsSubsetOf(s2), true) - gtest.Assert(s2.IsSubsetOf(s3), true) - gtest.Assert(s1.IsSubsetOf(s3), true) - gtest.Assert(s2.IsSubsetOf(s1), false) - gtest.Assert(s3.IsSubsetOf(s2), false) + t.Assert(s1.IsSubsetOf(s2), true) + t.Assert(s2.IsSubsetOf(s3), true) + t.Assert(s1.IsSubsetOf(s3), true) + t.Assert(s2.IsSubsetOf(s1), false) + t.Assert(s3.IsSubsetOf(s2), false) }) } func TestIntSet_Union(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s2 := gset.NewIntSet() s1.Add(1).Add(2) s2.Add(3).Add(4) s3 := s1.Union(s2) - gtest.Assert(s3.Contains(1), true) - gtest.Assert(s3.Contains(2), true) - gtest.Assert(s3.Contains(3), true) - gtest.Assert(s3.Contains(4), true) + t.Assert(s3.Contains(1), true) + t.Assert(s3.Contains(2), true) + t.Assert(s3.Contains(3), true) + t.Assert(s3.Contains(4), true) }) } func TestIntSet_Diff(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s2 := gset.NewIntSet() s1.Add(1).Add(2).Add(3) s2.Add(3).Add(4).Add(5) s3 := s1.Diff(s2) - gtest.Assert(s3.Contains(1), true) - gtest.Assert(s3.Contains(2), true) - gtest.Assert(s3.Contains(3), false) - gtest.Assert(s3.Contains(4), false) + t.Assert(s3.Contains(1), true) + t.Assert(s3.Contains(2), true) + t.Assert(s3.Contains(3), false) + t.Assert(s3.Contains(4), false) }) } func TestIntSet_Intersect(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s2 := gset.NewIntSet() s1.Add(1).Add(2).Add(3) s2.Add(3).Add(4).Add(5) s3 := s1.Intersect(s2) - gtest.Assert(s3.Contains(1), false) - gtest.Assert(s3.Contains(2), false) - gtest.Assert(s3.Contains(3), true) - gtest.Assert(s3.Contains(4), false) + t.Assert(s3.Contains(1), false) + t.Assert(s3.Contains(2), false) + t.Assert(s3.Contains(3), true) + t.Assert(s3.Contains(4), false) }) } func TestIntSet_Complement(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s2 := gset.NewIntSet() s1.Add(1).Add(2).Add(3) s2.Add(3).Add(4).Add(5) s3 := s1.Complement(s2) - gtest.Assert(s3.Contains(1), false) - gtest.Assert(s3.Contains(2), false) - gtest.Assert(s3.Contains(4), true) - gtest.Assert(s3.Contains(5), true) + t.Assert(s3.Contains(1), false) + t.Assert(s3.Contains(2), false) + t.Assert(s3.Contains(4), true) + t.Assert(s3.Contains(5), true) }) } func TestIntSet_Size(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet(true) s1.Add(1).Add(2).Add(3) - gtest.Assert(s1.Size(), 3) + t.Assert(s1.Size(), 3) }) } func TestIntSet_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s2 := gset.NewIntSet() s1.Add(1).Add(2).Add(3) s2.Add(3).Add(4).Add(5) s3 := s1.Merge(s2) - gtest.Assert(s3.Contains(1), true) - gtest.Assert(s3.Contains(5), true) - gtest.Assert(s3.Contains(6), false) + t.Assert(s3.Contains(1), true) + t.Assert(s3.Contains(5), true) + t.Assert(s3.Contains(6), false) }) } func TestIntSet_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s1.Add(1).Add(2).Add(3) s3 := s1.Join(",") - gtest.Assert(strings.Contains(s3, "1"), true) - gtest.Assert(strings.Contains(s3, "2"), true) - gtest.Assert(strings.Contains(s3, "3"), true) + t.Assert(strings.Contains(s3, "1"), true) + t.Assert(strings.Contains(s3, "2"), true) + t.Assert(strings.Contains(s3, "3"), true) }) } func TestIntSet_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s1.Add(1).Add(2).Add(3) s3 := s1.String() - gtest.Assert(strings.Contains(s3, "["), true) - gtest.Assert(strings.Contains(s3, "]"), true) - gtest.Assert(strings.Contains(s3, "1"), true) - gtest.Assert(strings.Contains(s3, "2"), true) - gtest.Assert(strings.Contains(s3, "3"), true) + t.Assert(strings.Contains(s3, "["), true) + t.Assert(strings.Contains(s3, "]"), true) + t.Assert(strings.Contains(s3, "1"), true) + t.Assert(strings.Contains(s3, "2"), true) + t.Assert(strings.Contains(s3, "3"), true) }) } func TestIntSet_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSet() s1.Add(1).Add(2).Add(3) s2 := gset.NewIntSet() s2.Add(5).Add(6).Add(7) - gtest.Assert(s2.Sum(), 18) + t.Assert(s2.Sum(), 18) }) } func TestIntSet_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewIntSet() s.Add(4).Add(2).Add(3) - gtest.Assert(s.Size(), 3) - gtest.AssertIN(s.Pop(), []int{4, 2, 3}) - gtest.AssertIN(s.Pop(), []int{4, 2, 3}) - gtest.Assert(s.Size(), 1) + t.Assert(s.Size(), 3) + t.AssertIN(s.Pop(), []int{4, 2, 3}) + t.AssertIN(s.Pop(), []int{4, 2, 3}) + t.Assert(s.Size(), 1) }) } func TestIntSet_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewIntSet() s.Add(1).Add(4).Add(2).Add(3) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Pops(0), nil) - gtest.AssertIN(s.Pops(1), []int{1, 4, 2, 3}) - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 4) + t.Assert(s.Pops(0), nil) + t.AssertIN(s.Pops(1), []int{1, 4, 2, 3}) + t.Assert(s.Size(), 3) a := s.Pops(2) - gtest.Assert(len(a), 2) - gtest.AssertIN(a, []int{1, 4, 2, 3}) - gtest.Assert(s.Size(), 1) + t.Assert(len(a), 2) + t.AssertIN(a, []int{1, 4, 2, 3}) + t.Assert(s.Size(), 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewIntSet(true) a := []int{1, 2, 3, 4} s.Add(a...) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Pops(-2), nil) - gtest.AssertIN(s.Pops(-1), a) + t.Assert(s.Size(), 4) + t.Assert(s.Pops(-2), nil) + t.AssertIN(s.Pops(-1), a) }) } func TestIntSet_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []int{1, 3, 2, 4} a1 := gset.NewIntSetFrom(s1) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(len(b1), len(b2)) - gtest.Assert(err1, err2) + t.Assert(len(b1), len(b2)) + t.Assert(err1, err2) a2 := gset.NewIntSet() err2 = json.Unmarshal(b2, &a2) - gtest.Assert(err2, nil) - gtest.Assert(a2.Contains(1), true) - gtest.Assert(a2.Contains(2), true) - gtest.Assert(a2.Contains(3), true) - gtest.Assert(a2.Contains(4), true) - gtest.Assert(a2.Contains(5), false) + t.Assert(err2, nil) + t.Assert(a2.Contains(1), true) + t.Assert(a2.Contains(2), true) + t.Assert(a2.Contains(3), true) + t.Assert(a2.Contains(4), true) + t.Assert(a2.Contains(5), false) var a3 gset.IntSet err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a2.Contains(1), true) - gtest.Assert(a2.Contains(2), true) - gtest.Assert(a2.Contains(3), true) - gtest.Assert(a2.Contains(4), true) - gtest.Assert(a2.Contains(5), false) + t.Assert(err, nil) + t.Assert(a2.Contains(1), true) + t.Assert(a2.Contains(2), true) + t.Assert(a2.Contains(3), true) + t.Assert(a2.Contains(4), true) + t.Assert(a2.Contains(5), false) }) } func TestIntSet_AddIfNotExistFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewIntSet(true) s.Add(1) - gtest.Assert(s.Contains(1), true) - gtest.Assert(s.Contains(2), false) + t.Assert(s.Contains(1), true) + t.Assert(s.Contains(2), false) s.AddIfNotExistFunc(2, func() int { return 3 }) - gtest.Assert(s.Contains(2), false) - gtest.Assert(s.Contains(3), true) + t.Assert(s.Contains(2), false) + t.Assert(s.Contains(3), true) s.AddIfNotExistFunc(3, func() int { return 4 }) - gtest.Assert(s.Contains(3), true) - gtest.Assert(s.Contains(4), false) + t.Assert(s.Contains(3), true) + t.Assert(s.Contains(4), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewIntSet(true) s.Add(1) - gtest.Assert(s.Contains(1), true) - gtest.Assert(s.Contains(2), false) + t.Assert(s.Contains(1), true) + t.Assert(s.Contains(2), false) s.AddIfNotExistFuncLock(2, func() int { return 3 }) - gtest.Assert(s.Contains(2), false) - gtest.Assert(s.Contains(3), true) + t.Assert(s.Contains(2), false) + t.Assert(s.Contains(3), true) s.AddIfNotExistFuncLock(3, func() int { return 4 }) - gtest.Assert(s.Contains(3), true) - gtest.Assert(s.Contains(4), false) + t.Assert(s.Contains(3), true) + t.Assert(s.Contains(4), false) }) } @@ -333,33 +333,33 @@ func TestIntSet_UnmarshalValue(t *testing.T) { Set *gset.IntSet } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "set": []byte(`[1,2,3]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Set.Size(), 3) - gtest.Assert(t.Set.Contains(1), true) - gtest.Assert(t.Set.Contains(2), true) - gtest.Assert(t.Set.Contains(3), true) - gtest.Assert(t.Set.Contains(4), false) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Set.Size(), 3) + t.Assert(t.Set.Contains(1), true) + t.Assert(t.Set.Contains(2), true) + t.Assert(t.Set.Contains(3), true) + t.Assert(t.Set.Contains(4), false) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "set": g.Slice{1, 2, 3}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Set.Size(), 3) - gtest.Assert(t.Set.Contains(1), true) - gtest.Assert(t.Set.Contains(2), true) - gtest.Assert(t.Set.Contains(3), true) - gtest.Assert(t.Set.Contains(4), false) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Set.Size(), 3) + t.Assert(t.Set.Contains(1), true) + t.Assert(t.Set.Contains(2), true) + t.Assert(t.Set.Contains(3), true) + t.Assert(t.Set.Contains(4), false) }) } diff --git a/container/gset/gset_z_unit_str_test.go b/container/gset/gset_z_unit_str_test.go index 9b9c69640..d178dce4a 100644 --- a/container/gset/gset_z_unit_str_test.go +++ b/container/gset/gset_z_unit_str_test.go @@ -21,30 +21,30 @@ import ( ) func TestStrSet_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewStrSet() s.Add("1").Add("1").Add("2") s.Add([]string{"3", "4"}...) - gtest.Assert(s.Size(), 4) - gtest.AssertIN("1", s.Slice()) - gtest.AssertIN("2", s.Slice()) - gtest.AssertIN("3", s.Slice()) - gtest.AssertIN("4", s.Slice()) - gtest.AssertNI("0", s.Slice()) - gtest.Assert(s.Contains("4"), true) - gtest.Assert(s.Contains("5"), false) + t.Assert(s.Size(), 4) + t.AssertIN("1", s.Slice()) + t.AssertIN("2", s.Slice()) + t.AssertIN("3", s.Slice()) + t.AssertIN("4", s.Slice()) + t.AssertNI("0", s.Slice()) + t.Assert(s.Contains("4"), true) + t.Assert(s.Contains("5"), false) s.Remove("1") - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) s.Clear() - gtest.Assert(s.Size(), 0) + t.Assert(s.Size(), 0) }) } func TestStrSet_Iterator(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewStrSet() s.Add("1").Add("2").Add("3") - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) a1 := garray.New(true) a2 := garray.New(true) @@ -56,22 +56,22 @@ func TestStrSet_Iterator(t *testing.T) { a2.Append("1") return true }) - gtest.Assert(a1.Len(), 1) - gtest.Assert(a2.Len(), 3) + t.Assert(a1.Len(), 1) + t.Assert(a2.Len(), 3) }) } func TestStrSet_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewStrSet() s.Add("1").Add("2").Add("3") - gtest.Assert(s.Size(), 3) + t.Assert(s.Size(), 3) s.LockFunc(func(m map[string]struct{}) { delete(m, "1") }) - gtest.Assert(s.Size(), 2) + t.Assert(s.Size(), 2) s.RLockFunc(func(m map[string]struct{}) { - gtest.Assert(m, map[string]struct{}{ + t.Assert(m, map[string]struct{}{ "3": struct{}{}, "2": struct{}{}, }) @@ -80,286 +80,286 @@ func TestStrSet_LockFunc(t *testing.T) { } func TestStrSet_Equal(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSet() s2 := gset.NewStrSet() s3 := gset.NewStrSet() s1.Add("1").Add("2").Add("3") s2.Add("1").Add("2").Add("3") s3.Add("1").Add("2").Add("3").Add("4") - gtest.Assert(s1.Equal(s2), true) - gtest.Assert(s1.Equal(s3), false) + t.Assert(s1.Equal(s2), true) + t.Assert(s1.Equal(s3), false) }) } func TestStrSet_IsSubsetOf(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSet() s2 := gset.NewStrSet() s3 := gset.NewStrSet() s1.Add("1").Add("2") s2.Add("1").Add("2").Add("3") s3.Add("1").Add("2").Add("3").Add("4") - gtest.Assert(s1.IsSubsetOf(s2), true) - gtest.Assert(s2.IsSubsetOf(s3), true) - gtest.Assert(s1.IsSubsetOf(s3), true) - gtest.Assert(s2.IsSubsetOf(s1), false) - gtest.Assert(s3.IsSubsetOf(s2), false) + t.Assert(s1.IsSubsetOf(s2), true) + t.Assert(s2.IsSubsetOf(s3), true) + t.Assert(s1.IsSubsetOf(s3), true) + t.Assert(s2.IsSubsetOf(s1), false) + t.Assert(s3.IsSubsetOf(s2), false) }) } func TestStrSet_Union(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSet() s2 := gset.NewStrSet() s1.Add("1").Add("2") s2.Add("3").Add("4") s3 := s1.Union(s2) - gtest.Assert(s3.Contains("1"), true) - gtest.Assert(s3.Contains("2"), true) - gtest.Assert(s3.Contains("3"), true) - gtest.Assert(s3.Contains("4"), true) + t.Assert(s3.Contains("1"), true) + t.Assert(s3.Contains("2"), true) + t.Assert(s3.Contains("3"), true) + t.Assert(s3.Contains("4"), true) }) } func TestStrSet_Diff(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSet() s2 := gset.NewStrSet() s1.Add("1").Add("2").Add("3") s2.Add("3").Add("4").Add("5") s3 := s1.Diff(s2) - gtest.Assert(s3.Contains("1"), true) - gtest.Assert(s3.Contains("2"), true) - gtest.Assert(s3.Contains("3"), false) - gtest.Assert(s3.Contains("4"), false) + t.Assert(s3.Contains("1"), true) + t.Assert(s3.Contains("2"), true) + t.Assert(s3.Contains("3"), false) + t.Assert(s3.Contains("4"), false) }) } func TestStrSet_Intersect(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSet() s2 := gset.NewStrSet() s1.Add("1").Add("2").Add("3") s2.Add("3").Add("4").Add("5") s3 := s1.Intersect(s2) - gtest.Assert(s3.Contains("1"), false) - gtest.Assert(s3.Contains("2"), false) - gtest.Assert(s3.Contains("3"), true) - gtest.Assert(s3.Contains("4"), false) + t.Assert(s3.Contains("1"), false) + t.Assert(s3.Contains("2"), false) + t.Assert(s3.Contains("3"), true) + t.Assert(s3.Contains("4"), false) }) } func TestStrSet_Complement(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSet() s2 := gset.NewStrSet() s1.Add("1").Add("2").Add("3") s2.Add("3").Add("4").Add("5") s3 := s1.Complement(s2) - gtest.Assert(s3.Contains("1"), false) - gtest.Assert(s3.Contains("2"), false) - gtest.Assert(s3.Contains("4"), true) - gtest.Assert(s3.Contains("5"), true) + t.Assert(s3.Contains("1"), false) + t.Assert(s3.Contains("2"), false) + t.Assert(s3.Contains("4"), true) + t.Assert(s3.Contains("5"), true) }) } func TestNewIntSetFrom(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewIntSetFrom([]int{1, 2, 3, 4}) s2 := gset.NewIntSetFrom([]int{5, 6, 7, 8}) - gtest.Assert(s1.Contains(3), true) - gtest.Assert(s1.Contains(5), false) - gtest.Assert(s2.Contains(3), false) - gtest.Assert(s2.Contains(5), true) + t.Assert(s1.Contains(3), true) + t.Assert(s1.Contains(5), false) + t.Assert(s2.Contains(3), false) + t.Assert(s2.Contains(5), true) }) } func TestStrSet_Merge(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSet() s2 := gset.NewStrSet() s1.Add("1").Add("2").Add("3") s2.Add("3").Add("4").Add("5") s3 := s1.Merge(s2) - gtest.Assert(s3.Contains("1"), true) - gtest.Assert(s3.Contains("6"), false) - gtest.Assert(s3.Contains("4"), true) - gtest.Assert(s3.Contains("5"), true) + t.Assert(s3.Contains("1"), true) + t.Assert(s3.Contains("6"), false) + t.Assert(s3.Contains("4"), true) + t.Assert(s3.Contains("5"), true) }) } func TestNewStrSetFrom(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSetFrom([]string{"a", "b", "c"}, true) - gtest.Assert(s1.Contains("b"), true) - gtest.Assert(s1.Contains("d"), false) + t.Assert(s1.Contains("b"), true) + t.Assert(s1.Contains("d"), false) }) } func TestStrSet_Join(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSetFrom([]string{"a", "b", "c"}, true) str1 := s1.Join(",") - gtest.Assert(strings.Contains(str1, "b"), true) - gtest.Assert(strings.Contains(str1, "d"), false) + t.Assert(strings.Contains(str1, "b"), true) + t.Assert(strings.Contains(str1, "d"), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSet() s1.Add("a").Add(`"b"`).Add(`\c`) str1 := s1.Join(",") - gtest.Assert(strings.Contains(str1, `"b"`), true) - gtest.Assert(strings.Contains(str1, `\c`), true) - gtest.Assert(strings.Contains(str1, `a`), true) + t.Assert(strings.Contains(str1, `"b"`), true) + t.Assert(strings.Contains(str1, `\c`), true) + t.Assert(strings.Contains(str1, `a`), true) }) } func TestStrSet_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSetFrom([]string{"a", "b", "c"}, true) str1 := s1.String() - gtest.Assert(strings.Contains(str1, "b"), true) - gtest.Assert(strings.Contains(str1, "d"), false) + t.Assert(strings.Contains(str1, "b"), true) + t.Assert(strings.Contains(str1, "d"), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.New(true) s1.Add("a").Add("a2").Add("b").Add("c") str1 := s1.String() - gtest.Assert(strings.Contains(str1, "["), true) - gtest.Assert(strings.Contains(str1, "]"), true) - gtest.Assert(strings.Contains(str1, "a2"), true) + t.Assert(strings.Contains(str1, "["), true) + t.Assert(strings.Contains(str1, "]"), true) + t.Assert(strings.Contains(str1, "a2"), true) }) } func TestStrSet_Sum(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSetFrom([]string{"a", "b", "c"}, true) s2 := gset.NewIntSetFrom([]int{2, 3, 4}, true) - gtest.Assert(s1.Sum(), 0) - gtest.Assert(s2.Sum(), 9) + t.Assert(s1.Sum(), 0) + t.Assert(s2.Sum(), 9) }) } func TestStrSet_Size(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSetFrom([]string{"a", "b", "c"}, true) - gtest.Assert(s1.Size(), 3) + t.Assert(s1.Size(), 3) }) } func TestStrSet_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := gset.NewStrSetFrom([]string{"a", "b", "c"}, true) s1 = s1.Remove("b") - gtest.Assert(s1.Contains("b"), false) - gtest.Assert(s1.Contains("c"), true) + t.Assert(s1.Contains("b"), false) + t.Assert(s1.Contains("c"), true) }) } func TestStrSet_Pop(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a := []string{"a", "b", "c", "d"} s := gset.NewStrSetFrom(a, true) - gtest.Assert(s.Size(), 4) - gtest.AssertIN(s.Pop(), a) - gtest.Assert(s.Size(), 3) - gtest.AssertIN(s.Pop(), a) - gtest.Assert(s.Size(), 2) + t.Assert(s.Size(), 4) + t.AssertIN(s.Pop(), a) + t.Assert(s.Size(), 3) + t.AssertIN(s.Pop(), a) + t.Assert(s.Size(), 2) }) } func TestStrSet_Pops(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a := []string{"a", "b", "c", "d"} s := gset.NewStrSetFrom(a, true) array := s.Pops(2) - gtest.Assert(len(array), 2) - gtest.Assert(s.Size(), 2) - gtest.AssertIN(array, a) - gtest.Assert(s.Pops(0), nil) - gtest.AssertIN(s.Pops(2), a) - gtest.Assert(s.Size(), 0) + t.Assert(len(array), 2) + t.Assert(s.Size(), 2) + t.AssertIN(array, a) + t.Assert(s.Pops(0), nil) + t.AssertIN(s.Pops(2), a) + t.Assert(s.Size(), 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewStrSet(true) a := []string{"1", "2", "3", "4"} s.Add(a...) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Pops(-2), nil) - gtest.AssertIN(s.Pops(-1), a) + t.Assert(s.Size(), 4) + t.Assert(s.Pops(-2), nil) + t.AssertIN(s.Pops(-1), a) }) } func TestStrSet_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := []string{"a", "b", "d", "c"} a1 := gset.NewStrSetFrom(s1) b1, err1 := json.Marshal(a1) b2, err2 := json.Marshal(s1) - gtest.Assert(len(b1), len(b2)) - gtest.Assert(err1, err2) + t.Assert(len(b1), len(b2)) + t.Assert(err1, err2) a2 := gset.NewStrSet() err2 = json.Unmarshal(b2, &a2) - gtest.Assert(err2, nil) - gtest.Assert(a2.Contains("a"), true) - gtest.Assert(a2.Contains("b"), true) - gtest.Assert(a2.Contains("c"), true) - gtest.Assert(a2.Contains("d"), true) - gtest.Assert(a2.Contains("e"), false) + t.Assert(err2, nil) + t.Assert(a2.Contains("a"), true) + t.Assert(a2.Contains("b"), true) + t.Assert(a2.Contains("c"), true) + t.Assert(a2.Contains("d"), true) + t.Assert(a2.Contains("e"), false) var a3 gset.StrSet err := json.Unmarshal(b2, &a3) - gtest.Assert(err, nil) - gtest.Assert(a3.Contains("a"), true) - gtest.Assert(a3.Contains("b"), true) - gtest.Assert(a3.Contains("c"), true) - gtest.Assert(a3.Contains("d"), true) - gtest.Assert(a3.Contains("e"), false) + t.Assert(err, nil) + t.Assert(a3.Contains("a"), true) + t.Assert(a3.Contains("b"), true) + t.Assert(a3.Contains("c"), true) + t.Assert(a3.Contains("d"), true) + t.Assert(a3.Contains("e"), false) }) } func TestStrSet_AddIfNotExistFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewStrSet(true) s.Add("1") - gtest.Assert(s.Contains("1"), true) - gtest.Assert(s.Contains("2"), false) + t.Assert(s.Contains("1"), true) + t.Assert(s.Contains("2"), false) s.AddIfNotExistFunc("2", func() string { return "3" }) - gtest.Assert(s.Contains("2"), false) - gtest.Assert(s.Contains("3"), true) + t.Assert(s.Contains("2"), false) + t.Assert(s.Contains("3"), true) s.AddIfNotExistFunc("3", func() string { return "4" }) - gtest.Assert(s.Contains("3"), true) - gtest.Assert(s.Contains("4"), false) + t.Assert(s.Contains("3"), true) + t.Assert(s.Contains("4"), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gset.NewStrSet(true) s.Add("1") - gtest.Assert(s.Contains("1"), true) - gtest.Assert(s.Contains("2"), false) + t.Assert(s.Contains("1"), true) + t.Assert(s.Contains("2"), false) s.AddIfNotExistFuncLock("2", func() string { return "3" }) - gtest.Assert(s.Contains("2"), false) - gtest.Assert(s.Contains("3"), true) + t.Assert(s.Contains("2"), false) + t.Assert(s.Contains("3"), true) s.AddIfNotExistFuncLock("3", func() string { return "4" }) - gtest.Assert(s.Contains("3"), true) - gtest.Assert(s.Contains("4"), false) + t.Assert(s.Contains("3"), true) + t.Assert(s.Contains("4"), false) }) } @@ -369,33 +369,33 @@ func TestStrSet_UnmarshalValue(t *testing.T) { Set *gset.StrSet } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "set": []byte(`["1","2","3"]`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Set.Size(), 3) - gtest.Assert(t.Set.Contains("1"), true) - gtest.Assert(t.Set.Contains("2"), true) - gtest.Assert(t.Set.Contains("3"), true) - gtest.Assert(t.Set.Contains("4"), false) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Set.Size(), 3) + t.Assert(t.Set.Contains("1"), true) + t.Assert(t.Set.Contains("2"), true) + t.Assert(t.Set.Contains("3"), true) + t.Assert(t.Set.Contains("4"), false) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "set": g.SliceStr{"1", "2", "3"}, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Set.Size(), 3) - gtest.Assert(t.Set.Contains("1"), true) - gtest.Assert(t.Set.Contains("2"), true) - gtest.Assert(t.Set.Contains("3"), true) - gtest.Assert(t.Set.Contains("4"), false) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Set.Size(), 3) + t.Assert(t.Set.Contains("1"), true) + t.Assert(t.Set.Contains("2"), true) + t.Assert(t.Set.Contains("3"), true) + t.Assert(t.Set.Contains("4"), false) }) } diff --git a/container/gtree/gtree_z_avl_tree_test.go b/container/gtree/gtree_z_avl_tree_test.go index 5d21c216d..2eb3a4224 100644 --- a/container/gtree/gtree_z_avl_tree_test.go +++ b/container/gtree/gtree_z_avl_tree_test.go @@ -17,93 +17,93 @@ import ( ) func Test_AVLTree_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTree(gutil.ComparatorString) m.Set("key1", "val1") - gtest.Assert(m.Keys(), []interface{}{"key1"}) + t.Assert(m.Keys(), []interface{}{"key1"}) - gtest.Assert(m.Get("key1"), "val1") - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("key1"), "val1") + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("key2", "val2"), "val2") - gtest.Assert(m.GetOrSet("key2", "val2"), "val2") - gtest.Assert(m.SetIfNotExist("key2", "val2"), false) + t.Assert(m.GetOrSet("key2", "val2"), "val2") + t.Assert(m.GetOrSet("key2", "val2"), "val2") + t.Assert(m.SetIfNotExist("key2", "val2"), false) - gtest.Assert(m.SetIfNotExist("key3", "val3"), true) + t.Assert(m.SetIfNotExist("key3", "val3"), true) - gtest.Assert(m.Remove("key2"), "val2") - gtest.Assert(m.Contains("key2"), false) + t.Assert(m.Remove("key2"), "val2") + t.Assert(m.Contains("key2"), false) - gtest.AssertIN("key3", m.Keys()) - gtest.AssertIN("key1", m.Keys()) - gtest.AssertIN("val3", m.Values()) - gtest.AssertIN("val1", m.Values()) + t.AssertIN("key3", m.Keys()) + t.AssertIN("key1", m.Keys()) + t.AssertIN("val3", m.Values()) + t.AssertIN("val1", m.Values()) m.Sets(map[interface{}]interface{}{"key3": "val3", "key1": "val1"}) m.Flip() - gtest.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) + t.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) m.Flip(gutil.ComparatorString) - gtest.Assert(m.Map(), map[interface{}]interface{}{"key3": "val3", "key1": "val1"}) + t.Assert(m.Map(), map[interface{}]interface{}{"key3": "val3", "key1": "val1"}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gtree.NewAVLTreeFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) - gtest.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) + t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) }) } func Test_AVLTree_Set_Fun(t *testing.T) { //GetOrSetFunc lock or unlock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTree(gutil.ComparatorString) - gtest.Assert(m.GetOrSetFunc("fun", getValue), 3) - gtest.Assert(m.GetOrSetFunc("fun", getValue), 3) - gtest.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) - gtest.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.GetOrSetFunc("fun", getValue), 3) + t.Assert(m.GetOrSetFunc("fun", getValue), 3) + t.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) + t.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) }) //SetIfNotExistFunc lock or unlock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTree(gutil.ComparatorString) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), true) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), false) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), true) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.SetIfNotExistFunc("fun", getValue), true) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), true) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) }) } func Test_AVLTree_Get_Set_Var(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTree(gutil.ComparatorString) - gtest.AssertEQ(m.SetIfNotExist("key1", "val1"), true) - gtest.AssertEQ(m.SetIfNotExist("key1", "val1"), false) - gtest.AssertEQ(m.GetVarOrSet("key1", "val1"), gvar.New("val1", true)) - gtest.AssertEQ(m.GetVar("key1"), gvar.New("val1", true)) + t.AssertEQ(m.SetIfNotExist("key1", "val1"), true) + t.AssertEQ(m.SetIfNotExist("key1", "val1"), false) + t.AssertEQ(m.GetVarOrSet("key1", "val1"), gvar.New("val1", true)) + t.AssertEQ(m.GetVar("key1"), gvar.New("val1", true)) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTree(gutil.ComparatorString) - gtest.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) }) } func Test_AVLTree_Batch(t *testing.T) { m := gtree.NewAVLTree(gutil.ComparatorString) m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) m.Removes([]interface{}{"key1", 1}) - gtest.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) } func Test_AVLTree_Iterator(t *testing.T) { @@ -115,22 +115,22 @@ func Test_AVLTree_Iterator(t *testing.T) { m := gtree.NewAVLTreeFrom(gutil.ComparatorString, expect) m.Iterator(func(k interface{}, v interface{}) bool { - gtest.Assert(k, keys[index]) + t.Assert(k, keys[index]) index++ - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) m.IteratorDesc(func(k interface{}, v interface{}) bool { index-- - gtest.Assert(k, keys[index]) - gtest.Assert(expect[k], v) + t.Assert(k, keys[index]) + t.Assert(expect[k], v) return true }) m.Print() // 断言返回值对遍历控制 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := 0 j := 0 m.Iterator(func(k interface{}, v interface{}) bool { @@ -141,11 +141,11 @@ func Test_AVLTree_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, keyLen) - gtest.Assert(j, 1) + t.Assert(i, keyLen) + t.Assert(j, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := 0 j := 0 m.IteratorDesc(func(k interface{}, v interface{}) bool { @@ -156,8 +156,8 @@ func Test_AVLTree_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, keyLen) - gtest.Assert(j, 1) + t.Assert(i, keyLen) + t.Assert(j, 1) }) } @@ -169,27 +169,27 @@ func Test_AVLTree_IteratorFrom(t *testing.T) { } tree := gtree.NewAVLTreeFrom(gutil.ComparatorInt, m) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { n := 5 tree.IteratorFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(n, key) - gtest.Assert(n*10, value) + t.Assert(n, key) + t.Assert(n*10, value) n++ return true }) i := 5 tree.IteratorAscFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(i, key) - gtest.Assert(i*10, value) + t.Assert(i, key) + t.Assert(i*10, value) i++ return true }) j := 5 tree.IteratorDescFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(j, key) - gtest.Assert(j*10, value) + t.Assert(j, key) + t.Assert(j*10, value) j-- return true }) @@ -202,26 +202,26 @@ func Test_AVLTree_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove("key1") //修改clone map,原 map 不影响 - gtest.AssertIN("key1", m.Keys()) + t.AssertIN("key1", m.Keys()) } func Test_AVLTree_LRNode(t *testing.T) { expect := map[interface{}]interface{}{"key4": "val4", "key1": "val1", "key2": "val2", "key3": "val3"} //safe - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTreeFrom(gutil.ComparatorString, expect) - gtest.Assert(m.Left().Key, "key1") - gtest.Assert(m.Right().Key, "key4") + t.Assert(m.Left().Key, "key1") + t.Assert(m.Right().Key, "key4") }) //unsafe - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTreeFrom(gutil.ComparatorString, expect, true) - gtest.Assert(m.Left().Key, "key1") - gtest.Assert(m.Right().Key, "key4") + t.Assert(m.Left().Key, "key1") + t.Assert(m.Right().Key, "key4") }) } @@ -237,34 +237,34 @@ func Test_AVLTree_CeilingFloor(t *testing.T) { 8: "val8", 4: "val4"} //found and eq - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTreeFrom(gutil.ComparatorInt, expect) c, cf := m.Ceiling(8) - gtest.Assert(cf, true) - gtest.Assert(c.Value, "val8") + t.Assert(cf, true) + t.Assert(c.Value, "val8") f, ff := m.Floor(20) - gtest.Assert(ff, true) - gtest.Assert(f.Value, "val20") + t.Assert(ff, true) + t.Assert(f.Value, "val20") }) //found and neq - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTreeFrom(gutil.ComparatorInt, expect) c, cf := m.Ceiling(9) - gtest.Assert(cf, true) - gtest.Assert(c.Value, "val10") + t.Assert(cf, true) + t.Assert(c.Value, "val10") f, ff := m.Floor(5) - gtest.Assert(ff, true) - gtest.Assert(f.Value, "val4") + t.Assert(ff, true) + t.Assert(f.Value, "val4") }) //nofound - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewAVLTreeFrom(gutil.ComparatorInt, expect) c, cf := m.Ceiling(21) - gtest.Assert(cf, false) - gtest.Assert(c, nil) + t.Assert(cf, false) + t.Assert(c, nil) f, ff := m.Floor(-1) - gtest.Assert(ff, false) - gtest.Assert(f, nil) + t.Assert(ff, false) + t.Assert(f, nil) }) } @@ -274,11 +274,11 @@ func Test_AVLTree_Remove(t *testing.T) { m.Set(i, fmt.Sprintf("val%d", i)) } expect := m.Map() - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for k, v := range expect { m1 := m.Clone() - gtest.Assert(m1.Remove(k), v) - gtest.Assert(m1.Remove(k), nil) + t.Assert(m1.Remove(k), v) + t.Assert(m1.Remove(k), nil) } }) } diff --git a/container/gtree/gtree_z_b_tree_test.go b/container/gtree/gtree_z_b_tree_test.go index c20839760..76197292a 100644 --- a/container/gtree/gtree_z_b_tree_test.go +++ b/container/gtree/gtree_z_b_tree_test.go @@ -17,88 +17,88 @@ import ( ) func Test_BTree_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewBTree(3, gutil.ComparatorString) m.Set("key1", "val1") - gtest.Assert(m.Height(), 1) + t.Assert(m.Height(), 1) - gtest.Assert(m.Keys(), []interface{}{"key1"}) + t.Assert(m.Keys(), []interface{}{"key1"}) - gtest.Assert(m.Get("key1"), "val1") - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("key1"), "val1") + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("key2", "val2"), "val2") - gtest.Assert(m.SetIfNotExist("key2", "val2"), false) + t.Assert(m.GetOrSet("key2", "val2"), "val2") + t.Assert(m.SetIfNotExist("key2", "val2"), false) - gtest.Assert(m.SetIfNotExist("key3", "val3"), true) + t.Assert(m.SetIfNotExist("key3", "val3"), true) - gtest.Assert(m.Remove("key2"), "val2") - gtest.Assert(m.Contains("key2"), false) + t.Assert(m.Remove("key2"), "val2") + t.Assert(m.Contains("key2"), false) - gtest.AssertIN("key3", m.Keys()) - gtest.AssertIN("key1", m.Keys()) - gtest.AssertIN("val3", m.Values()) - gtest.AssertIN("val1", m.Values()) + t.AssertIN("key3", m.Keys()) + t.AssertIN("key1", m.Keys()) + t.AssertIN("val3", m.Values()) + t.AssertIN("val1", m.Values()) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gtree.NewBTreeFrom(3, gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) - gtest.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) + t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) }) } func Test_BTree_Set_Fun(t *testing.T) { //GetOrSetFunc lock or unlock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewBTree(3, gutil.ComparatorString) - gtest.Assert(m.GetOrSetFunc("fun", getValue), 3) - gtest.Assert(m.GetOrSetFunc("fun", getValue), 3) - gtest.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) - gtest.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.GetOrSetFunc("fun", getValue), 3) + t.Assert(m.GetOrSetFunc("fun", getValue), 3) + t.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) + t.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) }) //SetIfNotExistFunc lock or unlock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewBTree(3, gutil.ComparatorString) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), true) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), false) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), true) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.SetIfNotExistFunc("fun", getValue), true) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), true) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) }) } func Test_BTree_Get_Set_Var(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewBTree(3, gutil.ComparatorString) - gtest.AssertEQ(m.SetIfNotExist("key1", "val1"), true) - gtest.AssertEQ(m.SetIfNotExist("key1", "val1"), false) - gtest.AssertEQ(m.GetVarOrSet("key1", "val1"), gvar.New("val1", true)) - gtest.AssertEQ(m.GetVar("key1"), gvar.New("val1", true)) + t.AssertEQ(m.SetIfNotExist("key1", "val1"), true) + t.AssertEQ(m.SetIfNotExist("key1", "val1"), false) + t.AssertEQ(m.GetVarOrSet("key1", "val1"), gvar.New("val1", true)) + t.AssertEQ(m.GetVar("key1"), gvar.New("val1", true)) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewBTree(3, gutil.ComparatorString) - gtest.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) }) } func Test_BTree_Batch(t *testing.T) { m := gtree.NewBTree(3, gutil.ComparatorString) m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) m.Removes([]interface{}{"key1", 1}) - gtest.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) } func Test_BTree_Iterator(t *testing.T) { @@ -110,22 +110,22 @@ func Test_BTree_Iterator(t *testing.T) { m := gtree.NewBTreeFrom(3, gutil.ComparatorString, expect) m.Iterator(func(k interface{}, v interface{}) bool { - gtest.Assert(k, keys[index]) + t.Assert(k, keys[index]) index++ - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) m.IteratorDesc(func(k interface{}, v interface{}) bool { index-- - gtest.Assert(k, keys[index]) - gtest.Assert(expect[k], v) + t.Assert(k, keys[index]) + t.Assert(expect[k], v) return true }) m.Print() // 断言返回值对遍历控制 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := 0 j := 0 m.Iterator(func(k interface{}, v interface{}) bool { @@ -136,11 +136,11 @@ func Test_BTree_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, keyLen) - gtest.Assert(j, 1) + t.Assert(i, keyLen) + t.Assert(j, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := 0 j := 0 m.IteratorDesc(func(k interface{}, v interface{}) bool { @@ -151,8 +151,8 @@ func Test_BTree_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, keyLen) - gtest.Assert(j, 1) + t.Assert(i, keyLen) + t.Assert(j, 1) }) } @@ -163,27 +163,27 @@ func Test_BTree_IteratorFrom(t *testing.T) { } tree := gtree.NewBTreeFrom(3, gutil.ComparatorInt, m) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { n := 5 tree.IteratorFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(n, key) - gtest.Assert(n*10, value) + t.Assert(n, key) + t.Assert(n*10, value) n++ return true }) i := 5 tree.IteratorAscFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(i, key) - gtest.Assert(i*10, value) + t.Assert(i, key) + t.Assert(i*10, value) i++ return true }) j := 5 tree.IteratorDescFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(j, key) - gtest.Assert(j*10, value) + t.Assert(j, key) + t.Assert(j*10, value) j-- return true }) @@ -196,26 +196,26 @@ func Test_BTree_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove("key1") //修改clone map,原 map 不影响 - gtest.AssertIN("key1", m.Keys()) + t.AssertIN("key1", m.Keys()) } func Test_BTree_LRNode(t *testing.T) { expect := map[interface{}]interface{}{"key4": "val4", "key1": "val1", "key2": "val2", "key3": "val3"} //safe - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewBTreeFrom(3, gutil.ComparatorString, expect) - gtest.Assert(m.Left().Key, "key1") - gtest.Assert(m.Right().Key, "key4") + t.Assert(m.Left().Key, "key1") + t.Assert(m.Right().Key, "key4") }) //unsafe - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewBTreeFrom(3, gutil.ComparatorString, expect, true) - gtest.Assert(m.Left().Key, "key1") - gtest.Assert(m.Right().Key, "key4") + t.Assert(m.Left().Key, "key1") + t.Assert(m.Right().Key, "key4") }) } @@ -225,11 +225,11 @@ func Test_BTree_Remove(t *testing.T) { m.Set(i, fmt.Sprintf("val%d", i)) } expect := m.Map() - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for k, v := range expect { m1 := m.Clone() - gtest.Assert(m1.Remove(k), v) - gtest.Assert(m1.Remove(k), nil) + t.Assert(m1.Remove(k), v) + t.Assert(m1.Remove(k), nil) } }) } diff --git a/container/gtree/gtree_z_redblack_tree_test.go b/container/gtree/gtree_z_redblack_tree_test.go index 17a72b947..dbb7bc50d 100644 --- a/container/gtree/gtree_z_redblack_tree_test.go +++ b/container/gtree/gtree_z_redblack_tree_test.go @@ -21,94 +21,94 @@ func getValue() interface{} { } func Test_RedBlackTree_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTree(gutil.ComparatorString) m.Set("key1", "val1") - gtest.Assert(m.Keys(), []interface{}{"key1"}) + t.Assert(m.Keys(), []interface{}{"key1"}) - gtest.Assert(m.Get("key1"), "val1") - gtest.Assert(m.Size(), 1) - gtest.Assert(m.IsEmpty(), false) + t.Assert(m.Get("key1"), "val1") + t.Assert(m.Size(), 1) + t.Assert(m.IsEmpty(), false) - gtest.Assert(m.GetOrSet("key2", "val2"), "val2") - gtest.Assert(m.GetOrSet("key2", "val2"), "val2") - gtest.Assert(m.SetIfNotExist("key2", "val2"), false) + t.Assert(m.GetOrSet("key2", "val2"), "val2") + t.Assert(m.GetOrSet("key2", "val2"), "val2") + t.Assert(m.SetIfNotExist("key2", "val2"), false) - gtest.Assert(m.SetIfNotExist("key3", "val3"), true) + t.Assert(m.SetIfNotExist("key3", "val3"), true) - gtest.Assert(m.Remove("key2"), "val2") - gtest.Assert(m.Contains("key2"), false) + t.Assert(m.Remove("key2"), "val2") + t.Assert(m.Contains("key2"), false) - gtest.AssertIN("key3", m.Keys()) - gtest.AssertIN("key1", m.Keys()) - gtest.AssertIN("val3", m.Values()) - gtest.AssertIN("val1", m.Values()) + t.AssertIN("key3", m.Keys()) + t.AssertIN("key1", m.Keys()) + t.AssertIN("val3", m.Values()) + t.AssertIN("val1", m.Values()) m.Sets(map[interface{}]interface{}{"key3": "val3", "key1": "val1"}) m.Flip() - gtest.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) + t.Assert(m.Map(), map[interface{}]interface{}{"val3": "key3", "val1": "key1"}) m.Flip(gutil.ComparatorString) - gtest.Assert(m.Map(), map[interface{}]interface{}{"key3": "val3", "key1": "val1"}) + t.Assert(m.Map(), map[interface{}]interface{}{"key3": "val3", "key1": "val1"}) m.Clear() - gtest.Assert(m.Size(), 0) - gtest.Assert(m.IsEmpty(), true) + t.Assert(m.Size(), 0) + t.Assert(m.IsEmpty(), true) m2 := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) - gtest.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) + t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) }) } func Test_RedBlackTree_Set_Fun(t *testing.T) { //GetOrSetFunc lock or unlock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTree(gutil.ComparatorString) - gtest.Assert(m.GetOrSetFunc("fun", getValue), 3) - gtest.Assert(m.GetOrSetFunc("fun", getValue), 3) - gtest.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) - gtest.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.GetOrSetFunc("fun", getValue), 3) + t.Assert(m.GetOrSetFunc("fun", getValue), 3) + t.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) + t.Assert(m.GetOrSetFuncLock("funlock", getValue), 3) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) }) //SetIfNotExistFunc lock or unlock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTree(gutil.ComparatorString) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), true) - gtest.Assert(m.SetIfNotExistFunc("fun", getValue), false) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), true) - gtest.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) - gtest.Assert(m.Get("funlock"), 3) - gtest.Assert(m.Get("fun"), 3) + t.Assert(m.SetIfNotExistFunc("fun", getValue), true) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), true) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) }) } func Test_RedBlackTree_Get_Set_Var(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTree(gutil.ComparatorString) - gtest.AssertEQ(m.SetIfNotExist("key1", "val1"), true) - gtest.AssertEQ(m.SetIfNotExist("key1", "val1"), false) - gtest.AssertEQ(m.GetVarOrSet("key1", "val1"), gvar.New("val1", true)) - gtest.AssertEQ(m.GetVar("key1"), gvar.New("val1", true)) + t.AssertEQ(m.SetIfNotExist("key1", "val1"), true) + t.AssertEQ(m.SetIfNotExist("key1", "val1"), false) + t.AssertEQ(m.GetVarOrSet("key1", "val1"), gvar.New("val1", true)) + t.AssertEQ(m.GetVar("key1"), gvar.New("val1", true)) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTree(gutil.ComparatorString) - gtest.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) - gtest.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFunc("fun", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) + t.AssertEQ(m.GetVarOrSetFuncLock("funlock", getValue), gvar.New(3, true)) }) } func Test_RedBlackTree_Batch(t *testing.T) { m := gtree.NewRedBlackTree(gutil.ComparatorString) m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - gtest.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) m.Removes([]interface{}{"key1", 1}) - gtest.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) } func Test_RedBlackTree_Iterator(t *testing.T) { @@ -120,22 +120,22 @@ func Test_RedBlackTree_Iterator(t *testing.T) { m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, expect) m.Iterator(func(k interface{}, v interface{}) bool { - gtest.Assert(k, keys[index]) + t.Assert(k, keys[index]) index++ - gtest.Assert(expect[k], v) + t.Assert(expect[k], v) return true }) m.IteratorDesc(func(k interface{}, v interface{}) bool { index-- - gtest.Assert(k, keys[index]) - gtest.Assert(expect[k], v) + t.Assert(k, keys[index]) + t.Assert(expect[k], v) return true }) m.Print() // 断言返回值对遍历控制 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := 0 j := 0 m.Iterator(func(k interface{}, v interface{}) bool { @@ -146,11 +146,11 @@ func Test_RedBlackTree_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, keyLen) - gtest.Assert(j, 1) + t.Assert(i, keyLen) + t.Assert(j, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := 0 j := 0 m.IteratorDesc(func(k interface{}, v interface{}) bool { @@ -161,8 +161,8 @@ func Test_RedBlackTree_Iterator(t *testing.T) { j++ return false }) - gtest.Assert(i, keyLen) - gtest.Assert(j, 1) + t.Assert(i, keyLen) + t.Assert(j, 1) }) } @@ -173,27 +173,27 @@ func Test_RedBlackTree_IteratorFrom(t *testing.T) { } tree := gtree.NewRedBlackTreeFrom(gutil.ComparatorInt, m) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { n := 5 tree.IteratorFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(n, key) - gtest.Assert(n*10, value) + t.Assert(n, key) + t.Assert(n*10, value) n++ return true }) i := 5 tree.IteratorAscFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(i, key) - gtest.Assert(i*10, value) + t.Assert(i, key) + t.Assert(i*10, value) i++ return true }) j := 5 tree.IteratorDescFrom(5, true, func(key, value interface{}) bool { - gtest.Assert(j, key) - gtest.Assert(j*10, value) + t.Assert(j, key) + t.Assert(j*10, value) j-- return true }) @@ -206,26 +206,26 @@ func Test_RedBlackTree_Clone(t *testing.T) { m_clone := m.Clone() m.Remove(1) //修改原 map,clone 后的 map 不影响 - gtest.AssertIN(1, m_clone.Keys()) + t.AssertIN(1, m_clone.Keys()) m_clone.Remove("key1") //修改clone map,原 map 不影响 - gtest.AssertIN("key1", m.Keys()) + t.AssertIN("key1", m.Keys()) } func Test_RedBlackTree_LRNode(t *testing.T) { expect := map[interface{}]interface{}{"key4": "val4", "key1": "val1", "key2": "val2", "key3": "val3"} //safe - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, expect) - gtest.Assert(m.Left().Key, "key1") - gtest.Assert(m.Right().Key, "key4") + t.Assert(m.Left().Key, "key1") + t.Assert(m.Right().Key, "key4") }) //unsafe - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, expect, true) - gtest.Assert(m.Left().Key, "key1") - gtest.Assert(m.Right().Key, "key4") + t.Assert(m.Left().Key, "key1") + t.Assert(m.Right().Key, "key4") }) } @@ -241,34 +241,34 @@ func Test_RedBlackTree_CeilingFloor(t *testing.T) { 8: "val8", 4: "val4"} //found and eq - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTreeFrom(gutil.ComparatorInt, expect) c, cf := m.Ceiling(8) - gtest.Assert(cf, true) - gtest.Assert(c.Value, "val8") + t.Assert(cf, true) + t.Assert(c.Value, "val8") f, ff := m.Floor(20) - gtest.Assert(ff, true) - gtest.Assert(f.Value, "val20") + t.Assert(ff, true) + t.Assert(f.Value, "val20") }) //found and neq - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTreeFrom(gutil.ComparatorInt, expect) c, cf := m.Ceiling(9) - gtest.Assert(cf, true) - gtest.Assert(c.Value, "val10") + t.Assert(cf, true) + t.Assert(c.Value, "val10") f, ff := m.Floor(5) - gtest.Assert(ff, true) - gtest.Assert(f.Value, "val4") + t.Assert(ff, true) + t.Assert(f.Value, "val4") }) //nofound - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gtree.NewRedBlackTreeFrom(gutil.ComparatorInt, expect) c, cf := m.Ceiling(21) - gtest.Assert(cf, false) - gtest.Assert(c, nil) + t.Assert(cf, false) + t.Assert(c, nil) f, ff := m.Floor(-1) - gtest.Assert(ff, false) - gtest.Assert(f, nil) + t.Assert(ff, false) + t.Assert(f, nil) }) } @@ -278,11 +278,11 @@ func Test_RedBlackTree_Remove(t *testing.T) { m.Set(i, fmt.Sprintf("val%d", i)) } expect := m.Map() - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for k, v := range expect { m1 := m.Clone() - gtest.Assert(m1.Remove(k), v) - gtest.Assert(m1.Remove(k), nil) + t.Assert(m1.Remove(k), v) + t.Assert(m1.Remove(k), nil) } }) } diff --git a/container/gtype/z_unit_bool_test.go b/container/gtype/z_unit_bool_test.go index 2538a2e7e..1ea796791 100644 --- a/container/gtype/z_unit_bool_test.go +++ b/container/gtype/z_unit_bool_test.go @@ -16,84 +16,84 @@ import ( ) func Test_Bool(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewBool(true) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(false), true) - gtest.AssertEQ(iClone.Val(), false) + t.AssertEQ(iClone.Set(false), true) + t.AssertEQ(iClone.Val(), false) i1 := gtype.NewBool(false) iClone1 := i1.Clone() - gtest.AssertEQ(iClone1.Set(true), false) - gtest.AssertEQ(iClone1.Val(), true) + t.AssertEQ(iClone1.Set(true), false) + t.AssertEQ(iClone1.Val(), true) //空参测试 i2 := gtype.NewBool() - gtest.AssertEQ(i2.Val(), false) + t.AssertEQ(i2.Val(), false) }) } func Test_Bool_JSON(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewBool(true) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewBool(false) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var err error i := gtype.NewBool() err = json.Unmarshal([]byte("true"), &i) - gtest.Assert(err, nil) - gtest.Assert(i.Val(), true) + t.Assert(err, nil) + t.Assert(i.Val(), true) err = json.Unmarshal([]byte("false"), &i) - gtest.Assert(err, nil) - gtest.Assert(i.Val(), false) + t.Assert(err, nil) + t.Assert(i.Val(), false) err = json.Unmarshal([]byte("1"), &i) - gtest.Assert(err, nil) - gtest.Assert(i.Val(), true) + t.Assert(err, nil) + t.Assert(i.Val(), true) err = json.Unmarshal([]byte("0"), &i) - gtest.Assert(err, nil) - gtest.Assert(i.Val(), false) + t.Assert(err, nil) + t.Assert(i.Val(), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewBool(true) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewBool() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), i.Val()) + t.Assert(err, nil) + t.Assert(i2.Val(), i.Val()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewBool(false) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewBool() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), i.Val()) + t.Assert(err, nil) + t.Assert(i2.Val(), i.Val()) }) } @@ -102,24 +102,24 @@ func Test_Bool_UnmarshalValue(t *testing.T) { Name string Var *gtype.Bool } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "true", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), true) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), true) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "false", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), false) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), false) }) } diff --git a/container/gtype/z_unit_byte_test.go b/container/gtype/z_unit_byte_test.go index 55e7c92c5..f6dd88505 100644 --- a/container/gtype/z_unit_byte_test.go +++ b/container/gtype/z_unit_byte_test.go @@ -17,13 +17,13 @@ import ( ) func Test_Byte(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 127 i := gtype.NewByte(byte(0)) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(byte(1)), byte(0)) - gtest.AssertEQ(iClone.Val(), byte(1)) + t.AssertEQ(iClone.Set(byte(1)), byte(0)) + t.AssertEQ(iClone.Val(), byte(1)) for index := 0; index < addTimes; index++ { wg.Add(1) go func() { @@ -32,30 +32,30 @@ func Test_Byte(t *testing.T) { }() } wg.Wait() - gtest.AssertEQ(byte(addTimes), i.Val()) + t.AssertEQ(byte(addTimes), i.Val()) //空参测试 i1 := gtype.NewByte() - gtest.AssertEQ(i1.Val(), byte(0)) + t.AssertEQ(i1.Val(), byte(0)) }) } func Test_Byte_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewByte(49) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var err error i := gtype.NewByte() err = json.Unmarshal([]byte("49"), &i) - gtest.Assert(err, nil) - gtest.Assert(i.Val(), "49") + t.Assert(err, nil) + t.Assert(i.Val(), "49") }) } @@ -64,14 +64,14 @@ func Test_Byte_UnmarshalValue(t *testing.T) { Name string Var *gtype.Byte } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "2", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "2") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "2") }) } diff --git a/container/gtype/z_unit_bytes_test.go b/container/gtype/z_unit_bytes_test.go index 71f0690c0..1100800b7 100644 --- a/container/gtype/z_unit_bytes_test.go +++ b/container/gtype/z_unit_bytes_test.go @@ -16,32 +16,32 @@ import ( ) func Test_Bytes(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewBytes([]byte("abc")) iClone := i.Clone() - gtest.AssertEQ(iClone.Set([]byte("123")), []byte("abc")) - gtest.AssertEQ(iClone.Val(), []byte("123")) + t.AssertEQ(iClone.Set([]byte("123")), []byte("abc")) + t.AssertEQ(iClone.Val(), []byte("123")) //空参测试 i1 := gtype.NewBytes() - gtest.AssertEQ(i1.Val(), nil) + t.AssertEQ(i1.Val(), nil) }) } func Test_Bytes_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { b := []byte("i love gf") i := gtype.NewBytes(b) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewBytes() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), b) + t.Assert(err, nil) + t.Assert(i2.Val(), b) }) } @@ -50,14 +50,14 @@ func Test_Bytes_UnmarshalValue(t *testing.T) { Name string Var *gtype.Bytes } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_float32_test.go b/container/gtype/z_unit_float32_test.go index 5383cd7ff..82c866ccd 100644 --- a/container/gtype/z_unit_float32_test.go +++ b/container/gtype/z_unit_float32_test.go @@ -16,33 +16,33 @@ import ( ) func Test_Float32(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewFloat32(0) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(0.1), float32(0)) - gtest.AssertEQ(iClone.Val(), float32(0.1)) + t.AssertEQ(iClone.Set(0.1), float32(0)) + t.AssertEQ(iClone.Val(), float32(0.1)) //空参测试 i1 := gtype.NewFloat32() - gtest.AssertEQ(i1.Val(), float32(0)) + t.AssertEQ(i1.Val(), float32(0)) }) } func Test_Float32_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := float32(math.MaxFloat32) i := gtype.NewFloat32(v) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewFloat32() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), v) + t.Assert(err, nil) + t.Assert(i2.Val(), v) }) } @@ -51,14 +51,14 @@ func Test_Float32_UnmarshalValue(t *testing.T) { Name string Var *gtype.Float32 } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123.456", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123.456") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123.456") }) } diff --git a/container/gtype/z_unit_float64_test.go b/container/gtype/z_unit_float64_test.go index 480c01df3..deec6de15 100644 --- a/container/gtype/z_unit_float64_test.go +++ b/container/gtype/z_unit_float64_test.go @@ -16,31 +16,31 @@ import ( ) func Test_Float64(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewFloat64(0) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(0.1), float64(0)) - gtest.AssertEQ(iClone.Val(), float64(0.1)) + t.AssertEQ(iClone.Set(0.1), float64(0)) + t.AssertEQ(iClone.Val(), float64(0.1)) //空参测试 i1 := gtype.NewFloat64() - gtest.AssertEQ(i1.Val(), float64(0)) + t.AssertEQ(i1.Val(), float64(0)) }) } func Test_Float64_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := math.MaxFloat64 i := gtype.NewFloat64(v) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewFloat64() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), v) + t.Assert(err, nil) + t.Assert(i2.Val(), v) }) } @@ -49,14 +49,14 @@ func Test_Float64_UnmarshalValue(t *testing.T) { Name string Var *gtype.Float64 } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123.456", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123.456") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123.456") }) } diff --git a/container/gtype/z_unit_int32_test.go b/container/gtype/z_unit_int32_test.go index 4870da7a2..3fba55d04 100644 --- a/container/gtype/z_unit_int32_test.go +++ b/container/gtype/z_unit_int32_test.go @@ -17,13 +17,13 @@ import ( ) func Test_Int32(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 i := gtype.NewInt32(0) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(1), int32(0)) - gtest.AssertEQ(iClone.Val(), int32(1)) + t.AssertEQ(iClone.Set(1), int32(0)) + t.AssertEQ(iClone.Val(), int32(1)) for index := 0; index < addTimes; index++ { wg.Add(1) go func() { @@ -32,28 +32,28 @@ func Test_Int32(t *testing.T) { }() } wg.Wait() - gtest.AssertEQ(int32(addTimes), i.Val()) + t.AssertEQ(int32(addTimes), i.Val()) //空参测试 i1 := gtype.NewInt32() - gtest.AssertEQ(i1.Val(), int32(0)) + t.AssertEQ(i1.Val(), int32(0)) }) } func Test_Int32_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := int32(math.MaxInt32) i := gtype.NewInt32(v) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewInt32() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), v) + t.Assert(err, nil) + t.Assert(i2.Val(), v) }) } @@ -62,14 +62,14 @@ func Test_Int32_UnmarshalValue(t *testing.T) { Name string Var *gtype.Int32 } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_int64_test.go b/container/gtype/z_unit_int64_test.go index 059f4ca2c..5fc1e8560 100644 --- a/container/gtype/z_unit_int64_test.go +++ b/container/gtype/z_unit_int64_test.go @@ -17,13 +17,13 @@ import ( ) func Test_Int64(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 i := gtype.NewInt64(0) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(1), int64(0)) - gtest.AssertEQ(iClone.Val(), int64(1)) + t.AssertEQ(iClone.Set(1), int64(0)) + t.AssertEQ(iClone.Val(), int64(1)) for index := 0; index < addTimes; index++ { wg.Add(1) go func() { @@ -32,27 +32,27 @@ func Test_Int64(t *testing.T) { }() } wg.Wait() - gtest.AssertEQ(int64(addTimes), i.Val()) + t.AssertEQ(int64(addTimes), i.Val()) //空参测试 i1 := gtype.NewInt64() - gtest.AssertEQ(i1.Val(), int64(0)) + t.AssertEQ(i1.Val(), int64(0)) }) } func Test_Int64_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewInt64(math.MaxInt64) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewInt64() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), i) + t.Assert(err, nil) + t.Assert(i2.Val(), i) }) } @@ -61,14 +61,14 @@ func Test_Int64_UnmarshalValue(t *testing.T) { Name string Var *gtype.Int64 } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_int_test.go b/container/gtype/z_unit_int_test.go index bd13b8b60..d56322464 100644 --- a/container/gtype/z_unit_int_test.go +++ b/container/gtype/z_unit_int_test.go @@ -16,13 +16,13 @@ import ( ) func Test_Int(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 i := gtype.NewInt(0) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(1), 0) - gtest.AssertEQ(iClone.Val(), 1) + t.AssertEQ(iClone.Set(1), 0) + t.AssertEQ(iClone.Val(), 1) for index := 0; index < addTimes; index++ { wg.Add(1) go func() { @@ -31,28 +31,28 @@ func Test_Int(t *testing.T) { }() } wg.Wait() - gtest.AssertEQ(addTimes, i.Val()) + t.AssertEQ(addTimes, i.Val()) //空参测试 i1 := gtype.NewInt() - gtest.AssertEQ(i1.Val(), 0) + t.AssertEQ(i1.Val(), 0) }) } func Test_Int_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := 666 i := gtype.NewInt(v) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewInt() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), v) + t.Assert(err, nil) + t.Assert(i2.Val(), v) }) } @@ -61,14 +61,14 @@ func Test_Int_UnmarshalValue(t *testing.T) { Name string Var *gtype.Int } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_interface_test.go b/container/gtype/z_unit_interface_test.go index 1f9af3bfb..2f39de61f 100644 --- a/container/gtype/z_unit_interface_test.go +++ b/container/gtype/z_unit_interface_test.go @@ -15,34 +15,34 @@ import ( ) func Test_Interface(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { t := Temp{Name: "gf", Age: 18} t1 := Temp{Name: "gf", Age: 19} i := gtype.New(t) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(t1), t) - gtest.AssertEQ(iClone.Val().(Temp), t1) + t.AssertEQ(iClone.Set(t1), t) + t.AssertEQ(iClone.Val().(Temp), t1) //空参测试 i1 := gtype.New() - gtest.AssertEQ(i1.Val(), nil) + t.AssertEQ(i1.Val(), nil) }) } func Test_Interface_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "i love gf" i := gtype.New(s) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.New() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), s) + t.Assert(err, nil) + t.Assert(i2.Val(), s) }) } @@ -51,14 +51,14 @@ func Test_Interface_UnmarshalValue(t *testing.T) { Name string Var *gtype.Interface } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_string_test.go b/container/gtype/z_unit_string_test.go index 7d010c64c..a2cc47b50 100644 --- a/container/gtype/z_unit_string_test.go +++ b/container/gtype/z_unit_string_test.go @@ -15,32 +15,32 @@ import ( ) func Test_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewString("abc") iClone := i.Clone() - gtest.AssertEQ(iClone.Set("123"), "abc") - gtest.AssertEQ(iClone.Val(), "123") + t.AssertEQ(iClone.Set("123"), "abc") + t.AssertEQ(iClone.Val(), "123") //空参测试 i1 := gtype.NewString() - gtest.AssertEQ(i1.Val(), "") + t.AssertEQ(i1.Val(), "") }) } func Test_String_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "i love gf" i1 := gtype.NewString(s) b1, err1 := json.Marshal(i1) b2, err2 := json.Marshal(i1.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewString() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), s) + t.Assert(err, nil) + t.Assert(i2.Val(), s) }) } @@ -49,14 +49,14 @@ func Test_String_UnmarshalValue(t *testing.T) { Name string Var *gtype.String } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_uint32_test.go b/container/gtype/z_unit_uint32_test.go index a58cc5656..177e2c0dd 100644 --- a/container/gtype/z_unit_uint32_test.go +++ b/container/gtype/z_unit_uint32_test.go @@ -17,13 +17,13 @@ import ( ) func Test_Uint32(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 i := gtype.NewUint32(0) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(1), uint32(0)) - gtest.AssertEQ(iClone.Val(), uint32(1)) + t.AssertEQ(iClone.Set(1), uint32(0)) + t.AssertEQ(iClone.Val(), uint32(1)) for index := 0; index < addTimes; index++ { wg.Add(1) go func() { @@ -32,27 +32,27 @@ func Test_Uint32(t *testing.T) { }() } wg.Wait() - gtest.AssertEQ(uint32(addTimes), i.Val()) + t.AssertEQ(uint32(addTimes), i.Val()) //空参测试 i1 := gtype.NewUint32() - gtest.AssertEQ(i1.Val(), uint32(0)) + t.AssertEQ(i1.Val(), uint32(0)) }) } func Test_Uint32_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewUint32(math.MaxUint32) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewUint32() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), i) + t.Assert(err, nil) + t.Assert(i2.Val(), i) }) } @@ -61,14 +61,14 @@ func Test_Uint32_UnmarshalValue(t *testing.T) { Name string Var *gtype.Uint32 } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_uint64_test.go b/container/gtype/z_unit_uint64_test.go index 987871a5d..dee3c861b 100644 --- a/container/gtype/z_unit_uint64_test.go +++ b/container/gtype/z_unit_uint64_test.go @@ -23,13 +23,13 @@ type Temp struct { } func Test_Uint64(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 i := gtype.NewUint64(0) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(1), uint64(0)) - gtest.AssertEQ(iClone.Val(), uint64(1)) + t.AssertEQ(iClone.Set(1), uint64(0)) + t.AssertEQ(iClone.Val(), uint64(1)) for index := 0; index < addTimes; index++ { wg.Add(1) go func() { @@ -38,26 +38,26 @@ func Test_Uint64(t *testing.T) { }() } wg.Wait() - gtest.AssertEQ(uint64(addTimes), i.Val()) + t.AssertEQ(uint64(addTimes), i.Val()) //空参测试 i1 := gtype.NewUint64() - gtest.AssertEQ(i1.Val(), uint64(0)) + t.AssertEQ(i1.Val(), uint64(0)) }) } func Test_Uint64_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewUint64(math.MaxUint64) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewUint64() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), i) + t.Assert(err, nil) + t.Assert(i2.Val(), i) }) } @@ -66,14 +66,14 @@ func Test_Uint64_UnmarshalValue(t *testing.T) { Name string Var *gtype.Uint64 } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_uint_test.go b/container/gtype/z_unit_uint_test.go index cffb4dae6..7f8d42083 100644 --- a/container/gtype/z_unit_uint_test.go +++ b/container/gtype/z_unit_uint_test.go @@ -16,13 +16,13 @@ import ( ) func Test_Uint(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var wg sync.WaitGroup addTimes := 1000 i := gtype.NewUint(0) iClone := i.Clone() - gtest.AssertEQ(iClone.Set(1), uint(0)) - gtest.AssertEQ(iClone.Val(), uint(1)) + t.AssertEQ(iClone.Set(1), uint(0)) + t.AssertEQ(iClone.Val(), uint(1)) for index := 0; index < addTimes; index++ { wg.Add(1) go func() { @@ -31,27 +31,27 @@ func Test_Uint(t *testing.T) { }() } wg.Wait() - gtest.AssertEQ(uint(addTimes), i.Val()) + t.AssertEQ(uint(addTimes), i.Val()) //空参测试 i1 := gtype.NewUint() - gtest.AssertEQ(i1.Val(), uint(0)) + t.AssertEQ(i1.Val(), uint(0)) }) } func Test_Uint_JSON(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := gtype.NewUint(666) b1, err1 := json.Marshal(i) b2, err2 := json.Marshal(i.Val()) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(b1, b2) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(b1, b2) i2 := gtype.NewUint() err := json.Unmarshal(b2, &i2) - gtest.Assert(err, nil) - gtest.Assert(i2.Val(), i) + t.Assert(err, nil) + t.Assert(i2.Val(), i) }) } @@ -60,14 +60,14 @@ func Test_Uint_UnmarshalValue(t *testing.T) { Name string Var *gtype.Uint } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.Val(), "123") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.Val(), "123") }) } diff --git a/container/gvar/gvar_z_unit_test.go b/container/gvar/gvar_z_unit_test.go index 16e38c3c9..f12f615eb 100644 --- a/container/gvar/gvar_z_unit_test.go +++ b/container/gvar/gvar_z_unit_test.go @@ -22,66 +22,66 @@ import ( ) func Test_Set(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var v gvar.Var v.Set(123.456) - gtest.Assert(v.Val(), 123.456) + t.Assert(v.Val(), 123.456) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var v gvar.Var v.Set(123.456) - gtest.Assert(v.Val(), 123.456) + t.Assert(v.Val(), 123.456) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := gvar.Create(123.456) - gtest.Assert(v.Val(), 123.456) + t.Assert(v.Val(), 123.456) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { objOne := gvar.New("old", true) objOneOld, _ := objOne.Set("new").(string) - gtest.Assert(objOneOld, "old") + t.Assert(objOneOld, "old") objTwo := gvar.New("old", false) objTwoOld, _ := objTwo.Set("new").(string) - gtest.Assert(objTwoOld, "old") + t.Assert(objTwoOld, "old") }) } func Test_Val(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { objOne := gvar.New(1, true) objOneOld, _ := objOne.Val().(int) - gtest.Assert(objOneOld, 1) + t.Assert(objOneOld, 1) objTwo := gvar.New(1, false) objTwoOld, _ := objTwo.Val().(int) - gtest.Assert(objTwoOld, 1) + t.Assert(objTwoOld, 1) }) } func Test_Interface(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { objOne := gvar.New(1, true) objOneOld, _ := objOne.Interface().(int) - gtest.Assert(objOneOld, 1) + t.Assert(objOneOld, 1) objTwo := gvar.New(1, false) objTwoOld, _ := objTwo.Interface().(int) - gtest.Assert(objTwoOld, 1) + t.Assert(objTwoOld, 1) }) } func Test_IsNil(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { objOne := gvar.New(nil, true) - gtest.Assert(objOne.IsNil(), true) + t.Assert(objOne.IsNil(), true) objTwo := gvar.New("noNil", false) - gtest.Assert(objTwo.IsNil(), false) + t.Assert(objTwo.IsNil(), false) }) } func Test_Bytes(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { x := int32(1) bytesBuffer := bytes.NewBuffer([]byte{}) binary.Write(bytesBuffer, binary.BigEndian, x) @@ -92,233 +92,233 @@ func Test_Bytes(t *testing.T) { var y int32 binary.Read(bBuf, binary.BigEndian, &y) - gtest.Assert(x, y) + t.Assert(x, y) }) } func Test_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var str string = "hello" objOne := gvar.New(str, true) - gtest.Assert(objOne.String(), str) + t.Assert(objOne.String(), str) }) } func Test_Bool(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ok bool = true objOne := gvar.New(ok, true) - gtest.Assert(objOne.Bool(), ok) + t.Assert(objOne.Bool(), ok) ok = false objTwo := gvar.New(ok, true) - gtest.Assert(objTwo.Bool(), ok) + t.Assert(objTwo.Bool(), ok) }) } func Test_Int(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num int = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Int(), num) + t.Assert(objOne.Int(), num) }) } func Test_Int8(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num int8 = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Int8(), num) + t.Assert(objOne.Int8(), num) }) } func Test_Int16(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num int16 = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Int16(), num) + t.Assert(objOne.Int16(), num) }) } func Test_Int32(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num int32 = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Int32(), num) + t.Assert(objOne.Int32(), num) }) } func Test_Int64(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num int64 = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Int64(), num) + t.Assert(objOne.Int64(), num) }) } func Test_Uint(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num uint = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Uint(), num) + t.Assert(objOne.Uint(), num) }) } func Test_Uint8(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num uint8 = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Uint8(), num) + t.Assert(objOne.Uint8(), num) }) } func Test_Uint16(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num uint16 = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Uint16(), num) + t.Assert(objOne.Uint16(), num) }) } func Test_Uint32(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num uint32 = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Uint32(), num) + t.Assert(objOne.Uint32(), num) }) } func Test_Uint64(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num uint64 = 1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Uint64(), num) + t.Assert(objOne.Uint64(), num) }) } func Test_Float32(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num float32 = 1.1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Float32(), num) + t.Assert(objOne.Float32(), num) }) } func Test_Float64(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var num float64 = 1.1 objOne := gvar.New(num, true) - gtest.Assert(objOne.Float64(), num) + t.Assert(objOne.Float64(), num) }) } func Test_Ints(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var arr = []int{1, 2, 3, 4, 5} objOne := gvar.New(arr, true) - gtest.Assert(objOne.Ints()[0], arr[0]) + t.Assert(objOne.Ints()[0], arr[0]) }) } func Test_Floats(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var arr = []float64{1, 2, 3, 4, 5} objOne := gvar.New(arr, true) - gtest.Assert(objOne.Floats()[0], arr[0]) + t.Assert(objOne.Floats()[0], arr[0]) }) } func Test_Strings(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var arr = []string{"hello", "world"} objOne := gvar.New(arr, true) - gtest.Assert(objOne.Strings()[0], arr[0]) + t.Assert(objOne.Strings()[0], arr[0]) }) } func Test_Interfaces(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var arr = []int{1, 2, 3, 4, 5} objOne := gvar.New(arr, true) - gtest.Assert(objOne.Interfaces(), arr) + t.Assert(objOne.Interfaces(), arr) }) } func Test_Slice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var arr = []int{1, 2, 3, 4, 5} objOne := gvar.New(arr, true) - gtest.Assert(objOne.Slice(), arr) + t.Assert(objOne.Slice(), arr) }) } func Test_Array(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var arr = []int{1, 2, 3, 4, 5} objOne := gvar.New(arr, false) - gtest.Assert(objOne.Array(), arr) + t.Assert(objOne.Array(), arr) }) } func Test_Vars(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { 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) + t.Assert(len(objOne.Vars()), 5) + t.Assert(objOne.Vars()[0].Int(), 1) + t.Assert(objOne.Vars()[4].Int(), 5) }) } func Test_Time(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var timeUnix int64 = 1556242660 objOne := gvar.New(timeUnix, true) - gtest.Assert(objOne.Time().Unix(), timeUnix) + t.Assert(objOne.Time().Unix(), timeUnix) }) } func Test_GTime(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var timeUnix int64 = 1556242660 objOne := gvar.New(timeUnix, true) - gtest.Assert(objOne.GTime().Unix(), timeUnix) + t.Assert(objOne.GTime().Unix(), timeUnix) }) } func Test_Duration(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var timeUnix int64 = 1556242660 objOne := gvar.New(timeUnix, true) - gtest.Assert(objOne.Duration(), time.Duration(timeUnix)) + t.Assert(objOne.Duration(), time.Duration(timeUnix)) }) } func Test_Map(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { 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"]) + t.Assert(objOne.Map()["k1"], m["k1"]) + t.Assert(objOne.Map()["k2"], m["k2"]) }) } func Test_Struct(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type StTest struct { Test int } @@ -332,60 +332,60 @@ func Test_Struct(t *testing.T) { objOne.Struct(testObj) - gtest.Assert(testObj.Test, Kv["Test"]) + t.Assert(testObj.Test, Kv["Test"]) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type StTest struct { Test int8 } o := &StTest{} v := gvar.New(g.Slice{"Test", "-25"}) v.Struct(o) - gtest.Assert(o.Test, -25) + t.Assert(o.Test, -25) }) } func Test_Json(t *testing.T) { // Marshal - gtest.Case(t, func() { + 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) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) - gtest.Case(t, func() { + 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) - gtest.Assert(err1, err2) - gtest.Assert(b1, b2) + t.Assert(err1, err2) + t.Assert(b1, b2) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "i love gf" v := gvar.New(nil) b, err := json.Marshal(s) - gtest.Assert(err, nil) + t.Assert(err, nil) err = json.Unmarshal(b, v) - gtest.Assert(err, nil) - gtest.Assert(v.String(), s) + t.Assert(err, nil) + t.Assert(v.String(), s) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var v gvar.Var s := "i love gf" b, err := json.Marshal(s) - gtest.Assert(err, nil) + t.Assert(err, nil) err = json.Unmarshal(b, &v) - gtest.Assert(err, nil) - gtest.Assert(v.String(), s) + t.Assert(err, nil) + t.Assert(v.String(), s) }) } @@ -394,14 +394,14 @@ func Test_UnmarshalValue(t *testing.T) { Name string Var *gvar.Var } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "v", }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Var.String(), "v") + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Var.String(), "v") }) } diff --git a/crypto/gaes/gaes_test.go b/crypto/gaes/gaes_test.go index 3c86e7767..58b1fc3c7 100644 --- a/crypto/gaes/gaes_test.go +++ b/crypto/gaes/gaes_test.go @@ -40,111 +40,111 @@ var ( ) func TestEncrypt(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { data, err := gaes.Encrypt(content, key_16) - gtest.Assert(err, nil) - gtest.Assert(data, []byte(content_16)) + t.Assert(err, nil) + t.Assert(data, []byte(content_16)) data, err = gaes.Encrypt(content, key_24) - gtest.Assert(err, nil) - gtest.Assert(data, []byte(content_24)) + t.Assert(err, nil) + t.Assert(data, []byte(content_24)) data, err = gaes.Encrypt(content, key_32) - gtest.Assert(err, nil) - gtest.Assert(data, []byte(content_32)) + t.Assert(err, nil) + t.Assert(data, []byte(content_32)) data, err = gaes.Encrypt(content, key_16, iv) - gtest.Assert(err, nil) - gtest.Assert(data, []byte(content_16_iv)) + t.Assert(err, nil) + t.Assert(data, []byte(content_16_iv)) data, err = gaes.Encrypt(content, key_32, iv) - gtest.Assert(err, nil) - gtest.Assert(data, []byte(content_32_iv)) + t.Assert(err, nil) + t.Assert(data, []byte(content_32_iv)) }) } func TestDecrypt(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { decrypt, err := gaes.Decrypt([]byte(content_16), key_16) - gtest.Assert(err, nil) - gtest.Assert(decrypt, content) + t.Assert(err, nil) + t.Assert(decrypt, content) decrypt, err = gaes.Decrypt([]byte(content_24), key_24) - gtest.Assert(err, nil) - gtest.Assert(decrypt, content) + t.Assert(err, nil) + t.Assert(decrypt, content) decrypt, err = gaes.Decrypt([]byte(content_32), key_32) - gtest.Assert(err, nil) - gtest.Assert(decrypt, content) + t.Assert(err, nil) + t.Assert(decrypt, content) decrypt, err = gaes.Decrypt([]byte(content_16_iv), key_16, iv) - gtest.Assert(err, nil) - gtest.Assert(decrypt, content) + t.Assert(err, nil) + t.Assert(decrypt, content) decrypt, err = gaes.Decrypt([]byte(content_32_iv), key_32, iv) - gtest.Assert(err, nil) - gtest.Assert(decrypt, content) + t.Assert(err, nil) + t.Assert(decrypt, content) decrypt, err = gaes.Decrypt([]byte(content_32_iv), keys, iv) - gtest.Assert(err, "invalid padding") + t.Assert(err, "invalid padding") }) } func TestEncryptErr(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // encrypt key error _, err := gaes.Encrypt(content, key_err) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func TestDecryptErr(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // decrypt key error encrypt, err := gaes.Encrypt(content, key_16) _, err = gaes.Decrypt(encrypt, key_err) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) // decrypt content too short error _, err = gaes.Decrypt([]byte("test"), key_16) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) // decrypt content size error _, err = gaes.Decrypt(key_17, key_16) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func TestPKCS5UnPaddingErr(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // PKCS5UnPadding blockSize zero _, err := gaes.PKCS5UnPadding(content, 0) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) // PKCS5UnPadding src len zero _, err = gaes.PKCS5UnPadding([]byte(""), 16) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) // PKCS5UnPadding src len > blockSize _, err = gaes.PKCS5UnPadding(key_17, 16) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) // PKCS5UnPadding src len > blockSize _, err = gaes.PKCS5UnPadding(key_32_err, 32) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func TestEncryptCFB(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var padding int = 0 data, err := gaes.EncryptCFB(content, key_16, &padding, iv) - gtest.Assert(err, nil) - gtest.Assert(padding, padding_size) - gtest.Assert(data, []byte(content_16_cfb)) + t.Assert(err, nil) + t.Assert(padding, padding_size) + t.Assert(data, []byte(content_16_cfb)) }) } func TestDecryptCFB(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { decrypt, err := gaes.DecryptCFB([]byte(content_16_cfb), key_16, padding_size, iv) - gtest.Assert(err, nil) - gtest.Assert(decrypt, content) + t.Assert(err, nil) + t.Assert(decrypt, content) }) } diff --git a/crypto/gcrc32/gcrc32_test.go b/crypto/gcrc32/gcrc32_test.go index 846a17dfd..f5682e439 100644 --- a/crypto/gcrc32/gcrc32_test.go +++ b/crypto/gcrc32/gcrc32_test.go @@ -17,17 +17,17 @@ import ( ) func TestEncrypt(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "pibigstar" result := 693191136 encrypt1 := gcrc32.Encrypt(s) encrypt2 := gcrc32.Encrypt([]byte(s)) - gtest.AssertEQ(int(encrypt1), result) - gtest.AssertEQ(int(encrypt2), result) + t.AssertEQ(int(encrypt1), result) + t.AssertEQ(int(encrypt2), result) strmd5, _ := gmd5.Encrypt(s) test1 := gcrc32.Encrypt(strmd5) test2 := gcrc32.Encrypt([]byte(strmd5)) - gtest.AssertEQ(test2, test1) + t.AssertEQ(test2, test1) }) } diff --git a/crypto/gdes/gdes_test.go b/crypto/gdes/gdes_test.go index 7cce587c6..384480713 100644 --- a/crypto/gdes/gdes_test.go +++ b/crypto/gdes/gdes_test.go @@ -21,81 +21,81 @@ var ( ) func TestDesECB(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := []byte("11111111") text := []byte("12345678") padding := gdes.NOPADDING result := "858b176da8b12503" // encrypt test cipherText, err := gdes.EncryptECB(text, key, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(hex.EncodeToString(cipherText), result) + t.AssertEQ(err, nil) + t.AssertEQ(hex.EncodeToString(cipherText), result) // decrypt test clearText, err := gdes.DecryptECB(cipherText, key, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(string(clearText), "12345678") + t.AssertEQ(err, nil) + t.AssertEQ(string(clearText), "12345678") // encrypt err test. when throw exception,the err is not equal nil and the string is nil errEncrypt, err := gdes.EncryptECB(text, key, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) errEncrypt, err = gdes.EncryptECB(text, errKey, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // err decrypt test. errDecrypt, err := gdes.DecryptECB(cipherText, errKey, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) errDecrypt, err = gdes.DecryptECB(cipherText, key, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := []byte("11111111") text := []byte("12345678") padding := gdes.PKCS5PADDING errPadding := 5 result := "858b176da8b12503ad6a88b4fa37833d" cipherText, err := gdes.EncryptECB(text, key, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(hex.EncodeToString(cipherText), result) + t.AssertEQ(err, nil) + t.AssertEQ(hex.EncodeToString(cipherText), result) // decrypt test clearText, err := gdes.DecryptECB(cipherText, key, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(string(clearText), "12345678") + t.AssertEQ(err, nil) + t.AssertEQ(string(clearText), "12345678") // err test errEncrypt, err := gdes.EncryptECB(text, key, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) errDecrypt, err := gdes.DecryptECB(cipherText, errKey, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) }) } func Test3DesECB(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := []byte("1111111111111234") text := []byte("1234567812345678") padding := gdes.NOPADDING result := "a23ee24b98c26263a23ee24b98c26263" // encrypt test cipherText, err := gdes.EncryptECBTriple(text, key, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(hex.EncodeToString(cipherText), result) + t.AssertEQ(err, nil) + t.AssertEQ(hex.EncodeToString(cipherText), result) // decrypt test clearText, err := gdes.DecryptECBTriple(cipherText, key, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(string(clearText), "1234567812345678") + t.AssertEQ(err, nil) + t.AssertEQ(string(clearText), "1234567812345678") // err test errEncrypt, err := gdes.EncryptECB(text, key, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := []byte("111111111111123412345678") text := []byte("123456789") padding := gdes.PKCS5PADDING @@ -103,29 +103,29 @@ func Test3DesECB(t *testing.T) { result := "37989b1effc07a6d00ff89a7d052e79f" // encrypt test cipherText, err := gdes.EncryptECBTriple(text, key, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(hex.EncodeToString(cipherText), result) + t.AssertEQ(err, nil) + t.AssertEQ(hex.EncodeToString(cipherText), result) // decrypt test clearText, err := gdes.DecryptECBTriple(cipherText, key, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(string(clearText), "123456789") + t.AssertEQ(err, nil) + t.AssertEQ(string(clearText), "123456789") // err test, when key is err, but text and padding is right errEncrypt, err := gdes.EncryptECBTriple(text, errKey, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // when padding is err,but key and text is right errEncrypt, err = gdes.EncryptECBTriple(text, key, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // decrypt err test,when key is err errEncrypt, err = gdes.DecryptECBTriple(text, errKey, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) }) } func TestDesCBC(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := []byte("11111111") text := []byte("1234567812345678") padding := gdes.NOPADDING @@ -133,39 +133,39 @@ func TestDesCBC(t *testing.T) { result := "40826a5800608c87585ca7c9efabee47" // encrypt test cipherText, err := gdes.EncryptCBC(text, key, iv, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(hex.EncodeToString(cipherText), result) + t.AssertEQ(err, nil) + t.AssertEQ(hex.EncodeToString(cipherText), result) // decrypt test clearText, err := gdes.DecryptCBC(cipherText, key, iv, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(string(clearText), "1234567812345678") + t.AssertEQ(err, nil) + t.AssertEQ(string(clearText), "1234567812345678") // encrypt err test. errEncrypt, err := gdes.EncryptCBC(text, errKey, iv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // the iv is err errEncrypt, err = gdes.EncryptCBC(text, key, errIv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // the padding is err errEncrypt, err = gdes.EncryptCBC(text, key, iv, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // decrypt err test. the key is err errDecrypt, err := gdes.DecryptCBC(cipherText, errKey, iv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) // the iv is err errDecrypt, err = gdes.DecryptCBC(cipherText, key, errIv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) // the padding is err errDecrypt, err = gdes.DecryptCBC(cipherText, key, iv, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := []byte("11111111") text := []byte("12345678") padding := gdes.PKCS5PADDING @@ -173,21 +173,21 @@ func TestDesCBC(t *testing.T) { result := "40826a5800608c87100a25d86ac7c52c" // encrypt test cipherText, err := gdes.EncryptCBC(text, key, iv, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(hex.EncodeToString(cipherText), result) + t.AssertEQ(err, nil) + t.AssertEQ(hex.EncodeToString(cipherText), result) // decrypt test clearText, err := gdes.DecryptCBC(cipherText, key, iv, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(string(clearText), "12345678") + t.AssertEQ(err, nil) + t.AssertEQ(string(clearText), "12345678") // err test errEncrypt, err := gdes.EncryptCBC(text, key, errIv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) }) } func Test3DesCBC(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := []byte("1111111112345678") text := []byte("1234567812345678") padding := gdes.NOPADDING @@ -195,38 +195,38 @@ func Test3DesCBC(t *testing.T) { result := "bfde1394e265d5f738d5cab170c77c88" // encrypt test cipherText, err := gdes.EncryptCBCTriple(text, key, iv, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(hex.EncodeToString(cipherText), result) + t.AssertEQ(err, nil) + t.AssertEQ(hex.EncodeToString(cipherText), result) // decrypt test clearText, err := gdes.DecryptCBCTriple(cipherText, key, iv, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(string(clearText), "1234567812345678") + t.AssertEQ(err, nil) + t.AssertEQ(string(clearText), "1234567812345678") // encrypt err test errEncrypt, err := gdes.EncryptCBCTriple(text, errKey, iv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // the iv is err errEncrypt, err = gdes.EncryptCBCTriple(text, key, errIv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // the padding is err errEncrypt, err = gdes.EncryptCBCTriple(text, key, iv, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errEncrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errEncrypt, nil) // decrypt err test errDecrypt, err := gdes.DecryptCBCTriple(cipherText, errKey, iv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) // the iv is err errDecrypt, err = gdes.DecryptCBCTriple(cipherText, key, errIv, padding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) // the padding is err errDecrypt, err = gdes.DecryptCBCTriple(cipherText, key, iv, errPadding) - gtest.AssertNE(err, nil) - gtest.AssertEQ(errDecrypt, nil) + t.AssertNE(err, nil) + t.AssertEQ(errDecrypt, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := []byte("111111111234567812345678") text := []byte("12345678") padding := gdes.PKCS5PADDING @@ -234,12 +234,12 @@ func Test3DesCBC(t *testing.T) { result := "40826a5800608c87100a25d86ac7c52c" // encrypt test cipherText, err := gdes.EncryptCBCTriple(text, key, iv, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(hex.EncodeToString(cipherText), result) + t.AssertEQ(err, nil) + t.AssertEQ(hex.EncodeToString(cipherText), result) // decrypt test clearText, err := gdes.DecryptCBCTriple(cipherText, key, iv, padding) - gtest.AssertEQ(err, nil) - gtest.AssertEQ(string(clearText), "12345678") + t.AssertEQ(err, nil) + t.AssertEQ(string(clearText), "12345678") }) } diff --git a/crypto/gmd5/gmd5_test.go b/crypto/gmd5/gmd5_test.go index 82eb3a306..286308373 100644 --- a/crypto/gmd5/gmd5_test.go +++ b/crypto/gmd5/gmd5_test.go @@ -29,16 +29,16 @@ type user struct { } func TestEncrypt(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { encryptString, _ := gmd5.Encrypt(s) - gtest.Assert(encryptString, result) + t.Assert(encryptString, result) result := "1427562bb29f88a1161590b76398ab72" encrypt, _ := gmd5.Encrypt(123456) - gtest.AssertEQ(encrypt, result) + t.AssertEQ(encrypt, result) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := &user{ name: "派大星", password: "123456", @@ -46,14 +46,14 @@ func TestEncrypt(t *testing.T) { } result := "70917ebce8bd2f78c736cda63870fb39" encrypt, _ := gmd5.Encrypt(user) - gtest.AssertEQ(encrypt, result) + t.AssertEQ(encrypt, result) }) } func TestEncryptString(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { encryptString, _ := gmd5.EncryptString(s) - gtest.Assert(encryptString, result) + t.Assert(encryptString, result) }) } @@ -61,17 +61,17 @@ func TestEncryptFile(t *testing.T) { path := "test.text" errorPath := "err.txt" result := "e6e6e1cd41895beebff16d5452dfce12" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { file, err := os.Create(path) defer os.Remove(path) defer file.Close() - gtest.Assert(err, nil) + t.Assert(err, nil) _, _ = file.Write([]byte("Hello Go Frame")) encryptFile, _ := gmd5.EncryptFile(path) - gtest.AssertEQ(encryptFile, result) + t.AssertEQ(encryptFile, result) // when the file is not exist,encrypt will return empty string errEncrypt, _ := gmd5.EncryptFile(errorPath) - gtest.AssertEQ(errEncrypt, "") + t.AssertEQ(errEncrypt, "") }) } diff --git a/crypto/gsha1/gsha1_test.go b/crypto/gsha1/gsha1_test.go index d7182d7c4..775a43ac9 100644 --- a/crypto/gsha1/gsha1_test.go +++ b/crypto/gsha1/gsha1_test.go @@ -23,7 +23,7 @@ type user struct { } func TestEncrypt(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := &user{ name: "派大星", password: "123456", @@ -31,29 +31,29 @@ func TestEncrypt(t *testing.T) { } result := "97386736e3ee4adee5ca595c78c12129f6032cad" encrypt := gsha1.Encrypt(user) - gtest.AssertEQ(encrypt, result) + t.AssertEQ(encrypt, result) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result := "5b4c1c2a08ca85ddd031ef8627414f4cb2620b41" s := gsha1.Encrypt("pibigstar") - gtest.AssertEQ(s, result) + t.AssertEQ(s, result) }) } func TestEncryptFile(t *testing.T) { path := "test.text" errPath := "err.text" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result := "8b05d3ba24b8d2374b8f5149d9f3fbada14ea984" file, err := os.Create(path) defer os.Remove(path) defer file.Close() - gtest.Assert(err, nil) + t.Assert(err, nil) _, _ = file.Write([]byte("Hello Go Frame")) encryptFile, _ := gsha1.EncryptFile(path) - gtest.AssertEQ(encryptFile, result) + t.AssertEQ(encryptFile, result) // when the file is not exist,encrypt will return empty string errEncrypt, _ := gsha1.EncryptFile(errPath) - gtest.AssertEQ(errEncrypt, "") + t.AssertEQ(errEncrypt, "") }) } diff --git a/database/gdb/gdb_unit_init_test.go b/database/gdb/gdb_unit_init_test.go index 2879fe6ab..8f29f2f82 100644 --- a/database/gdb/gdb_unit_init_test.go +++ b/database/gdb/gdb_unit_init_test.go @@ -36,7 +36,7 @@ func init() { "name": true, "type": true, }, false) - gtest.Assert(err, nil) + t.Assert(err, nil) configNode = gdb.ConfigNode{ Host: "127.0.0.1", Port: "3306", @@ -195,11 +195,11 @@ func createInitTableWithDb(db gdb.DB, table ...string) (name string) { } result, err := db.BatchInsert(name, array.Slice()) - gtest.Assert(err, nil) + t.Assert(err, nil) n, e := result.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, SIZE) + t.Assert(e, nil) + t.Assert(n, SIZE) return } diff --git a/database/gdb/gdb_unit_z_driver_test.go b/database/gdb/gdb_unit_z_driver_test.go index f4c125a6e..b17bbe35e 100644 --- a/database/gdb/gdb_unit_z_driver_test.go +++ b/database/gdb/gdb_unit_z_driver_test.go @@ -63,12 +63,12 @@ func Test_Custom_Driver(t *testing.T) { Role: "master", Charset: "utf8", }) - gtest.Case(t, func() { - gtest.Assert(latestSqlString.Val(), "") + gtest.C(t, func(t *gtest.T) { + t.Assert(latestSqlString.Val(), "") sqlString := "select 10000" value, err := g.DB("driver-test").GetValue(sqlString) - gtest.Assert(err, nil) - gtest.Assert(value, 10000) - gtest.Assert(latestSqlString.Val(), sqlString) + t.Assert(err, nil) + t.Assert(value, 10000) + t.Assert(latestSqlString.Val(), sqlString) }) } diff --git a/database/gdb/gdb_unit_z_func_test.go b/database/gdb/gdb_unit_z_func_test.go index 8d6971624..ba311c23c 100644 --- a/database/gdb/gdb_unit_z_func_test.go +++ b/database/gdb/gdb_unit_z_func_test.go @@ -13,33 +13,33 @@ import ( func Test_Func_bindArgsToQuery(t *testing.T) { // mysql - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var s string s = bindArgsToQuery("select * from table where id>=? and sex=?", []interface{}{100, 1}) - gtest.Assert(s, "select * from table where id>=100 and sex=1") + t.Assert(s, "select * from table where id>=100 and sex=1") }) // mssql - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var s string s = bindArgsToQuery("select * from table where id>=@p1 and sex=@p2", []interface{}{100, 1}) - gtest.Assert(s, "select * from table where id>=100 and sex=1") + t.Assert(s, "select * from table where id>=100 and sex=1") }) // pgsql - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var s string s = bindArgsToQuery("select * from table where id>=$1 and sex=$2", []interface{}{100, 1}) - gtest.Assert(s, "select * from table where id>=100 and sex=1") + t.Assert(s, "select * from table where id>=100 and sex=1") }) // oracle - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var s string s = bindArgsToQuery("select * from table where id>=:1 and sex=:2", []interface{}{100, 1}) - gtest.Assert(s, "select * from table where id>=100 and sex=1") + t.Assert(s, "select * from table where id>=100 and sex=1") }) } func Test_Func_doQuoteWord(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := map[string]string{ "user": "`user`", "user u": "user u", @@ -50,13 +50,13 @@ func Test_Func_doQuoteWord(t *testing.T) { "u.id asc, ut.uid desc": "u.id asc, ut.uid desc", } for k, v := range array { - gtest.Assert(doQuoteWord(k, "`", "`"), v) + t.Assert(doQuoteWord(k, "`", "`"), v) } }) } func Test_Func_doQuoteString(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // "user", "user u", "user,user_detail", "user u, user_detail ut", "u.id asc". array := map[string]string{ "user": "`user`", @@ -70,13 +70,13 @@ func Test_Func_doQuoteString(t *testing.T) { "user..user u, user.user_detail ut": "`user`..`user` u,`user`.`user_detail` ut", } for k, v := range array { - gtest.Assert(doQuoteString(k, "`", "`"), v) + t.Assert(doQuoteString(k, "`", "`"), v) } }) } func Test_Func_addTablePrefix(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { prefix := "" array := map[string]string{ "user": "`user`", @@ -90,10 +90,10 @@ func Test_Func_addTablePrefix(t *testing.T) { "UserCenter..user as u, user_detail as ut": "`UserCenter`..`user` as u,`user_detail` as ut", } for k, v := range array { - gtest.Assert(doHandleTableName(k, prefix, "`", "`"), v) + t.Assert(doHandleTableName(k, prefix, "`", "`"), v) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { prefix := "gf_" array := map[string]string{ "user": "`gf_user`", @@ -107,7 +107,7 @@ func Test_Func_addTablePrefix(t *testing.T) { "UserCenter..user as u, user_detail as ut": "`UserCenter`..`gf_user` as u,`gf_user_detail` as ut", } for k, v := range array { - gtest.Assert(doHandleTableName(k, prefix, "`", "`"), v) + t.Assert(doHandleTableName(k, prefix, "`", "`"), v) } }) } diff --git a/database/gdb/gdb_unit_z_mysql_basic_test.go b/database/gdb/gdb_unit_z_mysql_basic_test.go index 01902497a..045d751ac 100644 --- a/database/gdb/gdb_unit_z_mysql_basic_test.go +++ b/database/gdb/gdb_unit_z_mysql_basic_test.go @@ -14,16 +14,16 @@ import ( ) func Test_Instance(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := gdb.Instance("none") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) db, err := gdb.Instance() - gtest.Assert(err, nil) + t.Assert(err, nil) err1 := db.PingMaster() err2 := db.PingSlave() - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) }) } diff --git a/database/gdb/gdb_unit_z_mysql_method_test.go b/database/gdb/gdb_unit_z_mysql_method_test.go index 50faf28db..148cd6f1f 100644 --- a/database/gdb/gdb_unit_z_mysql_method_test.go +++ b/database/gdb/gdb_unit_z_mysql_method_test.go @@ -22,56 +22,56 @@ import ( ) func Test_DB_Ping(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err1 := db.PingMaster() err2 := db.PingSlave() - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) }) } func Test_DB_Query(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := db.Query("SELECT ?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) _, err = db.Query("SELECT ?+?", 1, 2) - gtest.Assert(err, nil) + t.Assert(err, nil) _, err = db.Query("SELECT ?+?", g.Slice{1, 2}) - gtest.Assert(err, nil) + t.Assert(err, nil) _, err = db.Query("ERROR") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_DB_Exec(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := db.Exec("SELECT ?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) _, err = db.Exec("ERROR") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_DB_Prepare(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { st, err := db.Prepare("SELECT 100") - gtest.Assert(err, nil) + t.Assert(err, nil) rows, err := st.Query() - gtest.Assert(err, nil) + t.Assert(err, nil) array, err := rows.Columns() - gtest.Assert(err, nil) - gtest.Assert(array[0], "100") + t.Assert(err, nil) + t.Assert(array[0], "100") err = rows.Close() - gtest.Assert(err, nil) + t.Assert(err, nil) }) } @@ -79,7 +79,7 @@ func Test_DB_Insert(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := db.Insert(table, g.Map{ "id": 1, "passport": "t1", @@ -87,7 +87,7 @@ func Test_DB_Insert(t *testing.T) { "nickname": "T1", "create_time": gtime.Now().String(), }) - gtest.Assert(err, nil) + t.Assert(err, nil) // normal map result, err := db.Insert(table, g.Map{ @@ -97,9 +97,9 @@ func Test_DB_Insert(t *testing.T) { "nickname": "name_2", "create_time": gtime.Now().String(), }) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) // struct type User struct { @@ -117,18 +117,18 @@ func Test_DB_Insert(t *testing.T) { Nickname: "name_3", CreateTime: timeStr, }) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("id", 3).One() - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Assert(one["id"].Int(), 3) - gtest.Assert(one["passport"].String(), "user_3") - gtest.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad") - gtest.Assert(one["nickname"].String(), "name_3") - gtest.Assert(one["create_time"].GTime().String(), timeStr) + t.Assert(one["id"].Int(), 3) + t.Assert(one["passport"].String(), "user_3") + t.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad") + t.Assert(one["nickname"].String(), "name_3") + t.Assert(one["create_time"].GTime().String(), timeStr) // *struct timeStr = gtime.Now().String() @@ -139,17 +139,17 @@ func Test_DB_Insert(t *testing.T) { Nickname: "name_4", CreateTime: timeStr, }) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err = db.Table(table).Where("id", 4).One() - gtest.Assert(err, nil) - gtest.Assert(one["id"].Int(), 4) - gtest.Assert(one["passport"].String(), "t4") - gtest.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad") - gtest.Assert(one["nickname"].String(), "name_4") - gtest.Assert(one["create_time"].GTime().String(), timeStr) + t.Assert(err, nil) + t.Assert(one["id"].Int(), 4) + t.Assert(one["passport"].String(), "t4") + t.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad") + t.Assert(one["nickname"].String(), "name_4") + t.Assert(one["create_time"].GTime().String(), timeStr) // batch with Insert timeStr = gtime.Now().String() @@ -169,24 +169,24 @@ func Test_DB_Insert(t *testing.T) { "create_time": timeStr, }, }) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = r.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) one, err = db.Table(table).Where("id", 200).One() - gtest.Assert(err, nil) - gtest.Assert(one["id"].Int(), 200) - gtest.Assert(one["passport"].String(), "t200") - gtest.Assert(one["password"].String(), "25d55ad283aa400af464c76d71qw07ad") - gtest.Assert(one["nickname"].String(), "T200") - gtest.Assert(one["create_time"].GTime().String(), timeStr) + t.Assert(err, nil) + t.Assert(one["id"].Int(), 200) + t.Assert(one["passport"].String(), "t200") + t.Assert(one["password"].String(), "25d55ad283aa400af464c76d71qw07ad") + t.Assert(one["nickname"].String(), "T200") + t.Assert(one["create_time"].GTime().String(), timeStr) }) } func Test_DB_InsertIgnore(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := db.Insert(table, g.Map{ "id": 1, "passport": "t1", @@ -194,9 +194,9 @@ func Test_DB_InsertIgnore(t *testing.T) { "nickname": "T1", "create_time": gtime.Now().String(), }) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := db.InsertIgnore(table, g.Map{ "id": 1, "passport": "t1", @@ -204,12 +204,12 @@ func Test_DB_InsertIgnore(t *testing.T) { "nickname": "T1", "create_time": gtime.Now().String(), }) - gtest.Assert(err, nil) + t.Assert(err, nil) }) } func Test_DB_BatchInsert(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) r, err := db.BatchInsert(table, g.List{ @@ -228,15 +228,15 @@ func Test_DB_BatchInsert(t *testing.T) { "create_time": gtime.Now().String(), }, }, 1) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) n, _ = r.LastInsertId() - gtest.Assert(n, 3) + t.Assert(n, 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) // []interface{} @@ -256,13 +256,13 @@ func Test_DB_BatchInsert(t *testing.T) { "create_time": gtime.Now().String(), }, }, 1) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) }) // batch insert map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) result, err := db.BatchInsert(table, g.Map{ @@ -272,16 +272,16 @@ func Test_DB_BatchInsert(t *testing.T) { "nickname": "T1", "create_time": gtime.Now().String(), }) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) }) } func Test_DB_BatchInsert_Struct(t *testing.T) { // batch insert struct - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) @@ -300,9 +300,9 @@ func Test_DB_BatchInsert_Struct(t *testing.T) { CreateTime: gtime.Now(), } result, err := db.BatchInsert(table, user) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) }) } @@ -310,7 +310,7 @@ func Test_DB_Save(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeStr := gtime.Now().String() _, err := db.Save(table, g.Map{ "id": 1, @@ -319,15 +319,15 @@ func Test_DB_Save(t *testing.T) { "nickname": "T11", "create_time": timeStr, }) - gtest.Assert(err, nil) + t.Assert(err, nil) one, err := db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.Assert(one["id"].Int(), 1) - gtest.Assert(one["passport"].String(), "t1") - gtest.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad") - gtest.Assert(one["nickname"].String(), "T11") - gtest.Assert(one["create_time"].GTime().String(), timeStr) + t.Assert(err, nil) + t.Assert(one["id"].Int(), 1) + t.Assert(one["passport"].String(), "t1") + t.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad") + t.Assert(one["nickname"].String(), "T11") + t.Assert(one["create_time"].GTime().String(), timeStr) }) } @@ -335,7 +335,7 @@ func Test_DB_Replace(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeStr := gtime.Now().String() _, err := db.Replace(table, g.Map{ "id": 1, @@ -344,15 +344,15 @@ func Test_DB_Replace(t *testing.T) { "nickname": "T11", "create_time": timeStr, }) - gtest.Assert(err, nil) + t.Assert(err, nil) one, err := db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.Assert(one["id"].Int(), 1) - gtest.Assert(one["passport"].String(), "t1") - gtest.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad") - gtest.Assert(one["nickname"].String(), "T11") - gtest.Assert(one["create_time"].GTime().String(), timeStr) + t.Assert(err, nil) + t.Assert(one["id"].Int(), 1) + t.Assert(one["passport"].String(), "t1") + t.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad") + t.Assert(one["nickname"].String(), "T11") + t.Assert(one["create_time"].GTime().String(), timeStr) }) } @@ -360,18 +360,18 @@ func Test_DB_Update(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Update(table, "password='987654321'", "id=3") - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("id", 3).One() - gtest.Assert(err, nil) - gtest.Assert(one["id"].Int(), 3) - gtest.Assert(one["passport"].String(), "user_3") - gtest.Assert(one["password"].String(), "987654321") - gtest.Assert(one["nickname"].String(), "name_3") + t.Assert(err, nil) + t.Assert(one["id"].Int(), 3) + t.Assert(one["passport"].String(), "user_3") + t.Assert(one["password"].String(), "987654321") + t.Assert(one["nickname"].String(), "name_3") }) } @@ -379,86 +379,86 @@ func Test_DB_GetAll(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.GetAll(fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 1) - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 1) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.GetAll(fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), g.Slice{1}) - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 1) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.GetAll(fmt.Sprintf("SELECT * FROM %s WHERE id in(?)", table), g.Slice{1, 2, 3}) - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) - gtest.Assert(result[1]["id"].Int(), 2) - gtest.Assert(result[2]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) + t.Assert(result[1]["id"].Int(), 2) + t.Assert(result[2]["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.GetAll(fmt.Sprintf("SELECT * FROM %s WHERE id in(?,?,?)", table), g.Slice{1, 2, 3}) - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) - gtest.Assert(result[1]["id"].Int(), 2) - gtest.Assert(result[2]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) + t.Assert(result[1]["id"].Int(), 2) + t.Assert(result[2]["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.GetAll(fmt.Sprintf("SELECT * FROM %s WHERE id in(?,?,?)", table), g.Slice{1, 2, 3}...) - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) - gtest.Assert(result[1]["id"].Int(), 2) - gtest.Assert(result[2]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) + t.Assert(result[1]["id"].Int(), 2) + t.Assert(result[2]["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.GetAll(fmt.Sprintf("SELECT * FROM %s WHERE id>=? AND id <=?", table), g.Slice{1, 3}) - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) - gtest.Assert(result[1]["id"].Int(), 2) - gtest.Assert(result[2]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) + t.Assert(result[1]["id"].Int(), 2) + t.Assert(result[2]["id"].Int(), 3) }) } func Test_DB_GetOne(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.GetOne(fmt.Sprintf("SELECT * FROM %s WHERE passport=?", table), "user_1") - gtest.Assert(err, nil) - gtest.Assert(record["nickname"].String(), "name_1") + t.Assert(err, nil) + t.Assert(record["nickname"].String(), "name_1") }) } func Test_DB_GetValue(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value, err := db.GetValue(fmt.Sprintf("SELECT id FROM %s WHERE passport=?", table), "user_3") - gtest.Assert(err, nil) - gtest.Assert(value.Int(), 3) + t.Assert(err, nil) + t.Assert(value.Int(), 3) }) } func Test_DB_GetCount(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { count, err := db.GetCount(fmt.Sprintf("SELECT * FROM %s", table)) - gtest.Assert(err, nil) - gtest.Assert(count, SIZE) + t.Assert(err, nil) + t.Assert(count, SIZE) }) } func Test_DB_GetStruct(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -468,10 +468,10 @@ func Test_DB_GetStruct(t *testing.T) { } user := new(User) err := db.GetStruct(user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_3") + t.Assert(err, nil) + t.Assert(user.NickName, "name_3") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -481,15 +481,15 @@ func Test_DB_GetStruct(t *testing.T) { } user := new(User) err := db.GetStruct(user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_3") + t.Assert(err, nil) + t.Assert(user.NickName, "name_3") }) } func Test_DB_GetStructs(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -499,17 +499,17 @@ func Test_DB_GetStructs(t *testing.T) { } var users []User err := db.GetStructs(&users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 1) - gtest.Assert(err, nil) - gtest.Assert(len(users), SIZE-1) - gtest.Assert(users[0].Id, 2) - gtest.Assert(users[1].Id, 3) - gtest.Assert(users[2].Id, 4) - gtest.Assert(users[0].NickName, "name_2") - gtest.Assert(users[1].NickName, "name_3") - gtest.Assert(users[2].NickName, "name_4") + t.Assert(err, nil) + t.Assert(len(users), SIZE-1) + t.Assert(users[0].Id, 2) + t.Assert(users[1].Id, 3) + t.Assert(users[2].Id, 4) + t.Assert(users[0].NickName, "name_2") + t.Assert(users[1].NickName, "name_3") + t.Assert(users[2].NickName, "name_4") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -519,21 +519,21 @@ func Test_DB_GetStructs(t *testing.T) { } var users []User err := db.GetStructs(&users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 1) - gtest.Assert(err, nil) - gtest.Assert(len(users), SIZE-1) - gtest.Assert(users[0].Id, 2) - gtest.Assert(users[1].Id, 3) - gtest.Assert(users[2].Id, 4) - gtest.Assert(users[0].NickName, "name_2") - gtest.Assert(users[1].NickName, "name_3") - gtest.Assert(users[2].NickName, "name_4") + t.Assert(err, nil) + t.Assert(len(users), SIZE-1) + t.Assert(users[0].Id, 2) + t.Assert(users[1].Id, 3) + t.Assert(users[2].Id, 4) + t.Assert(users[0].NickName, "name_2") + t.Assert(users[1].NickName, "name_3") + t.Assert(users[2].NickName, "name_4") }) } func Test_DB_GetScan(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -543,10 +543,10 @@ func Test_DB_GetScan(t *testing.T) { } user := new(User) err := db.GetScan(user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_3") + t.Assert(err, nil) + t.Assert(user.NickName, "name_3") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -556,11 +556,11 @@ func Test_DB_GetScan(t *testing.T) { } user := new(User) err := db.GetScan(user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_3") + t.Assert(err, nil) + t.Assert(user.NickName, "name_3") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -570,17 +570,17 @@ func Test_DB_GetScan(t *testing.T) { } var users []User err := db.GetScan(&users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 1) - gtest.Assert(err, nil) - gtest.Assert(len(users), SIZE-1) - gtest.Assert(users[0].Id, 2) - gtest.Assert(users[1].Id, 3) - gtest.Assert(users[2].Id, 4) - gtest.Assert(users[0].NickName, "name_2") - gtest.Assert(users[1].NickName, "name_3") - gtest.Assert(users[2].NickName, "name_4") + t.Assert(err, nil) + t.Assert(len(users), SIZE-1) + t.Assert(users[0].Id, 2) + t.Assert(users[1].Id, 3) + t.Assert(users[2].Id, 4) + t.Assert(users[0].NickName, "name_2") + t.Assert(users[1].NickName, "name_3") + t.Assert(users[2].NickName, "name_4") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -590,25 +590,25 @@ func Test_DB_GetScan(t *testing.T) { } var users []User err := db.GetScan(&users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 1) - gtest.Assert(err, nil) - gtest.Assert(len(users), SIZE-1) - gtest.Assert(users[0].Id, 2) - gtest.Assert(users[1].Id, 3) - gtest.Assert(users[2].Id, 4) - gtest.Assert(users[0].NickName, "name_2") - gtest.Assert(users[1].NickName, "name_3") - gtest.Assert(users[2].NickName, "name_4") + t.Assert(err, nil) + t.Assert(len(users), SIZE-1) + t.Assert(users[0].Id, 2) + t.Assert(users[1].Id, 3) + t.Assert(users[2].Id, 4) + t.Assert(users[0].NickName, "name_2") + t.Assert(users[1].NickName, "name_3") + t.Assert(users[2].NickName, "name_4") }) } func Test_DB_Delete(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Delete(table, nil) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, SIZE) + t.Assert(n, SIZE) }) } @@ -616,7 +616,7 @@ func Test_DB_Time(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Insert(table, g.Map{ "id": 200, "passport": "t200", @@ -628,13 +628,13 @@ func Test_DB_Time(t *testing.T) { gtest.Error(err) } n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) value, err := db.GetValue(fmt.Sprintf("select `passport` from `%s` where id=?", table), 200) - gtest.Assert(err, nil) - gtest.Assert(value.String(), "t200") + t.Assert(err, nil) + t.Assert(value.String(), "t200") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { t := time.Now() result, err := db.Insert(table, g.Map{ "id": 300, @@ -647,17 +647,17 @@ func Test_DB_Time(t *testing.T) { gtest.Error(err) } n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) value, err := db.GetValue(fmt.Sprintf("select `passport` from `%s` where id=?", table), 300) - gtest.Assert(err, nil) - gtest.Assert(value.String(), "t300") + t.Assert(err, nil) + t.Assert(value.String(), "t300") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Delete(table, nil) - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) }) } @@ -666,9 +666,9 @@ func Test_DB_ToJson(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Fields("*").Where("id =? ", 1).Select() if err != nil { gtest.Fatal(err) @@ -685,7 +685,7 @@ func Test_DB_ToJson(t *testing.T) { users := make([]User, 0) err = result.Structs(users) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) err = result.Structs(&users) if err != nil { @@ -698,18 +698,18 @@ func Test_DB_ToJson(t *testing.T) { gtest.Fatal(err) } - gtest.Assert(users[0].Id, resultJson.GetInt("0.id")) - gtest.Assert(users[0].Passport, resultJson.GetString("0.passport")) - gtest.Assert(users[0].Password, resultJson.GetString("0.password")) - gtest.Assert(users[0].NickName, resultJson.GetString("0.nickname")) - gtest.Assert(users[0].CreateTime, resultJson.GetString("0.create_time")) + t.Assert(users[0].Id, resultJson.GetInt("0.id")) + t.Assert(users[0].Passport, resultJson.GetString("0.passport")) + t.Assert(users[0].Password, resultJson.GetString("0.password")) + t.Assert(users[0].NickName, resultJson.GetString("0.nickname")) + t.Assert(users[0].CreateTime, resultJson.GetString("0.create_time")) result = nil err = result.Structs(&users) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Fields("*").Where("id =? ", 1).One() if err != nil { gtest.Fatal(err) @@ -732,7 +732,7 @@ func Test_DB_ToJson(t *testing.T) { result = nil err = result.Struct(&users) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } @@ -741,9 +741,9 @@ func Test_DB_ToXml(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).Fields("*").Where("id = ?", 1).One() if err != nil { gtest.Fatal(err) @@ -770,31 +770,31 @@ func Test_DB_ToXml(t *testing.T) { resultXml := result["doc"].(map[string]interface{}) if v, ok := resultXml["id"]; ok { - gtest.Assert(user.Id, v) + t.Assert(user.Id, v) } else { gtest.Fatal("FAIL") } if v, ok := resultXml["passport"]; ok { - gtest.Assert(user.Passport, v) + t.Assert(user.Passport, v) } else { gtest.Fatal("FAIL") } if v, ok := resultXml["password"]; ok { - gtest.Assert(user.Password, v) + t.Assert(user.Password, v) } else { gtest.Fatal("FAIL") } if v, ok := resultXml["nickname"]; ok { - gtest.Assert(user.NickName, v) + t.Assert(user.NickName, v) } else { gtest.Fatal("FAIL") } if v, ok := resultXml["create_time"]; ok { - gtest.Assert(user.CreateTime, v) + t.Assert(user.CreateTime, v) } else { gtest.Fatal("FAIL") } @@ -807,8 +807,8 @@ func Test_DB_ToStringMap(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - gtest.Assert(err, nil) - gtest.Case(t, func() { + t.Assert(err, nil) + gtest.C(t, func(t *gtest.T) { id := "1" result, err := db.Table(table).Fields("*").Where("id = ?", 1).Select() if err != nil { @@ -830,11 +830,11 @@ func Test_DB_ToStringMap(t *testing.T) { } resultStringMap := result.MapKeyStr("id") - gtest.Assert(t_users[0].Id, resultStringMap[id]["id"]) - gtest.Assert(t_users[0].Passport, resultStringMap[id]["passport"]) - gtest.Assert(t_users[0].Password, resultStringMap[id]["password"]) - gtest.Assert(t_users[0].NickName, resultStringMap[id]["nickname"]) - gtest.Assert(t_users[0].CreateTime, resultStringMap[id]["create_time"]) + t.Assert(t_users[0].Id, resultStringMap[id]["id"]) + t.Assert(t_users[0].Passport, resultStringMap[id]["passport"]) + t.Assert(t_users[0].Password, resultStringMap[id]["password"]) + t.Assert(t_users[0].NickName, resultStringMap[id]["nickname"]) + t.Assert(t_users[0].CreateTime, resultStringMap[id]["create_time"]) }) } @@ -843,9 +843,9 @@ func Test_DB_ToIntMap(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 1 result, err := db.Table(table).Fields("*").Where("id = ?", id).Select() if err != nil { @@ -867,11 +867,11 @@ func Test_DB_ToIntMap(t *testing.T) { } resultIntMap := result.MapKeyInt("id") - gtest.Assert(t_users[0].Id, resultIntMap[id]["id"]) - gtest.Assert(t_users[0].Passport, resultIntMap[id]["passport"]) - gtest.Assert(t_users[0].Password, resultIntMap[id]["password"]) - gtest.Assert(t_users[0].NickName, resultIntMap[id]["nickname"]) - gtest.Assert(t_users[0].CreateTime, resultIntMap[id]["create_time"]) + t.Assert(t_users[0].Id, resultIntMap[id]["id"]) + t.Assert(t_users[0].Passport, resultIntMap[id]["passport"]) + t.Assert(t_users[0].Password, resultIntMap[id]["password"]) + t.Assert(t_users[0].NickName, resultIntMap[id]["nickname"]) + t.Assert(t_users[0].CreateTime, resultIntMap[id]["create_time"]) }) } @@ -880,9 +880,9 @@ func Test_DB_ToUintMap(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 1 result, err := db.Table(table).Fields("*").Where("id = ?", id).Select() if err != nil { @@ -904,11 +904,11 @@ func Test_DB_ToUintMap(t *testing.T) { } resultUintMap := result.MapKeyUint("id") - gtest.Assert(t_users[0].Id, resultUintMap[uint(id)]["id"]) - gtest.Assert(t_users[0].Passport, resultUintMap[uint(id)]["passport"]) - gtest.Assert(t_users[0].Password, resultUintMap[uint(id)]["password"]) - gtest.Assert(t_users[0].NickName, resultUintMap[uint(id)]["nickname"]) - gtest.Assert(t_users[0].CreateTime, resultUintMap[uint(id)]["create_time"]) + t.Assert(t_users[0].Id, resultUintMap[uint(id)]["id"]) + t.Assert(t_users[0].Passport, resultUintMap[uint(id)]["passport"]) + t.Assert(t_users[0].Password, resultUintMap[uint(id)]["password"]) + t.Assert(t_users[0].NickName, resultUintMap[uint(id)]["nickname"]) + t.Assert(t_users[0].CreateTime, resultUintMap[uint(id)]["create_time"]) }) } @@ -918,9 +918,9 @@ func Test_DB_ToStringRecord(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 1 ids := "1" result, err := db.Table(table).Fields("*").Where("id = ?", id).Select() @@ -943,11 +943,11 @@ func Test_DB_ToStringRecord(t *testing.T) { } resultStringRecord := result.RecordKeyStr("id") - gtest.Assert(t_users[0].Id, resultStringRecord[ids]["id"].Int()) - gtest.Assert(t_users[0].Passport, resultStringRecord[ids]["passport"].String()) - gtest.Assert(t_users[0].Password, resultStringRecord[ids]["password"].String()) - gtest.Assert(t_users[0].NickName, resultStringRecord[ids]["nickname"].String()) - gtest.Assert(t_users[0].CreateTime, resultStringRecord[ids]["create_time"].String()) + t.Assert(t_users[0].Id, resultStringRecord[ids]["id"].Int()) + t.Assert(t_users[0].Passport, resultStringRecord[ids]["passport"].String()) + t.Assert(t_users[0].Password, resultStringRecord[ids]["password"].String()) + t.Assert(t_users[0].NickName, resultStringRecord[ids]["nickname"].String()) + t.Assert(t_users[0].CreateTime, resultStringRecord[ids]["create_time"].String()) }) } @@ -957,9 +957,9 @@ func Test_DB_ToIntRecord(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 1 result, err := db.Table(table).Fields("*").Where("id = ?", id).Select() if err != nil { @@ -981,11 +981,11 @@ func Test_DB_ToIntRecord(t *testing.T) { } resultIntRecord := result.RecordKeyInt("id") - gtest.Assert(t_users[0].Id, resultIntRecord[id]["id"].Int()) - gtest.Assert(t_users[0].Passport, resultIntRecord[id]["passport"].String()) - gtest.Assert(t_users[0].Password, resultIntRecord[id]["password"].String()) - gtest.Assert(t_users[0].NickName, resultIntRecord[id]["nickname"].String()) - gtest.Assert(t_users[0].CreateTime, resultIntRecord[id]["create_time"].String()) + t.Assert(t_users[0].Id, resultIntRecord[id]["id"].Int()) + t.Assert(t_users[0].Passport, resultIntRecord[id]["passport"].String()) + t.Assert(t_users[0].Password, resultIntRecord[id]["password"].String()) + t.Assert(t_users[0].NickName, resultIntRecord[id]["nickname"].String()) + t.Assert(t_users[0].CreateTime, resultIntRecord[id]["create_time"].String()) }) } @@ -995,9 +995,9 @@ func Test_DB_ToUintRecord(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 1 result, err := db.Table(table).Fields("*").Where("id = ?", id).Select() if err != nil { @@ -1019,11 +1019,11 @@ func Test_DB_ToUintRecord(t *testing.T) { } resultUintRecord := result.RecordKeyUint("id") - gtest.Assert(t_users[0].Id, resultUintRecord[uint(id)]["id"].Int()) - gtest.Assert(t_users[0].Passport, resultUintRecord[uint(id)]["passport"].String()) - gtest.Assert(t_users[0].Password, resultUintRecord[uint(id)]["password"].String()) - gtest.Assert(t_users[0].NickName, resultUintRecord[uint(id)]["nickname"].String()) - gtest.Assert(t_users[0].CreateTime, resultUintRecord[uint(id)]["create_time"].String()) + t.Assert(t_users[0].Id, resultUintRecord[uint(id)]["id"].Int()) + t.Assert(t_users[0].Passport, resultUintRecord[uint(id)]["passport"].String()) + t.Assert(t_users[0].Password, resultUintRecord[uint(id)]["password"].String()) + t.Assert(t_users[0].NickName, resultUintRecord[uint(id)]["nickname"].String()) + t.Assert(t_users[0].CreateTime, resultUintRecord[uint(id)]["create_time"].String()) }) } @@ -1069,7 +1069,7 @@ func Test_DB_TableField(t *testing.T) { if err != nil { gtest.Fatal(err) } else { - gtest.Assert(n, 1) + t.Assert(n, 1) } result, err := db.Table(name).Fields("*").Where("field_int = ?", 2).Select() @@ -1077,7 +1077,7 @@ func Test_DB_TableField(t *testing.T) { gtest.Fatal(err) } - gtest.Assert(result[0], data) + t.Assert(result[0], data) } func Test_DB_Prefix(t *testing.T) { @@ -1087,7 +1087,7 @@ func Test_DB_Prefix(t *testing.T) { createTableWithDb(db, table) defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 10000 result, err := db.Insert(name, g.Map{ "id": id, @@ -1096,14 +1096,14 @@ func Test_DB_Prefix(t *testing.T) { "nickname": fmt.Sprintf(`name_%d`, id), "create_time": gtime.NewFromStr("2018-10-24 10:00:00").String(), }) - gtest.Assert(err, nil) + t.Assert(err, nil) n, e := result.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, 1) + t.Assert(e, nil) + t.Assert(n, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 10000 result, err := db.Replace(name, g.Map{ "id": id, @@ -1112,14 +1112,14 @@ func Test_DB_Prefix(t *testing.T) { "nickname": fmt.Sprintf(`name_%d`, id), "create_time": gtime.NewFromStr("2018-10-24 10:00:01").String(), }) - gtest.Assert(err, nil) + t.Assert(err, nil) n, e := result.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, 2) + t.Assert(e, nil) + t.Assert(n, 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 10000 result, err := db.Save(name, g.Map{ "id": id, @@ -1128,14 +1128,14 @@ func Test_DB_Prefix(t *testing.T) { "nickname": fmt.Sprintf(`name_%d`, id), "create_time": gtime.NewFromStr("2018-10-24 10:00:02").String(), }) - gtest.Assert(err, nil) + t.Assert(err, nil) n, e := result.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, 2) + t.Assert(e, nil) + t.Assert(n, 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 10000 result, err := db.Update(name, g.Map{ "id": id, @@ -1144,24 +1144,24 @@ func Test_DB_Prefix(t *testing.T) { "nickname": fmt.Sprintf(`name_%d`, id), "create_time": gtime.NewFromStr("2018-10-24 10:00:03").String(), }, "id=?", id) - gtest.Assert(err, nil) + t.Assert(err, nil) n, e := result.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, 1) + t.Assert(e, nil) + t.Assert(n, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id := 10000 result, err := db.Delete(name, "id=?", id) - gtest.Assert(err, nil) + t.Assert(err, nil) n, e := result.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, 1) + t.Assert(e, nil) + t.Assert(n, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) for i := 1; i <= SIZE; i++ { array.Append(g.Map{ @@ -1174,17 +1174,17 @@ func Test_DB_Prefix(t *testing.T) { } result, err := db.BatchInsert(name, array.Slice()) - gtest.Assert(err, nil) + t.Assert(err, nil) n, e := result.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, SIZE) + t.Assert(e, nil) + t.Assert(n, SIZE) }) } func Test_Model_InnerJoin(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table1 := createInitTable("user1") table2 := createInitTable("user2") @@ -1201,26 +1201,26 @@ func Test_Model_InnerJoin(t *testing.T) { gtest.Fatal(err) } - gtest.Assert(n, 5) + t.Assert(n, 5) result, err := db.Table(table1+" u1").InnerJoin(table2+" u2", "u1.id = u2.id").OrderBy("u1.id").Select() if err != nil { gtest.Fatal(err) } - gtest.Assert(len(result), 5) + t.Assert(len(result), 5) result, err = db.Table(table1+" u1").InnerJoin(table2+" u2", "u1.id = u2.id").Where("u1.id > ?", 1).OrderBy("u1.id").Select() if err != nil { gtest.Fatal(err) } - gtest.Assert(len(result), 4) + t.Assert(len(result), 4) }) } func Test_Model_LeftJoin(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table1 := createInitTable("user1") table2 := createInitTable("user2") @@ -1236,7 +1236,7 @@ func Test_Model_LeftJoin(t *testing.T) { if err != nil { gtest.Fatal(err) } else { - gtest.Assert(n, 7) + t.Assert(n, 7) } result, err := db.Table(table1+" u1").LeftJoin(table2+" u2", "u1.id = u2.id").Select() @@ -1244,19 +1244,19 @@ func Test_Model_LeftJoin(t *testing.T) { gtest.Fatal(err) } - gtest.Assert(len(result), 10) + t.Assert(len(result), 10) result, err = db.Table(table1+" u1").LeftJoin(table2+" u2", "u1.id = u2.id").Where("u1.id > ? ", 2).Select() if err != nil { gtest.Fatal(err) } - gtest.Assert(len(result), 8) + t.Assert(len(result), 8) }) } func Test_Model_RightJoin(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table1 := createInitTable("user1") table2 := createInitTable("user2") @@ -1273,18 +1273,18 @@ func Test_Model_RightJoin(t *testing.T) { gtest.Fatal(err) } - gtest.Assert(n, 7) + t.Assert(n, 7) result, err := db.Table(table1+" u1").RightJoin(table2+" u2", "u1.id = u2.id").Select() if err != nil { gtest.Fatal(err) } - gtest.Assert(len(result), 10) + t.Assert(len(result), 10) result, err = db.Table(table1+" u1").RightJoin(table2+" u2", "u1.id = u2.id").Where("u1.id > 2").Select() if err != nil { gtest.Fatal(err) } - gtest.Assert(len(result), 1) + t.Assert(len(result), 1) }) } diff --git a/database/gdb/gdb_unit_z_mysql_model_test.go b/database/gdb/gdb_unit_z_mysql_model_test.go index e484e58e3..3a90f6592 100644 --- a/database/gdb/gdb_unit_z_mysql_model_test.go +++ b/database/gdb/gdb_unit_z_mysql_model_test.go @@ -23,7 +23,7 @@ import ( func Test_Model_Insert(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := db.From(table) result, err := user.Filter().Data(g.Map{ "id": 1, @@ -33,9 +33,9 @@ func Test_Model_Insert(t *testing.T) { "nickname": "name_1", "create_time": gtime.Now().String(), }).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.LastInsertId() - gtest.Assert(n, 1) + t.Assert(n, 1) result, err = db.Table(table).Filter().Data(g.Map{ "id": "2", @@ -45,9 +45,9 @@ func Test_Model_Insert(t *testing.T) { "nickname": "name_2", "create_time": gtime.Now().String(), }).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) type User struct { Id int `gconv:"id"` @@ -65,12 +65,12 @@ func Test_Model_Insert(t *testing.T) { Nickname: "name_3", CreateTime: gtime.Now().String(), }).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) value, err := db.Table(table).Fields("passport").Where("id=3").Value() - gtest.Assert(err, nil) - gtest.Assert(value.String(), "t3") + t.Assert(err, nil) + t.Assert(value.String(), "t3") result, err = db.Table(table).Filter().Data(&User{ Id: 4, @@ -80,17 +80,17 @@ func Test_Model_Insert(t *testing.T) { Nickname: "T4", CreateTime: gtime.Now().String(), }).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) value, err = db.Table(table).Fields("passport").Where("id=4").Value() - gtest.Assert(err, nil) - gtest.Assert(value.String(), "t4") + t.Assert(err, nil) + t.Assert(value.String(), "t4") result, err = db.Table(table).Where("id>?", 1).Delete() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = result.RowsAffected() - gtest.Assert(n, 3) + t.Assert(n, 3) }) } @@ -98,7 +98,7 @@ func Test_Model_Insert(t *testing.T) { func Test_Model_InsertIgnore(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := db.Table(table).Filter().Data(g.Map{ "id": 1, "uid": 1, @@ -107,9 +107,9 @@ func Test_Model_InsertIgnore(t *testing.T) { "nickname": "name_1", "create_time": gtime.Now().String(), }).Insert() - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := db.Table(table).Filter().Data(g.Map{ "id": 1, "uid": 1, @@ -118,13 +118,13 @@ func Test_Model_InsertIgnore(t *testing.T) { "nickname": "name_1", "create_time": gtime.Now().String(), }).InsertIgnore() - gtest.Assert(err, nil) + t.Assert(err, nil) }) } func Test_Model_Batch(t *testing.T) { // bacth insert - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) result, err := db.Table(table).Filter().Data(g.List{ @@ -149,41 +149,41 @@ func Test_Model_Batch(t *testing.T) { gtest.Error(err) } n, _ := result.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) }) // batch save - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) result, err := db.Table(table).All() - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) + t.Assert(err, nil) + t.Assert(len(result), SIZE) for _, v := range result { v["nickname"].Set(v["nickname"].String() + v["id"].String()) } r, e := db.Table(table).Data(result).Save() - gtest.Assert(e, nil) + t.Assert(e, nil) n, e := r.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, SIZE*2) + t.Assert(e, nil) + t.Assert(n, SIZE*2) }) // batch replace - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) result, err := db.Table(table).All() - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) + t.Assert(err, nil) + t.Assert(len(result), SIZE) for _, v := range result { v["nickname"].Set(v["nickname"].String() + v["id"].String()) } r, e := db.Table(table).Data(result).Replace() - gtest.Assert(e, nil) + t.Assert(e, nil) n, e := r.RowsAffected() - gtest.Assert(e, nil) - gtest.Assert(n, SIZE*2) + t.Assert(e, nil) + t.Assert(n, SIZE*2) }) } @@ -191,7 +191,7 @@ func Test_Model_Replace(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Data(g.Map{ "id": 1, "passport": "t11", @@ -199,16 +199,16 @@ func Test_Model_Replace(t *testing.T) { "nickname": "T11", "create_time": "2018-10-24 10:00:00", }).Replace() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) }) } func Test_Model_Save(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Data(g.Map{ "id": 1, "passport": "t111", @@ -216,9 +216,9 @@ func Test_Model_Save(t *testing.T) { "nickname": "T111", "create_time": "2018-10-24 10:00:00", }).Save() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) }) } @@ -226,41 +226,41 @@ func Test_Model_Update(t *testing.T) { table := createInitTable() defer dropTable(table) // UPDATE...LIMIT - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Data("nickname", "T100").Order("id desc").Limit(2).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) v1, err := db.Table(table).Fields("nickname").Where("id", 10).Value() - gtest.Assert(err, nil) - gtest.Assert(v1.String(), "T100") + t.Assert(err, nil) + t.Assert(v1.String(), "T100") v2, err := db.Table(table).Fields("nickname").Where("id", 8).Value() - gtest.Assert(err, nil) - gtest.Assert(v2.String(), "name_8") + t.Assert(err, nil) + t.Assert(v2.String(), "name_8") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Data("passport", "user_22").Where("passport=?", "user_2").Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Data("passport", "user_2").Where("passport='user_22'").Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) }) // Update + Data(string) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Data("passport='user_33'").Where("passport='user_3'").Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) }) } @@ -268,22 +268,22 @@ func Test_Model_Clone(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { md := db.Table(table).Where("id IN(?)", g.Slice{1, 3}) count, err := md.Count() - gtest.Assert(err, nil) + t.Assert(err, nil) record, err := md.Order("id DESC").One() - gtest.Assert(err, nil) + t.Assert(err, nil) result, err := md.Order("id ASC").All() - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Assert(count, 2) - gtest.Assert(record["id"].Int(), 3) - gtest.Assert(len(result), 2) - gtest.Assert(result[0]["id"].Int(), 1) - gtest.Assert(result[1]["id"].Int(), 3) + t.Assert(count, 2) + t.Assert(record["id"].Int(), 3) + t.Assert(len(result), 2) + t.Assert(result[0]["id"].Int(), 1) + t.Assert(result[1]["id"].Int(), 3) }) } @@ -291,57 +291,57 @@ func Test_Model_Safe(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { md := db.Table(table).Safe(false).Where("id IN(?)", g.Slice{1, 3}) count, err := md.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 2) + t.Assert(err, nil) + t.Assert(count, 2) md.And("id = ?", 1) count, err = md.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 1) + t.Assert(err, nil) + t.Assert(count, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { md := db.Table(table).Safe(true).Where("id IN(?)", g.Slice{1, 3}) count, err := md.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 2) + t.Assert(err, nil) + t.Assert(count, 2) md.And("id = ?", 1) count, err = md.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 2) + t.Assert(err, nil) + t.Assert(count, 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { md := db.Table(table).Safe().Where("id IN(?)", g.Slice{1, 3}) count, err := md.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 2) + t.Assert(err, nil) + t.Assert(count, 2) md.And("id = ?", 1) count, err = md.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 2) + t.Assert(err, nil) + t.Assert(count, 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { md1 := db.Table(table).Safe() md2 := md1.Where("id in (?)", g.Slice{1, 3}) count, err := md2.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 2) + t.Assert(err, nil) + t.Assert(count, 2) all, err := md2.All() - gtest.Assert(err, nil) - gtest.Assert(len(all), 2) + t.Assert(err, nil) + t.Assert(len(all), 2) all, err = md2.ForPage(1, 10).All() - gtest.Assert(err, nil) - gtest.Assert(len(all), 2) + t.Assert(err, nil) + t.Assert(len(all), 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) @@ -351,34 +351,34 @@ func Test_Model_Safe(t *testing.T) { // 1,3 count, err := md2.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 2) + t.Assert(err, nil) + t.Assert(count, 2) all, err := md2.Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(all), 2) - gtest.Assert(all[0]["id"].Int(), 1) - gtest.Assert(all[1]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(all), 2) + t.Assert(all[0]["id"].Int(), 1) + t.Assert(all[1]["id"].Int(), 3) all, err = md2.ForPage(1, 10).All() - gtest.Assert(err, nil) - gtest.Assert(len(all), 2) + t.Assert(err, nil) + t.Assert(len(all), 2) // 4,5,6 count, err = md3.Count() - gtest.Assert(err, nil) - gtest.Assert(count, 3) + t.Assert(err, nil) + t.Assert(count, 3) all, err = md3.Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(all), 3) - gtest.Assert(all[0]["id"].Int(), 4) - gtest.Assert(all[1]["id"].Int(), 5) - gtest.Assert(all[2]["id"].Int(), 6) + t.Assert(err, nil) + t.Assert(len(all), 3) + t.Assert(all[0]["id"].Int(), 4) + t.Assert(all[1]["id"].Int(), 5) + t.Assert(all[2]["id"].Int(), 6) all, err = md3.ForPage(1, 10).All() - gtest.Assert(err, nil) - gtest.Assert(len(all), 3) + t.Assert(err, nil) + t.Assert(len(all), 3) }) } @@ -386,15 +386,15 @@ func Test_Model_All(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).All() - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) + t.Assert(err, nil) + t.Assert(len(result), SIZE) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id<0").All() - gtest.Assert(result, nil) - gtest.Assert(err, nil) + t.Assert(result, nil) + t.Assert(err, nil) }) } @@ -402,37 +402,37 @@ func Test_Model_FindAll(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).FindAll(5) - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 5) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 5) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Order("id asc").FindAll("id", 8) - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 8) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 8) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Order("id asc").FindAll(g.Slice{3, 9}) - gtest.Assert(err, nil) - gtest.Assert(len(result), 2) - gtest.Assert(result[0]["id"].Int(), 3) - gtest.Assert(result[1]["id"].Int(), 9) + t.Assert(err, nil) + t.Assert(len(result), 2) + t.Assert(result[0]["id"].Int(), 3) + t.Assert(result[1]["id"].Int(), 9) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).FindAll() - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) + t.Assert(err, nil) + t.Assert(len(result), SIZE) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id<0").FindAll() - gtest.Assert(result, nil) - gtest.Assert(err, nil) + t.Assert(result, nil) + t.Assert(err, nil) }) } @@ -440,45 +440,45 @@ func Test_Model_FindAll_GTime(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).FindAll("create_time < ?", gtime.NewFromStr("2000-01-01 00:00:00")) - gtest.Assert(err, nil) - gtest.Assert(len(result), 0) + t.Assert(err, nil) + t.Assert(len(result), 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).FindAll("create_time > ?", gtime.NewFromStr("2000-01-01 00:00:00")) - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) + t.Assert(err, nil) + t.Assert(len(result), SIZE) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := g.NewVar("2000-01-01 00:00:00") result, err := db.Table(table).FindAll("create_time < ?", v) - gtest.Assert(err, nil) - gtest.Assert(len(result), 0) + t.Assert(err, nil) + t.Assert(len(result), 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := g.NewVar("2000-01-01 00:00:00") result, err := db.Table(table).FindAll("create_time > ?", v) - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) + t.Assert(err, nil) + t.Assert(len(result), SIZE) }) } func Test_Model_One(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.Assert(record["nickname"].String(), "name_1") + t.Assert(err, nil) + t.Assert(record["nickname"].String(), "name_1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).Where("id", 0).One() - gtest.Assert(err, nil) - gtest.Assert(record, nil) + t.Assert(err, nil) + t.Assert(record, nil) }) } @@ -486,34 +486,34 @@ func Test_Model_FindOne(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).FindOne(1) - gtest.Assert(err, nil) - gtest.Assert(record["nickname"].String(), "name_1") + t.Assert(err, nil) + t.Assert(record["nickname"].String(), "name_1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).FindOne(3) - gtest.Assert(err, nil) - gtest.Assert(record["nickname"].String(), "name_3") + t.Assert(err, nil) + t.Assert(record["nickname"].String(), "name_3") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).Where("id", 1).FindOne() - gtest.Assert(err, nil) - gtest.Assert(record["nickname"].String(), "name_1") + t.Assert(err, nil) + t.Assert(record["nickname"].String(), "name_1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).FindOne("id", 9) - gtest.Assert(err, nil) - gtest.Assert(record["nickname"].String(), "name_9") + t.Assert(err, nil) + t.Assert(record["nickname"].String(), "name_9") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).Where("id", 0).FindOne() - gtest.Assert(err, nil) - gtest.Assert(record, nil) + t.Assert(err, nil) + t.Assert(record, nil) }) } @@ -521,16 +521,16 @@ func Test_Model_Value(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value, err := db.Table(table).Fields("nickname").Where("id", 1).Value() - gtest.Assert(err, nil) - gtest.Assert(value.String(), "name_1") + t.Assert(err, nil) + t.Assert(value.String(), "name_1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value, err := db.Table(table).Fields("nickname").Where("id", 0).Value() - gtest.Assert(err, nil) - gtest.Assert(value, nil) + t.Assert(err, nil) + t.Assert(value, nil) }) } @@ -538,31 +538,31 @@ func Test_Model_Array(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { all, err := db.Table(table).Where("id", g.Slice{1, 2, 3}).All() - gtest.Assert(err, nil) - gtest.Assert(all.Array("id"), g.Slice{1, 2, 3}) - gtest.Assert(all.Array("nickname"), g.Slice{"name_1", "name_2", "name_3"}) + t.Assert(err, nil) + t.Assert(all.Array("id"), g.Slice{1, 2, 3}) + t.Assert(all.Array("nickname"), g.Slice{"name_1", "name_2", "name_3"}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array, err := db.Table(table).Fields("nickname").Where("id", g.Slice{1, 2, 3}).Array() - gtest.Assert(err, nil) - gtest.Assert(array, g.Slice{"name_1", "name_2", "name_3"}) + t.Assert(err, nil) + t.Assert(array, g.Slice{"name_1", "name_2", "name_3"}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array, err := db.Table(table).Array("nickname", "id", g.Slice{1, 2, 3}) - gtest.Assert(err, nil) - gtest.Assert(array, g.Slice{"name_1", "name_2", "name_3"}) + t.Assert(err, nil) + t.Assert(array, g.Slice{"name_1", "name_2", "name_3"}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array, err := db.Table(table).FindArray("nickname", "id", g.Slice{1, 2, 3}) - gtest.Assert(err, nil) - gtest.Assert(array, g.Slice{"name_1", "name_2", "name_3"}) + t.Assert(err, nil) + t.Assert(array, g.Slice{"name_1", "name_2", "name_3"}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array, err := db.Table(table).FindArray("nickname", g.Slice{1, 2, 3}) - gtest.Assert(err, nil) - gtest.Assert(array, g.Slice{"name_1", "name_2", "name_3"}) + t.Assert(err, nil) + t.Assert(array, g.Slice{"name_1", "name_2", "name_3"}) }) } @@ -570,75 +570,75 @@ func Test_Model_FindValue(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value, err := db.Table(table).FindValue("nickname", 1) - gtest.Assert(err, nil) - gtest.Assert(value.String(), "name_1") + t.Assert(err, nil) + t.Assert(value.String(), "name_1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value, err := db.Table(table).Order("id desc").FindValue("nickname") - gtest.Assert(err, nil) - gtest.Assert(value.String(), "name_10") + t.Assert(err, nil) + t.Assert(value.String(), "name_10") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value, err := db.Table(table).Fields("nickname").Where("id", 1).FindValue() - gtest.Assert(err, nil) - gtest.Assert(value.String(), "name_1") + t.Assert(err, nil) + t.Assert(value.String(), "name_1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value, err := db.Table(table).Fields("nickname").Where("id", 0).FindValue() - gtest.Assert(err, nil) - gtest.Assert(value, nil) + t.Assert(err, nil) + t.Assert(value, nil) }) } func Test_Model_Count(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { count, err := db.Table(table).Count() - gtest.Assert(err, nil) - gtest.Assert(count, SIZE) + t.Assert(err, nil) + t.Assert(count, SIZE) }) } func Test_Model_FindCount(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { count, err := db.Table(table).FindCount(g.Slice{1, 3}) - gtest.Assert(err, nil) - gtest.Assert(count, 2) + t.Assert(err, nil) + t.Assert(count, 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { count, err := db.Table(table).FindCount(g.Slice{1, 300000}) - gtest.Assert(err, nil) - gtest.Assert(count, 1) + t.Assert(err, nil) + t.Assert(count, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { count, err := db.Table(table).FindCount() - gtest.Assert(err, nil) - gtest.Assert(count, SIZE) + t.Assert(err, nil) + t.Assert(count, SIZE) }) } func Test_Model_Select(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Select() - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) + t.Assert(err, nil) + t.Assert(len(result), SIZE) }) } func Test_Model_Struct(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -648,11 +648,11 @@ func Test_Model_Struct(t *testing.T) { } user := new(User) err := db.Table(table).Where("id=1").Struct(user) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_1") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(err, nil) + t.Assert(user.NickName, "name_1") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -662,12 +662,12 @@ func Test_Model_Struct(t *testing.T) { } user := new(User) err := db.Table(table).Where("id=1").Struct(user) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_1") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(err, nil) + t.Assert(user.NickName, "name_1") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") }) // Auto creating struct object. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -677,12 +677,12 @@ func Test_Model_Struct(t *testing.T) { } user := (*User)(nil) err := db.Table(table).Where("id=1").Struct(&user) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_1") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(err, nil) + t.Assert(user.NickName, "name_1") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") }) // Just using Scan. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -695,11 +695,11 @@ func Test_Model_Struct(t *testing.T) { if err != nil { gtest.Error(err) } - gtest.Assert(user.NickName, "name_1") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(user.NickName, "name_1") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") }) // sql.ErrNoRows - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -709,7 +709,7 @@ func Test_Model_Struct(t *testing.T) { } user := new(User) err := db.Table(table).Where("id=-1").Struct(user) - gtest.Assert(err, sql.ErrNoRows) + t.Assert(err, sql.ErrNoRows) }) } @@ -719,7 +719,7 @@ func Test_Model_Struct_CustomType(t *testing.T) { type MyInt int - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id MyInt Passport string @@ -729,9 +729,9 @@ func Test_Model_Struct_CustomType(t *testing.T) { } user := new(User) err := db.Table(table).Where("id=1").Struct(user) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_1") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(err, nil) + t.Assert(user.NickName, "name_1") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") }) } @@ -739,7 +739,7 @@ func Test_Model_Structs(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -752,17 +752,17 @@ func Test_Model_Structs(t *testing.T) { if err != nil { gtest.Error(err) } - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") }) // Auto create struct slice. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -775,17 +775,17 @@ func Test_Model_Structs(t *testing.T) { if err != nil { gtest.Error(err) } - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") }) // Just using Scan. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -798,17 +798,17 @@ func Test_Model_Structs(t *testing.T) { if err != nil { gtest.Error(err) } - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") }) // sql.ErrNoRows - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -818,7 +818,7 @@ func Test_Model_Structs(t *testing.T) { } var users []*User err := db.Table(table).Where("id<0").Structs(&users) - gtest.Assert(err, sql.ErrNoRows) + t.Assert(err, sql.ErrNoRows) }) } @@ -826,7 +826,7 @@ func Test_Model_Scan(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -836,11 +836,11 @@ func Test_Model_Scan(t *testing.T) { } user := new(User) err := db.Table(table).Where("id=1").Scan(user) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_1") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(err, nil) + t.Assert(user.NickName, "name_1") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -850,11 +850,11 @@ func Test_Model_Scan(t *testing.T) { } user := new(User) err := db.Table(table).Where("id=1").Scan(user) - gtest.Assert(err, nil) - gtest.Assert(user.NickName, "name_1") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(err, nil) + t.Assert(user.NickName, "name_1") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -864,17 +864,17 @@ func Test_Model_Scan(t *testing.T) { } var users []User err := db.Table(table).Order("id asc").Scan(&users) - gtest.Assert(err, nil) - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(err, nil) + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -884,18 +884,18 @@ func Test_Model_Scan(t *testing.T) { } var users []*User err := db.Table(table).Order("id asc").Scan(&users) - gtest.Assert(err, nil) - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(err, nil) + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[0].CreateTime.String(), "2018-10-24 10:00:00") }) // sql.ErrNoRows - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Passport string @@ -907,8 +907,8 @@ func Test_Model_Scan(t *testing.T) { users := new([]*User) err1 := db.Table(table).Where("id < 0").Scan(user) err2 := db.Table(table).Where("id < 0").Scan(users) - gtest.Assert(err1, sql.ErrNoRows) - gtest.Assert(err2, sql.ErrNoRows) + t.Assert(err1, sql.ErrNoRows) + t.Assert(err2, sql.ErrNoRows) }) } @@ -916,11 +916,11 @@ func Test_Model_OrderBy(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Order("id DESC").Select() - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) - gtest.Assert(result[0]["nickname"].String(), fmt.Sprintf("name_%d", SIZE)) + t.Assert(err, nil) + t.Assert(len(result), SIZE) + t.Assert(result[0]["nickname"].String(), fmt.Sprintf("name_%d", SIZE)) }) } @@ -928,11 +928,11 @@ func Test_Model_GroupBy(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).GroupBy("id").Select() - gtest.Assert(err, nil) - gtest.Assert(len(result), SIZE) - gtest.Assert(result[0]["nickname"].String(), "name_1") + t.Assert(err, nil) + t.Assert(len(result), SIZE) + t.Assert(result[0]["nickname"].String(), "name_1") }) } @@ -940,11 +940,11 @@ func Test_Model_Data(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Data("nickname=?", "test").Where("id=?", 3).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) }) } @@ -953,161 +953,161 @@ func Test_Model_Where(t *testing.T) { defer dropTable(table) // string - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id=? and nickname=?", 3, "name_3").One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) // slice parameter - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id=? and nickname=?", g.Slice{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) // map like - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(g.Map{ "passport like": "user_1%", }).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 2) - gtest.Assert(result[0].GMap().Get("id"), 1) - gtest.Assert(result[1].GMap().Get("id"), 10) + t.Assert(err, nil) + t.Assert(len(result), 2) + t.Assert(result[0].GMap().Get("id"), 1) + t.Assert(result[1].GMap().Get("id"), 10) }) // map + slice parameter - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(g.Map{ "id": g.Slice{1, 2, 3}, "passport": g.Slice{"user_2", "user_3"}, }).And("id=? and nickname=?", g.Slice{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(g.Map{ "id": g.Slice{1, 2, 3}, "passport": g.Slice{"user_2", "user_3"}, }).Or("nickname=?", g.Slice{"name_4"}).And("id", 3).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id=3", g.Slice{}).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id=?", g.Slice{3}).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id", 3).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id", 3).Where("nickname", "name_3").One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id", 3).And("nickname", "name_3").One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id", 30).Or("nickname", "name_3").One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id", 30).Or("nickname", "name_3").And("id>?", 1).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id", 30).Or("nickname", "name_3").And("id>", 1).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // slice - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id=? AND nickname=?", g.Slice{3, "name_3"}...).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id=? AND nickname=?", g.Slice{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("passport like ? and nickname like ?", g.Slice{"user_3", "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(g.Map{"id": 3, "nickname": "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // map key operator - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(g.Map{"id>": 1, "id<": 3}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 2) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 2) }) // gmap.Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(gmap.NewFrom(g.MapAnyAny{"id": 3, "nickname": "name_3"})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // gmap.Map key operator - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(gmap.NewFrom(g.MapAnyAny{"id>": 1, "id<": 3})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 2) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 2) }) // list map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(gmap.NewListMapFrom(g.MapAnyAny{"id": 3, "nickname": "name_3"})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // list map key operator - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(gmap.NewListMapFrom(g.MapAnyAny{"id>": 1, "id<": 3})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 2) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 2) }) // tree map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(gmap.NewTreeMapFrom(gutil.ComparatorString, g.MapAnyAny{"id": 3, "nickname": "name_3"})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // tree map key operator - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(gmap.NewTreeMapFrom(gutil.ComparatorString, g.MapAnyAny{"id>": 1, "id<": 3})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 2) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 2) }) // complicated where 1 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //db.SetDebug(true) conditions := g.Map{ "nickname like ?": "%name%", @@ -1117,12 +1117,12 @@ func Test_Model_Where(t *testing.T) { "id": g.Slice{1, 2, 3}, } result, err := db.Table(table).Where(conditions).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) }) // complicated where 2 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //db.SetDebug(true) conditions := g.Map{ "nickname like ?": "%name%", @@ -1132,51 +1132,51 @@ func Test_Model_Where(t *testing.T) { "id in(?)": g.Slice{1, 2, 3}, } result, err := db.Table(table).Where(conditions).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) }) // struct - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int `json:"id"` Nickname string `gconv:"nickname"` } result, err := db.Table(table).Where(User{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) result, err = db.Table(table).Where(&User{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // slice single - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("id IN(?)", g.Slice{1, 3}).Order("id ASC").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 2) - gtest.Assert(result[0]["id"].Int(), 1) - gtest.Assert(result[1]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 2) + t.Assert(result[0]["id"].Int(), 1) + t.Assert(result[1]["id"].Int(), 3) }) // slice + string - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where("nickname=? AND id IN(?)", "name_3", g.Slice{1, 3}).Order("id ASC").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 3) }) // slice + map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Where(g.Map{ "id": g.Slice{1, 3}, "nickname": "name_3", }).Order("id ASC").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 3) }) // slice + struct - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Ids []int `json:"id"` Nickname string `gconv:"nickname"` @@ -1185,9 +1185,9 @@ func Test_Model_Where(t *testing.T) { Ids: []int{1, 3}, Nickname: "name_3", }).Order("id ASC").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 3) }) } @@ -1195,17 +1195,17 @@ func Test_Model_Where_ISNULL_1(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //db.SetDebug(true) result, err := db.Table(table).Data("nickname", nil).Where("id", 2).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("nickname", nil).One() - gtest.Assert(err, nil) - gtest.Assert(one.IsEmpty(), false) - gtest.Assert(one["id"], 2) + t.Assert(err, nil) + t.Assert(one.IsEmpty(), false) + t.Assert(one["id"], 2) }) } @@ -1214,7 +1214,7 @@ func Test_Model_Where_ISNULL_2(t *testing.T) { defer dropTable(table) // complicated one. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //db.SetDebug(true) conditions := g.Map{ "nickname like ?": "%name%", @@ -1224,9 +1224,9 @@ func Test_Model_Where_ISNULL_2(t *testing.T) { "id": g.Slice{1, 2, 3}, } result, err := db.Table(table).WherePri(conditions).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) }) } func Test_Model_WherePri(t *testing.T) { @@ -1234,176 +1234,176 @@ func Test_Model_WherePri(t *testing.T) { defer dropTable(table) // primary key - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { one, err := db.Table(table).WherePri(3).One() - gtest.Assert(err, nil) - gtest.AssertNE(one, nil) - gtest.Assert(one["id"].Int(), 3) + t.Assert(err, nil) + t.AssertNE(one, nil) + t.Assert(one["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { all, err := db.Table(table).WherePri(g.Slice{3, 9}).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(all), 2) - gtest.Assert(all[0]["id"].Int(), 3) - gtest.Assert(all[1]["id"].Int(), 9) + t.Assert(err, nil) + t.Assert(len(all), 2) + t.Assert(all[0]["id"].Int(), 3) + t.Assert(all[1]["id"].Int(), 9) }) // string - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id=? and nickname=?", 3, "name_3").One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) // slice parameter - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id=? and nickname=?", g.Slice{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) // map like - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(g.Map{ "passport like": "user_1%", }).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 2) - gtest.Assert(result[0].GMap().Get("id"), 1) - gtest.Assert(result[1].GMap().Get("id"), 10) + t.Assert(err, nil) + t.Assert(len(result), 2) + t.Assert(result[0].GMap().Get("id"), 1) + t.Assert(result[1].GMap().Get("id"), 10) }) // map + slice parameter - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(g.Map{ "id": g.Slice{1, 2, 3}, "passport": g.Slice{"user_2", "user_3"}, }).And("id=? and nickname=?", g.Slice{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(g.Map{ "id": g.Slice{1, 2, 3}, "passport": g.Slice{"user_2", "user_3"}, }).Or("nickname=?", g.Slice{"name_4"}).And("id", 3).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id=3", g.Slice{}).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id=?", g.Slice{3}).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id", 3).One() - gtest.Assert(err, nil) - gtest.AssertGT(len(result), 0) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.AssertGT(len(result), 0) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id", 3).WherePri("nickname", "name_3").One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id", 3).And("nickname", "name_3").One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id", 30).Or("nickname", "name_3").One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id", 30).Or("nickname", "name_3").And("id>?", 1).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id", 30).Or("nickname", "name_3").And("id>", 1).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // slice - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id=? AND nickname=?", g.Slice{3, "name_3"}...).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id=? AND nickname=?", g.Slice{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("passport like ? and nickname like ?", g.Slice{"user_3", "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(g.Map{"id": 3, "nickname": "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // map key operator - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(g.Map{"id>": 1, "id<": 3}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 2) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 2) }) // gmap.Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(gmap.NewFrom(g.MapAnyAny{"id": 3, "nickname": "name_3"})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // gmap.Map key operator - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(gmap.NewFrom(g.MapAnyAny{"id>": 1, "id<": 3})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 2) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 2) }) // list map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(gmap.NewListMapFrom(g.MapAnyAny{"id": 3, "nickname": "name_3"})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // list map key operator - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(gmap.NewListMapFrom(g.MapAnyAny{"id>": 1, "id<": 3})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 2) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 2) }) // tree map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(gmap.NewTreeMapFrom(gutil.ComparatorString, g.MapAnyAny{"id": 3, "nickname": "name_3"})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // tree map key operator - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(gmap.NewTreeMapFrom(gutil.ComparatorString, g.MapAnyAny{"id>": 1, "id<": 3})).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 2) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 2) }) // complicated where 1 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //db.SetDebug(true) conditions := g.Map{ "nickname like ?": "%name%", @@ -1413,12 +1413,12 @@ func Test_Model_WherePri(t *testing.T) { "id": g.Slice{1, 2, 3}, } result, err := db.Table(table).WherePri(conditions).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) }) // complicated where 2 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //db.SetDebug(true) conditions := g.Map{ "nickname like ?": "%name%", @@ -1428,51 +1428,51 @@ func Test_Model_WherePri(t *testing.T) { "id in(?)": g.Slice{1, 2, 3}, } result, err := db.Table(table).WherePri(conditions).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"].Int(), 1) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"].Int(), 1) }) // struct - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int `json:"id"` Nickname string `gconv:"nickname"` } result, err := db.Table(table).WherePri(User{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) result, err = db.Table(table).WherePri(&User{3, "name_3"}).One() - gtest.Assert(err, nil) - gtest.Assert(result["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(result["id"].Int(), 3) }) // slice single - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("id IN(?)", g.Slice{1, 3}).Order("id ASC").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 2) - gtest.Assert(result[0]["id"].Int(), 1) - gtest.Assert(result[1]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 2) + t.Assert(result[0]["id"].Int(), 1) + t.Assert(result[1]["id"].Int(), 3) }) // slice + string - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri("nickname=? AND id IN(?)", "name_3", g.Slice{1, 3}).Order("id ASC").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 3) }) // slice + map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).WherePri(g.Map{ "id": g.Slice{1, 3}, "nickname": "name_3", }).Order("id ASC").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 3) }) // slice + struct - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Ids []int `json:"id"` Nickname string `gconv:"nickname"` @@ -1481,9 +1481,9 @@ func Test_Model_WherePri(t *testing.T) { Ids: []int{1, 3}, Nickname: "name_3", }).Order("id ASC").All() - gtest.Assert(err, nil) - gtest.Assert(len(result), 1) - gtest.Assert(result[0]["id"].Int(), 3) + t.Assert(err, nil) + t.Assert(len(result), 1) + t.Assert(result[0]["id"].Int(), 3) }) } @@ -1492,18 +1492,18 @@ func Test_Model_Delete(t *testing.T) { defer dropTable(table) // DELETE...LIMIT - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Limit(2).Delete() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Delete() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, SIZE-2) + t.Assert(n, SIZE-2) }) } @@ -1512,10 +1512,10 @@ func Test_Model_Offset(t *testing.T) { defer dropTable(table) result, err := db.Table(table).Limit(2).Offset(5).Order("id").Select() - gtest.Assert(err, nil) - gtest.Assert(len(result), 2) - gtest.Assert(result[0]["id"], 6) - gtest.Assert(result[1]["id"], 7) + t.Assert(err, nil) + t.Assert(len(result), 2) + t.Assert(result[0]["id"], 6) + t.Assert(result[1]["id"], 7) } func Test_Model_ForPage(t *testing.T) { @@ -1523,15 +1523,15 @@ func Test_Model_ForPage(t *testing.T) { defer dropTable(table) result, err := db.Table(table).ForPage(3, 3).Order("id").Select() - gtest.Assert(err, nil) - gtest.Assert(len(result), 3) - gtest.Assert(result[0]["id"], 7) - gtest.Assert(result[1]["id"], 8) + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"], 7) + t.Assert(result[1]["id"], 8) } func Test_Model_Option_Map(t *testing.T) { // Insert - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) r, err := db.Table(table).Fields("id, passport").Data(g.Map{ @@ -1540,16 +1540,16 @@ func Test_Model_Option_Map(t *testing.T) { "password": "1", "nickname": "1", }).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.AssertNE(one["password"].String(), "1") - gtest.AssertNE(one["nickname"].String(), "1") - gtest.Assert(one["passport"].String(), "1") + t.Assert(err, nil) + t.AssertNE(one["password"].String(), "1") + t.AssertNE(one["nickname"].String(), "1") + t.Assert(one["passport"].String(), "1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) r, err := db.Table(table).Option(gdb.OPTION_OMITEMPTY).Data(g.Map{ @@ -1558,18 +1558,18 @@ func Test_Model_Option_Map(t *testing.T) { "password": 0, "nickname": "1", }).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.AssertNE(one["passport"].String(), "0") - gtest.AssertNE(one["password"].String(), "0") - gtest.Assert(one["nickname"].String(), "1") + t.Assert(err, nil) + t.AssertNE(one["passport"].String(), "0") + t.AssertNE(one["password"].String(), "0") + t.Assert(one["nickname"].String(), "1") }) // Replace - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) _, err := db.Table(table).Option(gdb.OPTION_OMITEMPTY).Data(g.Map{ @@ -1578,16 +1578,16 @@ func Test_Model_Option_Map(t *testing.T) { "password": 0, "nickname": "1", }).Replace() - gtest.Assert(err, nil) + t.Assert(err, nil) one, err := db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.AssertNE(one["passport"].String(), "0") - gtest.AssertNE(one["password"].String(), "0") - gtest.Assert(one["nickname"].String(), "1") + t.Assert(err, nil) + t.AssertNE(one["passport"].String(), "0") + t.AssertNE(one["password"].String(), "0") + t.Assert(one["nickname"].String(), "1") }) // Save - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) r, err := db.Table(table).Fields("id, passport").Data(g.Map{ @@ -1596,16 +1596,16 @@ func Test_Model_Option_Map(t *testing.T) { "password": "1", "nickname": "1", }).Save() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.AssertNE(one["password"].String(), "1") - gtest.AssertNE(one["nickname"].String(), "1") - gtest.Assert(one["passport"].String(), "1") + t.Assert(err, nil) + t.AssertNE(one["password"].String(), "1") + t.AssertNE(one["nickname"].String(), "1") + t.Assert(one["passport"].String(), "1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) _, err := db.Table(table).Option(gdb.OPTION_OMITEMPTY).Data(g.Map{ @@ -1614,12 +1614,12 @@ func Test_Model_Option_Map(t *testing.T) { "password": 0, "nickname": "1", }).Save() - gtest.Assert(err, nil) + t.Assert(err, nil) one, err := db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.AssertNE(one["passport"].String(), "0") - gtest.AssertNE(one["password"].String(), "0") - gtest.Assert(one["nickname"].String(), "1") + t.Assert(err, nil) + t.AssertNE(one["passport"].String(), "0") + t.AssertNE(one["password"].String(), "0") + t.Assert(one["nickname"].String(), "1") _, err = db.Table(table).Data(g.Map{ "id": 1, @@ -1627,34 +1627,34 @@ func Test_Model_Option_Map(t *testing.T) { "password": 0, "nickname": "1", }).Save() - gtest.Assert(err, nil) + t.Assert(err, nil) one, err = db.Table(table).Where("id", 1).One() - gtest.Assert(err, nil) - gtest.Assert(one["passport"].String(), "0") - gtest.Assert(one["password"].String(), "0") - gtest.Assert(one["nickname"].String(), "1") + t.Assert(err, nil) + t.Assert(one["passport"].String(), "0") + t.Assert(one["password"].String(), "0") + t.Assert(one["nickname"].String(), "1") }) // Update - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) r, err := db.Table(table).Data(g.Map{"nickname": ""}).Where("id", 1).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) _, err = db.Table(table).Option(gdb.OPTION_OMITEMPTY).Data(g.Map{"nickname": ""}).Where("id", 2).Update() - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) r, err = db.Table(table).OmitEmpty().Data(g.Map{"nickname": "", "password": "123"}).Where("id", 3).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) _, err = db.Table(table).OmitEmpty().Fields("nickname").Data(g.Map{"nickname": "", "password": "123"}).Where("id", 4).Update() - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) r, err = db.Table(table).OmitEmpty(). Fields("password").Data(g.Map{ @@ -1662,20 +1662,20 @@ func Test_Model_Option_Map(t *testing.T) { "passport": "123", "password": "456", }).Where("id", 5).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ = r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("id", 5).One() - gtest.Assert(err, nil) - gtest.Assert(one["password"], "456") - gtest.AssertNE(one["passport"].String(), "") - gtest.AssertNE(one["passport"].String(), "123") + t.Assert(err, nil) + t.Assert(one["password"], "456") + t.AssertNE(one["passport"].String(), "") + t.AssertNE(one["passport"].String(), "123") }) } func Test_Model_Option_List(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) r, err := db.Table(table).Fields("id, password").Data(g.List{ @@ -1692,24 +1692,24 @@ func Test_Model_Option_List(t *testing.T) { "nickname": "2", }, }).Save() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) list, err := db.Table(table).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(list), 2) - gtest.Assert(list[0]["id"].String(), "1") - gtest.Assert(list[0]["nickname"].String(), "") - gtest.Assert(list[0]["passport"].String(), "") - gtest.Assert(list[0]["password"].String(), "1") + t.Assert(err, nil) + t.Assert(len(list), 2) + t.Assert(list[0]["id"].String(), "1") + t.Assert(list[0]["nickname"].String(), "") + t.Assert(list[0]["passport"].String(), "") + t.Assert(list[0]["password"].String(), "1") - gtest.Assert(list[1]["id"].String(), "2") - gtest.Assert(list[1]["nickname"].String(), "") - gtest.Assert(list[1]["passport"].String(), "") - gtest.Assert(list[1]["password"].String(), "2") + t.Assert(list[1]["id"].String(), "2") + t.Assert(list[1]["nickname"].String(), "") + t.Assert(list[1]["passport"].String(), "") + t.Assert(list[1]["password"].String(), "2") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createTable() defer dropTable(table) r, err := db.Table(table).OmitEmpty().Fields("id, password").Data(g.List{ @@ -1726,45 +1726,45 @@ func Test_Model_Option_List(t *testing.T) { "nickname": "2", }, }).Save() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 2) + t.Assert(n, 2) list, err := db.Table(table).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(list), 2) - gtest.Assert(list[0]["id"].String(), "1") - gtest.Assert(list[0]["nickname"].String(), "") - gtest.Assert(list[0]["passport"].String(), "") - gtest.Assert(list[0]["password"].String(), "0") + t.Assert(err, nil) + t.Assert(len(list), 2) + t.Assert(list[0]["id"].String(), "1") + t.Assert(list[0]["nickname"].String(), "") + t.Assert(list[0]["passport"].String(), "") + t.Assert(list[0]["password"].String(), "0") - gtest.Assert(list[1]["id"].String(), "2") - gtest.Assert(list[1]["nickname"].String(), "") - gtest.Assert(list[1]["passport"].String(), "") - gtest.Assert(list[1]["password"].String(), "2") + t.Assert(list[1]["id"].String(), "2") + t.Assert(list[1]["nickname"].String(), "") + t.Assert(list[1]["passport"].String(), "") + t.Assert(list[1]["password"].String(), "2") }) } func Test_Model_Option_Where(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) r, err := db.Table(table).OmitEmpty().Data("nickname", 1).Where(g.Map{"id": 0, "passport": ""}).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, SIZE) + t.Assert(n, SIZE) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) r, err := db.Table(table).OmitEmpty().Data("nickname", 1).Where(g.Map{"id": 1, "passport": ""}).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) v, err := db.Table(table).Where("id", 1).Fields("nickname").Value() - gtest.Assert(err, nil) - gtest.Assert(v.String(), "1") + t.Assert(err, nil) + t.Assert(v.String(), "1") }) } @@ -1772,33 +1772,33 @@ func Test_Model_FieldsEx(t *testing.T) { table := createInitTable() defer dropTable(table) // Select. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r, err := db.Table(table).FieldsEx("create_time, id").Where("id in (?)", g.Slice{1, 2}).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(r), 2) - gtest.Assert(len(r[0]), 3) - gtest.Assert(r[0]["id"], "") - gtest.Assert(r[0]["passport"], "user_1") - gtest.Assert(r[0]["password"], "pass_1") - gtest.Assert(r[0]["nickname"], "name_1") - gtest.Assert(r[0]["create_time"], "") - gtest.Assert(r[1]["id"], "") - gtest.Assert(r[1]["passport"], "user_2") - gtest.Assert(r[1]["password"], "pass_2") - gtest.Assert(r[1]["nickname"], "name_2") - gtest.Assert(r[1]["create_time"], "") + t.Assert(err, nil) + t.Assert(len(r), 2) + t.Assert(len(r[0]), 3) + t.Assert(r[0]["id"], "") + t.Assert(r[0]["passport"], "user_1") + t.Assert(r[0]["password"], "pass_1") + t.Assert(r[0]["nickname"], "name_1") + t.Assert(r[0]["create_time"], "") + t.Assert(r[1]["id"], "") + t.Assert(r[1]["passport"], "user_2") + t.Assert(r[1]["password"], "pass_2") + t.Assert(r[1]["nickname"], "name_2") + t.Assert(r[1]["create_time"], "") }) // Update. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r, err := db.Table(table).FieldsEx("password").Data(g.Map{"nickname": "123", "password": "456"}).Where("id", 3).Update() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("id", 3).One() - gtest.Assert(err, nil) - gtest.Assert(one["nickname"], "123") - gtest.AssertNE(one["password"], "456") + t.Assert(err, nil) + t.Assert(one["nickname"], "123") + t.AssertNE(one["password"], "456") }) } @@ -1806,9 +1806,9 @@ func Test_Model_FieldsStr(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { - gtest.Assert(db.Table(table).FieldsStr(), "id,passport,password,nickname,create_time") - gtest.Assert(db.Table(table).FieldsStr("a."), "a.id,a.passport,a.password,a.nickname,a.create_time") + gtest.C(t, func(t *gtest.T) { + t.Assert(db.Table(table).FieldsStr(), "id,passport,password,nickname,create_time") + t.Assert(db.Table(table).FieldsStr("a."), "a.id,a.passport,a.password,a.nickname,a.create_time") }) } @@ -1816,9 +1816,9 @@ func Test_Model_FieldsExStr(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { - gtest.Assert(db.Table(table).FieldsExStr("create_time,nickname"), "id,passport,password") - gtest.Assert(db.Table(table).FieldsExStr("create_time,nickname", "a."), "a.id,a.passport,a.password") + gtest.C(t, func(t *gtest.T) { + t.Assert(db.Table(table).FieldsExStr("create_time,nickname"), "id,passport,password") + t.Assert(db.Table(table).FieldsExStr("create_time,nickname", "a."), "a.id,a.passport,a.password") }) } @@ -1828,35 +1828,35 @@ func Test_Model_Prefix(t *testing.T) { createInitTableWithDb(db, PREFIX1+table) defer dropTable(PREFIX1 + table) // Select. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r, err := db.Table(table).Where("id in (?)", g.Slice{1, 2}).Order("id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(r), 2) - gtest.Assert(r[0]["id"], "1") - gtest.Assert(r[1]["id"], "2") + t.Assert(err, nil) + t.Assert(len(r), 2) + t.Assert(r[0]["id"], "1") + t.Assert(r[1]["id"], "2") }) // Select with alias. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r, err := db.Table(table+" as u").Where("u.id in (?)", g.Slice{1, 2}).Order("u.id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(r), 2) - gtest.Assert(r[0]["id"], "1") - gtest.Assert(r[1]["id"], "2") + t.Assert(err, nil) + t.Assert(len(r), 2) + t.Assert(r[0]["id"], "1") + t.Assert(r[1]["id"], "2") }) // Select with alias and join statement. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r, err := db.Table(table+" as u1").LeftJoin(table+" as u2", "u2.id=u1.id").Where("u1.id in (?)", g.Slice{1, 2}).Order("u1.id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(r), 2) - gtest.Assert(r[0]["id"], "1") - gtest.Assert(r[1]["id"], "2") + t.Assert(err, nil) + t.Assert(len(r), 2) + t.Assert(r[0]["id"], "1") + t.Assert(r[1]["id"], "2") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { r, err := db.Table(table).As("u1").LeftJoin(table+" as u2", "u2.id=u1.id").Where("u1.id in (?)", g.Slice{1, 2}).Order("u1.id asc").All() - gtest.Assert(err, nil) - gtest.Assert(len(r), 2) - gtest.Assert(r[0]["id"], "1") - gtest.Assert(r[1]["id"], "2") + t.Assert(err, nil) + t.Assert(len(r), 2) + t.Assert(r[0]["id"], "1") + t.Assert(r[1]["id"], "2") }) } @@ -1877,47 +1877,47 @@ func Test_Model_Schema1(t *testing.T) { db.SetSchema(SCHEMA1) }() // Method. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { db.SetSchema(SCHEMA1) r, err := db.Table(table).Update(g.Map{"nickname": "name_100"}, "id=1") - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) v, err := db.Table(table).Value("nickname", "id=1") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_100") + t.Assert(err, nil) + t.Assert(v.String(), "name_100") db.SetSchema(SCHEMA2) v, err = db.Table(table).Value("nickname", "id=1") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_1") + t.Assert(err, nil) + t.Assert(v.String(), "name_1") }) // Model. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v, err := db.Table(table).Schema(SCHEMA1).Value("nickname", "id=2") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_2") + t.Assert(err, nil) + t.Assert(v.String(), "name_2") r, err := db.Table(table).Schema(SCHEMA1).Update(g.Map{"nickname": "name_200"}, "id=2") - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) v, err = db.Table(table).Schema(SCHEMA1).Value("nickname", "id=2") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_200") + t.Assert(err, nil) + t.Assert(v.String(), "name_200") v, err = db.Table(table).Schema(SCHEMA2).Value("nickname", "id=2") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_2") + t.Assert(err, nil) + t.Assert(v.String(), "name_2") v, err = db.Table(table).Schema(SCHEMA1).Value("nickname", "id=2") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_200") + t.Assert(err, nil) + t.Assert(v.String(), "name_200") }) // Model. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := 1000 _, err := db.Table(table).Schema(SCHEMA1).Filter().Insert(g.Map{ "id": i, @@ -1927,15 +1927,15 @@ func Test_Model_Schema1(t *testing.T) { "create_time": gtime.NewFromStr("2018-10-24 10:00:00").String(), "none-exist-field": 1, }) - gtest.Assert(err, nil) + t.Assert(err, nil) v, err := db.Table(table).Schema(SCHEMA1).Value("nickname", "id=?", i) - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_1000") + t.Assert(err, nil) + t.Assert(v.String(), "name_1000") v, err = db.Table(table).Schema(SCHEMA2).Value("nickname", "id=?", i) - gtest.Assert(err, nil) - gtest.Assert(v.String(), "") + t.Assert(err, nil) + t.Assert(v.String(), "") }) } @@ -1956,30 +1956,30 @@ func Test_Model_Schema2(t *testing.T) { db.SetSchema(SCHEMA1) }() // Schema. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v, err := db.Schema(SCHEMA1).Table(table).Value("nickname", "id=2") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_2") + t.Assert(err, nil) + t.Assert(v.String(), "name_2") r, err := db.Schema(SCHEMA1).Table(table).Update(g.Map{"nickname": "name_200"}, "id=2") - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) v, err = db.Schema(SCHEMA1).Table(table).Value("nickname", "id=2") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_200") + t.Assert(err, nil) + t.Assert(v.String(), "name_200") v, err = db.Schema(SCHEMA2).Table(table).Value("nickname", "id=2") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_2") + t.Assert(err, nil) + t.Assert(v.String(), "name_2") v, err = db.Schema(SCHEMA1).Table(table).Value("nickname", "id=2") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_200") + t.Assert(err, nil) + t.Assert(v.String(), "name_200") }) // Schema. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { i := 1000 _, err := db.Schema(SCHEMA1).Table(table).Filter().Insert(g.Map{ "id": i, @@ -1989,14 +1989,14 @@ func Test_Model_Schema2(t *testing.T) { "create_time": gtime.NewFromStr("2018-10-24 10:00:00").String(), "none-exist-field": 1, }) - gtest.Assert(err, nil) + t.Assert(err, nil) v, err := db.Schema(SCHEMA1).Table(table).Value("nickname", "id=?", i) - gtest.Assert(err, nil) - gtest.Assert(v.String(), "name_1000") + t.Assert(err, nil) + t.Assert(v.String(), "name_1000") v, err = db.Schema(SCHEMA2).Table(table).Value("nickname", "id=?", i) - gtest.Assert(err, nil) - gtest.Assert(v.String(), "") + t.Assert(err, nil) + t.Assert(v.String(), "") }) } diff --git a/database/gdb/gdb_unit_z_mysql_struct_test.go b/database/gdb/gdb_unit_z_mysql_struct_test.go index 8e7e3ea04..fb71a8344 100644 --- a/database/gdb/gdb_unit_z_mysql_struct_test.go +++ b/database/gdb/gdb_unit_z_mysql_struct_test.go @@ -18,7 +18,7 @@ func Test_Model_Inherit_Insert(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Base struct { Id int `json:"id"` Uid int `json:"uid"` @@ -40,12 +40,12 @@ func Test_Model_Inherit_Insert(t *testing.T) { CreateTime: gtime.Now().String(), }, }).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) value, err := db.Table(table).Fields("passport").Where("id=100").Value() - gtest.Assert(err, nil) - gtest.Assert(value.String(), "john-test") + t.Assert(err, nil) + t.Assert(value.String(), "john-test") }) } @@ -53,7 +53,7 @@ func Test_Model_Inherit_MapToStruct(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Ids struct { Id int `json:"id"` Uid int `json:"uid"` @@ -77,21 +77,21 @@ func Test_Model_Inherit_MapToStruct(t *testing.T) { "create_time": gtime.Now().String(), } result, err := db.Table(table).Filter().Data(data).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table(table).Where("id=100").One() - gtest.Assert(err, nil) + t.Assert(err, nil) user := new(User) - gtest.Assert(one.Struct(user), nil) - gtest.Assert(user.Id, data["id"]) - gtest.Assert(user.Passport, data["passport"]) - gtest.Assert(user.Password, data["password"]) - gtest.Assert(user.Nickname, data["nickname"]) - gtest.Assert(user.CreateTime, data["create_time"]) + t.Assert(one.Struct(user), nil) + t.Assert(user.Id, data["id"]) + t.Assert(user.Passport, data["passport"]) + t.Assert(user.Password, data["password"]) + t.Assert(user.Nickname, data["nickname"]) + t.Assert(user.CreateTime, data["create_time"]) }) diff --git a/database/gdb/gdb_unit_z_mysql_transaction_test.go b/database/gdb/gdb_unit_z_mysql_transaction_test.go index c3656c9b1..a90849abe 100644 --- a/database/gdb/gdb_unit_z_mysql_transaction_test.go +++ b/database/gdb/gdb_unit_z_mysql_transaction_test.go @@ -102,7 +102,7 @@ func Test_TX_Prepare(t *testing.T) { if err != nil { gtest.Error(err) } - gtest.Assert(array[0], "100") + t.Assert(array[0], "100") if err := rows.Close(); err != nil { gtest.Error(err) } @@ -115,7 +115,7 @@ func Test_TX_Insert(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -144,7 +144,7 @@ func Test_TX_Insert(t *testing.T) { if n, err := tx.Table(table).Count(); err != nil { gtest.Error(err) } else { - gtest.Assert(n, 2) + t.Assert(n, 2) } if err := tx.Commit(); err != nil { @@ -158,7 +158,7 @@ func Test_TX_BatchInsert(t *testing.T) { table := createTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -187,7 +187,7 @@ func Test_TX_BatchInsert(t *testing.T) { if n, err := db.Table(table).Count(); err != nil { gtest.Error(err) } else { - gtest.Assert(n, 2) + t.Assert(n, 2) } }) } @@ -196,7 +196,7 @@ func Test_TX_BatchReplace(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -225,12 +225,12 @@ func Test_TX_BatchReplace(t *testing.T) { if n, err := db.Table(table).Count(); err != nil { gtest.Error(err) } else { - gtest.Assert(n, SIZE) + t.Assert(n, SIZE) } if value, err := db.Table(table).Fields("password").Where("id", 2).Value(); err != nil { gtest.Error(err) } else { - gtest.Assert(value.String(), "PASS_2") + t.Assert(value.String(), "PASS_2") } }) } @@ -239,7 +239,7 @@ func Test_TX_BatchSave(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -262,13 +262,13 @@ func Test_TX_BatchSave(t *testing.T) { if n, err := db.Table(table).Count(); err != nil { gtest.Error(err) } else { - gtest.Assert(n, SIZE) + t.Assert(n, SIZE) } if value, err := db.Table(table).Fields("password").Where("id", 4).Value(); err != nil { gtest.Error(err) } else { - gtest.Assert(value.String(), "PASS_4") + t.Assert(value.String(), "PASS_4") } }) } @@ -277,7 +277,7 @@ func Test_TX_Replace(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -297,7 +297,7 @@ func Test_TX_Replace(t *testing.T) { if value, err := db.Table(table).Fields("nickname").Where("id", 1).Value(); err != nil { gtest.Error(err) } else { - gtest.Assert(value.String(), "name_1") + t.Assert(value.String(), "name_1") } }) @@ -307,7 +307,7 @@ func Test_TX_Save(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -327,7 +327,7 @@ func Test_TX_Save(t *testing.T) { if value, err := db.Table(table).Fields("nickname").Where("id", 1).Value(); err != nil { gtest.Error(err) } else { - gtest.Assert(value.String(), "NAME_1") + t.Assert(value.String(), "NAME_1") } }) } @@ -336,7 +336,7 @@ func Test_TX_Update(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -345,18 +345,18 @@ func Test_TX_Update(t *testing.T) { gtest.Error(err) } else { n, _ := result.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) } if err := tx.Commit(); err != nil { gtest.Error(err) } _, err = tx.Table(table).Fields("create_time").Where("id", 3).Value() - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) if value, err := db.Table(table).Fields("create_time").Where("id", 3).Value(); err != nil { gtest.Error(err) } else { - gtest.Assert(value.String(), "2019-10-24 10:00:00") + t.Assert(value.String(), "2019-10-24 10:00:00") } }) } @@ -365,7 +365,7 @@ func Test_TX_GetAll(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -373,7 +373,7 @@ func Test_TX_GetAll(t *testing.T) { if result, err := tx.GetAll(fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 1); err != nil { gtest.Error(err) } else { - gtest.Assert(len(result), 1) + t.Assert(len(result), 1) } if err := tx.Commit(); err != nil { gtest.Error(err) @@ -385,7 +385,7 @@ func Test_TX_GetOne(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -396,7 +396,7 @@ func Test_TX_GetOne(t *testing.T) { if record == nil { gtest.Error("FAIL") } - gtest.Assert(record["nickname"].String(), "name_2") + t.Assert(record["nickname"].String(), "name_2") } if err := tx.Commit(); err != nil { gtest.Error(err) @@ -408,7 +408,7 @@ func Test_TX_GetValue(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -416,7 +416,7 @@ func Test_TX_GetValue(t *testing.T) { if value, err := tx.GetValue(fmt.Sprintf("SELECT id FROM %s WHERE passport=?", table), "user_3"); err != nil { gtest.Error(err) } else { - gtest.Assert(value.Int(), 3) + t.Assert(value.Int(), 3) } if err := tx.Commit(); err != nil { gtest.Error(err) @@ -429,7 +429,7 @@ func Test_TX_GetCount(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -437,7 +437,7 @@ func Test_TX_GetCount(t *testing.T) { if count, err := tx.GetCount("SELECT * FROM " + table); err != nil { gtest.Error(err) } else { - gtest.Assert(count, SIZE) + t.Assert(count, SIZE) } if err := tx.Commit(); err != nil { gtest.Error(err) @@ -449,7 +449,7 @@ func Test_TX_GetStruct(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -465,13 +465,13 @@ func Test_TX_GetStruct(t *testing.T) { if err := tx.GetStruct(user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3); err != nil { gtest.Error(err) } - gtest.Assert(user.NickName, "name_3") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(user.NickName, "name_3") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") if err := tx.Commit(); err != nil { gtest.Error(err) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -487,8 +487,8 @@ func Test_TX_GetStruct(t *testing.T) { if err := tx.GetStruct(user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3); err != nil { gtest.Error(err) } - gtest.Assert(user.NickName, "name_3") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(user.NickName, "name_3") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") if err := tx.Commit(); err != nil { gtest.Error(err) } @@ -499,7 +499,7 @@ func Test_TX_GetStructs(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -515,20 +515,20 @@ func Test_TX_GetStructs(t *testing.T) { if err := tx.GetStructs(&users, fmt.Sprintf("SELECT * FROM %s WHERE id>=?", table), 1); err != nil { gtest.Error(err) } - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[2].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[2].CreateTime.String(), "2018-10-24 10:00:00") if err := tx.Commit(); err != nil { gtest.Error(err) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -544,14 +544,14 @@ func Test_TX_GetStructs(t *testing.T) { if err := tx.GetStructs(&users, fmt.Sprintf("SELECT * FROM %s WHERE id>=?", table), 1); err != nil { gtest.Error(err) } - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[2].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[2].CreateTime.String(), "2018-10-24 10:00:00") if err := tx.Commit(); err != nil { gtest.Error(err) } @@ -562,7 +562,7 @@ func Test_TX_GetScan(t *testing.T) { table := createInitTable() defer dropTable(table) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -578,13 +578,13 @@ func Test_TX_GetScan(t *testing.T) { if err := tx.GetScan(user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3); err != nil { gtest.Error(err) } - gtest.Assert(user.NickName, "name_3") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(user.NickName, "name_3") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") if err := tx.Commit(); err != nil { gtest.Error(err) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -600,14 +600,14 @@ func Test_TX_GetScan(t *testing.T) { if err := tx.GetScan(user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3); err != nil { gtest.Error(err) } - gtest.Assert(user.NickName, "name_3") - gtest.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(user.NickName, "name_3") + t.Assert(user.CreateTime.String(), "2018-10-24 10:00:00") if err := tx.Commit(); err != nil { gtest.Error(err) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -623,20 +623,20 @@ func Test_TX_GetScan(t *testing.T) { if err := tx.GetScan(&users, fmt.Sprintf("SELECT * FROM %s WHERE id>=?", table), 1); err != nil { gtest.Error(err) } - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[2].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[2].CreateTime.String(), "2018-10-24 10:00:00") if err := tx.Commit(); err != nil { gtest.Error(err) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tx, err := db.Begin() if err != nil { gtest.Error(err) @@ -652,14 +652,14 @@ func Test_TX_GetScan(t *testing.T) { if err := tx.GetScan(&users, fmt.Sprintf("SELECT * FROM %s WHERE id>=?", table), 1); err != nil { gtest.Error(err) } - gtest.Assert(len(users), SIZE) - gtest.Assert(users[0].Id, 1) - gtest.Assert(users[1].Id, 2) - gtest.Assert(users[2].Id, 3) - gtest.Assert(users[0].NickName, "name_1") - gtest.Assert(users[1].NickName, "name_2") - gtest.Assert(users[2].NickName, "name_3") - gtest.Assert(users[2].CreateTime.String(), "2018-10-24 10:00:00") + t.Assert(len(users), SIZE) + t.Assert(users[0].Id, 1) + t.Assert(users[1].Id, 2) + t.Assert(users[2].Id, 3) + t.Assert(users[0].NickName, "name_1") + t.Assert(users[1].NickName, "name_2") + t.Assert(users[2].NickName, "name_3") + t.Assert(users[2].CreateTime.String(), "2018-10-24 10:00:00") if err := tx.Commit(); err != nil { gtest.Error(err) } @@ -668,7 +668,7 @@ func Test_TX_GetScan(t *testing.T) { func Test_TX_Delete(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) tx, err := db.Begin() @@ -684,11 +684,11 @@ func Test_TX_Delete(t *testing.T) { if n, err := db.Table(table).Count(); err != nil { gtest.Error(err) } else { - gtest.Assert(n, 0) + t.Assert(n, 0) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { table := createInitTable() defer dropTable(table) tx, err := db.Begin() @@ -701,7 +701,7 @@ func Test_TX_Delete(t *testing.T) { if n, err := tx.Table(table).Count(); err != nil { gtest.Error(err) } else { - gtest.Assert(n, 0) + t.Assert(n, 0) } if err := tx.Rollback(); err != nil { gtest.Error(err) @@ -709,8 +709,8 @@ func Test_TX_Delete(t *testing.T) { if n, err := db.Table(table).Count(); err != nil { gtest.Error(err) } else { - gtest.Assert(n, SIZE) - gtest.AssertNE(n, 0) + t.Assert(n, SIZE) + t.AssertNE(n, 0) } }) diff --git a/database/gdb/gdb_unit_z_mysql_types_test.go b/database/gdb/gdb_unit_z_mysql_types_test.go index e537c0bb7..4dd235a5b 100644 --- a/database/gdb/gdb_unit_z_mysql_types_test.go +++ b/database/gdb/gdb_unit_z_mysql_types_test.go @@ -17,7 +17,7 @@ import ( func Test_Types(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { if _, err := db.Exec(fmt.Sprintf(` CREATE TABLE IF NOT EXISTS types ( id int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -50,21 +50,21 @@ func Test_Types(t *testing.T) { "bool": false, } r, err := db.Table("types").Data(data).Insert() - gtest.Assert(err, nil) + t.Assert(err, nil) n, _ := r.RowsAffected() - gtest.Assert(n, 1) + t.Assert(n, 1) one, err := db.Table("types").One() - gtest.Assert(err, nil) - gtest.Assert(one["id"].Int(), 1) - gtest.Assert(one["blob"].String(), data["blob"]) - gtest.Assert(one["binary"].String(), data["binary"]) - gtest.Assert(one["date"].String(), data["date"]) - gtest.Assert(one["time"].String(), data["time"]) - gtest.Assert(one["decimal"].String(), -123.46) - gtest.Assert(one["double"].String(), data["double"]) - gtest.Assert(one["bit"].Int(), data["bit"]) - gtest.Assert(one["tinyint"].Bool(), data["tinyint"]) - gtest.Assert(one["tinyint"].Bool(), data["tinyint"]) + t.Assert(err, nil) + t.Assert(one["id"].Int(), 1) + t.Assert(one["blob"].String(), data["blob"]) + t.Assert(one["binary"].String(), data["binary"]) + t.Assert(one["date"].String(), data["date"]) + t.Assert(one["time"].String(), data["time"]) + t.Assert(one["decimal"].String(), -123.46) + t.Assert(one["double"].String(), data["double"]) + t.Assert(one["bit"].Int(), data["bit"]) + t.Assert(one["tinyint"].Bool(), data["tinyint"]) + t.Assert(one["tinyint"].Bool(), data["tinyint"]) }) } diff --git a/database/gredis/gredis_unit_test.go b/database/gredis/gredis_unit_test.go index a69e4aab2..89665e9a8 100644 --- a/database/gredis/gredis_unit_test.go +++ b/database/gredis/gredis_unit_test.go @@ -29,35 +29,35 @@ var ( ) func Test_NewClose(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { redis := gredis.New(config) - gtest.AssertNE(redis, nil) + t.AssertNE(redis, nil) err := redis.Close() - gtest.Assert(err, nil) + t.Assert(err, nil) }) } func Test_Do(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { redis := gredis.New(config) defer redis.Close() _, err := redis.Do("SET", "k", "v") - gtest.Assert(err, nil) + t.Assert(err, nil) r, err := redis.Do("GET", "k") - gtest.Assert(err, nil) - gtest.Assert(r, []byte("v")) + t.Assert(err, nil) + t.Assert(r, []byte("v")) _, err = redis.Do("DEL", "k") - gtest.Assert(err, nil) + t.Assert(err, nil) r, err = redis.Do("GET", "k") - gtest.Assert(err, nil) - gtest.Assert(r, nil) + t.Assert(err, nil) + t.Assert(r, nil) }) } func Test_Stats(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { redis := gredis.New(config) defer redis.Close() redis.SetMaxIdle(2) @@ -70,24 +70,24 @@ func Test_Stats(t *testing.T) { array = append(array, redis.Conn()) } stats := redis.Stats() - gtest.Assert(stats.ActiveCount, 10) - gtest.Assert(stats.IdleCount, 0) + t.Assert(stats.ActiveCount, 10) + t.Assert(stats.IdleCount, 0) for i := 0; i < 10; i++ { array[i].Close() } stats = redis.Stats() - gtest.Assert(stats.ActiveCount, 2) - gtest.Assert(stats.IdleCount, 2) + t.Assert(stats.ActiveCount, 2) + t.Assert(stats.IdleCount, 2) //time.Sleep(3000*time.Millisecond) //stats = redis.Stats() //fmt.Println(stats) - //gtest.Assert(stats.ActiveCount, 0) - //gtest.Assert(stats.IdleCount, 0) + //t.Assert(stats.ActiveCount, 0) + //t.Assert(stats.IdleCount, 0) }) } func Test_Conn(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { redis := gredis.New(config) defer redis.Close() conn := redis.Conn() @@ -96,22 +96,22 @@ func Test_Conn(t *testing.T) { key := gconv.String(gtime.TimestampNano()) value := []byte("v") r, err := conn.Do("SET", key, value) - gtest.Assert(err, nil) + t.Assert(err, nil) r, err = conn.Do("GET", key) - gtest.Assert(err, nil) - gtest.Assert(r, value) + t.Assert(err, nil) + t.Assert(r, value) _, err = conn.Do("DEL", key) - gtest.Assert(err, nil) + t.Assert(err, nil) r, err = conn.Do("GET", key) - gtest.Assert(err, nil) - gtest.Assert(r, nil) + t.Assert(err, nil) + t.Assert(r, nil) }) } func Test_Instance(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { group := "my-test" gredis.SetConfig(config, group) defer gredis.RemoveConfig(group) @@ -122,22 +122,22 @@ func Test_Instance(t *testing.T) { defer conn.Close() _, err := conn.Do("SET", "k", "v") - gtest.Assert(err, nil) + t.Assert(err, nil) r, err := conn.Do("GET", "k") - gtest.Assert(err, nil) - gtest.Assert(r, []byte("v")) + t.Assert(err, nil) + t.Assert(r, []byte("v")) _, err = conn.Do("DEL", "k") - gtest.Assert(err, nil) + t.Assert(err, nil) r, err = conn.Do("GET", "k") - gtest.Assert(err, nil) - gtest.Assert(r, nil) + t.Assert(err, nil) + t.Assert(r, nil) }) } func Test_Error(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { config1 := gredis.Config{ Host: "127.0.0.2", Port: 6379, @@ -146,7 +146,7 @@ func Test_Error(t *testing.T) { } redis := gredis.New(config1) _, err := redis.Do("info") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) config1 = gredis.Config{ Host: "127.0.0.1", @@ -156,7 +156,7 @@ func Test_Error(t *testing.T) { } redis = gredis.New(config1) _, err = redis.Do("info") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) config1 = gredis.Config{ Host: "127.0.0.1", @@ -165,28 +165,28 @@ func Test_Error(t *testing.T) { } redis = gredis.New(config1) _, err = redis.Do("info") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) redis = gredis.Instance("gf") - gtest.Assert(redis == nil, true) + t.Assert(redis == nil, true) gredis.ClearConfig() redis = gredis.New(config) defer redis.Close() _, err = redis.DoVar("SET", "k", "v") - gtest.Assert(err, nil) + t.Assert(err, nil) v, err := redis.DoVar("GET", "k") - gtest.Assert(err, nil) - gtest.Assert(v.String(), "v") + t.Assert(err, nil) + t.Assert(v.String(), "v") conn := redis.GetConn() _, err = conn.DoVar("SET", "k", "v") - gtest.Assert(err, nil) + t.Assert(err, nil) //v, err = conn.ReceiveVar() - //gtest.Assert(err, nil) - //gtest.Assert(v.String(), "v") + //t.Assert(err, nil) + //t.Assert(v.String(), "v") psc := redis2.PubSubConn{Conn: conn} psc.Subscribe("gf") @@ -196,7 +196,7 @@ func Test_Error(t *testing.T) { v, _ := conn.ReceiveVar() switch obj := v.Val().(type) { case redis2.Message: - gtest.Assert(string(obj.Data), "gf test") + t.Assert(string(obj.Data), "gf test") case redis2.Subscription: } @@ -208,7 +208,7 @@ func Test_Error(t *testing.T) { } func Test_Bool(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { redis := gredis.New(config) defer func() { redis.Do("DEL", "key-true") @@ -216,66 +216,66 @@ func Test_Bool(t *testing.T) { }() _, err := redis.Do("SET", "key-true", true) - gtest.Assert(err, nil) + t.Assert(err, nil) _, err = redis.Do("SET", "key-false", false) - gtest.Assert(err, nil) + t.Assert(err, nil) r, err := redis.DoVar("GET", "key-true") - gtest.Assert(err, nil) - gtest.Assert(r.Bool(), true) + t.Assert(err, nil) + t.Assert(r.Bool(), true) r, err = redis.DoVar("GET", "key-false") - gtest.Assert(err, nil) - gtest.Assert(r.Bool(), false) + t.Assert(err, nil) + t.Assert(r.Bool(), false) }) } func Test_Int(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { redis := gredis.New(config) key := guuid.New() defer redis.Do("DEL", key) _, err := redis.Do("SET", key, 1) - gtest.Assert(err, nil) + t.Assert(err, nil) r, err := redis.DoVar("GET", key) - gtest.Assert(err, nil) - gtest.Assert(r.Int(), 1) + t.Assert(err, nil) + t.Assert(r.Int(), 1) }) } func Test_HSet(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { redis := gredis.New(config) key := guuid.New() defer redis.Do("DEL", key) _, err := redis.Do("HSET", key, "name", "john") - gtest.Assert(err, nil) + t.Assert(err, nil) r, err := redis.DoVar("HGETALL", key) - gtest.Assert(err, nil) - gtest.Assert(r.Strings(), g.ArrayStr{"name", "john"}) + t.Assert(err, nil) + t.Assert(r.Strings(), g.ArrayStr{"name", "john"}) }) } func Test_HGetAll(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var err error redis := gredis.New(config) key := guuid.New() defer redis.Do("DEL", key) _, err = redis.Do("HSET", key, "id", "100") - gtest.Assert(err, nil) + t.Assert(err, nil) _, err = redis.Do("HSET", key, "name", "john") - gtest.Assert(err, nil) + t.Assert(err, nil) r, err := redis.DoVar("HGETALL", key) - gtest.Assert(err, nil) - gtest.Assert(r.Map(), g.MapStrAny{ + t.Assert(err, nil) + t.Assert(r.Map(), g.MapStrAny{ "id": 100, "name": "john", }) diff --git a/encoding/gbase64/gbase64_test.go b/encoding/gbase64/gbase64_test.go index f13393587..70e1d89bd 100644 --- a/encoding/gbase64/gbase64_test.go +++ b/encoding/gbase64/gbase64_test.go @@ -46,22 +46,22 @@ var pairs = []testPair{ } func Test_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for k := range pairs { // Encode - gtest.Assert(gbase64.Encode([]byte(pairs[k].decoded)), []byte(pairs[k].encoded)) - gtest.Assert(gbase64.EncodeToString([]byte(pairs[k].decoded)), pairs[k].encoded) - gtest.Assert(gbase64.EncodeString(pairs[k].decoded), pairs[k].encoded) + t.Assert(gbase64.Encode([]byte(pairs[k].decoded)), []byte(pairs[k].encoded)) + t.Assert(gbase64.EncodeToString([]byte(pairs[k].decoded)), pairs[k].encoded) + t.Assert(gbase64.EncodeString(pairs[k].decoded), pairs[k].encoded) // Decode r1, _ := gbase64.Decode([]byte(pairs[k].encoded)) - gtest.Assert(r1, []byte(pairs[k].decoded)) + t.Assert(r1, []byte(pairs[k].decoded)) r2, _ := gbase64.DecodeString(pairs[k].encoded) - gtest.Assert(r2, []byte(pairs[k].decoded)) + t.Assert(r2, []byte(pairs[k].decoded)) r3, _ := gbase64.DecodeToString(pairs[k].encoded) - gtest.Assert(r3, pairs[k].decoded) + t.Assert(r3, pairs[k].decoded) } }) } @@ -69,29 +69,29 @@ func Test_Basic(t *testing.T) { func Test_File(t *testing.T) { path := gfile.Join(gdebug.TestDataPath(), "test") expect := "dGVzdA==" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { b, err := gbase64.EncodeFile(path) - gtest.Assert(err, nil) - gtest.Assert(string(b), expect) + t.Assert(err, nil) + t.Assert(string(b), expect) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s, err := gbase64.EncodeFileToString(path) - gtest.Assert(err, nil) - gtest.Assert(s, expect) + t.Assert(err, nil) + t.Assert(s, expect) }) } func Test_File_Error(t *testing.T) { path := "none-exist-file" expect := "" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { b, err := gbase64.EncodeFile(path) - gtest.AssertNE(err, nil) - gtest.Assert(string(b), expect) + t.AssertNE(err, nil) + t.Assert(string(b), expect) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s, err := gbase64.EncodeFileToString(path) - gtest.AssertNE(err, nil) - gtest.Assert(s, expect) + t.AssertNE(err, nil) + t.Assert(s, expect) }) } diff --git a/encoding/gbinary/gbinary_z_be_test.go b/encoding/gbinary/gbinary_z_be_test.go index 806ca4b3a..533811be0 100644 --- a/encoding/gbinary/gbinary_z_be_test.go +++ b/encoding/gbinary/gbinary_z_be_test.go @@ -21,47 +21,47 @@ func Test_BeEncodeAndBeDecode(t *testing.T) { //t.Logf("%s:%v, encoded:%v\n", k, v, ve) switch v.(type) { case int: - gtest.Assert(gbinary.BeDecodeToInt(ve), v) - gtest.Assert(gbinary.BeDecodeToInt(ve1), v) + t.Assert(gbinary.BeDecodeToInt(ve), v) + t.Assert(gbinary.BeDecodeToInt(ve1), v) case int8: - gtest.Assert(gbinary.BeDecodeToInt8(ve), v) - gtest.Assert(gbinary.BeDecodeToInt8(ve1), v) + t.Assert(gbinary.BeDecodeToInt8(ve), v) + t.Assert(gbinary.BeDecodeToInt8(ve1), v) case int16: - gtest.Assert(gbinary.BeDecodeToInt16(ve), v) - gtest.Assert(gbinary.BeDecodeToInt16(ve1), v) + t.Assert(gbinary.BeDecodeToInt16(ve), v) + t.Assert(gbinary.BeDecodeToInt16(ve1), v) case int32: - gtest.Assert(gbinary.BeDecodeToInt32(ve), v) - gtest.Assert(gbinary.BeDecodeToInt32(ve1), v) + t.Assert(gbinary.BeDecodeToInt32(ve), v) + t.Assert(gbinary.BeDecodeToInt32(ve1), v) case int64: - gtest.Assert(gbinary.BeDecodeToInt64(ve), v) - gtest.Assert(gbinary.BeDecodeToInt64(ve1), v) + t.Assert(gbinary.BeDecodeToInt64(ve), v) + t.Assert(gbinary.BeDecodeToInt64(ve1), v) case uint: - gtest.Assert(gbinary.BeDecodeToUint(ve), v) - gtest.Assert(gbinary.BeDecodeToUint(ve1), v) + t.Assert(gbinary.BeDecodeToUint(ve), v) + t.Assert(gbinary.BeDecodeToUint(ve1), v) case uint8: - gtest.Assert(gbinary.BeDecodeToUint8(ve), v) - gtest.Assert(gbinary.BeDecodeToUint8(ve1), v) + t.Assert(gbinary.BeDecodeToUint8(ve), v) + t.Assert(gbinary.BeDecodeToUint8(ve1), v) case uint16: - gtest.Assert(gbinary.BeDecodeToUint16(ve1), v) - gtest.Assert(gbinary.BeDecodeToUint16(ve), v) + t.Assert(gbinary.BeDecodeToUint16(ve1), v) + t.Assert(gbinary.BeDecodeToUint16(ve), v) case uint32: - gtest.Assert(gbinary.BeDecodeToUint32(ve1), v) - gtest.Assert(gbinary.BeDecodeToUint32(ve), v) + t.Assert(gbinary.BeDecodeToUint32(ve1), v) + t.Assert(gbinary.BeDecodeToUint32(ve), v) case uint64: - gtest.Assert(gbinary.BeDecodeToUint64(ve), v) - gtest.Assert(gbinary.BeDecodeToUint64(ve1), v) + t.Assert(gbinary.BeDecodeToUint64(ve), v) + t.Assert(gbinary.BeDecodeToUint64(ve1), v) case bool: - gtest.Assert(gbinary.BeDecodeToBool(ve), v) - gtest.Assert(gbinary.BeDecodeToBool(ve1), v) + t.Assert(gbinary.BeDecodeToBool(ve), v) + t.Assert(gbinary.BeDecodeToBool(ve1), v) case string: - gtest.Assert(gbinary.BeDecodeToString(ve), v) - gtest.Assert(gbinary.BeDecodeToString(ve1), v) + t.Assert(gbinary.BeDecodeToString(ve), v) + t.Assert(gbinary.BeDecodeToString(ve1), v) case float32: - gtest.Assert(gbinary.BeDecodeToFloat32(ve), v) - gtest.Assert(gbinary.BeDecodeToFloat32(ve1), v) + t.Assert(gbinary.BeDecodeToFloat32(ve), v) + t.Assert(gbinary.BeDecodeToFloat32(ve1), v) case float64: - gtest.Assert(gbinary.BeDecodeToFloat64(ve), v) - gtest.Assert(gbinary.BeDecodeToFloat64(ve1), v) + t.Assert(gbinary.BeDecodeToFloat64(ve), v) + t.Assert(gbinary.BeDecodeToFloat64(ve1), v) default: if v == nil { continue @@ -71,7 +71,7 @@ func Test_BeEncodeAndBeDecode(t *testing.T) { if err != nil { t.Errorf("test data: %s, %v, error:%v", k, v, err) } - gtest.Assert(res, v) + t.Assert(res, v) } } } @@ -80,5 +80,5 @@ func Test_BeEncodeStruct(t *testing.T) { user := User{"wenzi1", 999, "www.baidu.com"} ve := gbinary.BeEncode(user) s := gbinary.BeDecodeToString(ve) - gtest.Assert(string(s), s) + t.Assert(string(s), s) } diff --git a/encoding/gbinary/gbinary_z_le_test.go b/encoding/gbinary/gbinary_z_le_test.go index 71215197e..f534248e6 100644 --- a/encoding/gbinary/gbinary_z_le_test.go +++ b/encoding/gbinary/gbinary_z_le_test.go @@ -21,47 +21,47 @@ func Test_LeEncodeAndLeDecode(t *testing.T) { //t.Logf("%s:%v, encoded:%v\n", k, v, ve) switch v.(type) { case int: - gtest.Assert(gbinary.LeDecodeToInt(ve), v) - gtest.Assert(gbinary.LeDecodeToInt(ve1), v) + t.Assert(gbinary.LeDecodeToInt(ve), v) + t.Assert(gbinary.LeDecodeToInt(ve1), v) case int8: - gtest.Assert(gbinary.LeDecodeToInt8(ve), v) - gtest.Assert(gbinary.LeDecodeToInt8(ve1), v) + t.Assert(gbinary.LeDecodeToInt8(ve), v) + t.Assert(gbinary.LeDecodeToInt8(ve1), v) case int16: - gtest.Assert(gbinary.LeDecodeToInt16(ve), v) - gtest.Assert(gbinary.LeDecodeToInt16(ve1), v) + t.Assert(gbinary.LeDecodeToInt16(ve), v) + t.Assert(gbinary.LeDecodeToInt16(ve1), v) case int32: - gtest.Assert(gbinary.LeDecodeToInt32(ve), v) - gtest.Assert(gbinary.LeDecodeToInt32(ve1), v) + t.Assert(gbinary.LeDecodeToInt32(ve), v) + t.Assert(gbinary.LeDecodeToInt32(ve1), v) case int64: - gtest.Assert(gbinary.LeDecodeToInt64(ve), v) - gtest.Assert(gbinary.LeDecodeToInt64(ve1), v) + t.Assert(gbinary.LeDecodeToInt64(ve), v) + t.Assert(gbinary.LeDecodeToInt64(ve1), v) case uint: - gtest.Assert(gbinary.LeDecodeToUint(ve), v) - gtest.Assert(gbinary.LeDecodeToUint(ve1), v) + t.Assert(gbinary.LeDecodeToUint(ve), v) + t.Assert(gbinary.LeDecodeToUint(ve1), v) case uint8: - gtest.Assert(gbinary.LeDecodeToUint8(ve), v) - gtest.Assert(gbinary.LeDecodeToUint8(ve1), v) + t.Assert(gbinary.LeDecodeToUint8(ve), v) + t.Assert(gbinary.LeDecodeToUint8(ve1), v) case uint16: - gtest.Assert(gbinary.LeDecodeToUint16(ve1), v) - gtest.Assert(gbinary.LeDecodeToUint16(ve), v) + t.Assert(gbinary.LeDecodeToUint16(ve1), v) + t.Assert(gbinary.LeDecodeToUint16(ve), v) case uint32: - gtest.Assert(gbinary.LeDecodeToUint32(ve1), v) - gtest.Assert(gbinary.LeDecodeToUint32(ve), v) + t.Assert(gbinary.LeDecodeToUint32(ve1), v) + t.Assert(gbinary.LeDecodeToUint32(ve), v) case uint64: - gtest.Assert(gbinary.LeDecodeToUint64(ve), v) - gtest.Assert(gbinary.LeDecodeToUint64(ve1), v) + t.Assert(gbinary.LeDecodeToUint64(ve), v) + t.Assert(gbinary.LeDecodeToUint64(ve1), v) case bool: - gtest.Assert(gbinary.LeDecodeToBool(ve), v) - gtest.Assert(gbinary.LeDecodeToBool(ve1), v) + t.Assert(gbinary.LeDecodeToBool(ve), v) + t.Assert(gbinary.LeDecodeToBool(ve1), v) case string: - gtest.Assert(gbinary.LeDecodeToString(ve), v) - gtest.Assert(gbinary.LeDecodeToString(ve1), v) + t.Assert(gbinary.LeDecodeToString(ve), v) + t.Assert(gbinary.LeDecodeToString(ve1), v) case float32: - gtest.Assert(gbinary.LeDecodeToFloat32(ve), v) - gtest.Assert(gbinary.LeDecodeToFloat32(ve1), v) + t.Assert(gbinary.LeDecodeToFloat32(ve), v) + t.Assert(gbinary.LeDecodeToFloat32(ve1), v) case float64: - gtest.Assert(gbinary.LeDecodeToFloat64(ve), v) - gtest.Assert(gbinary.LeDecodeToFloat64(ve1), v) + t.Assert(gbinary.LeDecodeToFloat64(ve), v) + t.Assert(gbinary.LeDecodeToFloat64(ve1), v) default: if v == nil { continue @@ -71,7 +71,7 @@ func Test_LeEncodeAndLeDecode(t *testing.T) { if err != nil { t.Errorf("test data: %s, %v, error:%v", k, v, err) } - gtest.Assert(res, v) + t.Assert(res, v) } } } @@ -80,5 +80,5 @@ func Test_LeEncodeStruct(t *testing.T) { user := User{"wenzi1", 999, "www.baidu.com"} ve := gbinary.LeEncode(user) s := gbinary.LeDecodeToString(ve) - gtest.Assert(string(s), s) + t.Assert(string(s), s) } diff --git a/encoding/gbinary/gbinary_z_test.go b/encoding/gbinary/gbinary_z_test.go index 77cbb8ae7..55714f053 100644 --- a/encoding/gbinary/gbinary_z_test.go +++ b/encoding/gbinary/gbinary_z_test.go @@ -56,47 +56,47 @@ func Test_EncodeAndDecode(t *testing.T) { //t.Logf("%s:%v, encoded:%v\n", k, v, ve) switch v.(type) { case int: - gtest.Assert(gbinary.DecodeToInt(ve), v) - gtest.Assert(gbinary.DecodeToInt(ve1), v) + t.Assert(gbinary.DecodeToInt(ve), v) + t.Assert(gbinary.DecodeToInt(ve1), v) case int8: - gtest.Assert(gbinary.DecodeToInt8(ve), v) - gtest.Assert(gbinary.DecodeToInt8(ve1), v) + t.Assert(gbinary.DecodeToInt8(ve), v) + t.Assert(gbinary.DecodeToInt8(ve1), v) case int16: - gtest.Assert(gbinary.DecodeToInt16(ve), v) - gtest.Assert(gbinary.DecodeToInt16(ve1), v) + t.Assert(gbinary.DecodeToInt16(ve), v) + t.Assert(gbinary.DecodeToInt16(ve1), v) case int32: - gtest.Assert(gbinary.DecodeToInt32(ve), v) - gtest.Assert(gbinary.DecodeToInt32(ve1), v) + t.Assert(gbinary.DecodeToInt32(ve), v) + t.Assert(gbinary.DecodeToInt32(ve1), v) case int64: - gtest.Assert(gbinary.DecodeToInt64(ve), v) - gtest.Assert(gbinary.DecodeToInt64(ve1), v) + t.Assert(gbinary.DecodeToInt64(ve), v) + t.Assert(gbinary.DecodeToInt64(ve1), v) case uint: - gtest.Assert(gbinary.DecodeToUint(ve), v) - gtest.Assert(gbinary.DecodeToUint(ve1), v) + t.Assert(gbinary.DecodeToUint(ve), v) + t.Assert(gbinary.DecodeToUint(ve1), v) case uint8: - gtest.Assert(gbinary.DecodeToUint8(ve), v) - gtest.Assert(gbinary.DecodeToUint8(ve1), v) + t.Assert(gbinary.DecodeToUint8(ve), v) + t.Assert(gbinary.DecodeToUint8(ve1), v) case uint16: - gtest.Assert(gbinary.DecodeToUint16(ve1), v) - gtest.Assert(gbinary.DecodeToUint16(ve), v) + t.Assert(gbinary.DecodeToUint16(ve1), v) + t.Assert(gbinary.DecodeToUint16(ve), v) case uint32: - gtest.Assert(gbinary.DecodeToUint32(ve1), v) - gtest.Assert(gbinary.DecodeToUint32(ve), v) + t.Assert(gbinary.DecodeToUint32(ve1), v) + t.Assert(gbinary.DecodeToUint32(ve), v) case uint64: - gtest.Assert(gbinary.DecodeToUint64(ve), v) - gtest.Assert(gbinary.DecodeToUint64(ve1), v) + t.Assert(gbinary.DecodeToUint64(ve), v) + t.Assert(gbinary.DecodeToUint64(ve1), v) case bool: - gtest.Assert(gbinary.DecodeToBool(ve), v) - gtest.Assert(gbinary.DecodeToBool(ve1), v) + t.Assert(gbinary.DecodeToBool(ve), v) + t.Assert(gbinary.DecodeToBool(ve1), v) case string: - gtest.Assert(gbinary.DecodeToString(ve), v) - gtest.Assert(gbinary.DecodeToString(ve1), v) + t.Assert(gbinary.DecodeToString(ve), v) + t.Assert(gbinary.DecodeToString(ve1), v) case float32: - gtest.Assert(gbinary.DecodeToFloat32(ve), v) - gtest.Assert(gbinary.DecodeToFloat32(ve1), v) + t.Assert(gbinary.DecodeToFloat32(ve), v) + t.Assert(gbinary.DecodeToFloat32(ve1), v) case float64: - gtest.Assert(gbinary.DecodeToFloat64(ve), v) - gtest.Assert(gbinary.DecodeToFloat64(ve1), v) + t.Assert(gbinary.DecodeToFloat64(ve), v) + t.Assert(gbinary.DecodeToFloat64(ve1), v) default: if v == nil { continue @@ -106,7 +106,7 @@ func Test_EncodeAndDecode(t *testing.T) { if err != nil { t.Errorf("test data: %s, %v, error:%v", k, v, err) } - gtest.Assert(res, v) + t.Assert(res, v) } } } @@ -115,7 +115,7 @@ func Test_EncodeStruct(t *testing.T) { user := User{"wenzi1", 999, "www.baidu.com"} ve := gbinary.Encode(user) s := gbinary.DecodeToString(ve) - gtest.Assert(string(s), s) + t.Assert(string(s), s) } func Test_Bits(t *testing.T) { @@ -123,10 +123,10 @@ func Test_Bits(t *testing.T) { bits := make([]gbinary.Bit, 0) res := gbinary.EncodeBits(bits, testBitData[i], 64) - gtest.Assert(gbinary.DecodeBits(res), testBitData[i]) - gtest.Assert(gbinary.DecodeBitsToUint(res), uint(testBitData[i])) + t.Assert(gbinary.DecodeBits(res), testBitData[i]) + t.Assert(gbinary.DecodeBitsToUint(res), uint(testBitData[i])) - gtest.Assert(gbinary.DecodeBytesToBits(gbinary.EncodeBitsToBytes(res)), res) + t.Assert(gbinary.DecodeBytesToBits(gbinary.EncodeBitsToBytes(res)), res) } } diff --git a/encoding/gcharset/gcharset_test.go b/encoding/gcharset/gcharset_test.go index fae9e6c12..bee6e7b83 100644 --- a/encoding/gcharset/gcharset_test.go +++ b/encoding/gcharset/gcharset_test.go @@ -138,28 +138,28 @@ func TestConvert(t *testing.T) { } func TestConvertErr(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcCharset := "big5" dstCharset := "gbk" src := "Hello \xb1`\xa5\u03b0\xea\xa6r\xbc\u0437\u01e6r\xc5\xe9\xaa\xed" s1, e1 := gcharset.Convert(srcCharset, srcCharset, src) - gtest.Assert(e1, nil) - gtest.Assert(s1, src) + t.Assert(e1, nil) + t.Assert(s1, src) s2, e2 := gcharset.Convert(dstCharset, "no this charset", src) - gtest.AssertNE(e2, nil) - gtest.Assert(s2, src) + t.AssertNE(e2, nil) + t.Assert(s2, src) s3, e3 := gcharset.Convert("no this charset", srcCharset, src) - gtest.AssertNE(e3, nil) - gtest.Assert(s3, src) + t.AssertNE(e3, nil) + t.Assert(s3, src) }) } func TestSupported(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gcharset.Supported("UTF-8"), true) - gtest.Assert(gcharset.Supported("UTF-80"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gcharset.Supported("UTF-8"), true) + t.Assert(gcharset.Supported("UTF-80"), false) }) } diff --git a/encoding/gcompress/gcompress_z_unit_gzip_test.go b/encoding/gcompress/gcompress_z_unit_gzip_test.go index 694105344..2acf033a3 100644 --- a/encoding/gcompress/gcompress_z_unit_gzip_test.go +++ b/encoding/gcompress/gcompress_z_unit_gzip_test.go @@ -29,16 +29,16 @@ func Test_Gzip_UnGzip(t *testing.T) { 0x24, 0xa8, 0xd1, 0x0d, 0x00, 0x00, 0x00, } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { arr := []byte(src) data, _ := gcompress.Gzip(arr) - gtest.Assert(data, gzip) + t.Assert(data, gzip) data, _ = gcompress.UnGzip(gzip) - gtest.Assert(data, arr) + t.Assert(data, arr) data, _ = gcompress.UnGzip(gzip[1:]) - gtest.Assert(data, nil) + t.Assert(data, nil) }) } @@ -48,18 +48,18 @@ func Test_Gzip_UnGzip_File(t *testing.T) { dstPath2 := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), "file.txt") // Compress. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gcompress.GzipFile(srcPath, dstPath1, 9) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dstPath1) - gtest.Assert(gfile.Exists(dstPath1), true) + t.Assert(gfile.Exists(dstPath1), true) // Decompress. err = gcompress.UnGzipFile(dstPath1, dstPath2) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dstPath2) - gtest.Assert(gfile.Exists(dstPath2), true) + t.Assert(gfile.Exists(dstPath2), true) - gtest.Assert(gfile.GetContents(srcPath), gfile.GetContents(dstPath2)) + t.Assert(gfile.GetContents(srcPath), gfile.GetContents(dstPath2)) }) } diff --git a/encoding/gcompress/gcompress_z_unit_zip_test.go b/encoding/gcompress/gcompress_z_unit_zip_test.go index 399bc2783..5aa447260 100644 --- a/encoding/gcompress/gcompress_z_unit_zip_test.go +++ b/encoding/gcompress/gcompress_z_unit_zip_test.go @@ -19,64 +19,64 @@ import ( func Test_ZipPath(t *testing.T) { // file - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gfile.Join(gdebug.TestDataPath(), "zip", "path1", "1.txt") dstPath := gfile.Join(gdebug.TestDataPath(), "zip", "zip.zip") - gtest.Assert(gfile.Exists(dstPath), false) + t.Assert(gfile.Exists(dstPath), false) err := gcompress.ZipPath(srcPath, dstPath) - gtest.Assert(err, nil) - gtest.Assert(gfile.Exists(dstPath), true) + t.Assert(err, nil) + t.Assert(gfile.Exists(dstPath), true) defer gfile.Remove(dstPath) tempDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(tempDirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gcompress.UnZipFile(dstPath, tempDirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(tempDirPath) - gtest.Assert( + t.Assert( gfile.GetContents(gfile.Join(tempDirPath, "1.txt")), gfile.GetContents(gfile.Join(srcPath, "path1", "1.txt")), ) }) // directory - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gfile.Join(gdebug.TestDataPath(), "zip") dstPath := gfile.Join(gdebug.TestDataPath(), "zip", "zip.zip") pwd := gfile.Pwd() err := gfile.Chdir(srcPath) defer gfile.Chdir(pwd) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Assert(gfile.Exists(dstPath), false) + t.Assert(gfile.Exists(dstPath), false) err = gcompress.ZipPath(srcPath, dstPath) - gtest.Assert(err, nil) - gtest.Assert(gfile.Exists(dstPath), true) + t.Assert(err, nil) + t.Assert(gfile.Exists(dstPath), true) defer gfile.Remove(dstPath) tempDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(tempDirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gcompress.UnZipFile(dstPath, tempDirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(tempDirPath) - gtest.Assert( + t.Assert( gfile.GetContents(gfile.Join(tempDirPath, "zip", "path1", "1.txt")), gfile.GetContents(gfile.Join(srcPath, "path1", "1.txt")), ) - gtest.Assert( + t.Assert( gfile.GetContents(gfile.Join(tempDirPath, "zip", "path2", "2.txt")), gfile.GetContents(gfile.Join(srcPath, "path2", "2.txt")), ) }) // multiple paths joined using char ',' - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gfile.Join(gdebug.TestDataPath(), "zip") srcPath1 := gfile.Join(gdebug.TestDataPath(), "zip", "path1") srcPath2 := gfile.Join(gdebug.TestDataPath(), "zip", "path2") @@ -85,29 +85,29 @@ func Test_ZipPath(t *testing.T) { pwd := gfile.Pwd() err := gfile.Chdir(srcPath) defer gfile.Chdir(pwd) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Assert(gfile.Exists(dstPath), false) + t.Assert(gfile.Exists(dstPath), false) err = gcompress.ZipPath(srcPath1+", "+srcPath2, dstPath) - gtest.Assert(err, nil) - gtest.Assert(gfile.Exists(dstPath), true) + t.Assert(err, nil) + t.Assert(gfile.Exists(dstPath), true) defer gfile.Remove(dstPath) tempDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(tempDirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) zipContent := gfile.GetBytes(dstPath) - gtest.AssertGT(len(zipContent), 0) + t.AssertGT(len(zipContent), 0) err = gcompress.UnZipContent(zipContent, tempDirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(tempDirPath) - gtest.Assert( + t.Assert( gfile.GetContents(gfile.Join(tempDirPath, "path1", "1.txt")), gfile.GetContents(gfile.Join(srcPath, "path1", "1.txt")), ) - gtest.Assert( + t.Assert( gfile.GetContents(gfile.Join(tempDirPath, "path2", "2.txt")), gfile.GetContents(gfile.Join(srcPath, "path2", "2.txt")), ) @@ -115,7 +115,7 @@ func Test_ZipPath(t *testing.T) { } func Test_ZipPathWriter(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gfile.Join(gdebug.TestDataPath(), "zip") srcPath1 := gfile.Join(gdebug.TestDataPath(), "zip", "path1") srcPath2 := gfile.Join(gdebug.TestDataPath(), "zip", "path2") @@ -123,29 +123,29 @@ func Test_ZipPathWriter(t *testing.T) { pwd := gfile.Pwd() err := gfile.Chdir(srcPath) defer gfile.Chdir(pwd) - gtest.Assert(err, nil) + t.Assert(err, nil) writer := bytes.NewBuffer(nil) - gtest.Assert(writer.Len(), 0) + t.Assert(writer.Len(), 0) err = gcompress.ZipPathWriter(srcPath1+", "+srcPath2, writer) - gtest.Assert(err, nil) - gtest.AssertGT(writer.Len(), 0) + t.Assert(err, nil) + t.AssertGT(writer.Len(), 0) tempDirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(tempDirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) zipContent := writer.Bytes() - gtest.AssertGT(len(zipContent), 0) + t.AssertGT(len(zipContent), 0) err = gcompress.UnZipContent(zipContent, tempDirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(tempDirPath) - gtest.Assert( + t.Assert( gfile.GetContents(gfile.Join(tempDirPath, "path1", "1.txt")), gfile.GetContents(gfile.Join(srcPath, "path1", "1.txt")), ) - gtest.Assert( + t.Assert( gfile.GetContents(gfile.Join(tempDirPath, "path2", "2.txt")), gfile.GetContents(gfile.Join(srcPath, "path2", "2.txt")), ) diff --git a/encoding/gcompress/gcompress_z_unit_zlib_test.go b/encoding/gcompress/gcompress_z_unit_zlib_test.go index 68ea18703..5683fd297 100644 --- a/encoding/gcompress/gcompress_z_unit_zlib_test.go +++ b/encoding/gcompress/gcompress_z_unit_zlib_test.go @@ -14,21 +14,21 @@ import ( ) func Test_Zlib_UnZlib(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { src := "hello, world\n" dst := []byte{120, 156, 202, 72, 205, 201, 201, 215, 81, 40, 207, 47, 202, 73, 225, 2, 4, 0, 0, 255, 255, 33, 231, 4, 147} data, _ := gcompress.Zlib([]byte(src)) - gtest.Assert(data, dst) + t.Assert(data, dst) data, _ = gcompress.UnZlib(dst) - gtest.Assert(data, []byte(src)) + t.Assert(data, []byte(src)) data, _ = gcompress.Zlib(nil) - gtest.Assert(data, nil) + t.Assert(data, nil) data, _ = gcompress.UnZlib(nil) - gtest.Assert(data, nil) + t.Assert(data, nil) data, _ = gcompress.UnZlib(dst[1:]) - gtest.Assert(data, nil) + t.Assert(data, nil) }) } diff --git a/encoding/ghash/ghash_z_unit_basic_test.go b/encoding/ghash/ghash_z_unit_basic_test.go index e1d8ec908..e3219584a 100755 --- a/encoding/ghash/ghash_z_unit_basic_test.go +++ b/encoding/ghash/ghash_z_unit_basic_test.go @@ -13,128 +13,128 @@ var ( func Test_BKDRHash(t *testing.T) { var x uint32 = 200645773 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.BKDRHash(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_BKDRHash64(t *testing.T) { var x uint64 = 4214762819217104013 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.BKDRHash64(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_SDBMHash(t *testing.T) { var x uint32 = 1069170245 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.SDBMHash(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_SDBMHash64(t *testing.T) { var x uint64 = 9881052176572890693 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.SDBMHash64(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_RSHash(t *testing.T) { var x uint32 = 1944033799 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.RSHash(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_RSHash64(t *testing.T) { var x uint64 = 13439708950444349959 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.RSHash64(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_JSHash(t *testing.T) { var x uint32 = 498688898 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.JSHash(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_JSHash64(t *testing.T) { var x uint64 = 13410163655098759877 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.JSHash64(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_PJWHash(t *testing.T) { var x uint32 = 7244206 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.PJWHash(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_PJWHash64(t *testing.T) { var x uint64 = 31150 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.PJWHash64(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_ELFHash(t *testing.T) { var x uint32 = 7244206 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.ELFHash(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_ELFHash64(t *testing.T) { var x uint64 = 31150 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.ELFHash64(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_DJBHash(t *testing.T) { var x uint32 = 959862602 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.DJBHash(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_DJBHash64(t *testing.T) { var x uint64 = 2519720351310960458 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.DJBHash64(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_APHash(t *testing.T) { var x uint32 = 3998202516 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.APHash(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } func Test_APHash64(t *testing.T) { var x uint64 = 2531023058543352243 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := ghash.APHash64(strBasic) - gtest.Assert(j, x) + t.Assert(j, x) }) } diff --git a/encoding/ghtml/ghtml_test.go b/encoding/ghtml/ghtml_test.go index 5ebf2bada..0b7f43421 100644 --- a/encoding/ghtml/ghtml_test.go +++ b/encoding/ghtml/ghtml_test.go @@ -15,19 +15,19 @@ import ( func TestStripTags(t *testing.T) { src := `

Test paragraph.

Other text` dst := `Test paragraph. Other text` - gtest.Assert(ghtml.StripTags(src), dst) + t.Assert(ghtml.StripTags(src), dst) } func TestEntities(t *testing.T) { src := `A 'quote' "is" bold` dst := `A 'quote' "is" <b>bold</b>` - gtest.Assert(ghtml.Entities(src), dst) - gtest.Assert(ghtml.EntitiesDecode(dst), src) + t.Assert(ghtml.Entities(src), dst) + t.Assert(ghtml.EntitiesDecode(dst), src) } func TestSpecialChars(t *testing.T) { src := `A 'quote' "is" bold` dst := `A 'quote' "is" <b>bold</b>` - gtest.Assert(ghtml.SpecialChars(src), dst) - gtest.Assert(ghtml.SpecialCharsDecode(dst), src) + t.Assert(ghtml.SpecialChars(src), dst) + t.Assert(ghtml.SpecialCharsDecode(dst), src) } diff --git a/encoding/gini/gini_test.go b/encoding/gini/gini_test.go index 29a60dbd9..f5339cca2 100644 --- a/encoding/gini/gini_test.go +++ b/encoding/gini/gini_test.go @@ -33,19 +33,19 @@ enable=true ` func TestDecode(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { res, err := gini.Decode([]byte(iniContent)) if err != nil { gtest.Fatal(err) } - gtest.Assert(res["addr"].(map[string]interface{})["ip"], "127.0.0.1") - gtest.Assert(res["addr"].(map[string]interface{})["port"], "9001") - gtest.Assert(res["DBINFO"].(map[string]interface{})["user"], "root") - gtest.Assert(res["DBINFO"].(map[string]interface{})["type"], "mysql") - gtest.Assert(res["键"].(map[string]interface{})["呵呵"], "值") + t.Assert(res["addr"].(map[string]interface{})["ip"], "127.0.0.1") + t.Assert(res["addr"].(map[string]interface{})["port"], "9001") + t.Assert(res["DBINFO"].(map[string]interface{})["user"], "root") + t.Assert(res["DBINFO"].(map[string]interface{})["type"], "mysql") + t.Assert(res["键"].(map[string]interface{})["呵呵"], "值") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { errContent := ` a = b ` @@ -57,7 +57,7 @@ func TestDecode(t *testing.T) { } func TestEncode(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { iniMap, err := gini.Decode([]byte(iniContent)) if err != nil { gtest.Fatal(err) @@ -73,16 +73,16 @@ func TestEncode(t *testing.T) { gtest.Fatal(err) } - gtest.Assert(res["addr"].(map[string]interface{})["ip"], "127.0.0.1") - gtest.Assert(res["addr"].(map[string]interface{})["port"], "9001") - gtest.Assert(res["DBINFO"].(map[string]interface{})["user"], "root") - gtest.Assert(res["DBINFO"].(map[string]interface{})["type"], "mysql") + t.Assert(res["addr"].(map[string]interface{})["ip"], "127.0.0.1") + t.Assert(res["addr"].(map[string]interface{})["port"], "9001") + t.Assert(res["DBINFO"].(map[string]interface{})["user"], "root") + t.Assert(res["DBINFO"].(map[string]interface{})["type"], "mysql") }) } func TestToJson(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { jsonStr, err := gini.ToJson([]byte(iniContent)) if err != nil { gtest.Fatal(err) @@ -94,11 +94,11 @@ func TestToJson(t *testing.T) { } iniMap, err := gini.Decode([]byte(iniContent)) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Assert(iniMap["addr"].(map[string]interface{})["ip"], json.GetString("addr.ip")) - gtest.Assert(iniMap["addr"].(map[string]interface{})["port"], json.GetString("addr.port")) - gtest.Assert(iniMap["DBINFO"].(map[string]interface{})["user"], json.GetString("DBINFO.user")) - gtest.Assert(iniMap["DBINFO"].(map[string]interface{})["type"], json.GetString("DBINFO.type")) + t.Assert(iniMap["addr"].(map[string]interface{})["ip"], json.GetString("addr.ip")) + t.Assert(iniMap["addr"].(map[string]interface{})["port"], json.GetString("addr.port")) + t.Assert(iniMap["DBINFO"].(map[string]interface{})["user"], json.GetString("DBINFO.user")) + t.Assert(iniMap["DBINFO"].(map[string]interface{})["type"], json.GetString("DBINFO.type")) }) } diff --git a/encoding/gjson/gjson_api_new_load.go b/encoding/gjson/gjson_api_new_load.go index 03a6914a7..efaa5a7b1 100644 --- a/encoding/gjson/gjson_api_new_load.go +++ b/encoding/gjson/gjson_api_new_load.go @@ -72,8 +72,9 @@ func NewWithTag(data interface{}, tags string, safe ...bool) *Json { } case reflect.Map, reflect.Struct: i := interface{}(nil) - // Note that it uses MapDeep function implementing the converting. - i = gconv.MapDeep(data, tags) + // Note that it uses Map function implementing the converting. + // Note that it here should not use MapDeep function if you really know what it means. + i = gconv.Map(data, tags) j = &Json{ p: &i, c: byte(gDEFAULT_SPLIT_CHAR), diff --git a/encoding/gjson/gjson_z_unit_basic_test.go b/encoding/gjson/gjson_z_unit_basic_test.go index 7d89c2407..20fc7ab32 100644 --- a/encoding/gjson/gjson_z_unit_basic_test.go +++ b/encoding/gjson/gjson_z_unit_basic_test.go @@ -17,49 +17,49 @@ import ( func Test_New(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.New(data) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gmap.NewAnyAnyMapFrom(g.MapAnyAny{ "k1": "v1", "k2": "v2", }) j := gjson.New(m) - gtest.Assert(j.Get("k1"), "v1") - gtest.Assert(j.Get("k2"), "v2") - gtest.Assert(j.Get("k3"), nil) + t.Assert(j.Get("k1"), "v1") + t.Assert(j.Get("k2"), "v2") + t.Assert(j.Get("k3"), nil) }) } func Test_Valid(t *testing.T) { data1 := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data2 := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]`) - gtest.Case(t, func() { - gtest.Assert(gjson.Valid(data1), true) - gtest.Assert(gjson.Valid(data2), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gjson.Valid(data1), true) + t.Assert(gjson.Valid(data2), false) }) } func Test_Encode(t *testing.T) { value := g.Slice{1, 2, 3} - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { b, err := gjson.Encode(value) - gtest.Assert(err, nil) - gtest.Assert(b, []byte(`[1,2,3]`)) + t.Assert(err, nil) + t.Assert(b, []byte(`[1,2,3]`)) }) } func Test_Decode(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v, err := gjson.Decode(data) - gtest.Assert(err, nil) - gtest.Assert(v, g.Map{ + t.Assert(err, nil) + t.Assert(v, g.Map{ "n": 123456789, "a": g.Slice{1, 2, 3}, "m": g.Map{ @@ -67,11 +67,11 @@ func Test_Decode(t *testing.T) { }, }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var v interface{} err := gjson.DecodeTo(data, &v) - gtest.Assert(err, nil) - gtest.Assert(v, g.Map{ + t.Assert(err, nil) + t.Assert(v, g.Map{ "n": 123456789, "a": g.Slice{1, 2, 3}, "m": g.Map{ @@ -79,216 +79,216 @@ func Test_Decode(t *testing.T) { }, }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } func Test_SplitChar(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) j.SetSplitChar(byte('#')) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m#k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a#1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m#k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a#1"), 2) }) } func Test_ViolenceCheck(t *testing.T) { data := []byte(`{"m":{"a":[1,2,3], "v1.v2":"4"}}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("m.a.2"), 3) - gtest.Assert(j.Get("m.v1.v2"), nil) + t.Assert(err, nil) + t.Assert(j.Get("m.a.2"), 3) + t.Assert(j.Get("m.v1.v2"), nil) j.SetViolenceCheck(true) - gtest.Assert(j.Get("m.v1.v2"), 4) + t.Assert(j.Get("m.v1.v2"), 4) }) } func Test_GetVar(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) - 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}) + t.Assert(err, nil) + t.Assert(j.GetVar("n").String(), "123456789") + t.Assert(j.GetVar("m").Map(), g.Map{"k": "v"}) + t.Assert(j.GetVar("a").Interfaces(), g.Slice{1, 2, 3}) + t.Assert(j.GetVar("a").Slice(), g.Slice{1, 2, 3}) + t.Assert(j.GetVar("a").Array(), g.Slice{1, 2, 3}) }) } func Test_GetMap(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) - gtest.Assert(j.GetMap("n"), nil) - gtest.Assert(j.GetMap("m"), g.Map{"k": "v"}) - gtest.Assert(j.GetMap("a"), g.Map{"1": "2", "3": nil}) + t.Assert(err, nil) + t.Assert(j.GetMap("n"), nil) + t.Assert(j.GetMap("m"), g.Map{"k": "v"}) + t.Assert(j.GetMap("a"), g.Map{"1": "2", "3": nil}) }) } func Test_GetJson(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) + t.Assert(err, nil) j2 := j.GetJson("m") - gtest.AssertNE(j2, nil) - gtest.Assert(j2.Get("k"), "v") - gtest.Assert(j2.Get("a"), nil) - gtest.Assert(j2.Get("n"), nil) + t.AssertNE(j2, nil) + t.Assert(j2.Get("k"), "v") + t.Assert(j2.Get("a"), nil) + t.Assert(j2.Get("n"), nil) }) } func Test_GetArray(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) - gtest.Assert(j.GetArray("n"), g.Array{123456789}) - gtest.Assert(j.GetArray("m"), g.Array{g.Map{"k": "v"}}) - gtest.Assert(j.GetArray("a"), g.Array{1, 2, 3}) + t.Assert(err, nil) + t.Assert(j.GetArray("n"), g.Array{123456789}) + t.Assert(j.GetArray("m"), g.Array{g.Map{"k": "v"}}) + t.Assert(j.GetArray("a"), g.Array{1, 2, 3}) }) } func Test_GetString(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) - gtest.AssertEQ(j.GetString("n"), "123456789") - gtest.AssertEQ(j.GetString("m"), `{"k":"v"}`) - gtest.AssertEQ(j.GetString("a"), `[1,2,3]`) - gtest.AssertEQ(j.GetString("i"), "") + t.Assert(err, nil) + t.AssertEQ(j.GetString("n"), "123456789") + t.AssertEQ(j.GetString("m"), `{"k":"v"}`) + t.AssertEQ(j.GetString("a"), `[1,2,3]`) + t.AssertEQ(j.GetString("i"), "") }) } func Test_GetStrings(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) - gtest.AssertEQ(j.GetStrings("n"), g.SliceStr{"123456789"}) - gtest.AssertEQ(j.GetStrings("m"), g.SliceStr{`{"k":"v"}`}) - gtest.AssertEQ(j.GetStrings("a"), g.SliceStr{"1", "2", "3"}) - gtest.AssertEQ(j.GetStrings("i"), nil) + t.Assert(err, nil) + t.AssertEQ(j.GetStrings("n"), g.SliceStr{"123456789"}) + t.AssertEQ(j.GetStrings("m"), g.SliceStr{`{"k":"v"}`}) + t.AssertEQ(j.GetStrings("a"), g.SliceStr{"1", "2", "3"}) + t.AssertEQ(j.GetStrings("i"), nil) }) } func Test_GetInterfaces(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.DecodeToJson(data) - gtest.Assert(err, nil) - gtest.AssertEQ(j.GetInterfaces("n"), g.Array{123456789}) - gtest.AssertEQ(j.GetInterfaces("m"), g.Array{g.Map{"k": "v"}}) - gtest.AssertEQ(j.GetInterfaces("a"), g.Array{1, 2, 3}) + t.Assert(err, nil) + t.AssertEQ(j.GetInterfaces("n"), g.Array{123456789}) + t.AssertEQ(j.GetInterfaces("m"), g.Array{g.Map{"k": "v"}}) + t.AssertEQ(j.GetInterfaces("a"), g.Array{1, 2, 3}) }) } func Test_Len(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gjson.New(nil) p.Append("a", 1) p.Append("a", 2) - gtest.Assert(p.Len("a"), 2) + t.Assert(p.Len("a"), 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gjson.New(nil) p.Append("a.b", 1) p.Append("a.c", 2) - gtest.Assert(p.Len("a"), 2) + t.Assert(p.Len("a"), 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gjson.New(nil) p.Set("a", 1) - gtest.Assert(p.Len("a"), -1) + t.Assert(p.Len("a"), -1) }) } func Test_Append(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gjson.New(nil) p.Append("a", 1) p.Append("a", 2) - gtest.Assert(p.Get("a"), g.Slice{1, 2}) + t.Assert(p.Get("a"), g.Slice{1, 2}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gjson.New(nil) p.Append("a.b", 1) p.Append("a.c", 2) - gtest.Assert(p.Get("a"), g.Map{ + t.Assert(p.Get("a"), g.Map{ "b": g.Slice{1}, "c": g.Slice{2}, }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gjson.New(nil) p.Set("a", 1) err := p.Append("a", 2) - gtest.AssertNE(err, nil) - gtest.Assert(p.Get("a"), 1) + t.AssertNE(err, nil) + t.Assert(p.Get("a"), 1) }) } func TestJson_ToJson(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gjson.New("1") s, e := p.ToJsonString() - gtest.Assert(e, nil) - gtest.Assert(s, "1") + t.Assert(e, nil) + t.Assert(s, "1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gjson.New("a") s, e := p.ToJsonString() - gtest.Assert(e, nil) - gtest.Assert(s, `"a"`) + t.Assert(e, nil) + t.Assert(s, `"a"`) }) } func TestJson_Default(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.New(nil) - gtest.AssertEQ(j.Get("no", 100), 100) - gtest.AssertEQ(j.GetString("no", 100), "100") - gtest.AssertEQ(j.GetBool("no", "on"), true) - gtest.AssertEQ(j.GetInt("no", 100), 100) - gtest.AssertEQ(j.GetInt8("no", 100), int8(100)) - gtest.AssertEQ(j.GetInt16("no", 100), int16(100)) - gtest.AssertEQ(j.GetInt32("no", 100), int32(100)) - gtest.AssertEQ(j.GetInt64("no", 100), int64(100)) - gtest.AssertEQ(j.GetUint("no", 100), uint(100)) - gtest.AssertEQ(j.GetUint8("no", 100), uint8(100)) - gtest.AssertEQ(j.GetUint16("no", 100), uint16(100)) - gtest.AssertEQ(j.GetUint32("no", 100), uint32(100)) - gtest.AssertEQ(j.GetUint64("no", 100), uint64(100)) - gtest.AssertEQ(j.GetFloat32("no", 123.456), float32(123.456)) - gtest.AssertEQ(j.GetFloat64("no", 123.456), float64(123.456)) - gtest.AssertEQ(j.GetArray("no", g.Slice{1, 2, 3}), g.Slice{1, 2, 3}) - gtest.AssertEQ(j.GetInts("no", g.Slice{1, 2, 3}), g.SliceInt{1, 2, 3}) - gtest.AssertEQ(j.GetFloats("no", g.Slice{1, 2, 3}), []float64{1, 2, 3}) - gtest.AssertEQ(j.GetMap("no", g.Map{"k": "v"}), g.Map{"k": "v"}) - gtest.AssertEQ(j.GetVar("no", 123.456).Float64(), float64(123.456)) - gtest.AssertEQ(j.GetJson("no", g.Map{"k": "v"}).Get("k"), "v") - gtest.AssertEQ(j.GetJsons("no", g.Slice{ + t.AssertEQ(j.Get("no", 100), 100) + t.AssertEQ(j.GetString("no", 100), "100") + t.AssertEQ(j.GetBool("no", "on"), true) + t.AssertEQ(j.GetInt("no", 100), 100) + t.AssertEQ(j.GetInt8("no", 100), int8(100)) + t.AssertEQ(j.GetInt16("no", 100), int16(100)) + t.AssertEQ(j.GetInt32("no", 100), int32(100)) + t.AssertEQ(j.GetInt64("no", 100), int64(100)) + t.AssertEQ(j.GetUint("no", 100), uint(100)) + t.AssertEQ(j.GetUint8("no", 100), uint8(100)) + t.AssertEQ(j.GetUint16("no", 100), uint16(100)) + t.AssertEQ(j.GetUint32("no", 100), uint32(100)) + t.AssertEQ(j.GetUint64("no", 100), uint64(100)) + t.AssertEQ(j.GetFloat32("no", 123.456), float32(123.456)) + t.AssertEQ(j.GetFloat64("no", 123.456), float64(123.456)) + t.AssertEQ(j.GetArray("no", g.Slice{1, 2, 3}), g.Slice{1, 2, 3}) + t.AssertEQ(j.GetInts("no", g.Slice{1, 2, 3}), g.SliceInt{1, 2, 3}) + t.AssertEQ(j.GetFloats("no", g.Slice{1, 2, 3}), []float64{1, 2, 3}) + t.AssertEQ(j.GetMap("no", g.Map{"k": "v"}), g.Map{"k": "v"}) + t.AssertEQ(j.GetVar("no", 123.456).Float64(), float64(123.456)) + t.AssertEQ(j.GetJson("no", g.Map{"k": "v"}).Get("k"), "v") + t.AssertEQ(j.GetJsons("no", g.Slice{ g.Map{"k1": "v1"}, g.Map{"k2": "v2"}, g.Map{"k3": "v3"}, })[0].Get("k1"), "v1") - gtest.AssertEQ(j.GetJsonMap("no", g.Map{ + t.AssertEQ(j.GetJsonMap("no", g.Map{ "m1": g.Map{"k1": "v1"}, "m2": g.Map{"k2": "v2"}, })["m2"].Get("k2"), "v2") @@ -296,169 +296,169 @@ func TestJson_Default(t *testing.T) { } func Test_Convert(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.New(`{"name":"gf"}`) arr, err := j.ToXml() - gtest.Assert(err, nil) - gtest.Assert(string(arr), "gf") + t.Assert(err, nil) + t.Assert(string(arr), "gf") arr, err = j.ToXmlIndent() - gtest.Assert(err, nil) - gtest.Assert(string(arr), "gf") + t.Assert(err, nil) + t.Assert(string(arr), "gf") str, err := j.ToXmlString() - gtest.Assert(err, nil) - gtest.Assert(str, "gf") + t.Assert(err, nil) + t.Assert(str, "gf") str, err = j.ToXmlIndentString() - gtest.Assert(err, nil) - gtest.Assert(str, "gf") + t.Assert(err, nil) + t.Assert(str, "gf") arr, err = j.ToJsonIndent() - gtest.Assert(err, nil) - gtest.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}") + t.Assert(err, nil) + t.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}") str, err = j.ToJsonIndentString() - gtest.Assert(err, nil) - gtest.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}") + t.Assert(err, nil) + t.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}") arr, err = j.ToYaml() - gtest.Assert(err, nil) - gtest.Assert(string(arr), "name: gf\n") + t.Assert(err, nil) + t.Assert(string(arr), "name: gf\n") str, err = j.ToYamlString() - gtest.Assert(err, nil) - gtest.Assert(string(arr), "name: gf\n") + t.Assert(err, nil) + t.Assert(string(arr), "name: gf\n") arr, err = j.ToToml() - gtest.Assert(err, nil) - gtest.Assert(string(arr), "name = \"gf\"\n") + t.Assert(err, nil) + t.Assert(string(arr), "name = \"gf\"\n") str, err = j.ToTomlString() - gtest.Assert(err, nil) - gtest.Assert(string(arr), "name = \"gf\"\n") + t.Assert(err, nil) + t.Assert(string(arr), "name = \"gf\"\n") }) } func Test_Convert2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { name := struct { Name string }{} j := gjson.New(`{"name":"gf","time":"2019-06-12"}`) - gtest.Assert(j.Value().(g.Map)["name"], "gf") - gtest.Assert(j.GetMap("name1"), nil) - gtest.AssertNE(j.GetJson("name1"), nil) - gtest.Assert(j.GetJsons("name1"), nil) - gtest.Assert(j.GetJsonMap("name1"), nil) - gtest.Assert(j.Contains("name1"), 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") - gtest.Assert(j.GetDuration("time").String(), "0s") + t.Assert(j.Value().(g.Map)["name"], "gf") + t.Assert(j.GetMap("name1"), nil) + t.AssertNE(j.GetJson("name1"), nil) + t.Assert(j.GetJsons("name1"), nil) + t.Assert(j.GetJsonMap("name1"), nil) + t.Assert(j.Contains("name1"), false) + t.Assert(j.GetVar("name1").IsNil(), true) + t.Assert(j.GetVar("name").IsNil(), false) + t.Assert(j.Len("name1"), -1) + t.Assert(j.GetTime("time").Format("2006-01-02"), "2019-06-12") + t.Assert(j.GetGTime("time").Format("Y-m-d"), "2019-06-12") + t.Assert(j.GetDuration("time").String(), "0s") err := j.ToStruct(&name) - gtest.Assert(err, nil) - gtest.Assert(name.Name, "gf") + t.Assert(err, nil) + t.Assert(name.Name, "gf") //j.Dump() - gtest.Assert(err, nil) + t.Assert(err, nil) j = gjson.New(`{"person":{"name":"gf"}}`) err = j.GetStruct("person", &name) - gtest.Assert(err, nil) - gtest.Assert(name.Name, "gf") + t.Assert(err, nil) + t.Assert(name.Name, "gf") j = gjson.New(`{"name":"gf""}`) //j.Dump() - gtest.Assert(err, nil) + t.Assert(err, nil) j = gjson.New(`[1,2,3]`) - gtest.Assert(len(j.ToArray()), 3) + t.Assert(len(j.ToArray()), 3) }) } func Test_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.New(`{"name":"gf","time":"2019-06-12"}`) j.SetViolenceCheck(true) - gtest.Assert(j.Get(""), nil) - gtest.Assert(j.Get(".").(g.Map)["name"], "gf") - gtest.Assert(j.Get(".").(g.Map)["name1"], nil) + t.Assert(j.Get(""), nil) + t.Assert(j.Get(".").(g.Map)["name"], "gf") + t.Assert(j.Get(".").(g.Map)["name1"], nil) j.SetViolenceCheck(false) - gtest.Assert(j.Get(".").(g.Map)["name"], "gf") + t.Assert(j.Get(".").(g.Map)["name"], "gf") err := j.Set("name", "gf1") - gtest.Assert(err, nil) - gtest.Assert(j.Get("name"), "gf1") + t.Assert(err, nil) + t.Assert(j.Get("name"), "gf1") j = gjson.New(`[1,2,3]`) err = j.Set("\"0\".1", 11) - gtest.Assert(err, nil) - gtest.Assert(j.Get("1"), 11) + t.Assert(err, nil) + t.Assert(j.Get("1"), 11) j = gjson.New(`[1,2,3]`) err = j.Set("11111111111111111111111", 11) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) j = gjson.New(`[1,2,3]`) err = j.Remove("1") - gtest.Assert(err, nil) - gtest.Assert(j.Get("0"), 1) + t.Assert(err, nil) + t.Assert(j.Get("0"), 1) j = gjson.New(`[1,2,3]`) err = j.Remove("3") - gtest.Assert(err, nil) - gtest.Assert(j.Get("0"), 1) + t.Assert(err, nil) + t.Assert(j.Get("0"), 1) j = gjson.New(`[1,2,3]`) err = j.Remove("0.3") - gtest.Assert(err, nil) - gtest.Assert(len(j.Get("0").([]interface{})), 3) + t.Assert(err, nil) + t.Assert(len(j.Get("0").([]interface{})), 3) j = gjson.New(`[1,2,3]`) err = j.Remove("0.a") - gtest.Assert(err, nil) - gtest.Assert(len(j.Get("0").(g.Map)), 0) + t.Assert(err, nil) + t.Assert(len(j.Get("0").(g.Map)), 0) name := struct { Name string }{Name: "gf"} j = gjson.New(name) - gtest.Assert(j.Get("Name"), "gf") + t.Assert(j.Get("Name"), "gf") err = j.Remove("Name") - gtest.Assert(err, nil) - gtest.Assert(j.Get("Name"), nil) + t.Assert(err, nil) + t.Assert(j.Get("Name"), nil) err = j.Set("Name", "gf1") - gtest.Assert(err, nil) - gtest.Assert(j.Get("Name"), "gf1") + t.Assert(err, nil) + t.Assert(j.Get("Name"), "gf1") j = gjson.New(nil) err = j.Remove("Name") - gtest.Assert(err, nil) - gtest.Assert(j.Get("Name"), nil) + t.Assert(err, nil) + t.Assert(j.Get("Name"), nil) j = gjson.New(name) - gtest.Assert(j.Get("Name"), "gf") + t.Assert(j.Get("Name"), "gf") err = j.Set("Name1", g.Map{"Name": "gf1"}) - gtest.Assert(err, nil) - gtest.Assert(j.Get("Name1").(g.Map)["Name"], "gf1") + t.Assert(err, nil) + t.Assert(j.Get("Name1").(g.Map)["Name"], "gf1") err = j.Set("Name2", g.Slice{1, 2, 3}) - gtest.Assert(err, nil) - gtest.Assert(j.Get("Name2").(g.Slice)[0], 1) + t.Assert(err, nil) + t.Assert(j.Get("Name2").(g.Slice)[0], 1) err = j.Set("Name3", name) - gtest.Assert(err, nil) - gtest.Assert(j.Get("Name3").(g.Map)["Name"], "gf") + t.Assert(err, nil) + t.Assert(j.Get("Name3").(g.Map)["Name"], "gf") err = j.Set("Name4", &name) - gtest.Assert(err, nil) - gtest.Assert(j.Get("Name4").(g.Map)["Name"], "gf") + t.Assert(err, nil) + t.Assert(j.Get("Name4").(g.Map)["Name"], "gf") arr := [3]int{1, 2, 3} err = j.Set("Name5", arr) - gtest.Assert(err, nil) - gtest.Assert(j.Get("Name5").(g.Array)[0], 1) + t.Assert(err, nil) + t.Assert(j.Get("Name5").(g.Array)[0], 1) }) } func Test_IsNil(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.New(nil) - gtest.Assert(j.IsNil(), true) + t.Assert(j.IsNil(), true) }) } diff --git a/encoding/gjson/gjson_z_unit_implements_test.go b/encoding/gjson/gjson_z_unit_implements_test.go index 87938d448..0944857fa 100644 --- a/encoding/gjson/gjson_z_unit_implements_test.go +++ b/encoding/gjson/gjson_z_unit_implements_test.go @@ -18,15 +18,15 @@ import ( func TestJson_UnmarshalJSON(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.New(nil) err := json.Unmarshal(data, j) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } @@ -36,22 +36,22 @@ func TestJson_UnmarshalValue(t *testing.T) { Json *gjson.Json } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", "json": []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`), }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Json.Get("n"), "123456789") - gtest.Assert(t.Json.Get("m"), g.Map{"k": "v"}) - gtest.Assert(t.Json.Get("m.k"), "v") - gtest.Assert(t.Json.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(t.Json.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Json.Get("n"), "123456789") + t.Assert(t.Json.Get("m"), g.Map{"k": "v"}) + t.Assert(t.Json.Get("m.k"), "v") + t.Assert(t.Json.Get("a"), g.Slice{1, 2, 3}) + t.Assert(t.Json.Get("a.1"), 2) }) // Map - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *T err := gconv.Struct(g.Map{ "name": "john", @@ -61,12 +61,12 @@ func TestJson_UnmarshalValue(t *testing.T) { "a": g.Slice{1, 2, 3}, }, }, &t) - gtest.Assert(err, nil) - gtest.Assert(t.Name, "john") - gtest.Assert(t.Json.Get("n"), "123456789") - gtest.Assert(t.Json.Get("m"), g.Map{"k": "v"}) - gtest.Assert(t.Json.Get("m.k"), "v") - gtest.Assert(t.Json.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(t.Json.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(t.Name, "john") + t.Assert(t.Json.Get("n"), "123456789") + t.Assert(t.Json.Get("m"), g.Map{"k": "v"}) + t.Assert(t.Json.Get("m.k"), "v") + t.Assert(t.Json.Get("a"), g.Slice{1, 2, 3}) + t.Assert(t.Json.Get("a.1"), 2) }) } diff --git a/encoding/gjson/gjson_z_unit_json_test.go b/encoding/gjson/gjson_z_unit_json_test.go new file mode 100644 index 000000000..86f09d37d --- /dev/null +++ b/encoding/gjson/gjson_z_unit_json_test.go @@ -0,0 +1,48 @@ +// Copyright 2017 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 gjson_test + +import ( + "github.com/gogf/gf/encoding/gjson" + "github.com/gogf/gf/test/gtest" + "github.com/gogf/gf/text/gstr" + "testing" +) + +func Test_ToJson(t *testing.T) { + type ModifyFieldInfoType struct { + Id int64 `json:"id"` + New string `json:"new"` + } + type ModifyFieldInfosType struct { + Duration ModifyFieldInfoType `json:"duration"` + OMLevel ModifyFieldInfoType `json:"om_level"` + } + + type MediaRequestModifyInfo struct { + Modify ModifyFieldInfosType `json:"modifyFieldInfos"` + Field ModifyFieldInfosType `json:"fieldInfos"` + FeedID string `json:"feed_id"` + Vid string `json:"id"` + } + + gtest.C(t, func(t *gtest.T) { + jsonContent := `{"dataSetId":2001,"fieldInfos":{"duration":{"id":80079,"value":"59"},"om_level":{"id":2409,"value":"4"}},"id":"g0936lt1u0f","modifyFieldInfos":{"om_level":{"id":2409,"new":"4","old":""}},"timeStamp":1584599734}` + var info MediaRequestModifyInfo + err := gjson.DecodeTo(jsonContent, &info) + t.Assert(err, nil) + content := gjson.New(info).MustToJsonString() + t.Assert(gstr.Contains(content, `"feed_id":""`), true) + t.Assert(gstr.Contains(content, `"fieldInfos":{`), true) + t.Assert(gstr.Contains(content, `"id":80079`), true) + t.Assert(gstr.Contains(content, `"om_level":{`), true) + t.Assert(gstr.Contains(content, `"id":2409,`), true) + t.Assert(gstr.Contains(content, `"id":"g0936lt1u0f"`), true) + t.Assert(gstr.Contains(content, `"new":"4"`), true) + }) + +} diff --git a/encoding/gjson/gjson_z_unit_load_test.go b/encoding/gjson/gjson_z_unit_load_test.go index 334e0aed0..78c547a89 100644 --- a/encoding/gjson/gjson_z_unit_load_test.go +++ b/encoding/gjson/gjson_z_unit_load_test.go @@ -18,71 +18,71 @@ import ( func Test_Load_JSON1(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "test.json" gfile.PutBytes(path, data) defer gfile.Remove(path) j, err := gjson.Load(path) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } func Test_Load_JSON2(t *testing.T) { data := []byte(`{"n":123456789000000000000, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789000000000000") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789000000000000") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } func Test_Load_XML(t *testing.T) { data := []byte(`123v123456789`) // XML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("doc.n"), "123456789") - gtest.Assert(j.Get("doc.m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("doc.m.k"), "v") - gtest.Assert(j.Get("doc.a"), g.Slice{"1", "2", "3"}) - gtest.Assert(j.Get("doc.a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("doc.n"), "123456789") + t.Assert(j.Get("doc.m"), g.Map{"k": "v"}) + t.Assert(j.Get("doc.m.k"), "v") + t.Assert(j.Get("doc.a"), g.Slice{"1", "2", "3"}) + t.Assert(j.Get("doc.a.1"), 2) }) // XML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "test.xml" gfile.PutBytes(path, data) defer gfile.Remove(path) j, err := gjson.Load(path) - gtest.Assert(err, nil) - gtest.Assert(j.Get("doc.n"), "123456789") - gtest.Assert(j.Get("doc.m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("doc.m.k"), "v") - gtest.Assert(j.Get("doc.a"), g.Slice{"1", "2", "3"}) - gtest.Assert(j.Get("doc.a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("doc.n"), "123456789") + t.Assert(j.Get("doc.m"), g.Map{"k": "v"}) + t.Assert(j.Get("doc.m.k"), "v") + t.Assert(j.Get("doc.a"), g.Slice{"1", "2", "3"}) + t.Assert(j.Get("doc.a.1"), 2) }) // XML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { xml := ` @@ -94,9 +94,9 @@ func Test_Load_XML(t *testing.T) { ` j, err := gjson.LoadContent(xml) - gtest.Assert(err, nil) - gtest.Assert(j.Get("Output.ipageIndex"), "2") - gtest.Assert(j.Get("Output.itotalRecords"), "GF框架") + t.Assert(err, nil) + t.Assert(j.Get("Output.ipageIndex"), "2") + t.Assert(j.Get("Output.itotalRecords"), "GF框架") }) } @@ -111,36 +111,36 @@ m: "n": 123456789 `) // YAML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) // YAML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "test.yaml" gfile.PutBytes(path, data) defer gfile.Remove(path) j, err := gjson.Load(path) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } func Test_Load_YAML2(t *testing.T) { data := []byte("i : 123456789") - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("i"), "123456789") + t.Assert(err, nil) + t.Assert(j.Get("i"), "123456789") }) } @@ -153,59 +153,59 @@ n = 123456789 k = "v" `) // TOML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{"1", "2", "3"}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{"1", "2", "3"}) + t.Assert(j.Get("a.1"), 2) }) // TOML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "test.toml" gfile.PutBytes(path, data) defer gfile.Remove(path) j, err := gjson.Load(path) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{"1", "2", "3"}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{"1", "2", "3"}) + t.Assert(j.Get("a.1"), 2) }) } func Test_Load_TOML2(t *testing.T) { data := []byte("i=123456789") - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gjson.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("i"), "123456789") + t.Assert(err, nil) + t.Assert(j.Get("i"), "123456789") }) } func Test_Load_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.New(nil) - gtest.Assert(j.Value(), nil) + t.Assert(j.Value(), nil) _, err := gjson.Decode(nil) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) _, err = gjson.DecodeToJson(nil) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) j, err = gjson.LoadContent(nil) - gtest.Assert(err, nil) - gtest.Assert(j.Value(), nil) + t.Assert(err, nil) + t.Assert(j.Value(), nil) j, err = gjson.LoadContent(`{"name": "gf"}`) - gtest.Assert(err, nil) + t.Assert(err, nil) j, err = gjson.LoadContent(`{"name": "gf"""}`) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) j = gjson.New(&g.Map{"name": "gf"}) - gtest.Assert(j.GetString("name"), "gf") + t.Assert(j.GetString("name"), "gf") }) } @@ -228,18 +228,18 @@ enable=true ` - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { json, err := gjson.LoadContent(data) if err != nil { gtest.Fatal(err) } - gtest.Assert(json.GetString("addr.ip"), "127.0.0.1") - gtest.Assert(json.GetString("addr.port"), "9001") - gtest.Assert(json.GetString("addr.enable"), "true") - gtest.Assert(json.GetString("DBINFO.type"), "mysql") - gtest.Assert(json.GetString("DBINFO.user"), "root") - gtest.Assert(json.GetString("DBINFO.password"), "password") + t.Assert(json.GetString("addr.ip"), "127.0.0.1") + t.Assert(json.GetString("addr.port"), "9001") + t.Assert(json.GetString("addr.enable"), "true") + t.Assert(json.GetString("DBINFO.type"), "mysql") + t.Assert(json.GetString("DBINFO.user"), "root") + t.Assert(json.GetString("DBINFO.password"), "password") _, err = json.ToIni() if err != nil { diff --git a/encoding/gjson/gjson_z_unit_new_test.go b/encoding/gjson/gjson_z_unit_new_test.go index e431eb1e3..a431da8e5 100644 --- a/encoding/gjson/gjson_z_unit_new_test.go +++ b/encoding/gjson/gjson_z_unit_new_test.go @@ -25,25 +25,25 @@ func Test_Load_NewWithTag(t *testing.T) { Addr: "chengdu", } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.New(data) - gtest.AssertNE(j, nil) - gtest.Assert(j.Get("age-xml"), nil) - gtest.Assert(j.Get("age-json"), data.Age) - gtest.Assert(j.Get("name-xml"), nil) - gtest.Assert(j.Get("name-json"), data.Name) - gtest.Assert(j.Get("addr-xml"), nil) - gtest.Assert(j.Get("addr-json"), data.Addr) + t.AssertNE(j, nil) + t.Assert(j.Get("age-xml"), nil) + t.Assert(j.Get("age-json"), data.Age) + t.Assert(j.Get("name-xml"), nil) + t.Assert(j.Get("name-json"), data.Name) + t.Assert(j.Get("addr-xml"), nil) + t.Assert(j.Get("addr-json"), data.Addr) }) // XML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gjson.NewWithTag(data, "xml") - gtest.AssertNE(j, nil) - gtest.Assert(j.Get("age-xml"), data.Age) - gtest.Assert(j.Get("age-json"), nil) - gtest.Assert(j.Get("name-xml"), data.Name) - gtest.Assert(j.Get("name-json"), nil) - gtest.Assert(j.Get("addr-xml"), data.Addr) - gtest.Assert(j.Get("addr-json"), nil) + t.AssertNE(j, nil) + t.Assert(j.Get("age-xml"), data.Age) + t.Assert(j.Get("age-json"), nil) + t.Assert(j.Get("name-xml"), data.Name) + t.Assert(j.Get("name-json"), nil) + t.Assert(j.Get("addr-xml"), data.Addr) + t.Assert(j.Get("addr-json"), nil) }) } diff --git a/encoding/gjson/gjson_z_unit_struct_test.go b/encoding/gjson/gjson_z_unit_struct_test.go index decc310ee..b855fb0d4 100644 --- a/encoding/gjson/gjson_z_unit_struct_test.go +++ b/encoding/gjson/gjson_z_unit_struct_test.go @@ -14,7 +14,7 @@ import ( ) func Test_ToStruct1(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type BaseInfoItem struct { IdCardNumber string `db:"id_card_number" json:"idCardNumber" field:"id_card_number"` IsHouseholder bool `db:"is_householder" json:"isHouseholder" field:"is_householder"` @@ -88,15 +88,15 @@ func Test_ToStruct1(t *testing.T) { }` data := new(UserCollectionAddReq) j, err := gjson.LoadJson(jsonContent) - gtest.Assert(err, nil) + t.Assert(err, nil) err = j.ToStruct(data) - gtest.Assert(err, nil) + t.Assert(err, nil) g.Dump(data) }) } func Test_ToStructDeep(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Item struct { Title string `json:"title"` Key string `json:"key"` @@ -117,16 +117,16 @@ func Test_ToStructDeep(t *testing.T) { }` j, err := gjson.LoadContent(txt) - gtest.Assert(err, nil) - gtest.Assert(j.GetString("me.name"), "mikey") - gtest.Assert(j.GetString("items"), "") - gtest.Assert(j.GetBool("items"), false) - gtest.Assert(j.GetArray("items"), nil) + t.Assert(err, nil) + t.Assert(j.GetString("me.name"), "mikey") + t.Assert(j.GetString("items"), "") + t.Assert(j.GetBool("items"), false) + t.Assert(j.GetArray("items"), nil) m := new(M) err = j.ToStructDeep(m) - gtest.Assert(err, nil) - gtest.AssertNE(m.Me, nil) - gtest.Assert(m.Me["day"], "20009") - gtest.Assert(m.Items, nil) + t.Assert(err, nil) + t.AssertNE(m.Me, nil) + t.Assert(m.Me["day"], "20009") + t.Assert(m.Items, nil) }) } diff --git a/encoding/gparser/gparser_unit_basic_test.go b/encoding/gparser/gparser_unit_basic_test.go index aafd47e15..1eeca7bae 100644 --- a/encoding/gparser/gparser_unit_basic_test.go +++ b/encoding/gparser/gparser_unit_basic_test.go @@ -16,291 +16,291 @@ import ( func Test_New(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) v := j.Value().(g.Map) - gtest.Assert(v["n"], 123456789) + t.Assert(v["n"], 123456789) }) } func Test_NewUnsafe(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } func Test_Encode(t *testing.T) { value := g.Slice{1, 2, 3} - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { b, err := gparser.VarToJson(value) - gtest.Assert(err, nil) - gtest.Assert(b, []byte(`[1,2,3]`)) + t.Assert(err, nil) + t.Assert(b, []byte(`[1,2,3]`)) }) } func Test_Decode(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.AssertNE(j, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } func Test_SplitChar(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) j.SetSplitChar(byte('#')) - gtest.AssertNE(j, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m#k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a#1"), 2) + t.AssertNE(j, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m#k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a#1"), 2) }) } func Test_ViolenceCheck(t *testing.T) { data := []byte(`{"m":{"a":[1,2,3], "v1.v2":"4"}}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - gtest.Assert(j.Get("m.a.2"), 3) - gtest.Assert(j.Get("m.v1.v2"), nil) + t.AssertNE(j, nil) + t.Assert(j.Get("m.a.2"), 3) + t.Assert(j.Get("m.v1.v2"), nil) j.SetViolenceCheck(true) - gtest.Assert(j.Get("m.v1.v2"), 4) + t.Assert(j.Get("m.v1.v2"), 4) }) } func Test_GetVar(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - 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.GetMap("a"), g.Map{"1": "2", "3": nil}) + t.AssertNE(j, nil) + t.Assert(j.GetVar("n").String(), "123456789") + t.Assert(j.GetVar("m").Map(), g.Map{"k": "v"}) + t.Assert(j.GetVar("a").Interfaces(), g.Slice{1, 2, 3}) + t.Assert(j.GetVar("a").Slice(), g.Slice{1, 2, 3}) + t.Assert(j.GetMap("a"), g.Map{"1": "2", "3": nil}) }) } func Test_GetMap(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - gtest.Assert(j.GetMap("n"), nil) - gtest.Assert(j.GetMap("m"), g.Map{"k": "v"}) - gtest.Assert(j.GetMap("a"), g.Map{"1": "2", "3": nil}) + t.AssertNE(j, nil) + t.Assert(j.GetMap("n"), nil) + t.Assert(j.GetMap("m"), g.Map{"k": "v"}) + t.Assert(j.GetMap("a"), g.Map{"1": "2", "3": nil}) }) } func Test_GetArray(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - gtest.Assert(j.GetArray("n"), g.Array{123456789}) - gtest.Assert(j.GetArray("m"), g.Array{g.Map{"k": "v"}}) - gtest.Assert(j.GetArray("a"), g.Array{1, 2, 3}) + t.AssertNE(j, nil) + t.Assert(j.GetArray("n"), g.Array{123456789}) + t.Assert(j.GetArray("m"), g.Array{g.Map{"k": "v"}}) + t.Assert(j.GetArray("a"), g.Array{1, 2, 3}) }) } func Test_GetString(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - gtest.AssertEQ(j.GetString("n"), "123456789") - gtest.AssertEQ(j.GetString("m"), `{"k":"v"}`) - gtest.AssertEQ(j.GetString("a"), `[1,2,3]`) - gtest.AssertEQ(j.GetString("i"), "") + t.AssertNE(j, nil) + t.AssertEQ(j.GetString("n"), "123456789") + t.AssertEQ(j.GetString("m"), `{"k":"v"}`) + t.AssertEQ(j.GetString("a"), `[1,2,3]`) + t.AssertEQ(j.GetString("i"), "") }) } func Test_GetStrings(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - gtest.AssertEQ(j.GetStrings("n"), g.SliceStr{"123456789"}) - gtest.AssertEQ(j.GetStrings("m"), g.SliceStr{`{"k":"v"}`}) - gtest.AssertEQ(j.GetStrings("a"), g.SliceStr{"1", "2", "3"}) - gtest.AssertEQ(j.GetStrings("i"), nil) + t.AssertNE(j, nil) + t.AssertEQ(j.GetStrings("n"), g.SliceStr{"123456789"}) + t.AssertEQ(j.GetStrings("m"), g.SliceStr{`{"k":"v"}`}) + t.AssertEQ(j.GetStrings("a"), g.SliceStr{"1", "2", "3"}) + t.AssertEQ(j.GetStrings("i"), nil) }) } func Test_GetInterfaces(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - gtest.AssertEQ(j.GetInterfaces("n"), g.Array{123456789}) - gtest.AssertEQ(j.GetInterfaces("m"), g.Array{g.Map{"k": "v"}}) - gtest.AssertEQ(j.GetInterfaces("a"), g.Array{1, 2, 3}) + t.AssertNE(j, nil) + t.AssertEQ(j.GetInterfaces("n"), g.Array{123456789}) + t.AssertEQ(j.GetInterfaces("m"), g.Array{g.Map{"k": "v"}}) + t.AssertEQ(j.GetInterfaces("a"), g.Array{1, 2, 3}) }) } func Test_Len(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gparser.New(nil) p.Append("a", 1) p.Append("a", 2) - gtest.Assert(p.Len("a"), 2) + t.Assert(p.Len("a"), 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gparser.New(nil) p.Append("a.b", 1) p.Append("a.c", 2) - gtest.Assert(p.Len("a"), 2) + t.Assert(p.Len("a"), 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gparser.New(nil) p.Set("a", 1) - gtest.Assert(p.Len("a"), -1) + t.Assert(p.Len("a"), -1) }) } func Test_Append(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gparser.New(nil) p.Append("a", 1) p.Append("a", 2) - gtest.Assert(p.Get("a"), g.Slice{1, 2}) + t.Assert(p.Get("a"), g.Slice{1, 2}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gparser.New(nil) p.Append("a.b", 1) p.Append("a.c", 2) - gtest.Assert(p.Get("a"), g.Map{ + t.Assert(p.Get("a"), g.Map{ "b": g.Slice{1}, "c": g.Slice{2}, }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gparser.New(nil) p.Set("a", 1) err := p.Append("a", 2) - gtest.AssertNE(err, nil) - gtest.Assert(p.Get("a"), 1) + t.AssertNE(err, nil) + t.Assert(p.Get("a"), 1) }) } func Test_Convert(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gparser.New(`{"name":"gf","bool":true,"int":1,"float":1,"ints":[1,2],"floats":[1,2],"time":"2019-06-12","person": {"name": "gf"}}`) - gtest.Assert(p.GetVar("name").String(), "gf") - gtest.Assert(p.GetString("name"), "gf") - gtest.Assert(p.GetBool("bool"), true) - gtest.Assert(p.GetInt("int"), 1) - gtest.Assert(p.GetInt8("int"), 1) - gtest.Assert(p.GetInt16("int"), 1) - gtest.Assert(p.GetInt32("int"), 1) - gtest.Assert(p.GetInt64("int"), 1) - gtest.Assert(p.GetUint("int"), 1) - gtest.Assert(p.GetUint8("int"), 1) - gtest.Assert(p.GetUint16("int"), 1) - gtest.Assert(p.GetUint32("int"), 1) - gtest.Assert(p.GetUint64("int"), 1) - gtest.Assert(p.GetInts("ints")[0], 1) - gtest.Assert(p.GetFloat32("float"), 1) - gtest.Assert(p.GetFloat64("float"), 1) - gtest.Assert(p.GetFloats("floats")[0], 1) - gtest.Assert(p.GetTime("time").Format("2006-01-02"), "2019-06-12") - gtest.Assert(p.GetGTime("time").Format("Y-m-d"), "2019-06-12") - gtest.Assert(p.GetDuration("time").String(), "0s") + t.Assert(p.GetVar("name").String(), "gf") + t.Assert(p.GetString("name"), "gf") + t.Assert(p.GetBool("bool"), true) + t.Assert(p.GetInt("int"), 1) + t.Assert(p.GetInt8("int"), 1) + t.Assert(p.GetInt16("int"), 1) + t.Assert(p.GetInt32("int"), 1) + t.Assert(p.GetInt64("int"), 1) + t.Assert(p.GetUint("int"), 1) + t.Assert(p.GetUint8("int"), 1) + t.Assert(p.GetUint16("int"), 1) + t.Assert(p.GetUint32("int"), 1) + t.Assert(p.GetUint64("int"), 1) + t.Assert(p.GetInts("ints")[0], 1) + t.Assert(p.GetFloat32("float"), 1) + t.Assert(p.GetFloat64("float"), 1) + t.Assert(p.GetFloats("floats")[0], 1) + t.Assert(p.GetTime("time").Format("2006-01-02"), "2019-06-12") + t.Assert(p.GetGTime("time").Format("Y-m-d"), "2019-06-12") + t.Assert(p.GetDuration("time").String(), "0s") name := struct { Name string }{} err := p.GetStruct("person", &name) - gtest.Assert(err, nil) - gtest.Assert(name.Name, "gf") - gtest.Assert(p.ToMap()["name"], "gf") + t.Assert(err, nil) + t.Assert(name.Name, "gf") + t.Assert(p.ToMap()["name"], "gf") err = p.ToStruct(&name) - gtest.Assert(err, nil) - gtest.Assert(name.Name, "gf") + t.Assert(err, nil) + t.Assert(name.Name, "gf") //p.Dump() p = gparser.New(`[0,1,2]`) - gtest.Assert(p.ToArray()[0], 0) + t.Assert(p.ToArray()[0], 0) }) } func Test_Convert2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { xmlArr := []byte{60, 114, 111, 111, 116, 47, 62} p := gparser.New(``) arr, err := p.ToXml("root") - gtest.Assert(err, nil) - gtest.Assert(arr, xmlArr) + t.Assert(err, nil) + t.Assert(arr, xmlArr) arr, err = gparser.VarToXml(``, "root") - gtest.Assert(err, nil) - gtest.Assert(arr, xmlArr) + t.Assert(err, nil) + t.Assert(arr, xmlArr) arr, err = p.ToXmlIndent("root") - gtest.Assert(err, nil) - gtest.Assert(arr, xmlArr) + t.Assert(err, nil) + t.Assert(arr, xmlArr) arr, err = gparser.VarToXmlIndent(``, "root") - gtest.Assert(err, nil) - gtest.Assert(arr, xmlArr) + t.Assert(err, nil) + t.Assert(arr, xmlArr) p = gparser.New(`{"name":"gf"}`) str, err := p.ToJsonString() - gtest.Assert(err, nil) - gtest.Assert(str, `{"name":"gf"}`) + t.Assert(err, nil) + t.Assert(str, `{"name":"gf"}`) str, err = gparser.VarToJsonString(`{"name":"gf"}`) - gtest.Assert(err, nil) - gtest.Assert(str, `{"name":"gf"}`) + t.Assert(err, nil) + t.Assert(str, `{"name":"gf"}`) jsonIndentArr := []byte{123, 10, 9, 34, 110, 97, 109, 101, 34, 58, 32, 34, 103, 102, 34, 10, 125} arr, err = p.ToJsonIndent() - gtest.Assert(err, nil) - gtest.Assert(arr, jsonIndentArr) + t.Assert(err, nil) + t.Assert(arr, jsonIndentArr) arr, err = gparser.VarToJsonIndent(`{"name":"gf"}`) - gtest.Assert(err, nil) - gtest.Assert(arr, jsonIndentArr) + t.Assert(err, nil) + t.Assert(arr, jsonIndentArr) str, err = p.ToJsonIndentString() - gtest.Assert(err, nil) - gtest.Assert(str, "{\n\t\"name\": \"gf\"\n}") + t.Assert(err, nil) + t.Assert(str, "{\n\t\"name\": \"gf\"\n}") str, err = gparser.VarToJsonIndentString(`{"name":"gf"}`) - gtest.Assert(err, nil) - gtest.Assert(str, "{\n\t\"name\": \"gf\"\n}") + t.Assert(err, nil) + t.Assert(str, "{\n\t\"name\": \"gf\"\n}") p = gparser.New(g.Map{"name": "gf"}) arr, err = p.ToYaml() - gtest.Assert(err, nil) - gtest.Assert(arr, "name: gf\n") + t.Assert(err, nil) + t.Assert(arr, "name: gf\n") arr, err = gparser.VarToYaml(g.Map{"name": "gf"}) - gtest.Assert(err, nil) - gtest.Assert(arr, "name: gf\n") + t.Assert(err, nil) + t.Assert(arr, "name: gf\n") tomlArr := []byte{110, 97, 109, 101, 32, 61, 32, 34, 103, 102, 34, 10} p = gparser.New(` name= "gf" `) arr, err = p.ToToml() - gtest.Assert(err, nil) - gtest.Assert(arr, tomlArr) + t.Assert(err, nil) + t.Assert(arr, tomlArr) arr, err = gparser.VarToToml(` name= "gf" `) - gtest.Assert(err, nil) - gtest.Assert(arr, tomlArr) + t.Assert(err, nil) + t.Assert(arr, tomlArr) }) } diff --git a/encoding/gparser/gparser_unit_load_test.go b/encoding/gparser/gparser_unit_load_test.go index 1c24d9dbb..a92f50c9f 100644 --- a/encoding/gparser/gparser_unit_load_test.go +++ b/encoding/gparser/gparser_unit_load_test.go @@ -19,58 +19,58 @@ import ( func Test_Load_JSON(t *testing.T) { data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gparser.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "test.json" gfile.PutBytes(path, data) defer gfile.Remove(path) j, err := gparser.Load(path) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } func Test_Load_XML(t *testing.T) { data := []byte(`123v123456789`) // XML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gparser.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("doc.n"), "123456789") - gtest.Assert(j.Get("doc.m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("doc.m.k"), "v") - gtest.Assert(j.Get("doc.a"), g.Slice{"1", "2", "3"}) - gtest.Assert(j.Get("doc.a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("doc.n"), "123456789") + t.Assert(j.Get("doc.m"), g.Map{"k": "v"}) + t.Assert(j.Get("doc.m.k"), "v") + t.Assert(j.Get("doc.a"), g.Slice{"1", "2", "3"}) + t.Assert(j.Get("doc.a.1"), 2) }) // XML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "test.xml" gfile.PutBytes(path, data) defer gfile.Remove(path) j, err := gparser.Load(path) - gtest.Assert(err, nil) - gtest.Assert(j.Get("doc.n"), "123456789") - gtest.Assert(j.Get("doc.m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("doc.m.k"), "v") - gtest.Assert(j.Get("doc.a"), g.Slice{"1", "2", "3"}) - gtest.Assert(j.Get("doc.a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("doc.n"), "123456789") + t.Assert(j.Get("doc.m"), g.Map{"k": "v"}) + t.Assert(j.Get("doc.m.k"), "v") + t.Assert(j.Get("doc.a"), g.Slice{"1", "2", "3"}) + t.Assert(j.Get("doc.a.1"), 2) }) // XML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { xml := ` @@ -82,9 +82,9 @@ func Test_Load_XML(t *testing.T) { ` j, err := gparser.LoadContent(xml) - gtest.Assert(err, nil) - gtest.Assert(j.Get("Output.ipageIndex"), "2") - gtest.Assert(j.Get("Output.itotalRecords"), "GF框架") + t.Assert(err, nil) + t.Assert(j.Get("Output.ipageIndex"), "2") + t.Assert(j.Get("Output.itotalRecords"), "GF框架") }) } @@ -99,36 +99,36 @@ m: "n": 123456789 `) // YAML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gparser.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) // YAML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "test.yaml" gfile.PutBytes(path, data) defer gfile.Remove(path) j, err := gparser.Load(path) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{1, 2, 3}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{1, 2, 3}) + t.Assert(j.Get("a.1"), 2) }) } func Test_Load_YAML2(t *testing.T) { data := []byte("i : 123456789") - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gparser.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("i"), "123456789") + t.Assert(err, nil) + t.Assert(j.Get("i"), "123456789") }) } @@ -141,50 +141,50 @@ n = "123456789" k = "v" `) // TOML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gparser.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{"1", "2", "3"}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{"1", "2", "3"}) + t.Assert(j.Get("a.1"), 2) }) // TOML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "test.toml" gfile.PutBytes(path, data) defer gfile.Remove(path) j, err := gparser.Load(path) - gtest.Assert(err, nil) - gtest.Assert(j.Get("n"), "123456789") - gtest.Assert(j.Get("m"), g.Map{"k": "v"}) - gtest.Assert(j.Get("m.k"), "v") - gtest.Assert(j.Get("a"), g.Slice{"1", "2", "3"}) - gtest.Assert(j.Get("a.1"), 2) + t.Assert(err, nil) + t.Assert(j.Get("n"), "123456789") + t.Assert(j.Get("m"), g.Map{"k": "v"}) + t.Assert(j.Get("m.k"), "v") + t.Assert(j.Get("a"), g.Slice{"1", "2", "3"}) + t.Assert(j.Get("a.1"), 2) }) } func Test_Load_TOML2(t *testing.T) { data := []byte("i=123456789") - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j, err := gparser.LoadContent(data) - gtest.Assert(err, nil) - gtest.Assert(j.Get("i"), "123456789") + t.Assert(err, nil) + t.Assert(j.Get("i"), "123456789") }) } func Test_Load_Nil(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := gparser.New(nil) - gtest.Assert(p.Value(), nil) + t.Assert(p.Value(), nil) file := "test22222.json" filePath := gfile.Pwd() + gfile.Separator + file ioutil.WriteFile(filePath, []byte("{"), 0644) defer gfile.Remove(filePath) _, err := gparser.Load(file) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) _, err = gparser.LoadContent("{") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } diff --git a/encoding/gparser/gparser_unit_new_test.go b/encoding/gparser/gparser_unit_new_test.go index d3a4cd0f3..0f8984825 100644 --- a/encoding/gparser/gparser_unit_new_test.go +++ b/encoding/gparser/gparser_unit_new_test.go @@ -25,25 +25,25 @@ func Test_Load_NewWithTag(t *testing.T) { Addr: "chengdu", } // JSON - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.New(data) - gtest.AssertNE(j, nil) - gtest.Assert(j.Get("age-xml"), nil) - gtest.Assert(j.Get("age-json"), data.Age) - gtest.Assert(j.Get("name-xml"), nil) - gtest.Assert(j.Get("name-json"), data.Name) - gtest.Assert(j.Get("addr-xml"), nil) - gtest.Assert(j.Get("addr-json"), data.Addr) + t.AssertNE(j, nil) + t.Assert(j.Get("age-xml"), nil) + t.Assert(j.Get("age-json"), data.Age) + t.Assert(j.Get("name-xml"), nil) + t.Assert(j.Get("name-json"), data.Name) + t.Assert(j.Get("addr-xml"), nil) + t.Assert(j.Get("addr-json"), data.Addr) }) // XML - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gparser.NewWithTag(data, "xml") - gtest.AssertNE(j, nil) - gtest.Assert(j.Get("age-xml"), data.Age) - gtest.Assert(j.Get("age-json"), nil) - gtest.Assert(j.Get("name-xml"), data.Name) - gtest.Assert(j.Get("name-json"), nil) - gtest.Assert(j.Get("addr-xml"), data.Addr) - gtest.Assert(j.Get("addr-json"), nil) + t.AssertNE(j, nil) + t.Assert(j.Get("age-xml"), data.Age) + t.Assert(j.Get("age-json"), nil) + t.Assert(j.Get("name-xml"), data.Name) + t.Assert(j.Get("name-json"), nil) + t.Assert(j.Get("addr-xml"), data.Addr) + t.Assert(j.Get("addr-json"), nil) }) } diff --git a/encoding/gtoml/gtoml_test.go b/encoding/gtoml/gtoml_test.go index 345320c06..b9c4ccfd3 100644 --- a/encoding/gtoml/gtoml_test.go +++ b/encoding/gtoml/gtoml_test.go @@ -34,7 +34,7 @@ dd = 11 ` func TestEncode(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string]string) m["toml"] = tomlStr res, err := gtoml.Encode(m) @@ -49,10 +49,10 @@ func TestEncode(t *testing.T) { return } - gtest.Assert(p.GetString("toml"), tomlStr) + t.Assert(p.GetString("toml"), tomlStr) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := gtoml.Encode(tomlErr) if err == nil { t.Errorf("encode should be failed. %v", err) @@ -62,7 +62,7 @@ func TestEncode(t *testing.T) { } func TestDecode(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string]string) m["toml"] = tomlStr res, err := gtoml.Encode(m) @@ -77,7 +77,7 @@ func TestDecode(t *testing.T) { return } - gtest.Assert(decodeStr.(map[string]interface{})["toml"], tomlStr) + t.Assert(decodeStr.(map[string]interface{})["toml"], tomlStr) decodeStr1 := make(map[string]interface{}) err = gtoml.DecodeTo(res, &decodeStr1) @@ -85,10 +85,10 @@ func TestDecode(t *testing.T) { t.Errorf("decodeTo failed. %v", err) return } - gtest.Assert(decodeStr1["toml"], tomlStr) + t.Assert(decodeStr1["toml"], tomlStr) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := gtoml.Decode([]byte(tomlErr)) if err == nil { t.Errorf("decode failed. %v", err) @@ -105,7 +105,7 @@ func TestDecode(t *testing.T) { } func TestToJson(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string]string) m["toml"] = tomlStr res, err := gtoml.Encode(m) @@ -130,10 +130,10 @@ func TestToJson(t *testing.T) { t.Errorf("parser ToJson failed. %v", err) return } - gtest.Assert(jsonToml, expectJson) + t.Assert(jsonToml, expectJson) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := gtoml.ToJson([]byte(tomlErr)) if err == nil { t.Errorf("ToJson failed. %v", err) diff --git a/encoding/gurl/url_test.go b/encoding/gurl/url_test.go index 889fc3a40..63126cee8 100644 --- a/encoding/gurl/url_test.go +++ b/encoding/gurl/url_test.go @@ -18,28 +18,28 @@ var urlEncode string = `https%3A%2F%2Fgolang.org%2Fx%2Fcrypto%3Fgo-get%3D1+%2B` var rawUrlEncode string = `https%3A%2F%2Fgolang.org%2Fx%2Fcrypto%3Fgo-get%3D1%20%2B` func TestEncodeAndDecode(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gurl.Encode(urlStr), urlEncode) + gtest.C(t, func(t *gtest.T) { + t.Assert(gurl.Encode(urlStr), urlEncode) res, err := gurl.Decode(urlEncode) if err != nil { t.Errorf("decode failed. %v", err) return } - gtest.Assert(res, urlStr) + t.Assert(res, urlStr) }) } func TestRowEncodeAndDecode(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gurl.RawEncode(urlStr), rawUrlEncode) + gtest.C(t, func(t *gtest.T) { + t.Assert(gurl.RawEncode(urlStr), rawUrlEncode) res, err := gurl.RawDecode(rawUrlEncode) if err != nil { t.Errorf("decode failed. %v", err) return } - gtest.Assert(res, urlStr) + t.Assert(res, urlStr) }) } @@ -51,7 +51,7 @@ func TestBuildQuery(t *testing.T) { } expect := "a=a2&a=a1&b=b2&b=b1&c=c1&c=c2" - gtest.Assert(gurl.BuildQuery(src), expect) + t.Assert(gurl.BuildQuery(src), expect) } func TestParseURL(t *testing.T) { @@ -67,7 +67,7 @@ func TestParseURL(t *testing.T) { "fragment": "anchor", } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { component := 0 for k, v := range []string{"all", "scheme", "host", "port", "user", "pass", "path", "query", "fragment"} { if v == "all" { @@ -83,9 +83,9 @@ func TestParseURL(t *testing.T) { } if v == "all" { - gtest.Assert(res, expect) + t.Assert(res, expect) } else { - gtest.Assert(res[v], expect[v]) + t.Assert(res[v], expect[v]) } } diff --git a/encoding/gxml/gxml_test.go b/encoding/gxml/gxml_test.go index 86d602f2a..d9ea1970d 100644 --- a/encoding/gxml/gxml_test.go +++ b/encoding/gxml/gxml_test.go @@ -107,28 +107,28 @@ func Test_Decode1(t *testing.T) { } func Test_Decode2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { content := ` johngcn123456123456 ` m, err := gxml.Decode([]byte(content)) - gtest.Assert(err, nil) - gtest.Assert(m["doc"].(map[string]interface{})["username"], "johngcn") - gtest.Assert(m["doc"].(map[string]interface{})["password1"], "123456") - gtest.Assert(m["doc"].(map[string]interface{})["password2"], "123456") + t.Assert(err, nil) + t.Assert(m["doc"].(map[string]interface{})["username"], "johngcn") + t.Assert(m["doc"].(map[string]interface{})["password1"], "123456") + t.Assert(m["doc"].(map[string]interface{})["password2"], "123456") }) } func Test_DecodeWitoutRoot(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { content := ` johngcn123456123456 ` m, err := gxml.DecodeWithoutRoot([]byte(content)) - gtest.Assert(err, nil) - gtest.Assert(m["username"], "johngcn") - gtest.Assert(m["password1"], "123456") - gtest.Assert(m["password2"], "123456") + t.Assert(err, nil) + t.Assert(m["username"], "johngcn") + t.Assert(m["password1"], "123456") + t.Assert(m["password2"], "123456") }) } @@ -190,7 +190,7 @@ func TestErrXml(t *testing.T) { } func TestErrCase(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { errXml := `true100.92123hello world` _, err := gxml.ToJson([]byte(errXml)) if err == nil { @@ -198,7 +198,7 @@ func TestErrCase(t *testing.T) { } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { errXml := `true100.92123hello world` _, err := gxml.Decode([]byte(errXml)) if err == nil { diff --git a/encoding/gyaml/gyaml_test.go b/encoding/gyaml/gyaml_test.go index c9072c151..d5dc22954 100644 --- a/encoding/gyaml/gyaml_test.go +++ b/encoding/gyaml/gyaml_test.go @@ -39,13 +39,13 @@ dd = 11 ` func Test_Decode(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := gyaml.Decode([]byte(yamlStr)) - gtest.Assert(err, nil) + t.Assert(err, nil) m, ok := result.(map[string]interface{}) - gtest.Assert(ok, true) - gtest.Assert(m, map[string]interface{}{ + t.Assert(ok, true) + t.Assert(m, map[string]interface{}{ "url": "https://goframe.org", "server": g.Slice{"120.168.117.21", "120.168.117.22"}, "pi": 3.14, @@ -56,11 +56,11 @@ func Test_Decode(t *testing.T) { } func Test_DecodeTo(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result := make(map[string]interface{}) err := gyaml.DecodeTo([]byte(yamlStr), &result) - gtest.Assert(err, nil) - gtest.Assert(result, map[string]interface{}{ + t.Assert(err, nil) + t.Assert(result, map[string]interface{}{ "url": "https://goframe.org", "server": g.Slice{"120.168.117.21", "120.168.117.22"}, "pi": 3.14, @@ -71,18 +71,18 @@ func Test_DecodeTo(t *testing.T) { } func Test_DecodeError(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := gyaml.Decode([]byte(yamlErr)) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) result := make(map[string]interface{}) err = gyaml.DecodeTo([]byte(yamlErr), &result) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_ToJson(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string]string) m["yaml"] = yamlStr res, err := gyaml.Encode(m) @@ -107,10 +107,10 @@ func Test_ToJson(t *testing.T) { t.Errorf("parser ToJson failed. %v", err) return } - gtest.Assert(jsonyaml, expectJson) + t.Assert(jsonyaml, expectJson) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { _, err := gyaml.ToJson([]byte(yamlErr)) if err == nil { t.Errorf("ToJson failed. %v", err) diff --git a/errors/gerror/gerror_test.go b/errors/gerror/gerror_test.go index e5d41331a..e89662638 100644 --- a/errors/gerror/gerror_test.go +++ b/errors/gerror/gerror_test.go @@ -24,110 +24,110 @@ func nilError() error { } func Test_Nil(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gerror.New(""), nil) - gtest.Assert(gerror.Wrap(nilError(), "test"), nil) + gtest.C(t, func(t *gtest.T) { + t.Assert(gerror.New(""), nil) + t.Assert(gerror.Wrap(nilError(), "test"), nil) }) } func Test_Wrap(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := errors.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.AssertNE(err, nil) - gtest.Assert(err.Error(), "3: 2: 1") + t.AssertNE(err, nil) + t.Assert(err.Error(), "3: 2: 1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gerror.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.AssertNE(err, nil) - gtest.Assert(err.Error(), "3: 2: 1") + t.AssertNE(err, nil) + t.Assert(err.Error(), "3: 2: 1") }) } func Test_Cause(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := errors.New("1") - gtest.Assert(gerror.Cause(err), err) + t.Assert(gerror.Cause(err), err) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := errors.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.Assert(gerror.Cause(err), "1") + t.Assert(gerror.Cause(err), "1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gerror.New("1") - gtest.Assert(gerror.Cause(err), "1") + t.Assert(gerror.Cause(err), "1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gerror.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.Assert(gerror.Cause(err), "1") + t.Assert(gerror.Cause(err), "1") }) } func Test_Format(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := errors.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.AssertNE(err, nil) - gtest.Assert(fmt.Sprintf("%s", err), "3: 2: 1") - gtest.Assert(fmt.Sprintf("%v", err), "3: 2: 1") + t.AssertNE(err, nil) + t.Assert(fmt.Sprintf("%s", err), "3: 2: 1") + t.Assert(fmt.Sprintf("%v", err), "3: 2: 1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gerror.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.AssertNE(err, nil) - gtest.Assert(fmt.Sprintf("%s", err), "3: 2: 1") - gtest.Assert(fmt.Sprintf("%v", err), "3: 2: 1") + t.AssertNE(err, nil) + t.Assert(fmt.Sprintf("%s", err), "3: 2: 1") + t.Assert(fmt.Sprintf("%v", err), "3: 2: 1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gerror.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.AssertNE(err, nil) - gtest.Assert(fmt.Sprintf("%-s", err), "3") - gtest.Assert(fmt.Sprintf("%-v", err), "3") + t.AssertNE(err, nil) + t.Assert(fmt.Sprintf("%-s", err), "3") + t.Assert(fmt.Sprintf("%-v", err), "3") }) } func Test_Stack(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := errors.New("1") - gtest.Assert(fmt.Sprintf("%+v", err), "1") + t.Assert(fmt.Sprintf("%+v", err), "1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := errors.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) //fmt.Printf("%+v", err) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gerror.New("1") - gtest.AssertNE(fmt.Sprintf("%+v", err), "1") + t.AssertNE(fmt.Sprintf("%+v", err), "1") //fmt.Printf("%+v", err) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gerror.New("1") err = gerror.Wrap(err, "2") err = gerror.Wrap(err, "3") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) //fmt.Printf("%+v", err) }) } diff --git a/frame/gins/gins_z_unit_basic_test.go b/frame/gins/gins_z_unit_basic_test.go index 5820720e8..9ed95fabd 100644 --- a/frame/gins/gins_z_unit_basic_test.go +++ b/frame/gins/gins_z_unit_basic_test.go @@ -14,31 +14,31 @@ import ( ) func Test_SetGet(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gins.Set("test-user", 1) - gtest.Assert(gins.Get("test-user"), 1) - gtest.Assert(gins.Get("none-exists"), nil) + t.Assert(gins.Get("test-user"), 1) + t.Assert(gins.Get("none-exists"), nil) }) - gtest.Case(t, func() { - gtest.Assert(gins.GetOrSet("test-1", 1), 1) - gtest.Assert(gins.Get("test-1"), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gins.GetOrSet("test-1", 1), 1) + t.Assert(gins.Get("test-1"), 1) }) - gtest.Case(t, func() { - gtest.Assert(gins.GetOrSetFunc("test-2", func() interface{} { + gtest.C(t, func(t *gtest.T) { + t.Assert(gins.GetOrSetFunc("test-2", func() interface{} { return 2 }), 2) - gtest.Assert(gins.Get("test-2"), 2) + t.Assert(gins.Get("test-2"), 2) }) - gtest.Case(t, func() { - gtest.Assert(gins.GetOrSetFuncLock("test-3", func() interface{} { + gtest.C(t, func(t *gtest.T) { + t.Assert(gins.GetOrSetFuncLock("test-3", func() interface{} { return 3 }), 3) - gtest.Assert(gins.Get("test-3"), 3) + t.Assert(gins.Get("test-3"), 3) }) - gtest.Case(t, func() { - gtest.Assert(gins.SetIfNotExist("test-4", 4), true) - gtest.Assert(gins.Get("test-4"), 4) - gtest.Assert(gins.SetIfNotExist("test-4", 5), false) - gtest.Assert(gins.Get("test-4"), 4) + gtest.C(t, func(t *gtest.T) { + t.Assert(gins.SetIfNotExist("test-4", 4), true) + t.Assert(gins.Get("test-4"), 4) + t.Assert(gins.SetIfNotExist("test-4", 5), false) + t.Assert(gins.Get("test-4"), 4) }) } diff --git a/frame/gins/gins_z_unit_config_test.go b/frame/gins/gins_z_unit_config_test.go index 74c03d401..0beb16ed3 100644 --- a/frame/gins/gins_z_unit_config_test.go +++ b/frame/gins/gins_z_unit_config_test.go @@ -27,59 +27,59 @@ var ( ) func Test_Config1(t *testing.T) { - gtest.Case(t, func() { - gtest.AssertNE(configContent, "") + gtest.C(t, func(t *gtest.T) { + t.AssertNE(configContent, "") }) - gtest.Case(t, func() { - gtest.AssertNE(gins.Config(), nil) + gtest.C(t, func(t *gtest.T) { + t.AssertNE(gins.Config(), nil) }) } func Test_Config2(t *testing.T) { // relative path - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var err error dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dirPath) name := "config.toml" err = gfile.PutContents(gfile.Join(dirPath, name), configContent) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gins.Config().AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gins.Config().Clear() - gtest.Assert(gins.Config().Get("test"), "v=1") - gtest.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") - gtest.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") + t.Assert(gins.Config().Get("test"), "v=1") + t.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") }) // for gfsnotify callbacks to refresh cache of config file time.Sleep(500 * time.Millisecond) // relative path, config folder - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var err error dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dirPath) name := "config/config.toml" err = gfile.PutContents(gfile.Join(dirPath, name), configContent) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gins.Config().AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gins.Config().Clear() - gtest.Assert(gins.Config().Get("test"), "v=1") - gtest.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") - gtest.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") + t.Assert(gins.Config().Get("test"), "v=1") + t.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") // for gfsnotify callbacks to refresh cache of config file time.Sleep(500 * time.Millisecond) @@ -87,51 +87,51 @@ func Test_Config2(t *testing.T) { } func Test_Config3(t *testing.T) { - gtest.Case(t, func() { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { + gtest.C(t, func(t *gtest.T) { var err error dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dirPath) name := "test.toml" err = gfile.PutContents(gfile.Join(dirPath, name), configContent) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gins.Config("test").AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gins.Config("test").Clear() gins.Config("test").SetFileName("test.toml") - gtest.Assert(gins.Config("test").Get("test"), "v=1") - gtest.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") - gtest.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") + t.Assert(gins.Config("test").Get("test"), "v=1") + t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") }) // for gfsnotify callbacks to refresh cache of config file time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var err error dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dirPath) name := "config/test.toml" err = gfile.PutContents(gfile.Join(dirPath, name), configContent) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gins.Config("test").AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gins.Config("test").Clear() gins.Config("test").SetFileName("test.toml") - gtest.Assert(gins.Config("test").Get("test"), "v=1") - gtest.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") - gtest.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") + t.Assert(gins.Config("test").Get("test"), "v=1") + t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") }) // for gfsnotify callbacks to refresh cache of config file for next unit testing case. time.Sleep(500 * time.Millisecond) @@ -139,77 +139,77 @@ func Test_Config3(t *testing.T) { } func Test_Config4(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // absolute path - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.TimestampNano()) file := fmt.Sprintf(`%s/%s`, path, "config.toml") err := gfile.PutContents(file, configContent) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(file) defer gins.Config().Clear() - gtest.Assert(gins.Config().AddPath(path), nil) - gtest.Assert(gins.Config().Get("test"), "v=1") - gtest.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") - gtest.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") + t.Assert(gins.Config().AddPath(path), nil) + t.Assert(gins.Config().Get("test"), "v=1") + t.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") }) time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := fmt.Sprintf(`%s/%d/config`, gfile.TempDir(), gtime.TimestampNano()) file := fmt.Sprintf(`%s/%s`, path, "config.toml") err := gfile.PutContents(file, configContent) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(file) defer gins.Config().Clear() - gtest.Assert(gins.Config().AddPath(path), nil) - gtest.Assert(gins.Config().Get("test"), "v=1") - gtest.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") - gtest.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") + t.Assert(gins.Config().AddPath(path), nil) + t.Assert(gins.Config().Get("test"), "v=1") + t.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") }) time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.TimestampNano()) file := fmt.Sprintf(`%s/%s`, path, "test.toml") err := gfile.PutContents(file, configContent) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(file) defer gins.Config("test").Clear() gins.Config("test").SetFileName("test.toml") - gtest.Assert(gins.Config("test").AddPath(path), nil) - gtest.Assert(gins.Config("test").Get("test"), "v=1") - gtest.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") - gtest.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") + t.Assert(gins.Config("test").AddPath(path), nil) + t.Assert(gins.Config("test").Get("test"), "v=1") + t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") }) time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := fmt.Sprintf(`%s/%d/config`, gfile.TempDir(), gtime.TimestampNano()) file := fmt.Sprintf(`%s/%s`, path, "test.toml") err := gfile.PutContents(file, configContent) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(file) defer gins.Config().Clear() gins.Config("test").SetFileName("test.toml") - gtest.Assert(gins.Config("test").AddPath(path), nil) - gtest.Assert(gins.Config("test").Get("test"), "v=1") - gtest.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") - gtest.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") + t.Assert(gins.Config("test").AddPath(path), nil) + t.Assert(gins.Config("test").Get("test"), "v=1") + t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") }) }) } func Test_Basic2(t *testing.T) { config := `log-path = "logs"` - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gcfg.DEFAULT_CONFIG_FILE err := gfile.PutContents(path, config) - gtest.Assert(err, nil) + t.Assert(err, nil) defer func() { _ = gfile.Remove(path) }() - gtest.Assert(gins.Config().Get("log-path"), "logs") + t.Assert(gins.Config().Get("log-path"), "logs") }) } diff --git a/frame/gins/gins_z_unit_database_test.go b/frame/gins/gins_z_unit_database_test.go index 16d2b3a03..c0be272d4 100644 --- a/frame/gins/gins_z_unit_database_test.go +++ b/frame/gins/gins_z_unit_database_test.go @@ -23,32 +23,32 @@ func Test_Database(t *testing.T) { var err error dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dirPath) name := "config.toml" err = gfile.PutContents(gfile.Join(dirPath, name), databaseContent) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gins.Config().AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gins.Config().Clear() // for gfsnotify callbacks to refresh cache of config file time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //fmt.Println("gins Test_Database", Config().Get("test")) dbDefault := gins.Database() dbTest := gins.Database("test") - gtest.AssertNE(dbDefault, nil) - gtest.AssertNE(dbTest, nil) + t.AssertNE(dbDefault, nil) + t.AssertNE(dbTest, nil) - gtest.Assert(dbDefault.PingMaster(), nil) - gtest.Assert(dbDefault.PingSlave(), nil) - gtest.Assert(dbTest.PingMaster(), nil) - gtest.Assert(dbTest.PingSlave(), nil) + t.Assert(dbDefault.PingMaster(), nil) + t.Assert(dbDefault.PingSlave(), nil) + t.Assert(dbTest.PingMaster(), nil) + t.Assert(dbTest.PingSlave(), nil) }) } diff --git a/frame/gins/gins_z_unit_redis_test.go b/frame/gins/gins_z_unit_redis_test.go index 1101a81a8..7ec312fa6 100644 --- a/frame/gins/gins_z_unit_redis_test.go +++ b/frame/gins/gins_z_unit_redis_test.go @@ -23,43 +23,43 @@ func Test_Redis(t *testing.T) { var err error dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dirPath) name := "config.toml" err = gfile.PutContents(gfile.Join(dirPath, name), redisContent) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gins.Config().AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gins.Config().Clear() // for gfsnotify callbacks to refresh cache of config file time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //fmt.Println("gins Test_Redis", Config().Get("test")) redisDefault := gins.Redis() redisCache := gins.Redis("cache") redisDisk := gins.Redis("disk") - gtest.AssertNE(redisDefault, nil) - gtest.AssertNE(redisCache, nil) - gtest.AssertNE(redisDisk, nil) + t.AssertNE(redisDefault, nil) + t.AssertNE(redisCache, nil) + t.AssertNE(redisDisk, nil) r, err := redisDefault.Do("PING") - gtest.Assert(err, nil) - gtest.Assert(r, "PONG") + t.Assert(err, nil) + t.Assert(r, "PONG") r, err = redisCache.Do("PING") - gtest.Assert(err, nil) - gtest.Assert(r, "PONG") + t.Assert(err, nil) + t.Assert(r, "PONG") _, err = redisDisk.Do("SET", "k", "v") - gtest.Assert(err, nil) + t.Assert(err, nil) r, err = redisDisk.Do("GET", "k") - gtest.Assert(err, nil) - gtest.Assert(r, []byte("v")) + t.Assert(err, nil) + t.Assert(r, []byte("v")) }) } diff --git a/frame/gins/gins_z_unit_view_test.go b/frame/gins/gins_z_unit_view_test.go index a3ea55bb6..c8f0cf34b 100644 --- a/frame/gins/gins_z_unit_view_test.go +++ b/frame/gins/gins_z_unit_view_test.go @@ -18,124 +18,124 @@ import ( ) func Test_View(t *testing.T) { - gtest.Case(t, func() { - gtest.AssertNE(View(), nil) + gtest.C(t, func(t *gtest.T) { + t.AssertNE(View(), nil) b, e := View().ParseContent(`{{"我是中国人" | substr 2 -1}}`, nil) - gtest.Assert(e, nil) - gtest.Assert(b, "中国人") + t.Assert(e, nil) + t.Assert(b, "中国人") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tpl := "t.tpl" err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(tpl) b, e := View().Parse("t.tpl", nil) - gtest.Assert(e, nil) - gtest.Assert(b, "中国人") + t.Assert(e, nil) + t.Assert(b, "中国人") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.TimestampNano()) tpl := fmt.Sprintf(`%s/%s`, path, "t.tpl") err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(tpl) err = View().AddPath(path) - gtest.Assert(err, nil) + t.Assert(err, nil) b, e := View().Parse("t.tpl", nil) - gtest.Assert(e, nil) - gtest.Assert(b, "中国人") + t.Assert(e, nil) + t.Assert(b, "中国人") }) } func Test_View_Config(t *testing.T) { // view1 test1 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { dirPath := gfile.Join(gdebug.TestDataPath(), "view1") gcfg.SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml"))) defer gcfg.ClearContent() defer instances.Clear() view := View("test1") - gtest.AssertNE(view, nil) + t.AssertNE(view, nil) err := view.AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) str := `hello ${.name},version:${.version}` view.Assigns(map[string]interface{}{"version": "1.9.0"}) result, err := view.ParseContent(str, nil) - gtest.Assert(err, nil) - gtest.Assert(result, "hello test1,version:1.9.0") + t.Assert(err, nil) + t.Assert(result, "hello test1,version:1.9.0") result, err = view.ParseDefault() - gtest.Assert(err, nil) - gtest.Assert(result, "test1:test1") + t.Assert(err, nil) + t.Assert(result, "test1:test1") }) // view1 test2 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { dirPath := gfile.Join(gdebug.TestDataPath(), "view1") gcfg.SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml"))) defer gcfg.ClearContent() defer instances.Clear() view := View("test2") - gtest.AssertNE(view, nil) + t.AssertNE(view, nil) err := view.AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) str := `hello #{.name},version:#{.version}` view.Assigns(map[string]interface{}{"version": "1.9.0"}) result, err := view.ParseContent(str, nil) - gtest.Assert(err, nil) - gtest.Assert(result, "hello test2,version:1.9.0") + t.Assert(err, nil) + t.Assert(result, "hello test2,version:1.9.0") result, err = view.ParseDefault() - gtest.Assert(err, nil) - gtest.Assert(result, "test2:test2") + t.Assert(err, nil) + t.Assert(result, "test2:test2") }) // view2 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { dirPath := gfile.Join(gdebug.TestDataPath(), "view2") gcfg.SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml"))) defer gcfg.ClearContent() defer instances.Clear() view := View() - gtest.AssertNE(view, nil) + t.AssertNE(view, nil) err := view.AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) str := `hello {.name},version:{.version}` view.Assigns(map[string]interface{}{"version": "1.9.0"}) result, err := view.ParseContent(str, nil) - gtest.Assert(err, nil) - gtest.Assert(result, "hello test,version:1.9.0") + t.Assert(err, nil) + t.Assert(result, "hello test,version:1.9.0") result, err = view.ParseDefault() - gtest.Assert(err, nil) - gtest.Assert(result, "test:test") + t.Assert(err, nil) + t.Assert(result, "test:test") }) // view2 - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { dirPath := gfile.Join(gdebug.TestDataPath(), "view2") gcfg.SetContent(gfile.GetContents(gfile.Join(dirPath, "config.toml"))) defer gcfg.ClearContent() defer instances.Clear() view := View("test100") - gtest.AssertNE(view, nil) + t.AssertNE(view, nil) err := view.AddPath(dirPath) - gtest.Assert(err, nil) + t.Assert(err, nil) str := `hello {.name},version:{.version}` view.Assigns(map[string]interface{}{"version": "1.9.0"}) result, err := view.ParseContent(str, nil) - gtest.Assert(err, nil) - gtest.Assert(result, "hello test,version:1.9.0") + t.Assert(err, nil) + t.Assert(result, "hello test,version:1.9.0") result, err = view.ParseDefault() - gtest.Assert(err, nil) - gtest.Assert(result, "test:test") + t.Assert(err, nil) + t.Assert(result, "test:test") }) } diff --git a/i18n/gi18n/gi18n_unit_test.go b/i18n/gi18n/gi18n_unit_test.go index 36933c981..189864360 100644 --- a/i18n/gi18n/gi18n_unit_test.go +++ b/i18n/gi18n/gi18n_unit_test.go @@ -27,120 +27,120 @@ import ( ) func Test_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { t := gi18n.New(gi18n.Options{ Path: gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n", }) t.SetLanguage("none") - gtest.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") t.SetLanguage("ja") - gtest.Assert(t.T("{#hello}{#world}"), "こんにちは世界") + t.Assert(t.T("{#hello}{#world}"), "こんにちは世界") t.SetLanguage("zh-CN") - gtest.Assert(t.T("{#hello}{#world}"), "你好世界") + t.Assert(t.T("{#hello}{#world}"), "你好世界") t.SetDelimiters("{$", "}") - gtest.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") - gtest.Assert(t.T("{$hello}{$world}"), "你好世界") + t.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(t.T("{$hello}{$world}"), "你好世界") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { t := gi18n.New(gi18n.Options{ Path: gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-file", }) t.SetLanguage("none") - gtest.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") t.SetLanguage("ja") - gtest.Assert(t.T("{#hello}{#world}"), "こんにちは世界") + t.Assert(t.T("{#hello}{#world}"), "こんにちは世界") t.SetLanguage("zh-CN") - gtest.Assert(t.T("{#hello}{#world}"), "你好世界") + t.Assert(t.T("{#hello}{#world}"), "你好世界") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { t := gi18n.New(gi18n.Options{ Path: gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-dir", }) t.SetLanguage("none") - gtest.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") t.SetLanguage("ja") - gtest.Assert(t.T("{#hello}{#world}"), "こんにちは世界") + t.Assert(t.T("{#hello}{#world}"), "こんにちは世界") t.SetLanguage("zh-CN") - gtest.Assert(t.T("{#hello}{#world}"), "你好世界") + t.Assert(t.T("{#hello}{#world}"), "你好世界") }) } func Test_DefaultManager(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gi18n.SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n") - gtest.Assert(err, nil) + t.Assert(err, nil) gi18n.SetLanguage("none") - gtest.Assert(gi18n.T("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(gi18n.T("{#hello}{#world}"), "{#hello}{#world}") gi18n.SetLanguage("ja") - gtest.Assert(gi18n.T("{#hello}{#world}"), "こんにちは世界") + t.Assert(gi18n.T("{#hello}{#world}"), "こんにちは世界") gi18n.SetLanguage("zh-CN") - gtest.Assert(gi18n.T("{#hello}{#world}"), "你好世界") + t.Assert(gi18n.T("{#hello}{#world}"), "你好世界") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err := gi18n.SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-dir") - gtest.Assert(err, nil) + t.Assert(err, nil) gi18n.SetLanguage("none") - gtest.Assert(gi18n.Translate("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(gi18n.Translate("{#hello}{#world}"), "{#hello}{#world}") gi18n.SetLanguage("ja") - gtest.Assert(gi18n.Translate("{#hello}{#world}"), "こんにちは世界") + t.Assert(gi18n.Translate("{#hello}{#world}"), "こんにちは世界") gi18n.SetLanguage("zh-CN") - gtest.Assert(gi18n.Translate("{#hello}{#world}"), "你好世界") + t.Assert(gi18n.Translate("{#hello}{#world}"), "你好世界") }) } func Test_Instance(t *testing.T) { gres.Dump() - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gi18n.Instance() err := m.SetPath("i18n-dir") - gtest.Assert(err, nil) + t.Assert(err, nil) m.SetLanguage("zh-CN") - gtest.Assert(m.T("{#hello}{#world}"), "你好世界") + t.Assert(m.T("{#hello}{#world}"), "你好世界") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gi18n.Instance() - gtest.Assert(m.T("{#hello}{#world}"), "你好世界") + t.Assert(m.T("{#hello}{#world}"), "你好世界") }) - gtest.Case(t, func() { - gtest.Assert(g.I18n().T("{#hello}{#world}"), "你好世界") + gtest.C(t, func(t *gtest.T) { + t.Assert(g.I18n().T("{#hello}{#world}"), "你好世界") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := gi18n.Instance(gconv.String(gtime.TimestampNano())) - gtest.Assert(m.T("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(m.T("{#hello}{#world}"), "{#hello}{#world}") }) } func Test_Resource(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := g.I18n("resource") err := m.SetPath("i18n-dir") - gtest.Assert(err, nil) + t.Assert(err, nil) m.SetLanguage("none") - gtest.Assert(m.T("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(m.T("{#hello}{#world}"), "{#hello}{#world}") m.SetLanguage("ja") - gtest.Assert(m.T("{#hello}{#world}"), "こんにちは世界") + t.Assert(m.T("{#hello}{#world}"), "こんにちは世界") m.SetLanguage("zh-CN") - gtest.Assert(m.T("{#hello}{#world}"), "你好世界") + t.Assert(m.T("{#hello}{#world}"), "你好世界") }) } diff --git a/internal/cmdenv/cmdenv_test.go b/internal/cmdenv/cmdenv_test.go index b2c19d38f..03e0ef21b 100644 --- a/internal/cmdenv/cmdenv_test.go +++ b/internal/cmdenv/cmdenv_test.go @@ -20,10 +20,10 @@ func Test_Get(t *testing.T) { os.Setenv("GF_TEST_VALUE1", "222") os.Setenv("GF_TEST_VALUE2", "333") doInit() - gtest.Case(t, func() { - gtest.Assert(Get("gf.test.value1").String(), "111") - gtest.Assert(Get("gf.test.value2").String(), "333") - gtest.Assert(Get("gf.test.value3").String(), "") - gtest.Assert(Get("gf.test.value3", 1).String(), "1") + gtest.C(t, func(t *gtest.T) { + t.Assert(Get("gf.test.value1").String(), "111") + t.Assert(Get("gf.test.value2").String(), "333") + t.Assert(Get("gf.test.value3").String(), "") + t.Assert(Get("gf.test.value3", 1).String(), "1") }) } diff --git a/internal/empty/empty_test.go b/internal/empty/empty_test.go index df0425777..c7ab9be63 100644 --- a/internal/empty/empty_test.go +++ b/internal/empty/empty_test.go @@ -26,7 +26,7 @@ func (woman TestWoman) Say() string { } func TestIsEmpty(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { tmpT1 := "0" tmpT2 := func() {} tmpT2 = nil @@ -40,52 +40,52 @@ func TestIsEmpty(t *testing.T) { var tmpF4 TestPerson = TestWoman{} tmpF5 := &tmpF4 // true - gtest.Assert(empty.IsEmpty(nil), true) - gtest.Assert(empty.IsEmpty(gconv.Int(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Int8(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Int16(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Int32(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Int64(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Uint64(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Uint(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Uint16(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Uint32(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Uint64(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Float32(tmpT1)), true) - gtest.Assert(empty.IsEmpty(gconv.Float64(tmpT1)), true) - gtest.Assert(empty.IsEmpty(false), true) - gtest.Assert(empty.IsEmpty([]byte("")), true) - gtest.Assert(empty.IsEmpty(""), true) - gtest.Assert(empty.IsEmpty(g.Map{}), true) - gtest.Assert(empty.IsEmpty(g.Slice{}), true) - gtest.Assert(empty.IsEmpty(g.Array{}), true) - gtest.Assert(empty.IsEmpty(tmpT2), true) - gtest.Assert(empty.IsEmpty(tmpT3), true) - gtest.Assert(empty.IsEmpty(tmpT3), true) - gtest.Assert(empty.IsEmpty(tmpT4), true) - gtest.Assert(empty.IsEmpty(tmpT5), true) + t.Assert(empty.IsEmpty(nil), true) + t.Assert(empty.IsEmpty(gconv.Int(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Int8(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Int16(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Int32(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Int64(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Uint64(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Uint(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Uint16(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Uint32(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Uint64(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Float32(tmpT1)), true) + t.Assert(empty.IsEmpty(gconv.Float64(tmpT1)), true) + t.Assert(empty.IsEmpty(false), true) + t.Assert(empty.IsEmpty([]byte("")), true) + t.Assert(empty.IsEmpty(""), true) + t.Assert(empty.IsEmpty(g.Map{}), true) + t.Assert(empty.IsEmpty(g.Slice{}), true) + t.Assert(empty.IsEmpty(g.Array{}), true) + t.Assert(empty.IsEmpty(tmpT2), true) + t.Assert(empty.IsEmpty(tmpT3), true) + t.Assert(empty.IsEmpty(tmpT3), true) + t.Assert(empty.IsEmpty(tmpT4), true) + t.Assert(empty.IsEmpty(tmpT5), true) // false - gtest.Assert(empty.IsEmpty(gconv.Int(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Int8(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Int16(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Int32(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Int64(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Uint(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Uint8(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Uint16(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Uint32(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Uint64(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Float32(tmpF1)), false) - gtest.Assert(empty.IsEmpty(gconv.Float64(tmpF1)), false) - gtest.Assert(empty.IsEmpty(true), false) - gtest.Assert(empty.IsEmpty(tmpT1), false) - gtest.Assert(empty.IsEmpty([]byte("1")), false) - gtest.Assert(empty.IsEmpty(g.Map{"a": 1}), false) - gtest.Assert(empty.IsEmpty(g.Slice{"1"}), false) - gtest.Assert(empty.IsEmpty(g.Array{"1"}), false) - gtest.Assert(empty.IsEmpty(tmpF2), false) - gtest.Assert(empty.IsEmpty(tmpF3), false) - gtest.Assert(empty.IsEmpty(tmpF4), false) - gtest.Assert(empty.IsEmpty(tmpF5), false) + t.Assert(empty.IsEmpty(gconv.Int(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Int8(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Int16(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Int32(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Int64(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Uint(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Uint8(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Uint16(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Uint32(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Uint64(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Float32(tmpF1)), false) + t.Assert(empty.IsEmpty(gconv.Float64(tmpF1)), false) + t.Assert(empty.IsEmpty(true), false) + t.Assert(empty.IsEmpty(tmpT1), false) + t.Assert(empty.IsEmpty([]byte("1")), false) + t.Assert(empty.IsEmpty(g.Map{"a": 1}), false) + t.Assert(empty.IsEmpty(g.Slice{"1"}), false) + t.Assert(empty.IsEmpty(g.Array{"1"}), false) + t.Assert(empty.IsEmpty(tmpF2), false) + t.Assert(empty.IsEmpty(tmpF3), false) + t.Assert(empty.IsEmpty(tmpF4), false) + t.Assert(empty.IsEmpty(tmpF5), false) }) } diff --git a/internal/mutex/mutex_z_unit_test.go b/internal/mutex/mutex_z_unit_test.go index 9b02b0842..69c273804 100644 --- a/internal/mutex/mutex_z_unit_test.go +++ b/internal/mutex/mutex_z_unit_test.go @@ -16,29 +16,29 @@ import ( ) func TestMutexIsSafe(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { lock := mutex.New() - gtest.Assert(lock.IsSafe(), false) + t.Assert(lock.IsSafe(), false) lock = mutex.New(false) - gtest.Assert(lock.IsSafe(), false) + t.Assert(lock.IsSafe(), false) lock = mutex.New(false, false) - gtest.Assert(lock.IsSafe(), false) + t.Assert(lock.IsSafe(), false) lock = mutex.New(true, false) - gtest.Assert(lock.IsSafe(), true) + t.Assert(lock.IsSafe(), true) lock = mutex.New(true, true) - gtest.Assert(lock.IsSafe(), true) + t.Assert(lock.IsSafe(), true) lock = mutex.New(true) - gtest.Assert(lock.IsSafe(), true) + t.Assert(lock.IsSafe(), true) }) } func TestSafeMutex(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { safeLock := mutex.New(true) array := garray.New(true) @@ -58,18 +58,18 @@ func TestSafeMutex(t *testing.T) { safeLock.Unlock() }() time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(80 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 4) + t.Assert(array.Len(), 4) }) } func TestUnsafeMutex(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { unsafeLock := mutex.New() array := garray.New(true) @@ -89,12 +89,12 @@ func TestUnsafeMutex(t *testing.T) { unsafeLock.Unlock() }() time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 4) + t.Assert(array.Len(), 4) }) } diff --git a/internal/rwmutex/rwmutex_z_unit_test.go b/internal/rwmutex/rwmutex_z_unit_test.go index 3a8793a94..7f44d4590 100644 --- a/internal/rwmutex/rwmutex_z_unit_test.go +++ b/internal/rwmutex/rwmutex_z_unit_test.go @@ -16,29 +16,29 @@ import ( ) func TestRwmutexIsSafe(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { lock := rwmutex.New() - gtest.Assert(lock.IsSafe(), false) + t.Assert(lock.IsSafe(), false) lock = rwmutex.New(false) - gtest.Assert(lock.IsSafe(), false) + t.Assert(lock.IsSafe(), false) lock = rwmutex.New(false, false) - gtest.Assert(lock.IsSafe(), false) + t.Assert(lock.IsSafe(), false) lock = rwmutex.New(true, false) - gtest.Assert(lock.IsSafe(), true) + t.Assert(lock.IsSafe(), true) lock = rwmutex.New(true, true) - gtest.Assert(lock.IsSafe(), true) + t.Assert(lock.IsSafe(), true) lock = rwmutex.New(true) - gtest.Assert(lock.IsSafe(), true) + t.Assert(lock.IsSafe(), true) }) } func TestSafeRwmutex(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { safeLock := rwmutex.New(true) array := garray.New(true) @@ -58,18 +58,18 @@ func TestSafeRwmutex(t *testing.T) { safeLock.Unlock() }() time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(80 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 4) + t.Assert(array.Len(), 4) }) } func TestSafeReaderRwmutex(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { safeLock := rwmutex.New(true) array := garray.New(true) @@ -97,18 +97,18 @@ func TestSafeReaderRwmutex(t *testing.T) { safeLock.Unlock() }() time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 4) + t.Assert(array.Len(), 4) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 6) + t.Assert(array.Len(), 6) }) } func TestUnsafeRwmutex(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { unsafeLock := rwmutex.New() array := garray.New(true) @@ -128,12 +128,12 @@ func TestUnsafeRwmutex(t *testing.T) { unsafeLock.Unlock() }() time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 4) + t.Assert(array.Len(), 4) }) } diff --git a/internal/structs/structs_test.go b/internal/structs/structs_test.go index efedeb9e5..1f5074d93 100644 --- a/internal/structs/structs_test.go +++ b/internal/structs/structs_test.go @@ -17,22 +17,22 @@ import ( ) func Test_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int Name string `params:"name"` Pass string `my-tag1:"pass1" my-tag2:"pass2" params:"pass"` } var user User - gtest.Assert(structs.TagMapName(user, []string{"params"}, true), g.Map{"name": "Name", "pass": "Pass"}) - gtest.Assert(structs.TagMapName(&user, []string{"params"}, true), g.Map{"name": "Name", "pass": "Pass"}) + t.Assert(structs.TagMapName(user, []string{"params"}, true), g.Map{"name": "Name", "pass": "Pass"}) + t.Assert(structs.TagMapName(&user, []string{"params"}, true), g.Map{"name": "Name", "pass": "Pass"}) - gtest.Assert(structs.TagMapName(&user, []string{"params", "my-tag1"}, true), g.Map{"name": "Name", "pass": "Pass"}) - gtest.Assert(structs.TagMapName(&user, []string{"my-tag1", "params"}, true), g.Map{"name": "Name", "pass1": "Pass"}) - gtest.Assert(structs.TagMapName(&user, []string{"my-tag2", "params"}, true), g.Map{"name": "Name", "pass2": "Pass"}) + t.Assert(structs.TagMapName(&user, []string{"params", "my-tag1"}, true), g.Map{"name": "Name", "pass": "Pass"}) + t.Assert(structs.TagMapName(&user, []string{"my-tag1", "params"}, true), g.Map{"name": "Name", "pass1": "Pass"}) + t.Assert(structs.TagMapName(&user, []string{"my-tag2", "params"}, true), g.Map{"name": "Name", "pass2": "Pass"}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Base struct { Pass1 string `params:"password1"` Pass2 string `params:"password2"` @@ -43,14 +43,14 @@ func Test_Basic(t *testing.T) { Base `params:"base"` } user := new(UserWithBase) - gtest.Assert(structs.TagMapName(user, []string{"params"}, true), g.Map{ + t.Assert(structs.TagMapName(user, []string{"params"}, true), g.Map{ "base": "Base", "password1": "Pass1", "password2": "Pass2", }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Base struct { Pass1 string `params:"password1"` Pass2 string `params:"password2"` @@ -67,7 +67,7 @@ func Test_Basic(t *testing.T) { } user1 := new(UserWithBase1) user2 := new(UserWithBase2) - gtest.Assert(structs.TagMapName(user1, []string{"params"}, true), g.Map{"password1": "Pass1", "password2": "Pass2"}) - gtest.Assert(structs.TagMapName(user2, []string{"params"}, true), g.Map{"password1": "Pass1", "password2": "Pass2"}) + t.Assert(structs.TagMapName(user1, []string{"params"}, true), g.Map{"password1": "Pass1", "password2": "Pass2"}) + t.Assert(structs.TagMapName(user2, []string{"params"}, true), g.Map{"password1": "Pass1", "password2": "Pass2"}) }) } diff --git a/net/ghttp/ghttp_client_request.go b/net/ghttp/ghttp_client_request.go index 6b45fa6b9..9df02cc90 100644 --- a/net/ghttp/ghttp_client_request.go +++ b/net/ghttp/ghttp_client_request.go @@ -248,12 +248,12 @@ func (c *Client) DoRequest(method, url string, data ...interface{}) (*ClientResp } } r := &ClientResponse{ - cookies: make(map[string]string), + Response: resp, } - r.Response = resp // Auto sending cookie content. if c.browserMode { now := time.Now() + r.cookies = make(map[string]string) for _, v := range r.Cookies() { if v.Expires.UnixNano() < now.UnixNano() { delete(c.cookies, v.Name) diff --git a/net/ghttp/ghttp_client_response.go b/net/ghttp/ghttp_client_response.go index 84a4dd57c..cb5ff4df2 100644 --- a/net/ghttp/ghttp_client_response.go +++ b/net/ghttp/ghttp_client_response.go @@ -19,10 +19,11 @@ type ClientResponse struct { cookies map[string]string } -// GetCookie retrieves and returns the cookie value of specified . -func (r *ClientResponse) GetCookie(key string) string { - if len(r.cookies) == 0 { +// initCookie initializes the cookie map attribute of ClientResponse. +func (r *ClientResponse) initCookie() { + if r.cookies == nil { now := time.Now() + r.cookies = make(map[string]string) for _, v := range r.Cookies() { if v.Expires.UnixNano() < now.UnixNano() { continue @@ -30,9 +31,24 @@ func (r *ClientResponse) GetCookie(key string) string { r.cookies[v.Name] = v.Value } } +} + +// GetCookie retrieves and returns the cookie value of specified . +func (r *ClientResponse) GetCookie(key string) string { + r.initCookie() return r.cookies[key] } +// GetCookieMap retrieves and returns a copy of current cookie values map. +func (r *ClientResponse) GetCookieMap() map[string]string { + r.initCookie() + m := make(map[string]string, len(r.cookies)) + for k, v := range r.cookies { + m[k] = v + } + return m +} + // ReadAll retrieves and returns the response content as []byte. func (r *ClientResponse) ReadAll() []byte { body, err := ioutil.ReadAll(r.Body) diff --git a/net/ghttp/ghttp_unit_client_test.go b/net/ghttp/ghttp_unit_client_test.go index 47765c2e8..3b04b3b95 100644 --- a/net/ghttp/ghttp_unit_client_test.go +++ b/net/ghttp/ghttp_unit_client_test.go @@ -28,15 +28,69 @@ func Test_Client_Basic(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { url := fmt.Sprintf("http://127.0.0.1:%d", p) client := ghttp.NewClient() client.SetPrefix(url) - gtest.Assert(ghttp.GetContent(""), ``) - gtest.Assert(client.GetContent("/hello"), `hello`) + t.Assert(ghttp.GetContent(""), ``) + t.Assert(client.GetContent("/hello"), `hello`) _, err := ghttp.Post("") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) + }) +} + +func Test_Client_Cookie(t *testing.T) { + p := ports.PopRand() + s := g.Server(p) + s.BindHandler("/cookie", func(r *ghttp.Request) { + r.Response.Write(r.Cookie.Get("test")) + }) + s.SetPort(p) + s.SetDumpRouterMap(false) + s.Start() + defer s.Shutdown() + + time.Sleep(100 * time.Millisecond) + gtest.C(t, func(t *gtest.T) { + c := ghttp.NewClient() + c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) + + c.SetCookie("test", "0123456789") + t.Assert(c.PostContent("/cookie"), "0123456789") + }) +} + +func Test_Client_Cookies(t *testing.T) { + p := ports.PopRand() + s := g.Server(p) + s.BindHandler("/cookie", func(r *ghttp.Request) { + r.Cookie.Set("test1", "1") + r.Cookie.Set("test2", "2") + r.Response.Write("ok") + }) + s.SetPort(p) + s.SetDumpRouterMap(false) + s.Start() + defer s.Shutdown() + + time.Sleep(100 * time.Millisecond) + gtest.C(t, func(t *gtest.T) { + c := ghttp.NewClient() + c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) + + resp, err := c.Get("/cookie") + t.Assert(err, nil) + defer resp.Close() + + t.AssertNE(resp.Header.Get("Set-Cookie"), "") + + m := resp.GetCookieMap() + t.Assert(len(m), 2) + t.Assert(m["test1"], 1) + t.Assert(m["test2"], 2) + t.Assert(resp.GetCookie("test1"), 1) + t.Assert(resp.GetCookie("test2"), 2) }) } diff --git a/net/ghttp/ghttp_unit_config_test.go b/net/ghttp/ghttp_unit_config_test.go index b6e1d44f3..e00de18e1 100644 --- a/net/ghttp/ghttp_unit_config_test.go +++ b/net/ghttp/ghttp_unit_config_test.go @@ -19,7 +19,7 @@ import ( ) func Test_ConfigFromMap(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := g.Map{ "address": ":8199", "readTimeout": "60s", @@ -28,19 +28,19 @@ func Test_ConfigFromMap(t *testing.T) { "cookieMaxAge": "1y", } config, err := ghttp.ConfigFromMap(m) - gtest.Assert(err, nil) + t.Assert(err, nil) d1, _ := time.ParseDuration(gconv.String(m["readTimeout"])) d2, _ := time.ParseDuration(gconv.String(m["cookieMaxAge"])) - gtest.Assert(config.Address, m["address"]) - gtest.Assert(config.ReadTimeout, d1) - gtest.Assert(config.CookieMaxAge, d2) - gtest.Assert(config.IndexFiles, m["indexFiles"]) - gtest.Assert(config.ErrorLogEnabled, m["errorLogEnabled"]) + t.Assert(config.Address, m["address"]) + t.Assert(config.ReadTimeout, d1) + t.Assert(config.CookieMaxAge, d2) + t.Assert(config.IndexFiles, m["indexFiles"]) + t.Assert(config.ErrorLogEnabled, m["errorLogEnabled"]) }) } func Test_SetConfigWithMap(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := g.Map{ "Address": ":8199", //"ServerRoot": "/var/www/MyServerRoot", @@ -55,6 +55,6 @@ func Test_SetConfigWithMap(t *testing.T) { } s := g.Server() err := s.SetConfigWithMap(m) - gtest.Assert(err, nil) + t.Assert(err, nil) }) } diff --git a/net/ghttp/ghttp_unit_context_test.go b/net/ghttp/ghttp_unit_context_test.go index d9f0636af..c186f7a82 100644 --- a/net/ghttp/ghttp_unit_context_test.go +++ b/net/ghttp/ghttp_unit_context_test.go @@ -35,10 +35,10 @@ func Test_Context(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), `123`) + t.Assert(client.GetContent("/"), `123`) }) } diff --git a/net/ghttp/ghttp_unit_cookie_test.go b/net/ghttp/ghttp_unit_cookie_test.go index 293414bd4..2a0be679f 100644 --- a/net/ghttp/ghttp_unit_cookie_test.go +++ b/net/ghttp/ghttp_unit_cookie_test.go @@ -34,7 +34,7 @@ func Test_Cookie(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetBrowserMode(true) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) @@ -42,18 +42,18 @@ func Test_Cookie(t *testing.T) { if r1 != nil { defer r1.Close() } - gtest.Assert(e1, nil) - gtest.Assert(r1.ReadAllString(), "") + t.Assert(e1, nil) + t.Assert(r1.ReadAllString(), "") - gtest.Assert(client.GetContent("/set?k=key2&v=200"), "") + t.Assert(client.GetContent("/set?k=key2&v=200"), "") - gtest.Assert(client.GetContent("/get?k=key1"), "100") - gtest.Assert(client.GetContent("/get?k=key2"), "200") - gtest.Assert(client.GetContent("/get?k=key3"), "") - gtest.Assert(client.GetContent("/remove?k=key1"), "") - gtest.Assert(client.GetContent("/remove?k=key3"), "") - gtest.Assert(client.GetContent("/remove?k=key4"), "") - gtest.Assert(client.GetContent("/get?k=key1"), "") - gtest.Assert(client.GetContent("/get?k=key2"), "200") + t.Assert(client.GetContent("/get?k=key1"), "100") + t.Assert(client.GetContent("/get?k=key2"), "200") + t.Assert(client.GetContent("/get?k=key3"), "") + t.Assert(client.GetContent("/remove?k=key1"), "") + t.Assert(client.GetContent("/remove?k=key3"), "") + t.Assert(client.GetContent("/remove?k=key4"), "") + t.Assert(client.GetContent("/get?k=key1"), "") + t.Assert(client.GetContent("/get?k=key2"), "200") }) } diff --git a/net/ghttp/ghttp_unit_log_test.go b/net/ghttp/ghttp_unit_log_test.go index e540fa8aa..aca814df0 100644 --- a/net/ghttp/ghttp_unit_log_test.go +++ b/net/ghttp/ghttp_unit_log_test.go @@ -22,7 +22,7 @@ import ( ) func Test_Log(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { logDir := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) p := ports.PopRand() s := g.Server(p) @@ -44,19 +44,19 @@ func Test_Log(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/hello"), "hello") - gtest.Assert(client.GetContent("/error"), "custom error") + t.Assert(client.GetContent("/hello"), "hello") + t.Assert(client.GetContent("/error"), "custom error") logPath1 := gfile.Join(logDir, gtime.Now().Format("Y-m-d")+".log") - gtest.Assert(gstr.Contains(gfile.GetContents(logPath1), "http server started listening on"), true) - gtest.Assert(gstr.Contains(gfile.GetContents(logPath1), "HANDLER"), true) + t.Assert(gstr.Contains(gfile.GetContents(logPath1), "http server started listening on"), true) + t.Assert(gstr.Contains(gfile.GetContents(logPath1), "HANDLER"), true) logPath2 := gfile.Join(logDir, "access-"+gtime.Now().Format("Ymd")+".log") fmt.Println(gfile.GetContents(logPath2)) - gtest.Assert(gstr.Contains(gfile.GetContents(logPath2), " /hello "), true) + t.Assert(gstr.Contains(gfile.GetContents(logPath2), " /hello "), true) logPath3 := gfile.Join(logDir, "error-"+gtime.Now().Format("Ymd")+".log") - gtest.Assert(gstr.Contains(gfile.GetContents(logPath3), "[ERRO]"), true) - gtest.Assert(gstr.Contains(gfile.GetContents(logPath3), "custom error"), true) + t.Assert(gstr.Contains(gfile.GetContents(logPath3), "[ERRO]"), true) + t.Assert(gstr.Contains(gfile.GetContents(logPath3), "custom error"), true) }) } diff --git a/net/ghttp/ghttp_unit_mess_test.go b/net/ghttp/ghttp_unit_mess_test.go index fe0cd0ee6..6c4c4acda 100644 --- a/net/ghttp/ghttp_unit_mess_test.go +++ b/net/ghttp/ghttp_unit_mess_test.go @@ -28,12 +28,12 @@ func Test_GetUrl(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { prefix := fmt.Sprintf("http://127.0.0.1:%d", p) client := ghttp.NewClient() client.SetBrowserMode(true) client.SetPrefix(prefix) - gtest.Assert(client.GetContent("/url"), prefix+"/url") + t.Assert(client.GetContent("/url"), prefix+"/url") }) } diff --git a/net/ghttp/ghttp_unit_middleware_basic_test.go b/net/ghttp/ghttp_unit_middleware_basic_test.go index aa4eec40e..62f188b2f 100644 --- a/net/ghttp/ghttp_unit_middleware_basic_test.go +++ b/net/ghttp/ghttp_unit_middleware_basic_test.go @@ -50,13 +50,13 @@ func Test_BindMiddleware_Basic1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/test"), "1342") - gtest.Assert(client.GetContent("/test/test"), "57test86") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/test"), "1342") + t.Assert(client.GetContent("/test/test"), "57test86") }) } @@ -77,13 +77,13 @@ func Test_BindMiddleware_Basic2(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "12") - gtest.Assert(client.GetContent("/test"), "12") - gtest.Assert(client.GetContent("/test/test"), "1test2") + t.Assert(client.GetContent("/"), "12") + t.Assert(client.GetContent("/test"), "12") + t.Assert(client.GetContent("/test/test"), "1test2") }) } @@ -117,17 +117,17 @@ func Test_BindMiddleware_Basic3(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/test"), "Not Found") - gtest.Assert(client.PutContent("/test"), "1342") - gtest.Assert(client.PostContent("/test"), "Not Found") - gtest.Assert(client.GetContent("/test/test"), "test") - gtest.Assert(client.PutContent("/test/test"), "test") - gtest.Assert(client.PostContent("/test/test"), "57test86") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/test"), "Not Found") + t.Assert(client.PutContent("/test"), "1342") + t.Assert(client.PostContent("/test"), "Not Found") + t.Assert(client.GetContent("/test/test"), "test") + t.Assert(client.PutContent("/test/test"), "test") + t.Assert(client.PostContent("/test/test"), "57test86") }) } @@ -153,13 +153,13 @@ func Test_BindMiddleware_Basic4(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/test"), "1test2") - gtest.Assert(client.PutContent("/test/none"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/test"), "1test2") + t.Assert(client.PutContent("/test/none"), "Not Found") }) } @@ -182,14 +182,14 @@ func Test_Middleware_With_Static(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "index") - gtest.Assert(client.GetContent("/test.html"), "test") - gtest.Assert(client.GetContent("/none"), "Not Found") - gtest.Assert(client.GetContent("/user/list"), "1list2") + t.Assert(client.GetContent("/"), "index") + t.Assert(client.GetContent("/test.html"), "test") + t.Assert(client.GetContent("/none"), "Not Found") + t.Assert(client.GetContent("/user/list"), "1list2") }) } @@ -210,17 +210,17 @@ func Test_Middleware_Status(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/user/list"), "200") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/user/list"), "200") resp, err := client.Get("/") defer resp.Close() - gtest.Assert(err, nil) - gtest.Assert(resp.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp.StatusCode, 404) }) } @@ -254,27 +254,27 @@ func Test_Middleware_Hook_With_Static(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) // The length assert sometimes fails, so I added time.Sleep here for debug purpose. - gtest.Assert(client.GetContent("/"), "index") + t.Assert(client.GetContent("/"), "index") time.Sleep(100 * time.Millisecond) - gtest.Assert(a.Len(), 2) + t.Assert(a.Len(), 2) - gtest.Assert(client.GetContent("/test.html"), "test") + t.Assert(client.GetContent("/test.html"), "test") time.Sleep(100 * time.Millisecond) - gtest.Assert(a.Len(), 4) + t.Assert(a.Len(), 4) - gtest.Assert(client.GetContent("/none"), "ab") + t.Assert(client.GetContent("/none"), "ab") time.Sleep(100 * time.Millisecond) - gtest.Assert(a.Len(), 6) + t.Assert(a.Len(), 6) - gtest.Assert(client.GetContent("/user/list"), "a1list2b") + t.Assert(client.GetContent("/user/list"), "a1list2b") time.Sleep(100 * time.Millisecond) - gtest.Assert(a.Len(), 8) + t.Assert(a.Len(), 8) }) } @@ -293,14 +293,14 @@ func Test_BindMiddleware_Status(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/test"), "Not Found") - gtest.Assert(client.GetContent("/test/test"), "test") - gtest.Assert(client.GetContent("/test/test/test"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/test"), "Not Found") + t.Assert(client.GetContent("/test/test"), "test") + t.Assert(client.GetContent("/test/test/test"), "Not Found") }) } @@ -326,12 +326,12 @@ func Test_BindMiddlewareDefault_Basic1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "1342") - gtest.Assert(client.GetContent("/test/test"), "13test42") + t.Assert(client.GetContent("/"), "1342") + t.Assert(client.GetContent("/test/test"), "13test42") }) } @@ -357,14 +357,14 @@ func Test_BindMiddlewareDefault_Basic2(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "1342") - gtest.Assert(client.PutContent("/"), "1342") - gtest.Assert(client.GetContent("/test/test"), "1342") - gtest.Assert(client.PutContent("/test/test"), "13test42") + t.Assert(client.GetContent("/"), "1342") + t.Assert(client.PutContent("/"), "1342") + t.Assert(client.GetContent("/test/test"), "1342") + t.Assert(client.PutContent("/test/test"), "13test42") }) } @@ -388,12 +388,12 @@ func Test_BindMiddlewareDefault_Basic3(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "12") - gtest.Assert(client.GetContent("/test/test"), "1test2") + t.Assert(client.GetContent("/"), "12") + t.Assert(client.GetContent("/test/test"), "1test2") }) } @@ -417,12 +417,12 @@ func Test_BindMiddlewareDefault_Basic4(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "21") - gtest.Assert(client.GetContent("/test/test"), "2test1") + t.Assert(client.GetContent("/"), "21") + t.Assert(client.GetContent("/test/test"), "2test1") }) } @@ -446,12 +446,12 @@ func Test_BindMiddlewareDefault_Basic5(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "12") - gtest.Assert(client.GetContent("/test/test"), "12test") + t.Assert(client.GetContent("/"), "12") + t.Assert(client.GetContent("/test/test"), "12test") }) } @@ -470,12 +470,12 @@ func Test_BindMiddlewareDefault_Status(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/test/test"), "test") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/test/test"), "test") }) } @@ -521,16 +521,16 @@ func Test_BindMiddlewareDefault_Basic6(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "13100Object Index20042") - gtest.Assert(client.GetContent("/init"), "1342") - gtest.Assert(client.GetContent("/shut"), "1342") - gtest.Assert(client.GetContent("/index"), "13100Object Index20042") - gtest.Assert(client.GetContent("/show"), "13100Object Show20042") - gtest.Assert(client.GetContent("/none-exist"), "1342") + t.Assert(client.GetContent("/"), "13100Object Index20042") + t.Assert(client.GetContent("/init"), "1342") + t.Assert(client.GetContent("/shut"), "1342") + t.Assert(client.GetContent("/index"), "13100Object Index20042") + t.Assert(client.GetContent("/show"), "13100Object Show20042") + t.Assert(client.GetContent("/none-exist"), "1342") }) } @@ -568,12 +568,12 @@ func Test_Hook_Middleware_Basic1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "ac1342bd") - gtest.Assert(client.GetContent("/test/test"), "ac13test42bd") + t.Assert(client.GetContent("/"), "ac1342bd") + t.Assert(client.GetContent("/test/test"), "ac13test42bd") }) } @@ -606,23 +606,23 @@ func Test_Middleware_CORSAndAuth(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) // Common Checks. - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/api.v2"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/api.v2"), "Not Found") // Auth Checks. - gtest.Assert(client.PostContent("/api.v2/user/list"), "Forbidden") - gtest.Assert(client.PostContent("/api.v2/user/list", "token=123456"), "list") + t.Assert(client.PostContent("/api.v2/user/list"), "Forbidden") + t.Assert(client.PostContent("/api.v2/user/list", "token=123456"), "list") // CORS Checks. resp, err := client.Post("/api.v2/user/list", "token=123456") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) - gtest.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") - gtest.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") - gtest.Assert(resp.Header["Access-Control-Allow-Origin"][0], "*") - gtest.Assert(resp.Header["Access-Control-Max-Age"][0], "3628800") + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) + t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") + t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") + t.Assert(resp.Header["Access-Control-Allow-Origin"][0], "*") + t.Assert(resp.Header["Access-Control-Max-Age"][0], "3628800") resp.Close() }) } @@ -671,14 +671,14 @@ func Test_Middleware_Scope(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/scope1"), "a1b") - gtest.Assert(client.GetContent("/scope2"), "ac2db") - gtest.Assert(client.GetContent("/scope3"), "ae3fb") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/scope1"), "a1b") + t.Assert(client.GetContent("/scope2"), "ac2db") + t.Assert(client.GetContent("/scope3"), "ae3fb") }) } @@ -706,10 +706,10 @@ func Test_Middleware_Panic(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "error") + t.Assert(client.GetContent("/"), "error") }) } diff --git a/net/ghttp/ghttp_unit_middleware_cors_test.go b/net/ghttp/ghttp_unit_middleware_cors_test.go index c5d24529e..81498ab45 100644 --- a/net/ghttp/ghttp_unit_middleware_cors_test.go +++ b/net/ghttp/ghttp_unit_middleware_cors_test.go @@ -29,51 +29,51 @@ func Test_Middleware_CORS1(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) // Common Checks. - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/api.v2"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/api.v2"), "Not Found") // GET request does not any route. resp, err := client.Get("/api.v2/user/list") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) - gtest.Assert(resp.StatusCode, 404) + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) + t.Assert(resp.StatusCode, 404) resp.Close() // POST request matches the route and CORS middleware. resp, err = client.Post("/api.v2/user/list") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) - gtest.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") - gtest.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") - gtest.Assert(resp.Header["Access-Control-Allow-Origin"][0], "*") - gtest.Assert(resp.Header["Access-Control-Max-Age"][0], "3628800") + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) + t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") + t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") + t.Assert(resp.Header["Access-Control-Allow-Origin"][0], "*") + t.Assert(resp.Header["Access-Control-Max-Age"][0], "3628800") resp.Close() }) // OPTIONS GET - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) client.SetHeader("Access-Control-Request-Method", "GET") resp, err := client.Options("/api.v2/user/list") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) - gtest.Assert(resp.ReadAllString(), "Not Found") - gtest.Assert(resp.StatusCode, 404) + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) + t.Assert(resp.ReadAllString(), "Not Found") + t.Assert(resp.StatusCode, 404) resp.Close() }) // OPTIONS POST - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) client.SetHeader("Access-Control-Request-Method", "POST") resp, err := client.Options("/api.v2/user/list") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) - gtest.Assert(resp.StatusCode, 200) + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) + t.Assert(resp.StatusCode, 200) resp.Close() }) } @@ -92,54 +92,54 @@ func Test_Middleware_CORS2(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) // Common Checks. - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/api.v2"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/api.v2"), "Not Found") // Get request. resp, err := client.Get("/api.v2/user/list/1") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) - gtest.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") - gtest.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") - gtest.Assert(resp.Header["Access-Control-Allow-Origin"][0], "*") - gtest.Assert(resp.Header["Access-Control-Max-Age"][0], "3628800") - gtest.Assert(resp.ReadAllString(), "1") + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) + t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") + t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") + t.Assert(resp.Header["Access-Control-Allow-Origin"][0], "*") + t.Assert(resp.Header["Access-Control-Max-Age"][0], "3628800") + t.Assert(resp.ReadAllString(), "1") resp.Close() }) // OPTIONS GET None. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) client.SetHeader("Access-Control-Request-Method", "GET") resp, err := client.Options("/api.v2/user") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) - gtest.Assert(resp.StatusCode, 404) + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) + t.Assert(resp.StatusCode, 404) resp.Close() }) // OPTIONS GET - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) client.SetHeader("Access-Control-Request-Method", "GET") resp, err := client.Options("/api.v2/user/list/1") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) - gtest.Assert(resp.StatusCode, 200) + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) + t.Assert(resp.StatusCode, 200) resp.Close() }) // OPTIONS POST - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) client.SetHeader("Access-Control-Request-Method", "POST") resp, err := client.Options("/api.v2/user/list/1") - gtest.Assert(err, nil) - gtest.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) - gtest.Assert(resp.StatusCode, 404) + t.Assert(err, nil) + t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) + t.Assert(resp.StatusCode, 404) resp.Close() }) } diff --git a/net/ghttp/ghttp_unit_param_file_test.go b/net/ghttp/ghttp_unit_param_file_test.go index de0dd51ba..b21b5beb2 100644 --- a/net/ghttp/ghttp_unit_param_file_test.go +++ b/net/ghttp/ghttp_unit_param_file_test.go @@ -41,7 +41,7 @@ func Test_Params_File_Single(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) // normal name - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) @@ -50,14 +50,14 @@ func Test_Params_File_Single(t *testing.T) { content := client.PostContent("/upload/single", g.Map{ "file": "@file:" + srcPath, }) - gtest.AssertNE(content, "") - gtest.AssertNE(content, "upload file cannot be empty") - gtest.AssertNE(content, "upload failed") - gtest.Assert(content, "file1.txt") - gtest.Assert(gfile.GetContents(dstPath), gfile.GetContents(srcPath)) + t.AssertNE(content, "") + t.AssertNE(content, "upload file cannot be empty") + t.AssertNE(content, "upload failed") + t.Assert(content, "file1.txt") + t.Assert(gfile.GetContents(dstPath), gfile.GetContents(srcPath)) }) // randomly rename. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) @@ -67,10 +67,10 @@ func Test_Params_File_Single(t *testing.T) { "randomlyRename": true, }) dstPath := gfile.Join(dstDirPath, content) - gtest.AssertNE(content, "") - gtest.AssertNE(content, "upload file cannot be empty") - gtest.AssertNE(content, "upload failed") - gtest.Assert(gfile.GetContents(dstPath), gfile.GetContents(srcPath)) + t.AssertNE(content, "") + t.AssertNE(content, "upload file cannot be empty") + t.AssertNE(content, "upload failed") + t.Assert(gfile.GetContents(dstPath), gfile.GetContents(srcPath)) }) } @@ -94,7 +94,7 @@ func Test_Params_File_CustomName(t *testing.T) { s.Start() defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) @@ -103,11 +103,11 @@ func Test_Params_File_CustomName(t *testing.T) { content := client.PostContent("/upload/single", g.Map{ "file": "@file:" + srcPath, }) - gtest.AssertNE(content, "") - gtest.AssertNE(content, "upload file cannot be empty") - gtest.AssertNE(content, "upload failed") - gtest.Assert(content, "my.txt") - gtest.Assert(gfile.GetContents(dstPath), gfile.GetContents(srcPath)) + t.AssertNE(content, "") + t.AssertNE(content, "upload file cannot be empty") + t.AssertNE(content, "upload failed") + t.Assert(content, "my.txt") + t.Assert(gfile.GetContents(dstPath), gfile.GetContents(srcPath)) }) } @@ -131,7 +131,7 @@ func Test_Params_File_Batch(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) // normal name - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) @@ -143,15 +143,15 @@ func Test_Params_File_Batch(t *testing.T) { "file[0]": "@file:" + srcPath1, "file[1]": "@file:" + srcPath2, }) - gtest.AssertNE(content, "") - gtest.AssertNE(content, "upload file cannot be empty") - gtest.AssertNE(content, "upload failed") - gtest.Assert(content, "file1.txt,file2.txt") - gtest.Assert(gfile.GetContents(dstPath1), gfile.GetContents(srcPath1)) - gtest.Assert(gfile.GetContents(dstPath2), gfile.GetContents(srcPath2)) + t.AssertNE(content, "") + t.AssertNE(content, "upload file cannot be empty") + t.AssertNE(content, "upload failed") + t.Assert(content, "file1.txt,file2.txt") + t.Assert(gfile.GetContents(dstPath1), gfile.GetContents(srcPath1)) + t.Assert(gfile.GetContents(dstPath2), gfile.GetContents(srcPath2)) }) // randomly rename. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) @@ -162,15 +162,15 @@ func Test_Params_File_Batch(t *testing.T) { "file[1]": "@file:" + srcPath2, "randomlyRename": true, }) - gtest.AssertNE(content, "") - gtest.AssertNE(content, "upload file cannot be empty") - gtest.AssertNE(content, "upload failed") + t.AssertNE(content, "") + t.AssertNE(content, "upload file cannot be empty") + t.AssertNE(content, "upload failed") array := gstr.SplitAndTrim(content, ",") - gtest.Assert(len(array), 2) + t.Assert(len(array), 2) dstPath1 := gfile.Join(dstDirPath, array[0]) dstPath2 := gfile.Join(dstDirPath, array[1]) - gtest.Assert(gfile.GetContents(dstPath1), gfile.GetContents(srcPath1)) - gtest.Assert(gfile.GetContents(dstPath2), gfile.GetContents(srcPath2)) + t.Assert(gfile.GetContents(dstPath1), gfile.GetContents(srcPath1)) + t.Assert(gfile.GetContents(dstPath2), gfile.GetContents(srcPath2)) }) } diff --git a/net/ghttp/ghttp_unit_param_json_test.go b/net/ghttp/ghttp_unit_param_json_test.go index af5a55d87..61112a2e1 100644 --- a/net/ghttp/ghttp_unit_param_json_test.go +++ b/net/ghttp/ghttp_unit_param_json_test.go @@ -50,14 +50,14 @@ func Test_Params_Json_Request(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/get", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john`) - gtest.Assert(client.GetContent("/map", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`) - gtest.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`) - gtest.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123"}`), `密码强度不足; 两次密码不一致`) + t.Assert(client.GetContent("/get", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john`) + t.Assert(client.GetContent("/map", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`) + t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`) + t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123"}`), `密码强度不足; 两次密码不一致`) }) } @@ -139,40 +139,40 @@ func Test_Params_Json_Response(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) map1 := make(map[string]interface{}) err1 := json.Unmarshal([]byte(client.GetContent("/json1")), &map1) - gtest.Assert(err1, nil) - gtest.Assert(len(map1), 4) - gtest.Assert(map1["Name"], "john") - gtest.Assert(map1["Uid"], 100) - gtest.Assert(map1["password1"], "123") - gtest.Assert(map1["password2"], "456") + t.Assert(err1, nil) + t.Assert(len(map1), 4) + t.Assert(map1["Name"], "john") + t.Assert(map1["Uid"], 100) + t.Assert(map1["password1"], "123") + t.Assert(map1["password2"], "456") map2 := make(map[string]interface{}) err2 := json.Unmarshal([]byte(client.GetContent("/json2")), &map2) - gtest.Assert(err2, nil) - gtest.Assert(len(map2), 4) - gtest.Assert(map2["Name"], "john") - gtest.Assert(map2["Uid"], 100) - gtest.Assert(map2["password1"], "123") - gtest.Assert(map2["password2"], "456") + t.Assert(err2, nil) + t.Assert(len(map2), 4) + t.Assert(map2["Name"], "john") + t.Assert(map2["Uid"], 100) + t.Assert(map2["password1"], "123") + t.Assert(map2["password2"], "456") map3 := make(map[string]interface{}) err3 := json.Unmarshal([]byte(client.GetContent("/json3")), &map3) - gtest.Assert(err3, nil) - gtest.Assert(len(map3), 2) - gtest.Assert(map3["success"], "true") - gtest.Assert(map3["message"], g.Map{"body": "测试", "code": 3, "error": "error"}) + t.Assert(err3, nil) + t.Assert(len(map3), 2) + t.Assert(map3["success"], "true") + t.Assert(map3["message"], g.Map{"body": "测试", "code": 3, "error": "error"}) map4 := make(map[string]interface{}) err4 := json.Unmarshal([]byte(client.GetContent("/json4")), &map4) - gtest.Assert(err4, nil) - gtest.Assert(len(map4), 2) - gtest.Assert(map4["success"], "true") - gtest.Assert(map4["message"], g.Map{"body": "测试", "code": 3, "error": "error"}) + t.Assert(err4, nil) + t.Assert(len(map4), 2) + t.Assert(map4["success"], "true") + t.Assert(map4["message"], g.Map{"body": "测试", "code": 3, "error": "error"}) }) } diff --git a/net/ghttp/ghttp_unit_param_page_test.go b/net/ghttp/ghttp_unit_param_page_test.go index 865781b08..fd4d04fb3 100644 --- a/net/ghttp/ghttp_unit_param_page_test.go +++ b/net/ghttp/ghttp_unit_param_page_test.go @@ -35,14 +35,14 @@ func Test_Params_Page(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/list"), `首页上一页123下一页尾页`) - gtest.Assert(client.GetContent("/list?page=3"), `首页上一页123下一页尾页`) + t.Assert(client.GetContent("/list"), `首页上一页123下一页尾页`) + t.Assert(client.GetContent("/list?page=3"), `首页上一页123下一页尾页`) - gtest.Assert(client.GetContent("/list/1.html"), `首页上一页123下一页尾页`) - gtest.Assert(client.GetContent("/list/3.html"), `首页上一页123下一页尾页`) + t.Assert(client.GetContent("/list/1.html"), `首页上一页123下一页尾页`) + t.Assert(client.GetContent("/list/3.html"), `首页上一页123下一页尾页`) }) } diff --git a/net/ghttp/ghttp_unit_param_struct_test.go b/net/ghttp/ghttp_unit_param_struct_test.go index cf39ebbbf..eebdd1408 100644 --- a/net/ghttp/ghttp_unit_param_struct_test.go +++ b/net/ghttp/ghttp_unit_param_struct_test.go @@ -74,17 +74,17 @@ func Test_Params_Struct(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`) - gtest.Assert(client.PostContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`) - gtest.Assert(client.PostContent("/struct2", `id=1&name=john&password1=123&password2=456`), `1john123456`) - gtest.Assert(client.PostContent("/struct2", ``), ``) - gtest.Assert(client.PostContent("/struct-valid", `id=1&name=john&password1=123&password2=0`), `字段长度为2到20个字符; 密码强度不足`) - gtest.Assert(client.PostContent("/parse", `id=1&name=john&password1=123&password2=0`), `字段长度为2到20个字符; 密码强度不足`) - gtest.Assert(client.GetContent("/parse", `id=1&name=john&password1=123&password2=456`), `密码强度不足`) - gtest.Assert(client.GetContent("/parse", `id=1&name=john&password1=123Abc!@#&password2=123Abc!@#`), `1john123Abc!@#123Abc!@#`) - gtest.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`) + t.Assert(client.GetContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`) + t.Assert(client.PostContent("/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`) + t.Assert(client.PostContent("/struct2", `id=1&name=john&password1=123&password2=456`), `1john123456`) + t.Assert(client.PostContent("/struct2", ``), ``) + t.Assert(client.PostContent("/struct-valid", `id=1&name=john&password1=123&password2=0`), `字段长度为2到20个字符; 密码强度不足`) + t.Assert(client.PostContent("/parse", `id=1&name=john&password1=123&password2=0`), `字段长度为2到20个字符; 密码强度不足`) + t.Assert(client.GetContent("/parse", `id=1&name=john&password1=123&password2=456`), `密码强度不足`) + t.Assert(client.GetContent("/parse", `id=1&name=john&password1=123Abc!@#&password2=123Abc!@#`), `1john123Abc!@#123Abc!@#`) + t.Assert(client.PostContent("/parse", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), `1john123Abc!@#123Abc!@#`) }) } diff --git a/net/ghttp/ghttp_unit_param_test.go b/net/ghttp/ghttp_unit_param_test.go index b2f370912..a118d0c08 100644 --- a/net/ghttp/ghttp_unit_param_test.go +++ b/net/ghttp/ghttp_unit_param_test.go @@ -293,114 +293,114 @@ func Test_Params_Basic(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) // GET - gtest.Assert(client.GetContent("/get", "array[]=1&array[]=2"), `["1","2"]`) - gtest.Assert(client.GetContent("/get", "slice=1&slice=2"), `2`) - gtest.Assert(client.GetContent("/get", "bool=1"), `true`) - gtest.Assert(client.GetContent("/get", "bool=0"), `false`) - gtest.Assert(client.GetContent("/get", "float32=0.11"), `0.11`) - gtest.Assert(client.GetContent("/get", "float64=0.22"), `0.22`) - gtest.Assert(client.GetContent("/get", "int=-10000"), `-10000`) - gtest.Assert(client.GetContent("/get", "int=10000"), `10000`) - gtest.Assert(client.GetContent("/get", "uint=10000"), `10000`) - gtest.Assert(client.GetContent("/get", "uint=9"), `9`) - gtest.Assert(client.GetContent("/get", "string=key"), `key`) - gtest.Assert(client.GetContent("/get", "map[a]=1&map[b]=2"), `2`) - gtest.Assert(client.GetContent("/get", "a=1&b=2"), `1`) + t.Assert(client.GetContent("/get", "array[]=1&array[]=2"), `["1","2"]`) + t.Assert(client.GetContent("/get", "slice=1&slice=2"), `2`) + t.Assert(client.GetContent("/get", "bool=1"), `true`) + t.Assert(client.GetContent("/get", "bool=0"), `false`) + t.Assert(client.GetContent("/get", "float32=0.11"), `0.11`) + t.Assert(client.GetContent("/get", "float64=0.22"), `0.22`) + t.Assert(client.GetContent("/get", "int=-10000"), `-10000`) + t.Assert(client.GetContent("/get", "int=10000"), `10000`) + t.Assert(client.GetContent("/get", "uint=10000"), `10000`) + t.Assert(client.GetContent("/get", "uint=9"), `9`) + t.Assert(client.GetContent("/get", "string=key"), `key`) + t.Assert(client.GetContent("/get", "map[a]=1&map[b]=2"), `2`) + t.Assert(client.GetContent("/get", "a=1&b=2"), `1`) // PUT - gtest.Assert(client.PutContent("/put", "array[]=1&array[]=2"), `["1","2"]`) - gtest.Assert(client.PutContent("/put", "slice=1&slice=2"), `2`) - gtest.Assert(client.PutContent("/put", "bool=1"), `true`) - gtest.Assert(client.PutContent("/put", "bool=0"), `false`) - gtest.Assert(client.PutContent("/put", "float32=0.11"), `0.11`) - gtest.Assert(client.PutContent("/put", "float64=0.22"), `0.22`) - gtest.Assert(client.PutContent("/put", "int=-10000"), `-10000`) - gtest.Assert(client.PutContent("/put", "int=10000"), `10000`) - gtest.Assert(client.PutContent("/put", "uint=10000"), `10000`) - gtest.Assert(client.PutContent("/put", "uint=9"), `9`) - gtest.Assert(client.PutContent("/put", "string=key"), `key`) - gtest.Assert(client.PutContent("/put", "map[a]=1&map[b]=2"), `2`) - gtest.Assert(client.PutContent("/put", "a=1&b=2"), `1`) + t.Assert(client.PutContent("/put", "array[]=1&array[]=2"), `["1","2"]`) + t.Assert(client.PutContent("/put", "slice=1&slice=2"), `2`) + t.Assert(client.PutContent("/put", "bool=1"), `true`) + t.Assert(client.PutContent("/put", "bool=0"), `false`) + t.Assert(client.PutContent("/put", "float32=0.11"), `0.11`) + t.Assert(client.PutContent("/put", "float64=0.22"), `0.22`) + t.Assert(client.PutContent("/put", "int=-10000"), `-10000`) + t.Assert(client.PutContent("/put", "int=10000"), `10000`) + t.Assert(client.PutContent("/put", "uint=10000"), `10000`) + t.Assert(client.PutContent("/put", "uint=9"), `9`) + t.Assert(client.PutContent("/put", "string=key"), `key`) + t.Assert(client.PutContent("/put", "map[a]=1&map[b]=2"), `2`) + t.Assert(client.PutContent("/put", "a=1&b=2"), `1`) // POST - gtest.Assert(client.PostContent("/post", "array[]=1&array[]=2"), `["1","2"]`) - gtest.Assert(client.PostContent("/post", "slice=1&slice=2"), `2`) - gtest.Assert(client.PostContent("/post", "bool=1"), `true`) - gtest.Assert(client.PostContent("/post", "bool=0"), `false`) - gtest.Assert(client.PostContent("/post", "float32=0.11"), `0.11`) - gtest.Assert(client.PostContent("/post", "float64=0.22"), `0.22`) - gtest.Assert(client.PostContent("/post", "int=-10000"), `-10000`) - gtest.Assert(client.PostContent("/post", "int=10000"), `10000`) - gtest.Assert(client.PostContent("/post", "uint=10000"), `10000`) - gtest.Assert(client.PostContent("/post", "uint=9"), `9`) - gtest.Assert(client.PostContent("/post", "string=key"), `key`) - gtest.Assert(client.PostContent("/post", "map[a]=1&map[b]=2"), `2`) - gtest.Assert(client.PostContent("/post", "a=1&b=2"), `1`) + t.Assert(client.PostContent("/post", "array[]=1&array[]=2"), `["1","2"]`) + t.Assert(client.PostContent("/post", "slice=1&slice=2"), `2`) + t.Assert(client.PostContent("/post", "bool=1"), `true`) + t.Assert(client.PostContent("/post", "bool=0"), `false`) + t.Assert(client.PostContent("/post", "float32=0.11"), `0.11`) + t.Assert(client.PostContent("/post", "float64=0.22"), `0.22`) + t.Assert(client.PostContent("/post", "int=-10000"), `-10000`) + t.Assert(client.PostContent("/post", "int=10000"), `10000`) + t.Assert(client.PostContent("/post", "uint=10000"), `10000`) + t.Assert(client.PostContent("/post", "uint=9"), `9`) + t.Assert(client.PostContent("/post", "string=key"), `key`) + t.Assert(client.PostContent("/post", "map[a]=1&map[b]=2"), `2`) + t.Assert(client.PostContent("/post", "a=1&b=2"), `1`) // DELETE - gtest.Assert(client.DeleteContent("/delete", "array[]=1&array[]=2"), `["1","2"]`) - gtest.Assert(client.DeleteContent("/delete", "slice=1&slice=2"), `2`) - gtest.Assert(client.DeleteContent("/delete", "bool=1"), `true`) - gtest.Assert(client.DeleteContent("/delete", "bool=0"), `false`) - gtest.Assert(client.DeleteContent("/delete", "float32=0.11"), `0.11`) - gtest.Assert(client.DeleteContent("/delete", "float64=0.22"), `0.22`) - gtest.Assert(client.DeleteContent("/delete", "int=-10000"), `-10000`) - gtest.Assert(client.DeleteContent("/delete", "int=10000"), `10000`) - gtest.Assert(client.DeleteContent("/delete", "uint=10000"), `10000`) - gtest.Assert(client.DeleteContent("/delete", "uint=9"), `9`) - gtest.Assert(client.DeleteContent("/delete", "string=key"), `key`) - gtest.Assert(client.DeleteContent("/delete", "map[a]=1&map[b]=2"), `2`) - gtest.Assert(client.DeleteContent("/delete", "a=1&b=2"), `1`) + t.Assert(client.DeleteContent("/delete", "array[]=1&array[]=2"), `["1","2"]`) + t.Assert(client.DeleteContent("/delete", "slice=1&slice=2"), `2`) + t.Assert(client.DeleteContent("/delete", "bool=1"), `true`) + t.Assert(client.DeleteContent("/delete", "bool=0"), `false`) + t.Assert(client.DeleteContent("/delete", "float32=0.11"), `0.11`) + t.Assert(client.DeleteContent("/delete", "float64=0.22"), `0.22`) + t.Assert(client.DeleteContent("/delete", "int=-10000"), `-10000`) + t.Assert(client.DeleteContent("/delete", "int=10000"), `10000`) + t.Assert(client.DeleteContent("/delete", "uint=10000"), `10000`) + t.Assert(client.DeleteContent("/delete", "uint=9"), `9`) + t.Assert(client.DeleteContent("/delete", "string=key"), `key`) + t.Assert(client.DeleteContent("/delete", "map[a]=1&map[b]=2"), `2`) + t.Assert(client.DeleteContent("/delete", "a=1&b=2"), `1`) // PATCH - gtest.Assert(client.PatchContent("/patch", "array[]=1&array[]=2"), `["1","2"]`) - gtest.Assert(client.PatchContent("/patch", "slice=1&slice=2"), `2`) - gtest.Assert(client.PatchContent("/patch", "bool=1"), `true`) - gtest.Assert(client.PatchContent("/patch", "bool=0"), `false`) - gtest.Assert(client.PatchContent("/patch", "float32=0.11"), `0.11`) - gtest.Assert(client.PatchContent("/patch", "float64=0.22"), `0.22`) - gtest.Assert(client.PatchContent("/patch", "int=-10000"), `-10000`) - gtest.Assert(client.PatchContent("/patch", "int=10000"), `10000`) - gtest.Assert(client.PatchContent("/patch", "uint=10000"), `10000`) - gtest.Assert(client.PatchContent("/patch", "uint=9"), `9`) - gtest.Assert(client.PatchContent("/patch", "string=key"), `key`) - gtest.Assert(client.PatchContent("/patch", "map[a]=1&map[b]=2"), `2`) - gtest.Assert(client.PatchContent("/patch", "a=1&b=2"), `1`) + t.Assert(client.PatchContent("/patch", "array[]=1&array[]=2"), `["1","2"]`) + t.Assert(client.PatchContent("/patch", "slice=1&slice=2"), `2`) + t.Assert(client.PatchContent("/patch", "bool=1"), `true`) + t.Assert(client.PatchContent("/patch", "bool=0"), `false`) + t.Assert(client.PatchContent("/patch", "float32=0.11"), `0.11`) + t.Assert(client.PatchContent("/patch", "float64=0.22"), `0.22`) + t.Assert(client.PatchContent("/patch", "int=-10000"), `-10000`) + t.Assert(client.PatchContent("/patch", "int=10000"), `10000`) + t.Assert(client.PatchContent("/patch", "uint=10000"), `10000`) + t.Assert(client.PatchContent("/patch", "uint=9"), `9`) + t.Assert(client.PatchContent("/patch", "string=key"), `key`) + t.Assert(client.PatchContent("/patch", "map[a]=1&map[b]=2"), `2`) + t.Assert(client.PatchContent("/patch", "a=1&b=2"), `1`) // Form - gtest.Assert(client.PostContent("/form", "array[]=1&array[]=2"), `["1","2"]`) - gtest.Assert(client.PostContent("/form", "slice=1&slice=2"), `2`) - gtest.Assert(client.PostContent("/form", "bool=1"), `true`) - gtest.Assert(client.PostContent("/form", "bool=0"), `false`) - gtest.Assert(client.PostContent("/form", "float32=0.11"), `0.11`) - gtest.Assert(client.PostContent("/form", "float64=0.22"), `0.22`) - gtest.Assert(client.PostContent("/form", "int=-10000"), `-10000`) - gtest.Assert(client.PostContent("/form", "int=10000"), `10000`) - gtest.Assert(client.PostContent("/form", "uint=10000"), `10000`) - gtest.Assert(client.PostContent("/form", "uint=9"), `9`) - gtest.Assert(client.PostContent("/form", "string=key"), `key`) - gtest.Assert(client.PostContent("/form", "map[a]=1&map[b]=2"), `2`) - gtest.Assert(client.PostContent("/form", "a=1&b=2"), `1`) + t.Assert(client.PostContent("/form", "array[]=1&array[]=2"), `["1","2"]`) + t.Assert(client.PostContent("/form", "slice=1&slice=2"), `2`) + t.Assert(client.PostContent("/form", "bool=1"), `true`) + t.Assert(client.PostContent("/form", "bool=0"), `false`) + t.Assert(client.PostContent("/form", "float32=0.11"), `0.11`) + t.Assert(client.PostContent("/form", "float64=0.22"), `0.22`) + t.Assert(client.PostContent("/form", "int=-10000"), `-10000`) + t.Assert(client.PostContent("/form", "int=10000"), `10000`) + t.Assert(client.PostContent("/form", "uint=10000"), `10000`) + t.Assert(client.PostContent("/form", "uint=9"), `9`) + t.Assert(client.PostContent("/form", "string=key"), `key`) + t.Assert(client.PostContent("/form", "map[a]=1&map[b]=2"), `2`) + t.Assert(client.PostContent("/form", "a=1&b=2"), `1`) // Map - gtest.Assert(client.GetContent("/map", "id=1&name=john"), `john`) - gtest.Assert(client.PostContent("/map", "id=1&name=john"), `john`) + t.Assert(client.GetContent("/map", "id=1&name=john"), `john`) + t.Assert(client.PostContent("/map", "id=1&name=john"), `john`) // Raw - gtest.Assert(client.PutContent("/raw", "id=1&name=john"), `id=1&name=john`) + t.Assert(client.PutContent("/raw", "id=1&name=john"), `id=1&name=john`) // Json - gtest.Assert(client.PostContent("/json", `{"id":1, "name":"john"}`), `john`) + t.Assert(client.PostContent("/json", `{"id":1, "name":"john"}`), `john`) // Struct - gtest.Assert(client.GetContent("/struct", `id=1&name=john&password1=123&password2=456`), `1john123456`) - gtest.Assert(client.PostContent("/struct", `id=1&name=john&password1=123&password2=456`), `1john123456`) - gtest.Assert(client.PostContent("/struct-with-nil", ``), ``) - gtest.Assert(client.PostContent("/struct-with-base", `id=1&name=john&password1=123&password2=456`), "1john1234561john123456") + t.Assert(client.GetContent("/struct", `id=1&name=john&password1=123&password2=456`), `1john123456`) + t.Assert(client.PostContent("/struct", `id=1&name=john&password1=123&password2=456`), `1john123456`) + t.Assert(client.PostContent("/struct-with-nil", ``), ``) + t.Assert(client.PostContent("/struct-with-base", `id=1&name=john&password1=123&password2=456`), "1john1234561john123456") }) } @@ -419,13 +419,13 @@ func Test_Params_SupportChars(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { prefix := fmt.Sprintf("http://127.0.0.1:%d", p) client := ghttp.NewClient() client.SetPrefix(prefix) - gtest.Assert(client.PostContent("/form-value", "test-value=100"), "100") - gtest.Assert(client.PostContent("/form-array", "test-array[]=1&test-array[]=2"), `["1","2"]`) + t.Assert(client.PostContent("/form-value", "test-value=100"), "100") + t.Assert(client.PostContent("/form-array", "test-array[]=1&test-array[]=2"), `["1","2"]`) }) } @@ -456,16 +456,16 @@ func Test_Params_Priority(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { prefix := fmt.Sprintf("http://127.0.0.1:%d", p) client := ghttp.NewClient() client.SetPrefix(prefix) - gtest.Assert(client.GetContent("/query?a=1", "a=100"), "1") - gtest.Assert(client.PostContent("/post?a=1", "a=100"), "100") - gtest.Assert(client.PostContent("/form?a=1", "a=100"), "100") - gtest.Assert(client.PutContent("/form?a=1", "a=100"), "100") - gtest.Assert(client.GetContent("/request?a=1", "a=100"), "100") - gtest.Assert(client.GetContent("/request-map?a=1&b=2&c=3", "a=100&b=200&c=300"), `{"a":"100","b":"200"}`) + t.Assert(client.GetContent("/query?a=1", "a=100"), "1") + t.Assert(client.PostContent("/post?a=1", "a=100"), "100") + t.Assert(client.PostContent("/form?a=1", "a=100"), "100") + t.Assert(client.PutContent("/form?a=1", "a=100"), "100") + t.Assert(client.GetContent("/request?a=1", "a=100"), "100") + t.Assert(client.GetContent("/request-map?a=1&b=2&c=3", "a=100&b=200&c=300"), `{"a":"100","b":"200"}`) }) } diff --git a/net/ghttp/ghttp_unit_param_xml_test.go b/net/ghttp/ghttp_unit_param_xml_test.go index 999e39697..3dc118a9b 100644 --- a/net/ghttp/ghttp_unit_param_xml_test.go +++ b/net/ghttp/ghttp_unit_param_xml_test.go @@ -49,17 +49,17 @@ func Test_Params_Xml_Request(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) content1 := `1john123Abc!@#123Abc!@#` content2 := `1john123Abc!@#123` - gtest.Assert(client.GetContent("/get", content1), `1john`) - gtest.Assert(client.PostContent("/get", content1), `1john`) - gtest.Assert(client.GetContent("/map", content1), `1john123Abc!@#123Abc!@#`) - gtest.Assert(client.PostContent("/map", content1), `1john123Abc!@#123Abc!@#`) - gtest.Assert(client.PostContent("/parse", content1), `1john123Abc!@#123Abc!@#`) - gtest.Assert(client.PostContent("/parse", content2), `密码强度不足; 两次密码不一致`) + t.Assert(client.GetContent("/get", content1), `1john`) + t.Assert(client.PostContent("/get", content1), `1john`) + t.Assert(client.GetContent("/map", content1), `1john123Abc!@#123Abc!@#`) + t.Assert(client.PostContent("/map", content1), `1john123Abc!@#123Abc!@#`) + t.Assert(client.PostContent("/parse", content1), `1john123Abc!@#123Abc!@#`) + t.Assert(client.PostContent("/parse", content2), `密码强度不足; 两次密码不一致`) }) } diff --git a/net/ghttp/ghttp_unit_pprof_test.go b/net/ghttp/ghttp_unit_pprof_test.go index 3d5d8e771..f44a8dbf7 100644 --- a/net/ghttp/ghttp_unit_pprof_test.go +++ b/net/ghttp/ghttp_unit_pprof_test.go @@ -19,7 +19,7 @@ import ( ) func TestServer_EnablePProf(t *testing.T) { - Case(t, func() { + C(t, func(t *T) { p := ports.PopRand() s := g.Server(p) s.EnablePProf("/pprof") diff --git a/net/ghttp/ghttp_unit_router_basic_test.go b/net/ghttp/ghttp_unit_router_basic_test.go index 558e29b12..9b4386fdb 100644 --- a/net/ghttp/ghttp_unit_router_basic_test.go +++ b/net/ghttp/ghttp_unit_router_basic_test.go @@ -40,13 +40,13 @@ func Test_Router_Basic(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/john"), "") - gtest.Assert(client.GetContent("/john/update"), "john") - gtest.Assert(client.GetContent("/john/edit"), "edit") - gtest.Assert(client.GetContent("/user/list/100.html"), "100") + t.Assert(client.GetContent("/john"), "") + t.Assert(client.GetContent("/john/update"), "john") + t.Assert(client.GetContent("/john/edit"), "edit") + t.Assert(client.GetContent("/user/list/100.html"), "100") }) } @@ -66,29 +66,29 @@ func Test_Router_Method(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) resp1, err := client.Get("/get") defer resp1.Close() - gtest.Assert(err, nil) - gtest.Assert(resp1.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp1.StatusCode, 200) resp2, err := client.Post("/get") defer resp2.Close() - gtest.Assert(err, nil) - gtest.Assert(resp2.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp2.StatusCode, 404) resp3, err := client.Get("/post") defer resp3.Close() - gtest.Assert(err, nil) - gtest.Assert(resp3.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp3.StatusCode, 404) resp4, err := client.Post("/post") defer resp4.Close() - gtest.Assert(err, nil) - gtest.Assert(resp4.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp4.StatusCode, 200) }) } @@ -107,13 +107,13 @@ func Test_Router_ExtraChar(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/api/test"), "test") - gtest.Assert(client.GetContent("/api/test/"), "test") - gtest.Assert(client.GetContent("/api/test//"), "test") + t.Assert(client.GetContent("/api/test"), "test") + t.Assert(client.GetContent("/api/test/"), "test") + t.Assert(client.GetContent("/api/test//"), "test") }) } @@ -139,34 +139,34 @@ func Test_Router_Status(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) resp1, err := client.Get("/200") defer resp1.Close() - gtest.Assert(err, nil) - gtest.Assert(resp1.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp1.StatusCode, 200) resp2, err := client.Get("/300") defer resp2.Close() - gtest.Assert(err, nil) - gtest.Assert(resp2.StatusCode, 300) + t.Assert(err, nil) + t.Assert(resp2.StatusCode, 300) resp3, err := client.Get("/400") defer resp3.Close() - gtest.Assert(err, nil) - gtest.Assert(resp3.StatusCode, 400) + t.Assert(err, nil) + t.Assert(resp3.StatusCode, 400) resp4, err := client.Get("/500") defer resp4.Close() - gtest.Assert(err, nil) - gtest.Assert(resp4.StatusCode, 500) + t.Assert(err, nil) + t.Assert(resp4.StatusCode, 500) resp5, err := client.Get("/404") defer resp5.Close() - gtest.Assert(err, nil) - gtest.Assert(resp5.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp5.StatusCode, 404) }) } @@ -185,16 +185,16 @@ func Test_Router_CustomStatusHandler(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "hello") + t.Assert(client.GetContent("/"), "hello") resp, err := client.Get("/ThisDoesNotExist") defer resp.Close() - gtest.Assert(err, nil) - gtest.Assert(resp.StatusCode, 404) - gtest.Assert(resp.ReadAllString(), "404 page") + t.Assert(err, nil) + t.Assert(resp.StatusCode, 404) + t.Assert(resp.ReadAllString(), "404 page") }) } @@ -211,15 +211,15 @@ func Test_Router_404(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "hello") + t.Assert(client.GetContent("/"), "hello") resp, err := client.Get("/ThisDoesNotExist") defer resp.Close() - gtest.Assert(err, nil) - gtest.Assert(resp.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp.StatusCode, 404) }) } @@ -244,13 +244,13 @@ func Test_Router_Priority(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/admin"), "admin") - gtest.Assert(client.GetContent("/admin-1"), "admin-{page}") - gtest.Assert(client.GetContent("/admin-goods"), "admin-goods") - gtest.Assert(client.GetContent("/admin-goods-2"), "admin-goods-{page}") + t.Assert(client.GetContent("/admin"), "admin") + t.Assert(client.GetContent("/admin-1"), "admin-{page}") + t.Assert(client.GetContent("/admin-goods"), "admin-goods") + t.Assert(client.GetContent("/admin-goods-2"), "admin-goods-{page}") }) } diff --git a/net/ghttp/ghttp_unit_router_controller_rest_test.go b/net/ghttp/ghttp_unit_router_controller_rest_test.go index 149e7d11f..f56f9d0d3 100644 --- a/net/ghttp/ghttp_unit_router_controller_rest_test.go +++ b/net/ghttp/ghttp_unit_router_controller_rest_test.go @@ -62,32 +62,32 @@ func Test_Router_ControllerRest(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "1Controller Get2") - gtest.Assert(client.PutContent("/"), "1Controller Put2") - gtest.Assert(client.PostContent("/"), "1Controller Post2") - gtest.Assert(client.DeleteContent("/"), "1Controller Delete2") + t.Assert(client.GetContent("/"), "1Controller Get2") + t.Assert(client.PutContent("/"), "1Controller Put2") + t.Assert(client.PostContent("/"), "1Controller Post2") + t.Assert(client.DeleteContent("/"), "1Controller Delete2") resp1, err := client.Head("/") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "1") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/controller-rest/get"), "1Controller Get2") - gtest.Assert(client.PutContent("/controller-rest/put"), "1Controller Put2") - gtest.Assert(client.PostContent("/controller-rest/post"), "1Controller Post2") - gtest.Assert(client.DeleteContent("/controller-rest/delete"), "1Controller Delete2") + t.Assert(client.GetContent("/controller-rest/get"), "1Controller Get2") + t.Assert(client.PutContent("/controller-rest/put"), "1Controller Put2") + t.Assert(client.PostContent("/controller-rest/post"), "1Controller Post2") + t.Assert(client.DeleteContent("/controller-rest/delete"), "1Controller Delete2") resp2, err := client.Head("/controller-rest/head") if err == nil { defer resp2.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp2.Header.Get("head-ok"), "1") + t.Assert(err, nil) + t.Assert(resp2.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_router_controller_test.go b/net/ghttp/ghttp_unit_router_controller_test.go index f9834b9ed..12a3591bf 100644 --- a/net/ghttp/ghttp_unit_router_controller_test.go +++ b/net/ghttp/ghttp_unit_router_controller_test.go @@ -54,23 +54,23 @@ func Test_Router_Controller1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "1Controller Index2") - gtest.Assert(client.GetContent("/init"), "Not Found") - gtest.Assert(client.GetContent("/shut"), "Not Found") - gtest.Assert(client.GetContent("/index"), "1Controller Index2") - gtest.Assert(client.GetContent("/show"), "1Controller Show2") + t.Assert(client.GetContent("/"), "1Controller Index2") + t.Assert(client.GetContent("/init"), "Not Found") + t.Assert(client.GetContent("/shut"), "Not Found") + t.Assert(client.GetContent("/index"), "1Controller Index2") + t.Assert(client.GetContent("/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "1Controller Index2") - gtest.Assert(client.GetContent("/controller/show"), "1Controller Show2") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "1Controller Index2") + t.Assert(client.GetContent("/controller/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } @@ -84,19 +84,19 @@ func Test_Router_Controller2(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "Not Found") - gtest.Assert(client.GetContent("/controller/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/controller/info"), "1Controller Info2") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "Not Found") + t.Assert(client.GetContent("/controller/show"), "1Controller Show2") + t.Assert(client.GetContent("/controller/info"), "1Controller Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } @@ -110,19 +110,19 @@ func Test_Router_ControllerMethod(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "Not Found") - gtest.Assert(client.GetContent("/controller/show"), "Not Found") - gtest.Assert(client.GetContent("/controller/info"), "Not Found") - gtest.Assert(client.GetContent("/controller-info"), "1Controller Info2") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "Not Found") + t.Assert(client.GetContent("/controller/show"), "Not Found") + t.Assert(client.GetContent("/controller/info"), "Not Found") + t.Assert(client.GetContent("/controller-info"), "1Controller Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_router_domain_basic_test.go b/net/ghttp/ghttp_unit_router_domain_basic_test.go index 8ca2ee647..17a2fa05e 100644 --- a/net/ghttp/ghttp_unit_router_domain_basic_test.go +++ b/net/ghttp/ghttp_unit_router_domain_basic_test.go @@ -42,29 +42,29 @@ func Test_Router_DomainBasic(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/john"), "Not Found") - gtest.Assert(client.GetContent("/john/update"), "Not Found") - gtest.Assert(client.GetContent("/john/edit"), "Not Found") - gtest.Assert(client.GetContent("/user/list/100.html"), "Not Found") + t.Assert(client.GetContent("/john"), "Not Found") + t.Assert(client.GetContent("/john/update"), "Not Found") + t.Assert(client.GetContent("/john/edit"), "Not Found") + t.Assert(client.GetContent("/user/list/100.html"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/john"), "") - gtest.Assert(client.GetContent("/john/update"), "john") - gtest.Assert(client.GetContent("/john/edit"), "edit") - gtest.Assert(client.GetContent("/user/list/100.html"), "100") + t.Assert(client.GetContent("/john"), "") + t.Assert(client.GetContent("/john/update"), "john") + t.Assert(client.GetContent("/john/edit"), "edit") + t.Assert(client.GetContent("/user/list/100.html"), "100") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/john"), "") - gtest.Assert(client.GetContent("/john/update"), "john") - gtest.Assert(client.GetContent("/john/edit"), "edit") - gtest.Assert(client.GetContent("/user/list/100.html"), "100") + t.Assert(client.GetContent("/john"), "") + t.Assert(client.GetContent("/john/update"), "john") + t.Assert(client.GetContent("/john/edit"), "edit") + t.Assert(client.GetContent("/user/list/100.html"), "100") }) } @@ -84,79 +84,79 @@ func Test_Router_DomainMethod(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) resp1, err := client.Get("/get") defer resp1.Close() - gtest.Assert(err, nil) - gtest.Assert(resp1.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp1.StatusCode, 404) resp2, err := client.Post("/get") defer resp2.Close() - gtest.Assert(err, nil) - gtest.Assert(resp2.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp2.StatusCode, 404) resp3, err := client.Get("/post") defer resp3.Close() - gtest.Assert(err, nil) - gtest.Assert(resp3.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp3.StatusCode, 404) resp4, err := client.Post("/post") defer resp4.Close() - gtest.Assert(err, nil) - gtest.Assert(resp4.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp4.StatusCode, 404) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) resp1, err := client.Get("/get") defer resp1.Close() - gtest.Assert(err, nil) - gtest.Assert(resp1.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp1.StatusCode, 200) resp2, err := client.Post("/get") defer resp2.Close() - gtest.Assert(err, nil) - gtest.Assert(resp2.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp2.StatusCode, 404) resp3, err := client.Get("/post") defer resp3.Close() - gtest.Assert(err, nil) - gtest.Assert(resp3.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp3.StatusCode, 404) resp4, err := client.Post("/post") defer resp4.Close() - gtest.Assert(err, nil) - gtest.Assert(resp4.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp4.StatusCode, 200) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) resp1, err := client.Get("/get") defer resp1.Close() - gtest.Assert(err, nil) - gtest.Assert(resp1.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp1.StatusCode, 200) resp2, err := client.Post("/get") defer resp2.Close() - gtest.Assert(err, nil) - gtest.Assert(resp2.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp2.StatusCode, 404) resp3, err := client.Get("/post") defer resp3.Close() - gtest.Assert(err, nil) - gtest.Assert(resp3.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp3.StatusCode, 404) resp4, err := client.Post("/post") defer resp4.Close() - gtest.Assert(err, nil) - gtest.Assert(resp4.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp4.StatusCode, 200) }) } @@ -182,77 +182,77 @@ func Test_Router_DomainStatus(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) resp1, err := client.Get("/200") defer resp1.Close() - gtest.Assert(err, nil) - gtest.Assert(resp1.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp1.StatusCode, 404) resp2, err := client.Get("/300") defer resp2.Close() - gtest.Assert(err, nil) - gtest.Assert(resp2.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp2.StatusCode, 404) resp3, err := client.Get("/400") defer resp3.Close() - gtest.Assert(err, nil) - gtest.Assert(resp3.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp3.StatusCode, 404) resp4, err := client.Get("/500") defer resp4.Close() - gtest.Assert(err, nil) - gtest.Assert(resp4.StatusCode, 404) + t.Assert(err, nil) + t.Assert(resp4.StatusCode, 404) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) resp1, err := client.Get("/200") defer resp1.Close() - gtest.Assert(err, nil) - gtest.Assert(resp1.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp1.StatusCode, 200) resp2, err := client.Get("/300") defer resp2.Close() - gtest.Assert(err, nil) - gtest.Assert(resp2.StatusCode, 300) + t.Assert(err, nil) + t.Assert(resp2.StatusCode, 300) resp3, err := client.Get("/400") defer resp3.Close() - gtest.Assert(err, nil) - gtest.Assert(resp3.StatusCode, 400) + t.Assert(err, nil) + t.Assert(resp3.StatusCode, 400) resp4, err := client.Get("/500") defer resp4.Close() - gtest.Assert(err, nil) - gtest.Assert(resp4.StatusCode, 500) + t.Assert(err, nil) + t.Assert(resp4.StatusCode, 500) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) resp1, err := client.Get("/200") defer resp1.Close() - gtest.Assert(err, nil) - gtest.Assert(resp1.StatusCode, 200) + t.Assert(err, nil) + t.Assert(resp1.StatusCode, 200) resp2, err := client.Get("/300") defer resp2.Close() - gtest.Assert(err, nil) - gtest.Assert(resp2.StatusCode, 300) + t.Assert(err, nil) + t.Assert(resp2.StatusCode, 300) resp3, err := client.Get("/400") defer resp3.Close() - gtest.Assert(err, nil) - gtest.Assert(resp3.StatusCode, 400) + t.Assert(err, nil) + t.Assert(resp3.StatusCode, 400) resp4, err := client.Get("/500") defer resp4.Close() - gtest.Assert(err, nil) - gtest.Assert(resp4.StatusCode, 500) + t.Assert(err, nil) + t.Assert(resp4.StatusCode, 500) }) } @@ -272,26 +272,26 @@ func Test_Router_DomainCustomStatusHandler(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/ThisDoesNotExist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/ThisDoesNotExist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "hello") - gtest.Assert(client.GetContent("/ThisDoesNotExist"), "404 page") + t.Assert(client.GetContent("/"), "hello") + t.Assert(client.GetContent("/ThisDoesNotExist"), "404 page") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "hello") - gtest.Assert(client.GetContent("/ThisDoesNotExist"), "404 page") + t.Assert(client.GetContent("/"), "hello") + t.Assert(client.GetContent("/ThisDoesNotExist"), "404 page") }) } @@ -308,23 +308,23 @@ func Test_Router_Domain404(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "hello") + t.Assert(client.GetContent("/"), "hello") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "hello") + t.Assert(client.GetContent("/"), "hello") }) } @@ -354,23 +354,23 @@ func Test_Router_DomainGroup(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client1 := ghttp.NewClient() client1.SetPrefix(fmt.Sprintf("http://local:%d", p)) client2 := ghttp.NewClient() client2.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client1.GetContent("/app/t/list/2.html"), "t&2") - gtest.Assert(client2.GetContent("/app/t/list/2.html"), "Not Found") + t.Assert(client1.GetContent("/app/t/list/2.html"), "t&2") + t.Assert(client2.GetContent("/app/t/list/2.html"), "Not Found") - gtest.Assert(client1.GetContent("/app/order/info/2"), "2") - gtest.Assert(client2.GetContent("/app/order/info/2"), "Not Found") + t.Assert(client1.GetContent("/app/order/info/2"), "2") + t.Assert(client2.GetContent("/app/order/info/2"), "Not Found") - gtest.Assert(client1.GetContent("/app/comment/20"), "Not Found") - gtest.Assert(client2.GetContent("/app/comment/20"), "Not Found") + t.Assert(client1.GetContent("/app/comment/20"), "Not Found") + t.Assert(client2.GetContent("/app/comment/20"), "Not Found") - gtest.Assert(client1.DeleteContent("/app/comment/20"), "20") - gtest.Assert(client2.DeleteContent("/app/comment/20"), "Not Found") + t.Assert(client1.DeleteContent("/app/comment/20"), "20") + t.Assert(client2.DeleteContent("/app/comment/20"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_router_domain_controller_rest_test.go b/net/ghttp/ghttp_unit_router_domain_controller_rest_test.go index 40d67de39..f8f191ecb 100644 --- a/net/ghttp/ghttp_unit_router_domain_controller_rest_test.go +++ b/net/ghttp/ghttp_unit_router_domain_controller_rest_test.go @@ -70,58 +70,58 @@ func Test_Router_DomainControllerRest(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.PutContent("/"), "Not Found") - gtest.Assert(client.PostContent("/"), "Not Found") - gtest.Assert(client.DeleteContent("/"), "Not Found") - gtest.Assert(client.PatchContent("/"), "Not Found") - gtest.Assert(client.OptionsContent("/"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.PutContent("/"), "Not Found") + t.Assert(client.PostContent("/"), "Not Found") + t.Assert(client.DeleteContent("/"), "Not Found") + t.Assert(client.PatchContent("/"), "Not Found") + t.Assert(client.OptionsContent("/"), "Not Found") resp1, err := client.Head("/") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "1Controller Get2") - gtest.Assert(client.PutContent("/"), "1Controller Put2") - gtest.Assert(client.PostContent("/"), "1Controller Post2") - gtest.Assert(client.DeleteContent("/"), "1Controller Delete2") - gtest.Assert(client.PatchContent("/"), "1Controller Patch2") - gtest.Assert(client.OptionsContent("/"), "1Controller Options2") + t.Assert(client.GetContent("/"), "1Controller Get2") + t.Assert(client.PutContent("/"), "1Controller Put2") + t.Assert(client.PostContent("/"), "1Controller Post2") + t.Assert(client.DeleteContent("/"), "1Controller Delete2") + t.Assert(client.PatchContent("/"), "1Controller Patch2") + t.Assert(client.OptionsContent("/"), "1Controller Options2") resp1, err := client.Head("/") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "1") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "1Controller Get2") - gtest.Assert(client.PutContent("/"), "1Controller Put2") - gtest.Assert(client.PostContent("/"), "1Controller Post2") - gtest.Assert(client.DeleteContent("/"), "1Controller Delete2") - gtest.Assert(client.PatchContent("/"), "1Controller Patch2") - gtest.Assert(client.OptionsContent("/"), "1Controller Options2") + t.Assert(client.GetContent("/"), "1Controller Get2") + t.Assert(client.PutContent("/"), "1Controller Put2") + t.Assert(client.PostContent("/"), "1Controller Post2") + t.Assert(client.DeleteContent("/"), "1Controller Delete2") + t.Assert(client.PatchContent("/"), "1Controller Patch2") + t.Assert(client.OptionsContent("/"), "1Controller Options2") resp1, err := client.Head("/") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "1") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_router_domain_controller_test.go b/net/ghttp/ghttp_unit_router_domain_controller_test.go index b63265206..756417989 100644 --- a/net/ghttp/ghttp_unit_router_domain_controller_test.go +++ b/net/ghttp/ghttp_unit_router_domain_controller_test.go @@ -52,43 +52,43 @@ func Test_Router_DomainController1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/init"), "Not Found") - gtest.Assert(client.GetContent("/shut"), "Not Found") - gtest.Assert(client.GetContent("/index"), "Not Found") - gtest.Assert(client.GetContent("/show"), "Not Found") - gtest.Assert(client.GetContent("/info"), "Not Found") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/init"), "Not Found") + t.Assert(client.GetContent("/shut"), "Not Found") + t.Assert(client.GetContent("/index"), "Not Found") + t.Assert(client.GetContent("/show"), "Not Found") + t.Assert(client.GetContent("/info"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "1Controller Index2") - gtest.Assert(client.GetContent("/init"), "Not Found") - gtest.Assert(client.GetContent("/shut"), "Not Found") - gtest.Assert(client.GetContent("/index"), "1Controller Index2") - gtest.Assert(client.GetContent("/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/info"), "1Controller Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "1Controller Index2") + t.Assert(client.GetContent("/init"), "Not Found") + t.Assert(client.GetContent("/shut"), "Not Found") + t.Assert(client.GetContent("/index"), "1Controller Index2") + t.Assert(client.GetContent("/show"), "1Controller Show2") + t.Assert(client.GetContent("/info"), "1Controller Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "1Controller Index2") - gtest.Assert(client.GetContent("/init"), "Not Found") - gtest.Assert(client.GetContent("/shut"), "Not Found") - gtest.Assert(client.GetContent("/index"), "1Controller Index2") - gtest.Assert(client.GetContent("/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/info"), "1Controller Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "1Controller Index2") + t.Assert(client.GetContent("/init"), "Not Found") + t.Assert(client.GetContent("/shut"), "Not Found") + t.Assert(client.GetContent("/index"), "1Controller Index2") + t.Assert(client.GetContent("/show"), "1Controller Show2") + t.Assert(client.GetContent("/info"), "1Controller Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } @@ -102,46 +102,46 @@ func Test_Router_DomainController2(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "Not Found") - gtest.Assert(client.GetContent("/controller/show"), "Not Found") - gtest.Assert(client.GetContent("/controller/info"), "Not Found") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "Not Found") + t.Assert(client.GetContent("/controller/show"), "Not Found") + t.Assert(client.GetContent("/controller/info"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "Not Found") - gtest.Assert(client.GetContent("/controller/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/controller/info"), "1Controller Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "Not Found") + t.Assert(client.GetContent("/controller/show"), "1Controller Show2") + t.Assert(client.GetContent("/controller/info"), "1Controller Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "Not Found") - gtest.Assert(client.GetContent("/controller/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/controller/info"), "1Controller Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "Not Found") + t.Assert(client.GetContent("/controller/show"), "1Controller Show2") + t.Assert(client.GetContent("/controller/info"), "1Controller Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } @@ -155,46 +155,46 @@ func Test_Router_DomainControllerMethod(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "Not Found") - gtest.Assert(client.GetContent("/controller/show"), "Not Found") - gtest.Assert(client.GetContent("/controller/info"), "Not Found") - gtest.Assert(client.GetContent("/controller-info"), "Not Found") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "Not Found") + t.Assert(client.GetContent("/controller/show"), "Not Found") + t.Assert(client.GetContent("/controller/info"), "Not Found") + t.Assert(client.GetContent("/controller-info"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "Not Found") - gtest.Assert(client.GetContent("/controller/show"), "Not Found") - gtest.Assert(client.GetContent("/controller/info"), "Not Found") - gtest.Assert(client.GetContent("/controller-info"), "1Controller Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "Not Found") + t.Assert(client.GetContent("/controller/show"), "Not Found") + t.Assert(client.GetContent("/controller/info"), "Not Found") + t.Assert(client.GetContent("/controller-info"), "1Controller Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/controller"), "Not Found") - gtest.Assert(client.GetContent("/controller/init"), "Not Found") - gtest.Assert(client.GetContent("/controller/shut"), "Not Found") - gtest.Assert(client.GetContent("/controller/index"), "Not Found") - gtest.Assert(client.GetContent("/controller/show"), "Not Found") - gtest.Assert(client.GetContent("/controller/info"), "Not Found") - gtest.Assert(client.GetContent("/controller-info"), "1Controller Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/controller"), "Not Found") + t.Assert(client.GetContent("/controller/init"), "Not Found") + t.Assert(client.GetContent("/controller/shut"), "Not Found") + t.Assert(client.GetContent("/controller/index"), "Not Found") + t.Assert(client.GetContent("/controller/show"), "Not Found") + t.Assert(client.GetContent("/controller/info"), "Not Found") + t.Assert(client.GetContent("/controller-info"), "1Controller Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_router_domain_object_rest_test.go b/net/ghttp/ghttp_unit_router_domain_object_rest_test.go index c726c0c49..6f3dbf1c9 100644 --- a/net/ghttp/ghttp_unit_router_domain_object_rest_test.go +++ b/net/ghttp/ghttp_unit_router_domain_object_rest_test.go @@ -65,58 +65,58 @@ func Test_Router_DomainObjectRest(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.PutContent("/"), "Not Found") - gtest.Assert(client.PostContent("/"), "Not Found") - gtest.Assert(client.DeleteContent("/"), "Not Found") - gtest.Assert(client.PatchContent("/"), "Not Found") - gtest.Assert(client.OptionsContent("/"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.PutContent("/"), "Not Found") + t.Assert(client.PostContent("/"), "Not Found") + t.Assert(client.DeleteContent("/"), "Not Found") + t.Assert(client.PatchContent("/"), "Not Found") + t.Assert(client.OptionsContent("/"), "Not Found") resp1, err := client.Head("/") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "1Object Get2") - gtest.Assert(client.PutContent("/"), "1Object Put2") - gtest.Assert(client.PostContent("/"), "1Object Post2") - gtest.Assert(client.DeleteContent("/"), "1Object Delete2") - gtest.Assert(client.PatchContent("/"), "1Object Patch2") - gtest.Assert(client.OptionsContent("/"), "1Object Options2") + t.Assert(client.GetContent("/"), "1Object Get2") + t.Assert(client.PutContent("/"), "1Object Put2") + t.Assert(client.PostContent("/"), "1Object Post2") + t.Assert(client.DeleteContent("/"), "1Object Delete2") + t.Assert(client.PatchContent("/"), "1Object Patch2") + t.Assert(client.OptionsContent("/"), "1Object Options2") resp1, err := client.Head("/") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "1") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "1Object Get2") - gtest.Assert(client.PutContent("/"), "1Object Put2") - gtest.Assert(client.PostContent("/"), "1Object Post2") - gtest.Assert(client.DeleteContent("/"), "1Object Delete2") - gtest.Assert(client.PatchContent("/"), "1Object Patch2") - gtest.Assert(client.OptionsContent("/"), "1Object Options2") + t.Assert(client.GetContent("/"), "1Object Get2") + t.Assert(client.PutContent("/"), "1Object Put2") + t.Assert(client.PostContent("/"), "1Object Post2") + t.Assert(client.DeleteContent("/"), "1Object Delete2") + t.Assert(client.PatchContent("/"), "1Object Patch2") + t.Assert(client.OptionsContent("/"), "1Object Options2") resp1, err := client.Head("/") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "1") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_router_domain_object_test.go b/net/ghttp/ghttp_unit_router_domain_object_test.go index 95e8ecef5..5b67aeeb1 100644 --- a/net/ghttp/ghttp_unit_router_domain_object_test.go +++ b/net/ghttp/ghttp_unit_router_domain_object_test.go @@ -48,42 +48,42 @@ func Test_Router_DomainObject1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/init"), "Not Found") - gtest.Assert(client.GetContent("/shut"), "Not Found") - gtest.Assert(client.GetContent("/index"), "Not Found") - gtest.Assert(client.GetContent("/show"), "Not Found") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/init"), "Not Found") + t.Assert(client.GetContent("/shut"), "Not Found") + t.Assert(client.GetContent("/index"), "Not Found") + t.Assert(client.GetContent("/show"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "1Object Index2") - gtest.Assert(client.GetContent("/init"), "Not Found") - gtest.Assert(client.GetContent("/shut"), "Not Found") - gtest.Assert(client.GetContent("/index"), "1Object Index2") - gtest.Assert(client.GetContent("/show"), "1Object Show2") - gtest.Assert(client.GetContent("/info"), "1Object Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "1Object Index2") + t.Assert(client.GetContent("/init"), "Not Found") + t.Assert(client.GetContent("/shut"), "Not Found") + t.Assert(client.GetContent("/index"), "1Object Index2") + t.Assert(client.GetContent("/show"), "1Object Show2") + t.Assert(client.GetContent("/info"), "1Object Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "1Object Index2") - gtest.Assert(client.GetContent("/init"), "Not Found") - gtest.Assert(client.GetContent("/shut"), "Not Found") - gtest.Assert(client.GetContent("/index"), "1Object Index2") - gtest.Assert(client.GetContent("/show"), "1Object Show2") - gtest.Assert(client.GetContent("/info"), "1Object Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "1Object Index2") + t.Assert(client.GetContent("/init"), "Not Found") + t.Assert(client.GetContent("/shut"), "Not Found") + t.Assert(client.GetContent("/index"), "1Object Index2") + t.Assert(client.GetContent("/show"), "1Object Show2") + t.Assert(client.GetContent("/info"), "1Object Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } @@ -97,44 +97,44 @@ func Test_Router_DomainObject2(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "Not Found") - gtest.Assert(client.GetContent("/object/show"), "Not Found") - gtest.Assert(client.GetContent("/object/info"), "Not Found") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "Not Found") + t.Assert(client.GetContent("/object/show"), "Not Found") + t.Assert(client.GetContent("/object/info"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "Not Found") - gtest.Assert(client.GetContent("/object/show"), "1Object Show2") - gtest.Assert(client.GetContent("/object/info"), "1Object Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "Not Found") + t.Assert(client.GetContent("/object/show"), "1Object Show2") + t.Assert(client.GetContent("/object/info"), "1Object Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "Not Found") - gtest.Assert(client.GetContent("/object/show"), "1Object Show2") - gtest.Assert(client.GetContent("/object/info"), "1Object Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "Not Found") + t.Assert(client.GetContent("/object/show"), "1Object Show2") + t.Assert(client.GetContent("/object/info"), "1Object Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } @@ -148,46 +148,46 @@ func Test_Router_DomainObjectMethod(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "Not Found") - gtest.Assert(client.GetContent("/object/show"), "Not Found") - gtest.Assert(client.GetContent("/object/info"), "Not Found") - gtest.Assert(client.GetContent("/object-info"), "Not Found") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "Not Found") + t.Assert(client.GetContent("/object/show"), "Not Found") + t.Assert(client.GetContent("/object/info"), "Not Found") + t.Assert(client.GetContent("/object-info"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://localhost:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "Not Found") - gtest.Assert(client.GetContent("/object/show"), "Not Found") - gtest.Assert(client.GetContent("/object/info"), "Not Found") - gtest.Assert(client.GetContent("/object-info"), "1Object Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "Not Found") + t.Assert(client.GetContent("/object/show"), "Not Found") + t.Assert(client.GetContent("/object/info"), "Not Found") + t.Assert(client.GetContent("/object-info"), "1Object Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://local:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "Not Found") - gtest.Assert(client.GetContent("/object/show"), "Not Found") - gtest.Assert(client.GetContent("/object/info"), "Not Found") - gtest.Assert(client.GetContent("/object-info"), "1Object Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "Not Found") + t.Assert(client.GetContent("/object/show"), "Not Found") + t.Assert(client.GetContent("/object/info"), "Not Found") + t.Assert(client.GetContent("/object-info"), "1Object Info2") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_router_exit_test.go b/net/ghttp/ghttp_unit_router_exit_test.go index 437aab164..81fd7a9a7 100644 --- a/net/ghttp/ghttp_unit_router_exit_test.go +++ b/net/ghttp/ghttp_unit_router_exit_test.go @@ -36,12 +36,12 @@ func Test_Router_Exit(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "123") - gtest.Assert(client.GetContent("/test/test"), "1test-start23") + t.Assert(client.GetContent("/"), "123") + t.Assert(client.GetContent("/test/test"), "1test-start23") }) } @@ -74,12 +74,12 @@ func Test_Router_ExitHook(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/priority/show"), "3show") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/priority/show"), "3show") }) } @@ -112,11 +112,11 @@ func Test_Router_ExitAll(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/priority/show"), "3") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/priority/show"), "3") }) } diff --git a/net/ghttp/ghttp_unit_router_group_group_test.go b/net/ghttp/ghttp_unit_router_group_group_test.go index 152b7b5c9..d2c5890a6 100644 --- a/net/ghttp/ghttp_unit_router_group_group_test.go +++ b/net/ghttp/ghttp_unit_router_group_group_test.go @@ -62,23 +62,23 @@ func Test_Router_Group_Group(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/api.v2"), "Not Found") - gtest.Assert(client.GetContent("/api.v2/test"), "1test2") - gtest.Assert(client.GetContent("/api.v2/hook"), "hook any") - gtest.Assert(client.GetContent("/api.v2/hook/name"), "hook namehook any") - gtest.Assert(client.GetContent("/api.v2/hook/name/any"), "hook any") - gtest.Assert(client.GetContent("/api.v2/order/list"), "1list2") - gtest.Assert(client.GetContent("/api.v2/order/update"), "Not Found") - gtest.Assert(client.PutContent("/api.v2/order/update"), "1update2") - gtest.Assert(client.GetContent("/api.v2/user/drop"), "Not Found") - gtest.Assert(client.DeleteContent("/api.v2/user/drop"), "1drop2") - gtest.Assert(client.GetContent("/api.v2/user/edit"), "Not Found") - gtest.Assert(client.PostContent("/api.v2/user/edit"), "1edit2") - gtest.Assert(client.GetContent("/api.v2/user/info"), "1info2") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/api.v2"), "Not Found") + t.Assert(client.GetContent("/api.v2/test"), "1test2") + t.Assert(client.GetContent("/api.v2/hook"), "hook any") + t.Assert(client.GetContent("/api.v2/hook/name"), "hook namehook any") + t.Assert(client.GetContent("/api.v2/hook/name/any"), "hook any") + t.Assert(client.GetContent("/api.v2/order/list"), "1list2") + t.Assert(client.GetContent("/api.v2/order/update"), "Not Found") + t.Assert(client.PutContent("/api.v2/order/update"), "1update2") + t.Assert(client.GetContent("/api.v2/user/drop"), "Not Found") + t.Assert(client.DeleteContent("/api.v2/user/drop"), "1drop2") + t.Assert(client.GetContent("/api.v2/user/edit"), "Not Found") + t.Assert(client.PostContent("/api.v2/user/edit"), "1edit2") + t.Assert(client.GetContent("/api.v2/user/info"), "1info2") }) } diff --git a/net/ghttp/ghttp_unit_router_group_hook_test.go b/net/ghttp/ghttp_unit_router_group_hook_test.go index 15a79880e..21c3c5a10 100644 --- a/net/ghttp/ghttp_unit_router_group_hook_test.go +++ b/net/ghttp/ghttp_unit_router_group_hook_test.go @@ -36,12 +36,12 @@ func Test_Router_Group_Hook1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/api/handler"), "012") - gtest.Assert(client.PostContent("/api/handler"), "02") - gtest.Assert(client.GetContent("/api/ThisDoesNotExist"), "Not Found") + t.Assert(client.GetContent("/api/handler"), "012") + t.Assert(client.PostContent("/api/handler"), "02") + t.Assert(client.GetContent("/api/ThisDoesNotExist"), "Not Found") }) } @@ -65,13 +65,13 @@ func Test_Router_Group_Hook2(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/api/handler"), "012") - gtest.Assert(client.PostContent("/api/handler"), "Not Found") - gtest.Assert(client.GetContent("/api/ThisDoesNotExist"), "02") - gtest.Assert(client.PostContent("/api/ThisDoesNotExist"), "Not Found") + t.Assert(client.GetContent("/api/handler"), "012") + t.Assert(client.PostContent("/api/handler"), "Not Found") + t.Assert(client.GetContent("/api/ThisDoesNotExist"), "02") + t.Assert(client.PostContent("/api/ThisDoesNotExist"), "Not Found") }) } @@ -96,11 +96,11 @@ func Test_Router_Group_Hook3(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/api/handler"), "012") - gtest.Assert(client.PostContent("/api/handler"), "012") - gtest.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "02") + t.Assert(client.GetContent("/api/handler"), "012") + t.Assert(client.PostContent("/api/handler"), "012") + t.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "02") }) } diff --git a/net/ghttp/ghttp_unit_router_group_rest_test.go b/net/ghttp/ghttp_unit_router_group_rest_test.go index e0688e1b3..dcb0eef41 100644 --- a/net/ghttp/ghttp_unit_router_group_rest_test.go +++ b/net/ghttp/ghttp_unit_router_group_rest_test.go @@ -113,62 +113,62 @@ func Test_Router_GroupRest(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/api/ctl"), "1Controller Get2") - gtest.Assert(client.PutContent("/api/ctl"), "1Controller Put2") - gtest.Assert(client.PostContent("/api/ctl"), "1Controller Post2") - gtest.Assert(client.DeleteContent("/api/ctl"), "1Controller Delete2") - gtest.Assert(client.PatchContent("/api/ctl"), "1Controller Patch2") - gtest.Assert(client.OptionsContent("/api/ctl"), "1Controller Options2") + t.Assert(client.GetContent("/api/ctl"), "1Controller Get2") + t.Assert(client.PutContent("/api/ctl"), "1Controller Put2") + t.Assert(client.PostContent("/api/ctl"), "1Controller Post2") + t.Assert(client.DeleteContent("/api/ctl"), "1Controller Delete2") + t.Assert(client.PatchContent("/api/ctl"), "1Controller Patch2") + t.Assert(client.OptionsContent("/api/ctl"), "1Controller Options2") resp1, err := client.Head("/api/ctl") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "1") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/api/obj"), "1Object Get2") - gtest.Assert(client.PutContent("/api/obj"), "1Object Put2") - gtest.Assert(client.PostContent("/api/obj"), "1Object Post2") - gtest.Assert(client.DeleteContent("/api/obj"), "1Object Delete2") - gtest.Assert(client.PatchContent("/api/obj"), "1Object Patch2") - gtest.Assert(client.OptionsContent("/api/obj"), "1Object Options2") + t.Assert(client.GetContent("/api/obj"), "1Object Get2") + t.Assert(client.PutContent("/api/obj"), "1Object Put2") + t.Assert(client.PostContent("/api/obj"), "1Object Post2") + t.Assert(client.DeleteContent("/api/obj"), "1Object Delete2") + t.Assert(client.PatchContent("/api/obj"), "1Object Patch2") + t.Assert(client.OptionsContent("/api/obj"), "1Object Options2") resp2, err := client.Head("/api/obj") if err == nil { defer resp2.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp2.Header.Get("head-ok"), "1") + t.Assert(err, nil) + t.Assert(resp2.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/api/group-ctl-rest"), "Not Found") - gtest.Assert(client.GetContent("/api/group-ctl-rest/get"), "1Controller Get2") - gtest.Assert(client.PutContent("/api/group-ctl-rest/put"), "1Controller Put2") - gtest.Assert(client.PostContent("/api/group-ctl-rest/post"), "1Controller Post2") - gtest.Assert(client.DeleteContent("/api/group-ctl-rest/delete"), "1Controller Delete2") - gtest.Assert(client.PatchContent("/api/group-ctl-rest/patch"), "1Controller Patch2") - gtest.Assert(client.OptionsContent("/api/group-ctl-rest/options"), "1Controller Options2") + t.Assert(client.GetContent("/api/group-ctl-rest"), "Not Found") + t.Assert(client.GetContent("/api/group-ctl-rest/get"), "1Controller Get2") + t.Assert(client.PutContent("/api/group-ctl-rest/put"), "1Controller Put2") + t.Assert(client.PostContent("/api/group-ctl-rest/post"), "1Controller Post2") + t.Assert(client.DeleteContent("/api/group-ctl-rest/delete"), "1Controller Delete2") + t.Assert(client.PatchContent("/api/group-ctl-rest/patch"), "1Controller Patch2") + t.Assert(client.OptionsContent("/api/group-ctl-rest/options"), "1Controller Options2") resp3, err := client.Head("/api/group-ctl-rest/head") if err == nil { defer resp3.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp3.Header.Get("head-ok"), "1") + t.Assert(err, nil) + t.Assert(resp3.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/api/group-obj-rest"), "Not Found") - gtest.Assert(client.GetContent("/api/group-obj-rest/get"), "1Object Get2") - gtest.Assert(client.PutContent("/api/group-obj-rest/put"), "1Object Put2") - gtest.Assert(client.PostContent("/api/group-obj-rest/post"), "1Object Post2") - gtest.Assert(client.DeleteContent("/api/group-obj-rest/delete"), "1Object Delete2") - gtest.Assert(client.PatchContent("/api/group-obj-rest/patch"), "1Object Patch2") - gtest.Assert(client.OptionsContent("/api/group-obj-rest/options"), "1Object Options2") + t.Assert(client.GetContent("/api/group-obj-rest"), "Not Found") + t.Assert(client.GetContent("/api/group-obj-rest/get"), "1Object Get2") + t.Assert(client.PutContent("/api/group-obj-rest/put"), "1Object Put2") + t.Assert(client.PostContent("/api/group-obj-rest/post"), "1Object Post2") + t.Assert(client.DeleteContent("/api/group-obj-rest/delete"), "1Object Delete2") + t.Assert(client.PatchContent("/api/group-obj-rest/patch"), "1Object Patch2") + t.Assert(client.OptionsContent("/api/group-obj-rest/options"), "1Object Options2") resp4, err := client.Head("/api/group-obj-rest/head") if err == nil { defer resp4.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp4.Header.Get("head-ok"), "1") + t.Assert(err, nil) + t.Assert(resp4.Header.Get("head-ok"), "1") }) } diff --git a/net/ghttp/ghttp_unit_router_group_test.go b/net/ghttp/ghttp_unit_router_group_test.go index d05a98697..f447560da 100644 --- a/net/ghttp/ghttp_unit_router_group_test.go +++ b/net/ghttp/ghttp_unit_router_group_test.go @@ -90,30 +90,30 @@ func Test_Router_GroupBasic1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/api/handler"), "Handler") + t.Assert(client.GetContent("/api/handler"), "Handler") - gtest.Assert(client.GetContent("/api/ctl"), "1Controller Index2") - gtest.Assert(client.GetContent("/api/ctl/"), "1Controller Index2") - gtest.Assert(client.GetContent("/api/ctl/index"), "1Controller Index2") - gtest.Assert(client.GetContent("/api/ctl/my-show"), "1Controller Show2") - gtest.Assert(client.GetContent("/api/ctl/post"), "1Controller Post2") - gtest.Assert(client.GetContent("/api/ctl/show"), "1Controller Show2") - gtest.Assert(client.PostContent("/api/ctl/rest"), "1Controller Post2") + t.Assert(client.GetContent("/api/ctl"), "1Controller Index2") + t.Assert(client.GetContent("/api/ctl/"), "1Controller Index2") + t.Assert(client.GetContent("/api/ctl/index"), "1Controller Index2") + t.Assert(client.GetContent("/api/ctl/my-show"), "1Controller Show2") + t.Assert(client.GetContent("/api/ctl/post"), "1Controller Post2") + t.Assert(client.GetContent("/api/ctl/show"), "1Controller Show2") + t.Assert(client.PostContent("/api/ctl/rest"), "1Controller Post2") - gtest.Assert(client.GetContent("/api/obj"), "1Object Index2") - gtest.Assert(client.GetContent("/api/obj/"), "1Object Index2") - gtest.Assert(client.GetContent("/api/obj/index"), "1Object Index2") - gtest.Assert(client.GetContent("/api/obj/delete"), "1Object Delete2") - gtest.Assert(client.GetContent("/api/obj/my-show"), "1Object Show2") - gtest.Assert(client.GetContent("/api/obj/show"), "1Object Show2") - gtest.Assert(client.DeleteContent("/api/obj/rest"), "1Object Delete2") + t.Assert(client.GetContent("/api/obj"), "1Object Index2") + t.Assert(client.GetContent("/api/obj/"), "1Object Index2") + t.Assert(client.GetContent("/api/obj/index"), "1Object Index2") + t.Assert(client.GetContent("/api/obj/delete"), "1Object Delete2") + t.Assert(client.GetContent("/api/obj/my-show"), "1Object Show2") + t.Assert(client.GetContent("/api/obj/show"), "1Object Show2") + t.Assert(client.DeleteContent("/api/obj/rest"), "1Object Delete2") - gtest.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found") - gtest.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found") + t.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found") + t.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found") }) } @@ -138,24 +138,24 @@ func Test_Router_GroupBasic2(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/api/handler"), "Handler") + t.Assert(client.GetContent("/api/handler"), "Handler") - gtest.Assert(client.GetContent("/api/ctl/my-show"), "1Controller Show2") - gtest.Assert(client.GetContent("/api/ctl/post"), "1Controller Post2") - gtest.Assert(client.GetContent("/api/ctl/show"), "1Controller Show2") - gtest.Assert(client.PostContent("/api/ctl/rest"), "1Controller Post2") + t.Assert(client.GetContent("/api/ctl/my-show"), "1Controller Show2") + t.Assert(client.GetContent("/api/ctl/post"), "1Controller Post2") + t.Assert(client.GetContent("/api/ctl/show"), "1Controller Show2") + t.Assert(client.PostContent("/api/ctl/rest"), "1Controller Post2") - gtest.Assert(client.GetContent("/api/obj/delete"), "1Object Delete2") - gtest.Assert(client.GetContent("/api/obj/my-show"), "1Object Show2") - gtest.Assert(client.GetContent("/api/obj/show"), "1Object Show2") - gtest.Assert(client.DeleteContent("/api/obj/rest"), "1Object Delete2") + t.Assert(client.GetContent("/api/obj/delete"), "1Object Delete2") + t.Assert(client.GetContent("/api/obj/my-show"), "1Object Show2") + t.Assert(client.GetContent("/api/obj/show"), "1Object Show2") + t.Assert(client.DeleteContent("/api/obj/rest"), "1Object Delete2") - gtest.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found") - gtest.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found") + t.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found") + t.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found") }) } @@ -174,20 +174,20 @@ func Test_Router_GroupBuildInVar(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/api/group-controller/index"), "1Controller Index2") - gtest.Assert(client.GetContent("/api/group-controller/post"), "1Controller Post2") - gtest.Assert(client.GetContent("/api/group-controller/show"), "1Controller Show2") + t.Assert(client.GetContent("/api/group-controller/index"), "1Controller Index2") + t.Assert(client.GetContent("/api/group-controller/post"), "1Controller Post2") + t.Assert(client.GetContent("/api/group-controller/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/api/group-object/index"), "1Object Index2") - gtest.Assert(client.GetContent("/api/group-object/delete"), "1Object Delete2") - gtest.Assert(client.GetContent("/api/group-object/show"), "1Object Show2") + t.Assert(client.GetContent("/api/group-object/index"), "1Object Index2") + t.Assert(client.GetContent("/api/group-object/delete"), "1Object Delete2") + t.Assert(client.GetContent("/api/group-object/show"), "1Object Show2") - gtest.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found") - gtest.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found") + t.Assert(client.DeleteContent("/ThisDoesNotExist"), "Not Found") + t.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found") }) } @@ -205,12 +205,12 @@ func Test_Router_Group_Mthods(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/ctl/show"), "1Controller Show2") - gtest.Assert(client.GetContent("/ctl/post"), "1Controller Post2") - gtest.Assert(client.GetContent("/obj/show"), "1Object Show2") - gtest.Assert(client.GetContent("/obj/delete"), "1Object Delete2") + t.Assert(client.GetContent("/ctl/show"), "1Controller Show2") + t.Assert(client.GetContent("/ctl/post"), "1Controller Post2") + t.Assert(client.GetContent("/obj/show"), "1Object Show2") + t.Assert(client.GetContent("/obj/delete"), "1Object Delete2") }) } diff --git a/net/ghttp/ghttp_unit_router_hook_test.go b/net/ghttp/ghttp_unit_router_hook_test.go index c3b592b79..a36fd7b98 100644 --- a/net/ghttp/ghttp_unit_router_hook_test.go +++ b/net/ghttp/ghttp_unit_router_hook_test.go @@ -34,12 +34,12 @@ func Test_Router_Hook_Basic(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "123") - gtest.Assert(client.GetContent("/test/test"), "1test23") + t.Assert(client.GetContent("/"), "123") + t.Assert(client.GetContent("/test/test"), "1test23") }) } @@ -75,15 +75,15 @@ func Test_Router_Hook_Fuzzy_Router(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/john"), "Not Found") - gtest.Assert(client.GetContent("/john/info"), "1000") - gtest.Assert(client.GetContent("/john/info"), "1001") - gtest.Assert(client.GetContent("/john/list/1.java"), "john&1&1002") - gtest.Assert(client.GetContent("/john/list/2.java"), "john&2&1002") + t.Assert(client.GetContent("/john"), "Not Found") + t.Assert(client.GetContent("/john/info"), "1000") + t.Assert(client.GetContent("/john/info"), "1001") + t.Assert(client.GetContent("/john/list/1.java"), "john&1&1002") + t.Assert(client.GetContent("/john/list/2.java"), "john&2&1002") }) } @@ -115,14 +115,14 @@ func Test_Router_Hook_Priority(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/priority/show"), "312show") - gtest.Assert(client.GetContent("/priority/any/any"), "2") - gtest.Assert(client.GetContent("/priority/name"), "12") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/priority/show"), "312show") + t.Assert(client.GetContent("/priority/any/any"), "2") + t.Assert(client.GetContent("/priority/name"), "12") }) } @@ -149,11 +149,11 @@ func Test_Router_Hook_Multi(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/multi-hook"), "12show") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/multi-hook"), "12show") }) } diff --git a/net/ghttp/ghttp_unit_router_names_test.go b/net/ghttp/ghttp_unit_router_names_test.go index c3b975afe..5216b12fe 100644 --- a/net/ghttp/ghttp_unit_router_names_test.go +++ b/net/ghttp/ghttp_unit_router_names_test.go @@ -33,13 +33,13 @@ func Test_NameToUri_FullName(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetBrowserMode(true) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/NamesObject"), "Not Found") - gtest.Assert(client.GetContent("/NamesObject/ShowName"), "Object Show Name") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/NamesObject"), "Not Found") + t.Assert(client.GetContent("/NamesObject/ShowName"), "Object Show Name") }) } @@ -54,13 +54,13 @@ func Test_NameToUri_AllLower(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetBrowserMode(true) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/NamesObject"), "Not Found") - gtest.Assert(client.GetContent("/namesobject/showname"), "Object Show Name") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/NamesObject"), "Not Found") + t.Assert(client.GetContent("/namesobject/showname"), "Object Show Name") }) } @@ -75,13 +75,13 @@ func Test_NameToUri_Camel(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetBrowserMode(true) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/NamesObject"), "Not Found") - gtest.Assert(client.GetContent("/namesObject/showName"), "Object Show Name") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/NamesObject"), "Not Found") + t.Assert(client.GetContent("/namesObject/showName"), "Object Show Name") }) } @@ -96,12 +96,12 @@ func Test_NameToUri_Default(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetBrowserMode(true) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/NamesObject"), "Not Found") - gtest.Assert(client.GetContent("/names-object/show-name"), "Object Show Name") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/NamesObject"), "Not Found") + t.Assert(client.GetContent("/names-object/show-name"), "Object Show Name") }) } diff --git a/net/ghttp/ghttp_unit_router_object_rest1_test.go b/net/ghttp/ghttp_unit_router_object_rest1_test.go index 015687605..506e41021 100644 --- a/net/ghttp/ghttp_unit_router_object_rest1_test.go +++ b/net/ghttp/ghttp_unit_router_object_rest1_test.go @@ -65,36 +65,36 @@ func Test_Router_ObjectRest(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "1Object Get2") - gtest.Assert(client.PutContent("/"), "1Object Put2") - gtest.Assert(client.PostContent("/"), "1Object Post2") - gtest.Assert(client.DeleteContent("/"), "1Object Delete2") - gtest.Assert(client.PatchContent("/"), "1Object Patch2") - gtest.Assert(client.OptionsContent("/"), "1Object Options2") + t.Assert(client.GetContent("/"), "1Object Get2") + t.Assert(client.PutContent("/"), "1Object Put2") + t.Assert(client.PostContent("/"), "1Object Post2") + t.Assert(client.DeleteContent("/"), "1Object Delete2") + t.Assert(client.PatchContent("/"), "1Object Patch2") + t.Assert(client.OptionsContent("/"), "1Object Options2") resp1, err := client.Head("/") if err == nil { defer resp1.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp1.Header.Get("head-ok"), "1") + t.Assert(err, nil) + t.Assert(resp1.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/object-rest/get"), "1Object Get2") - gtest.Assert(client.PutContent("/object-rest/put"), "1Object Put2") - gtest.Assert(client.PostContent("/object-rest/post"), "1Object Post2") - gtest.Assert(client.DeleteContent("/object-rest/delete"), "1Object Delete2") - gtest.Assert(client.PatchContent("/object-rest/patch"), "1Object Patch2") - gtest.Assert(client.OptionsContent("/object-rest/options"), "1Object Options2") + t.Assert(client.GetContent("/object-rest/get"), "1Object Get2") + t.Assert(client.PutContent("/object-rest/put"), "1Object Put2") + t.Assert(client.PostContent("/object-rest/post"), "1Object Post2") + t.Assert(client.DeleteContent("/object-rest/delete"), "1Object Delete2") + t.Assert(client.PatchContent("/object-rest/patch"), "1Object Patch2") + t.Assert(client.OptionsContent("/object-rest/options"), "1Object Options2") resp2, err := client.Head("/object-rest/head") if err == nil { defer resp2.Close() } - gtest.Assert(err, nil) - gtest.Assert(resp2.Header.Get("head-ok"), "1") + t.Assert(err, nil) + t.Assert(resp2.Header.Get("head-ok"), "1") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_router_object_rest2_test.go b/net/ghttp/ghttp_unit_router_object_rest2_test.go index 4db262d22..08f6b4861 100644 --- a/net/ghttp/ghttp_unit_router_object_rest2_test.go +++ b/net/ghttp/ghttp_unit_router_object_rest2_test.go @@ -52,13 +52,13 @@ func Test_Router_ObjectRest_Id(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/object/99"), "1Object Get992") - gtest.Assert(client.PutContent("/object/99"), "1Object Put992") - gtest.Assert(client.PostContent("/object/99"), "1Object Post992") - gtest.Assert(client.DeleteContent("/object/99"), "1Object Delete992") + t.Assert(client.GetContent("/object/99"), "1Object Get992") + t.Assert(client.PutContent("/object/99"), "1Object Put992") + t.Assert(client.PostContent("/object/99"), "1Object Post992") + t.Assert(client.DeleteContent("/object/99"), "1Object Delete992") }) } diff --git a/net/ghttp/ghttp_unit_router_object_test.go b/net/ghttp/ghttp_unit_router_object_test.go index fac436fa1..ef18e7934 100644 --- a/net/ghttp/ghttp_unit_router_object_test.go +++ b/net/ghttp/ghttp_unit_router_object_test.go @@ -49,23 +49,23 @@ func Test_Router_Object1(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "1Object Index2") - gtest.Assert(client.GetContent("/init"), "Not Found") - gtest.Assert(client.GetContent("/shut"), "Not Found") - gtest.Assert(client.GetContent("/index"), "1Object Index2") - gtest.Assert(client.GetContent("/show"), "1Object Show2") + t.Assert(client.GetContent("/"), "1Object Index2") + t.Assert(client.GetContent("/init"), "Not Found") + t.Assert(client.GetContent("/shut"), "Not Found") + t.Assert(client.GetContent("/index"), "1Object Index2") + t.Assert(client.GetContent("/show"), "1Object Show2") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "1Object Index2") - gtest.Assert(client.GetContent("/object/show"), "1Object Show2") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "1Object Index2") + t.Assert(client.GetContent("/object/show"), "1Object Show2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } @@ -79,19 +79,19 @@ func Test_Router_Object2(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "Not Found") - gtest.Assert(client.GetContent("/object/show"), "1Object Show2") - gtest.Assert(client.GetContent("/object/info"), "1Object Info2") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "Not Found") + t.Assert(client.GetContent("/object/show"), "1Object Show2") + t.Assert(client.GetContent("/object/info"), "1Object Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } @@ -105,19 +105,19 @@ func Test_Router_ObjectMethod(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Not Found") - gtest.Assert(client.GetContent("/object"), "Not Found") - gtest.Assert(client.GetContent("/object/init"), "Not Found") - gtest.Assert(client.GetContent("/object/shut"), "Not Found") - gtest.Assert(client.GetContent("/object/index"), "Not Found") - gtest.Assert(client.GetContent("/object/show"), "Not Found") - gtest.Assert(client.GetContent("/object/info"), "Not Found") - gtest.Assert(client.GetContent("/object-info"), "1Object Info2") + t.Assert(client.GetContent("/"), "Not Found") + t.Assert(client.GetContent("/object"), "Not Found") + t.Assert(client.GetContent("/object/init"), "Not Found") + t.Assert(client.GetContent("/object/shut"), "Not Found") + t.Assert(client.GetContent("/object/index"), "Not Found") + t.Assert(client.GetContent("/object/show"), "Not Found") + t.Assert(client.GetContent("/object/info"), "Not Found") + t.Assert(client.GetContent("/object-info"), "1Object Info2") - gtest.Assert(client.GetContent("/none-exist"), "Not Found") + t.Assert(client.GetContent("/none-exist"), "Not Found") }) } diff --git a/net/ghttp/ghttp_unit_session_test.go b/net/ghttp/ghttp_unit_session_test.go index ae68e93ec..894d1f59e 100644 --- a/net/ghttp/ghttp_unit_session_test.go +++ b/net/ghttp/ghttp_unit_session_test.go @@ -37,7 +37,7 @@ func Test_Session_Cookie(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetBrowserMode(true) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) @@ -45,21 +45,21 @@ func Test_Session_Cookie(t *testing.T) { if r1 != nil { defer r1.Close() } - gtest.Assert(e1, nil) - gtest.Assert(r1.ReadAllString(), "") + t.Assert(e1, nil) + t.Assert(r1.ReadAllString(), "") - gtest.Assert(client.GetContent("/set?k=key2&v=200"), "") + t.Assert(client.GetContent("/set?k=key2&v=200"), "") - gtest.Assert(client.GetContent("/get?k=key1"), "100") - gtest.Assert(client.GetContent("/get?k=key2"), "200") - gtest.Assert(client.GetContent("/get?k=key3"), "") - gtest.Assert(client.GetContent("/remove?k=key1"), "") - gtest.Assert(client.GetContent("/remove?k=key3"), "") - gtest.Assert(client.GetContent("/remove?k=key4"), "") - gtest.Assert(client.GetContent("/get?k=key1"), "") - gtest.Assert(client.GetContent("/get?k=key2"), "200") - gtest.Assert(client.GetContent("/clear"), "") - gtest.Assert(client.GetContent("/get?k=key2"), "") + t.Assert(client.GetContent("/get?k=key1"), "100") + t.Assert(client.GetContent("/get?k=key2"), "200") + t.Assert(client.GetContent("/get?k=key3"), "") + t.Assert(client.GetContent("/remove?k=key1"), "") + t.Assert(client.GetContent("/remove?k=key3"), "") + t.Assert(client.GetContent("/remove?k=key4"), "") + t.Assert(client.GetContent("/get?k=key1"), "") + t.Assert(client.GetContent("/get?k=key2"), "200") + t.Assert(client.GetContent("/clear"), "") + t.Assert(client.GetContent("/get?k=key2"), "") }) } @@ -84,7 +84,7 @@ func Test_Session_Header(t *testing.T) { defer s.Shutdown() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) response, e1 := client.Get("/set?k=key1&v=100") @@ -92,24 +92,24 @@ func Test_Session_Header(t *testing.T) { defer response.Close() } sessionId := response.GetCookie(s.GetSessionIdName()) - gtest.Assert(e1, nil) - gtest.AssertNE(sessionId, nil) - gtest.Assert(response.ReadAllString(), "") + t.Assert(e1, nil) + t.AssertNE(sessionId, nil) + t.Assert(response.ReadAllString(), "") client.SetHeader(s.GetSessionIdName(), sessionId) - gtest.Assert(client.GetContent("/set?k=key2&v=200"), "") + t.Assert(client.GetContent("/set?k=key2&v=200"), "") - gtest.Assert(client.GetContent("/get?k=key1"), "100") - gtest.Assert(client.GetContent("/get?k=key2"), "200") - gtest.Assert(client.GetContent("/get?k=key3"), "") - gtest.Assert(client.GetContent("/remove?k=key1"), "") - gtest.Assert(client.GetContent("/remove?k=key3"), "") - gtest.Assert(client.GetContent("/remove?k=key4"), "") - gtest.Assert(client.GetContent("/get?k=key1"), "") - gtest.Assert(client.GetContent("/get?k=key2"), "200") - gtest.Assert(client.GetContent("/clear"), "") - gtest.Assert(client.GetContent("/get?k=key2"), "") + t.Assert(client.GetContent("/get?k=key1"), "100") + t.Assert(client.GetContent("/get?k=key2"), "200") + t.Assert(client.GetContent("/get?k=key3"), "") + t.Assert(client.GetContent("/remove?k=key1"), "") + t.Assert(client.GetContent("/remove?k=key3"), "") + t.Assert(client.GetContent("/remove?k=key4"), "") + t.Assert(client.GetContent("/get?k=key1"), "") + t.Assert(client.GetContent("/get?k=key2"), "200") + t.Assert(client.GetContent("/clear"), "") + t.Assert(client.GetContent("/get?k=key2"), "") }) } @@ -131,7 +131,7 @@ func Test_Session_StorageFile(t *testing.T) { time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) response, e1 := client.Get("/set?k=key&v=100") @@ -139,16 +139,16 @@ func Test_Session_StorageFile(t *testing.T) { defer response.Close() } sessionId = response.GetCookie(s.GetSessionIdName()) - gtest.Assert(e1, nil) - gtest.AssertNE(sessionId, nil) - gtest.Assert(response.ReadAllString(), "key=100") + t.Assert(e1, nil) + t.AssertNE(sessionId, nil) + t.Assert(response.ReadAllString(), "key=100") }) time.Sleep(time.Second) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) client.SetHeader(s.GetSessionIdName(), sessionId) - gtest.Assert(client.GetContent("/get?k=key"), "100") - gtest.Assert(client.GetContent("/get?k=key1"), "") + t.Assert(client.GetContent("/get?k=key"), "100") + t.Assert(client.GetContent("/get?k=key1"), "") }) } diff --git a/net/ghttp/ghttp_unit_static_test.go b/net/ghttp/ghttp_unit_static_test.go index 361c82959..8cafbf169 100644 --- a/net/ghttp/ghttp_unit_static_test.go +++ b/net/ghttp/ghttp_unit_static_test.go @@ -24,7 +24,7 @@ import ( func Test_Static_ServerRoot(t *testing.T) { // SetServerRoot with absolute path - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := ports.PopRand() s := g.Server(p) path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.TempDir(), p) @@ -38,12 +38,12 @@ func Test_Static_ServerRoot(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "index") - gtest.Assert(client.GetContent("/index.htm"), "index") + t.Assert(client.GetContent("/"), "index") + t.Assert(client.GetContent("/index.htm"), "index") }) // SetServerRoot with relative path - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := ports.PopRand() s := g.Server(p) path := fmt.Sprintf(`static/test/%d`, p) @@ -57,13 +57,13 @@ func Test_Static_ServerRoot(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "index") - gtest.Assert(client.GetContent("/index.htm"), "index") + t.Assert(client.GetContent("/"), "index") + t.Assert(client.GetContent("/index.htm"), "index") }) } func Test_Static_ServerRoot_Security(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := ports.PopRand() s := g.Server(p) s.SetServerRoot(gfile.Join(gdebug.TestDataPath(), "static1")) @@ -74,17 +74,17 @@ func Test_Static_ServerRoot_Security(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "index") - gtest.Assert(client.GetContent("/index.htm"), "Not Found") - gtest.Assert(client.GetContent("/index.html"), "index") - gtest.Assert(client.GetContent("/test.html"), "test") - gtest.Assert(client.GetContent("/../main.html"), "Not Found") - gtest.Assert(client.GetContent("/..%2Fmain.html"), "Not Found") + t.Assert(client.GetContent("/"), "index") + t.Assert(client.GetContent("/index.htm"), "Not Found") + t.Assert(client.GetContent("/index.html"), "index") + t.Assert(client.GetContent("/test.html"), "test") + t.Assert(client.GetContent("/../main.html"), "Not Found") + t.Assert(client.GetContent("/..%2Fmain.html"), "Not Found") }) } func Test_Static_Folder_Forbidden(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := ports.PopRand() s := g.Server(p) path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.TempDir(), p) @@ -98,14 +98,14 @@ func Test_Static_Folder_Forbidden(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.Assert(client.GetContent("/"), "Forbidden") - gtest.Assert(client.GetContent("/index.html"), "Not Found") - gtest.Assert(client.GetContent("/test.html"), "test") + t.Assert(client.GetContent("/"), "Forbidden") + t.Assert(client.GetContent("/index.html"), "Not Found") + t.Assert(client.GetContent("/test.html"), "test") }) } func Test_Static_IndexFolder(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p := ports.PopRand() s := g.Server(p) path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.TempDir(), p) @@ -120,15 +120,15 @@ func Test_Static_IndexFolder(t *testing.T) { client := ghttp.NewClient() client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) - gtest.AssertNE(client.GetContent("/"), "Forbidden") - gtest.AssertNE(gstr.Pos(client.GetContent("/"), ` %d`, i)) + t.Assert(err, nil) + t.Assert(string(result), fmt.Sprintf(`> %d`, i)) conn.Close() } }) // gudp.Send - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { err := gudp.Send(fmt.Sprintf("127.0.0.1:%d", p), []byte(gconv.String(i))) - gtest.Assert(err, nil) + t.Assert(err, nil) } }) // gudp.SendRecv - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte(gconv.String(i)), -1) - gtest.Assert(err, nil) - gtest.Assert(string(result), fmt.Sprintf(`> %d`, i)) + t.Assert(err, nil) + t.Assert(string(result), fmt.Sprintf(`> %d`, i)) } }) } @@ -93,14 +93,14 @@ func Test_Buffer(t *testing.T) { go s.Run() defer s.Close() time.Sleep(100 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte("123"), -1) - gtest.Assert(err, nil) - gtest.Assert(string(result), "1") + t.Assert(err, nil) + t.Assert(string(result), "1") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte("456"), -1) - gtest.Assert(err, nil) - gtest.Assert(string(result), "4") + t.Assert(err, nil) + t.Assert(string(result), "4") }) } diff --git a/os/gcache/gcache_z_unit_1_test.go b/os/gcache/gcache_z_unit_1_test.go index c2f446b35..64267bb72 100644 --- a/os/gcache/gcache_z_unit_1_test.go +++ b/os/gcache/gcache_z_unit_1_test.go @@ -26,183 +26,183 @@ func clear() { } func TestCache_Set(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.Set(1, 11, 0) - gtest.Assert(cache.Get(1), 11) - gtest.Assert(cache.Contains(1), true) + t.Assert(cache.Get(1), 11) + t.Assert(cache.Contains(1), true) clear() gcache.Set(1, 11, 0) - gtest.Assert(gcache.Get(1), 11) - gtest.Assert(gcache.Contains(1), true) + t.Assert(gcache.Get(1), 11) + t.Assert(gcache.Contains(1), true) }) } func TestCache_Set_Expire(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.Set(2, 22, 100*time.Millisecond) - gtest.Assert(cache.Get(2), 22) + t.Assert(cache.Get(2), 22) time.Sleep(200 * time.Millisecond) - gtest.Assert(cache.Get(2), nil) + t.Assert(cache.Get(2), nil) time.Sleep(3 * time.Second) - gtest.Assert(cache.Size(), 0) + t.Assert(cache.Size(), 0) cache.Close() }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.Set(1, 11, 100*time.Millisecond) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) time.Sleep(200 * time.Millisecond) - gtest.Assert(cache.Get(1), nil) + t.Assert(cache.Get(1), nil) }) } func TestCache_Keys_Values(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() for i := 0; i < 10; i++ { cache.Set(i, i*10, 0) } - gtest.Assert(len(cache.Keys()), 10) - gtest.Assert(len(cache.Values()), 10) - gtest.AssertIN(0, cache.Keys()) - gtest.AssertIN(90, cache.Values()) + t.Assert(len(cache.Keys()), 10) + t.Assert(len(cache.Values()), 10) + t.AssertIN(0, cache.Keys()) + t.AssertIN(90, cache.Values()) }) } func TestCache_LRU(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New(2) for i := 0; i < 10; i++ { cache.Set(i, i, 0) } - gtest.Assert(cache.Size(), 10) - gtest.Assert(cache.Get(6), 6) + t.Assert(cache.Size(), 10) + t.Assert(cache.Get(6), 6) time.Sleep(4 * time.Second) - gtest.Assert(cache.Size(), 2) - gtest.Assert(cache.Get(6), 6) - gtest.Assert(cache.Get(1), nil) + t.Assert(cache.Size(), 2) + t.Assert(cache.Get(6), 6) + t.Assert(cache.Get(1), nil) cache.Close() }) } func TestCache_LRU_expire(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New(2) cache.Set(1, nil, 1000) - gtest.Assert(cache.Size(), 1) - gtest.Assert(cache.Get(1), nil) + t.Assert(cache.Size(), 1) + t.Assert(cache.Get(1), nil) }) } func TestCache_SetIfNotExist(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.SetIfNotExist(1, 11, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) cache.SetIfNotExist(1, 22, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) cache.SetIfNotExist(2, 22, 0) - gtest.Assert(cache.Get(2), 22) + t.Assert(cache.Get(2), 22) clear() gcache.SetIfNotExist(1, 11, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) gcache.SetIfNotExist(1, 22, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) }) } func TestCache_Sets(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.Sets(g.MapAnyAny{1: 11, 2: 22}, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) clear() gcache.Sets(g.MapAnyAny{1: 11, 2: 22}, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) }) } func TestCache_GetOrSet(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.GetOrSet(1, 11, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) cache.GetOrSet(1, 111, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) clear() gcache.GetOrSet(1, 11, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) gcache.GetOrSet(1, 111, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) }) } func TestCache_GetOrSetFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.GetOrSetFunc(1, func() interface{} { return 11 }, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) cache.GetOrSetFunc(1, func() interface{} { return 111 }, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) clear() gcache.GetOrSetFunc(1, func() interface{} { return 11 }, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) gcache.GetOrSetFunc(1, func() interface{} { return 111 }, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) }) } func TestCache_GetOrSetFuncLock(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.GetOrSetFuncLock(1, func() interface{} { return 11 }, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) cache.GetOrSetFuncLock(1, func() interface{} { return 111 }, 0) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Get(1), 11) clear() gcache.GetOrSetFuncLock(1, func() interface{} { return 11 }, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) gcache.GetOrSetFuncLock(1, func() interface{} { return 111 }, 0) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Get(1), 11) }) } func TestCache_Clear(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() cache.Sets(g.MapAnyAny{1: 11, 2: 22}, 0) cache.Clear() - gtest.Assert(cache.Size(), 0) + t.Assert(cache.Size(), 0) }) } func TestCache_SetConcurrency(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cache := gcache.New() pool := grpool.New(4) go func() { @@ -232,51 +232,51 @@ func TestCache_SetConcurrency(t *testing.T) { } func TestCache_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { { cache := gcache.New() cache.Sets(g.MapAnyAny{1: 11, 2: 22}, 0) - gtest.Assert(cache.Contains(1), true) - gtest.Assert(cache.Get(1), 11) + t.Assert(cache.Contains(1), true) + t.Assert(cache.Get(1), 11) data := cache.Data() - gtest.Assert(data[1], 11) - gtest.Assert(data[2], 22) - gtest.Assert(data[3], nil) - gtest.Assert(cache.Size(), 2) + t.Assert(data[1], 11) + t.Assert(data[2], 22) + t.Assert(data[3], nil) + t.Assert(cache.Size(), 2) keys := cache.Keys() - gtest.Assert(gset.NewFrom(g.Slice{1, 2}).Equal(gset.NewFrom(keys)), true) + t.Assert(gset.NewFrom(g.Slice{1, 2}).Equal(gset.NewFrom(keys)), true) keyStrs := cache.KeyStrings() - gtest.Assert(gset.NewFrom(g.Slice{"1", "2"}).Equal(gset.NewFrom(keyStrs)), true) + t.Assert(gset.NewFrom(g.Slice{"1", "2"}).Equal(gset.NewFrom(keyStrs)), true) values := cache.Values() - gtest.Assert(gset.NewFrom(g.Slice{11, 22}).Equal(gset.NewFrom(values)), true) + t.Assert(gset.NewFrom(g.Slice{11, 22}).Equal(gset.NewFrom(values)), true) removeData1 := cache.Remove(1) - gtest.Assert(removeData1, 11) - gtest.Assert(cache.Size(), 1) + t.Assert(removeData1, 11) + t.Assert(cache.Size(), 1) cache.Removes(g.Slice{2}) - gtest.Assert(cache.Size(), 0) + t.Assert(cache.Size(), 0) } clear() { gcache.Sets(g.MapAnyAny{1: 11, 2: 22}, 0) - gtest.Assert(gcache.Contains(1), true) - gtest.Assert(gcache.Get(1), 11) + t.Assert(gcache.Contains(1), true) + t.Assert(gcache.Get(1), 11) data := gcache.Data() - gtest.Assert(data[1], 11) - gtest.Assert(data[2], 22) - gtest.Assert(data[3], nil) - gtest.Assert(gcache.Size(), 2) + t.Assert(data[1], 11) + t.Assert(data[2], 22) + t.Assert(data[3], nil) + t.Assert(gcache.Size(), 2) keys := gcache.Keys() - gtest.Assert(gset.NewFrom(g.Slice{1, 2}).Equal(gset.NewFrom(keys)), true) + t.Assert(gset.NewFrom(g.Slice{1, 2}).Equal(gset.NewFrom(keys)), true) keyStrs := gcache.KeyStrings() - gtest.Assert(gset.NewFrom(g.Slice{"1", "2"}).Equal(gset.NewFrom(keyStrs)), true) + t.Assert(gset.NewFrom(g.Slice{"1", "2"}).Equal(gset.NewFrom(keyStrs)), true) values := gcache.Values() - gtest.Assert(gset.NewFrom(g.Slice{11, 22}).Equal(gset.NewFrom(values)), true) + t.Assert(gset.NewFrom(g.Slice{11, 22}).Equal(gset.NewFrom(values)), true) removeData1 := gcache.Remove(1) - gtest.Assert(removeData1, 11) - gtest.Assert(gcache.Size(), 1) + t.Assert(removeData1, 11) + t.Assert(gcache.Size(), 1) gcache.Removes(g.Slice{2}) - gtest.Assert(gcache.Size(), 0) + t.Assert(gcache.Size(), 0) } }) } diff --git a/os/gcfg/gcfg_z_unit_test.go b/os/gcfg/gcfg_z_unit_test.go index e9b16a645..bd2fc94e5 100644 --- a/os/gcfg/gcfg_z_unit_test.go +++ b/os/gcfg/gcfg_z_unit_test.go @@ -36,68 +36,68 @@ array = [1,2,3] disk = "127.0.0.1:6379,0" cache = "127.0.0.1:6379,1" ` - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gcfg.DEFAULT_CONFIG_FILE err := gfile.PutContents(path, config) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) c := gcfg.New() - gtest.Assert(c.Get("v1"), 1) - gtest.AssertEQ(c.GetInt("v1"), 1) - gtest.AssertEQ(c.GetInt8("v1"), int8(1)) - gtest.AssertEQ(c.GetInt16("v1"), int16(1)) - gtest.AssertEQ(c.GetInt32("v1"), int32(1)) - gtest.AssertEQ(c.GetInt64("v1"), int64(1)) - gtest.AssertEQ(c.GetUint("v1"), uint(1)) - gtest.AssertEQ(c.GetUint8("v1"), uint8(1)) - gtest.AssertEQ(c.GetUint16("v1"), uint16(1)) - gtest.AssertEQ(c.GetUint32("v1"), uint32(1)) - gtest.AssertEQ(c.GetUint64("v1"), uint64(1)) + t.Assert(c.Get("v1"), 1) + t.AssertEQ(c.GetInt("v1"), 1) + t.AssertEQ(c.GetInt8("v1"), int8(1)) + t.AssertEQ(c.GetInt16("v1"), int16(1)) + t.AssertEQ(c.GetInt32("v1"), int32(1)) + t.AssertEQ(c.GetInt64("v1"), int64(1)) + t.AssertEQ(c.GetUint("v1"), uint(1)) + t.AssertEQ(c.GetUint8("v1"), uint8(1)) + t.AssertEQ(c.GetUint16("v1"), uint16(1)) + t.AssertEQ(c.GetUint32("v1"), uint32(1)) + t.AssertEQ(c.GetUint64("v1"), uint64(1)) - gtest.AssertEQ(c.GetVar("v1").String(), "1") - gtest.AssertEQ(c.GetVar("v1").Bool(), true) - gtest.AssertEQ(c.GetVar("v2").String(), "true") - gtest.AssertEQ(c.GetVar("v2").Bool(), true) + t.AssertEQ(c.GetVar("v1").String(), "1") + t.AssertEQ(c.GetVar("v1").Bool(), true) + t.AssertEQ(c.GetVar("v2").String(), "true") + t.AssertEQ(c.GetVar("v2").Bool(), true) - gtest.AssertEQ(c.GetString("v1"), "1") - gtest.AssertEQ(c.GetFloat32("v4"), float32(1.23)) - gtest.AssertEQ(c.GetFloat64("v4"), float64(1.23)) - gtest.AssertEQ(c.GetString("v2"), "true") - gtest.AssertEQ(c.GetBool("v2"), true) - gtest.AssertEQ(c.GetBool("v3"), false) + t.AssertEQ(c.GetString("v1"), "1") + t.AssertEQ(c.GetFloat32("v4"), float32(1.23)) + t.AssertEQ(c.GetFloat64("v4"), float64(1.23)) + t.AssertEQ(c.GetString("v2"), "true") + t.AssertEQ(c.GetBool("v2"), true) + t.AssertEQ(c.GetBool("v3"), false) - gtest.AssertEQ(c.Contains("v1"), true) - gtest.AssertEQ(c.Contains("v2"), true) - gtest.AssertEQ(c.Contains("v3"), true) - gtest.AssertEQ(c.Contains("v4"), true) - gtest.AssertEQ(c.Contains("v5"), false) + t.AssertEQ(c.Contains("v1"), true) + t.AssertEQ(c.Contains("v2"), true) + t.AssertEQ(c.Contains("v3"), true) + t.AssertEQ(c.Contains("v4"), true) + t.AssertEQ(c.Contains("v5"), false) - gtest.AssertEQ(c.GetInts("array"), []int{1, 2, 3}) - gtest.AssertEQ(c.GetStrings("array"), []string{"1", "2", "3"}) - gtest.AssertEQ(c.GetArray("array"), []interface{}{1, 2, 3}) - gtest.AssertEQ(c.GetInterfaces("array"), []interface{}{1, 2, 3}) - gtest.AssertEQ(c.GetMap("redis"), map[string]interface{}{ + t.AssertEQ(c.GetInts("array"), []int{1, 2, 3}) + t.AssertEQ(c.GetStrings("array"), []string{"1", "2", "3"}) + t.AssertEQ(c.GetArray("array"), []interface{}{1, 2, 3}) + t.AssertEQ(c.GetInterfaces("array"), []interface{}{1, 2, 3}) + t.AssertEQ(c.GetMap("redis"), map[string]interface{}{ "disk": "127.0.0.1:6379,0", "cache": "127.0.0.1:6379,1", }) - gtest.AssertEQ(c.FilePath(), gfile.Pwd()+gfile.Separator+path) + t.AssertEQ(c.FilePath(), gfile.Pwd()+gfile.Separator+path) }) } func Test_Basic2(t *testing.T) { config := `log-path = "logs"` - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gcfg.DEFAULT_CONFIG_FILE err := gfile.PutContents(path, config) - gtest.Assert(err, nil) + t.Assert(err, nil) defer func() { _ = gfile.Remove(path) }() c := gcfg.New() - gtest.Assert(c.Get("log-path"), "logs") + t.Assert(c.Get("log-path"), "logs") }) } @@ -115,43 +115,43 @@ array = [1,2,3] gcfg.SetContent(content) defer gcfg.ClearContent() - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { c := gcfg.New() - gtest.Assert(c.Get("v1"), 1) - gtest.AssertEQ(c.GetInt("v1"), 1) - gtest.AssertEQ(c.GetInt8("v1"), int8(1)) - gtest.AssertEQ(c.GetInt16("v1"), int16(1)) - gtest.AssertEQ(c.GetInt32("v1"), int32(1)) - gtest.AssertEQ(c.GetInt64("v1"), int64(1)) - gtest.AssertEQ(c.GetUint("v1"), uint(1)) - gtest.AssertEQ(c.GetUint8("v1"), uint8(1)) - gtest.AssertEQ(c.GetUint16("v1"), uint16(1)) - gtest.AssertEQ(c.GetUint32("v1"), uint32(1)) - gtest.AssertEQ(c.GetUint64("v1"), uint64(1)) + t.Assert(c.Get("v1"), 1) + t.AssertEQ(c.GetInt("v1"), 1) + t.AssertEQ(c.GetInt8("v1"), int8(1)) + t.AssertEQ(c.GetInt16("v1"), int16(1)) + t.AssertEQ(c.GetInt32("v1"), int32(1)) + t.AssertEQ(c.GetInt64("v1"), int64(1)) + t.AssertEQ(c.GetUint("v1"), uint(1)) + t.AssertEQ(c.GetUint8("v1"), uint8(1)) + t.AssertEQ(c.GetUint16("v1"), uint16(1)) + t.AssertEQ(c.GetUint32("v1"), uint32(1)) + t.AssertEQ(c.GetUint64("v1"), uint64(1)) - gtest.AssertEQ(c.GetVar("v1").String(), "1") - gtest.AssertEQ(c.GetVar("v1").Bool(), true) - gtest.AssertEQ(c.GetVar("v2").String(), "true") - gtest.AssertEQ(c.GetVar("v2").Bool(), true) + t.AssertEQ(c.GetVar("v1").String(), "1") + t.AssertEQ(c.GetVar("v1").Bool(), true) + t.AssertEQ(c.GetVar("v2").String(), "true") + t.AssertEQ(c.GetVar("v2").Bool(), true) - gtest.AssertEQ(c.GetString("v1"), "1") - gtest.AssertEQ(c.GetFloat32("v4"), float32(1.23)) - gtest.AssertEQ(c.GetFloat64("v4"), float64(1.23)) - gtest.AssertEQ(c.GetString("v2"), "true") - gtest.AssertEQ(c.GetBool("v2"), true) - gtest.AssertEQ(c.GetBool("v3"), false) + t.AssertEQ(c.GetString("v1"), "1") + t.AssertEQ(c.GetFloat32("v4"), float32(1.23)) + t.AssertEQ(c.GetFloat64("v4"), float64(1.23)) + t.AssertEQ(c.GetString("v2"), "true") + t.AssertEQ(c.GetBool("v2"), true) + t.AssertEQ(c.GetBool("v3"), false) - gtest.AssertEQ(c.Contains("v1"), true) - gtest.AssertEQ(c.Contains("v2"), true) - gtest.AssertEQ(c.Contains("v3"), true) - gtest.AssertEQ(c.Contains("v4"), true) - gtest.AssertEQ(c.Contains("v5"), false) + t.AssertEQ(c.Contains("v1"), true) + t.AssertEQ(c.Contains("v2"), true) + t.AssertEQ(c.Contains("v3"), true) + t.AssertEQ(c.Contains("v4"), true) + t.AssertEQ(c.Contains("v5"), false) - gtest.AssertEQ(c.GetInts("array"), []int{1, 2, 3}) - gtest.AssertEQ(c.GetStrings("array"), []string{"1", "2", "3"}) - gtest.AssertEQ(c.GetArray("array"), []interface{}{1, 2, 3}) - gtest.AssertEQ(c.GetInterfaces("array"), []interface{}{1, 2, 3}) - gtest.AssertEQ(c.GetMap("redis"), map[string]interface{}{ + t.AssertEQ(c.GetInts("array"), []int{1, 2, 3}) + t.AssertEQ(c.GetStrings("array"), []string{"1", "2", "3"}) + t.AssertEQ(c.GetArray("array"), []interface{}{1, 2, 3}) + t.AssertEQ(c.GetInterfaces("array"), []interface{}{1, 2, 3}) + t.AssertEQ(c.GetMap("redis"), map[string]interface{}{ "disk": "127.0.0.1:6379,0", "cache": "127.0.0.1:6379,1", }) @@ -176,55 +176,55 @@ func Test_SetFileName(t *testing.T) { "v4": "1.234" } ` - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "config.json" err := gfile.PutContents(path, config) - gtest.Assert(err, nil) + t.Assert(err, nil) defer func() { _ = gfile.Remove(path) }() c := gcfg.New() c.SetFileName(path) - gtest.Assert(c.Get("v1"), 1) - gtest.AssertEQ(c.GetInt("v1"), 1) - gtest.AssertEQ(c.GetInt8("v1"), int8(1)) - gtest.AssertEQ(c.GetInt16("v1"), int16(1)) - gtest.AssertEQ(c.GetInt32("v1"), int32(1)) - gtest.AssertEQ(c.GetInt64("v1"), int64(1)) - gtest.AssertEQ(c.GetUint("v1"), uint(1)) - gtest.AssertEQ(c.GetUint8("v1"), uint8(1)) - gtest.AssertEQ(c.GetUint16("v1"), uint16(1)) - gtest.AssertEQ(c.GetUint32("v1"), uint32(1)) - gtest.AssertEQ(c.GetUint64("v1"), uint64(1)) + t.Assert(c.Get("v1"), 1) + t.AssertEQ(c.GetInt("v1"), 1) + t.AssertEQ(c.GetInt8("v1"), int8(1)) + t.AssertEQ(c.GetInt16("v1"), int16(1)) + t.AssertEQ(c.GetInt32("v1"), int32(1)) + t.AssertEQ(c.GetInt64("v1"), int64(1)) + t.AssertEQ(c.GetUint("v1"), uint(1)) + t.AssertEQ(c.GetUint8("v1"), uint8(1)) + t.AssertEQ(c.GetUint16("v1"), uint16(1)) + t.AssertEQ(c.GetUint32("v1"), uint32(1)) + t.AssertEQ(c.GetUint64("v1"), uint64(1)) - gtest.AssertEQ(c.GetVar("v1").String(), "1") - gtest.AssertEQ(c.GetVar("v1").Bool(), true) - gtest.AssertEQ(c.GetVar("v2").String(), "true") - gtest.AssertEQ(c.GetVar("v2").Bool(), true) + t.AssertEQ(c.GetVar("v1").String(), "1") + t.AssertEQ(c.GetVar("v1").Bool(), true) + t.AssertEQ(c.GetVar("v2").String(), "true") + t.AssertEQ(c.GetVar("v2").Bool(), true) - gtest.AssertEQ(c.GetString("v1"), "1") - gtest.AssertEQ(c.GetFloat32("v4"), float32(1.234)) - gtest.AssertEQ(c.GetFloat64("v4"), float64(1.234)) - gtest.AssertEQ(c.GetString("v2"), "true") - gtest.AssertEQ(c.GetBool("v2"), true) - gtest.AssertEQ(c.GetBool("v3"), false) + t.AssertEQ(c.GetString("v1"), "1") + t.AssertEQ(c.GetFloat32("v4"), float32(1.234)) + t.AssertEQ(c.GetFloat64("v4"), float64(1.234)) + t.AssertEQ(c.GetString("v2"), "true") + t.AssertEQ(c.GetBool("v2"), true) + t.AssertEQ(c.GetBool("v3"), false) - gtest.AssertEQ(c.Contains("v1"), true) - gtest.AssertEQ(c.Contains("v2"), true) - gtest.AssertEQ(c.Contains("v3"), true) - gtest.AssertEQ(c.Contains("v4"), true) - gtest.AssertEQ(c.Contains("v5"), false) + t.AssertEQ(c.Contains("v1"), true) + t.AssertEQ(c.Contains("v2"), true) + t.AssertEQ(c.Contains("v3"), true) + t.AssertEQ(c.Contains("v4"), true) + t.AssertEQ(c.Contains("v5"), false) - gtest.AssertEQ(c.GetInts("array"), []int{1, 2, 3}) - gtest.AssertEQ(c.GetStrings("array"), []string{"1", "2", "3"}) - gtest.AssertEQ(c.GetArray("array"), []interface{}{1, 2, 3}) - gtest.AssertEQ(c.GetInterfaces("array"), []interface{}{1, 2, 3}) - gtest.AssertEQ(c.GetMap("redis"), map[string]interface{}{ + t.AssertEQ(c.GetInts("array"), []int{1, 2, 3}) + t.AssertEQ(c.GetStrings("array"), []string{"1", "2", "3"}) + t.AssertEQ(c.GetArray("array"), []interface{}{1, 2, 3}) + t.AssertEQ(c.GetInterfaces("array"), []interface{}{1, 2, 3}) + t.AssertEQ(c.GetMap("redis"), map[string]interface{}{ "disk": "127.0.0.1:6379,0", "cache": "127.0.0.1:6379,1", }) - gtest.AssertEQ(c.FilePath(), gfile.Pwd()+gfile.Separator+path) + t.AssertEQ(c.FilePath(), gfile.Pwd()+gfile.Separator+path) }) } @@ -247,166 +247,166 @@ func Test_Instance(t *testing.T) { "v4": "1.234" } ` - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gcfg.DEFAULT_CONFIG_FILE err := gfile.PutContents(path, config) - gtest.Assert(err, nil) + t.Assert(err, nil) defer func() { - gtest.Assert(gfile.Remove(path), nil) + t.Assert(gfile.Remove(path), nil) }() c := gcfg.Instance() - gtest.Assert(c.Get("v1"), 1) - gtest.AssertEQ(c.GetInt("v1"), 1) - gtest.AssertEQ(c.GetInt8("v1"), int8(1)) - gtest.AssertEQ(c.GetInt16("v1"), int16(1)) - gtest.AssertEQ(c.GetInt32("v1"), int32(1)) - gtest.AssertEQ(c.GetInt64("v1"), int64(1)) - gtest.AssertEQ(c.GetUint("v1"), uint(1)) - gtest.AssertEQ(c.GetUint8("v1"), uint8(1)) - gtest.AssertEQ(c.GetUint16("v1"), uint16(1)) - gtest.AssertEQ(c.GetUint32("v1"), uint32(1)) - gtest.AssertEQ(c.GetUint64("v1"), uint64(1)) + t.Assert(c.Get("v1"), 1) + t.AssertEQ(c.GetInt("v1"), 1) + t.AssertEQ(c.GetInt8("v1"), int8(1)) + t.AssertEQ(c.GetInt16("v1"), int16(1)) + t.AssertEQ(c.GetInt32("v1"), int32(1)) + t.AssertEQ(c.GetInt64("v1"), int64(1)) + t.AssertEQ(c.GetUint("v1"), uint(1)) + t.AssertEQ(c.GetUint8("v1"), uint8(1)) + t.AssertEQ(c.GetUint16("v1"), uint16(1)) + t.AssertEQ(c.GetUint32("v1"), uint32(1)) + t.AssertEQ(c.GetUint64("v1"), uint64(1)) - gtest.AssertEQ(c.GetVar("v1").String(), "1") - gtest.AssertEQ(c.GetVar("v1").Bool(), true) - gtest.AssertEQ(c.GetVar("v2").String(), "true") - gtest.AssertEQ(c.GetVar("v2").Bool(), true) + t.AssertEQ(c.GetVar("v1").String(), "1") + t.AssertEQ(c.GetVar("v1").Bool(), true) + t.AssertEQ(c.GetVar("v2").String(), "true") + t.AssertEQ(c.GetVar("v2").Bool(), true) - gtest.AssertEQ(c.GetString("v1"), "1") - gtest.AssertEQ(c.GetFloat32("v4"), float32(1.234)) - gtest.AssertEQ(c.GetFloat64("v4"), float64(1.234)) - gtest.AssertEQ(c.GetString("v2"), "true") - gtest.AssertEQ(c.GetBool("v2"), true) - gtest.AssertEQ(c.GetBool("v3"), false) + t.AssertEQ(c.GetString("v1"), "1") + t.AssertEQ(c.GetFloat32("v4"), float32(1.234)) + t.AssertEQ(c.GetFloat64("v4"), float64(1.234)) + t.AssertEQ(c.GetString("v2"), "true") + t.AssertEQ(c.GetBool("v2"), true) + t.AssertEQ(c.GetBool("v3"), false) - gtest.AssertEQ(c.Contains("v1"), true) - gtest.AssertEQ(c.Contains("v2"), true) - gtest.AssertEQ(c.Contains("v3"), true) - gtest.AssertEQ(c.Contains("v4"), true) - gtest.AssertEQ(c.Contains("v5"), false) + t.AssertEQ(c.Contains("v1"), true) + t.AssertEQ(c.Contains("v2"), true) + t.AssertEQ(c.Contains("v3"), true) + t.AssertEQ(c.Contains("v4"), true) + t.AssertEQ(c.Contains("v5"), false) - gtest.AssertEQ(c.GetInts("array"), []int{1, 2, 3}) - gtest.AssertEQ(c.GetStrings("array"), []string{"1", "2", "3"}) - gtest.AssertEQ(c.GetArray("array"), []interface{}{1, 2, 3}) - gtest.AssertEQ(c.GetInterfaces("array"), []interface{}{1, 2, 3}) - gtest.AssertEQ(c.GetMap("redis"), map[string]interface{}{ + t.AssertEQ(c.GetInts("array"), []int{1, 2, 3}) + t.AssertEQ(c.GetStrings("array"), []string{"1", "2", "3"}) + t.AssertEQ(c.GetArray("array"), []interface{}{1, 2, 3}) + t.AssertEQ(c.GetInterfaces("array"), []interface{}{1, 2, 3}) + t.AssertEQ(c.GetMap("redis"), map[string]interface{}{ "disk": "127.0.0.1:6379,0", "cache": "127.0.0.1:6379,1", }) - gtest.AssertEQ(c.FilePath(), gfile.Pwd()+gfile.Separator+path) + t.AssertEQ(c.FilePath(), gfile.Pwd()+gfile.Separator+path) }) } func TestCfg_New(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { os.Setenv("GF_GCFG_PATH", "config") c := gcfg.New("config.yml") - gtest.Assert(c.Get("name"), nil) - gtest.Assert(c.GetFileName(), "config.yml") + t.Assert(c.Get("name"), nil) + t.Assert(c.GetFileName(), "config.yml") configPath := gfile.Pwd() + gfile.Separator + "config" _ = gfile.Mkdir(configPath) defer gfile.Remove(configPath) c = gcfg.New("config.yml") - gtest.Assert(c.Get("name"), nil) + t.Assert(c.Get("name"), nil) _ = os.Unsetenv("GF_GCFG_PATH") c = gcfg.New("config.yml") - gtest.Assert(c.Get("name"), nil) + t.Assert(c.Get("name"), nil) }) } func TestCfg_SetPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { c := gcfg.New("config.yml") err := c.SetPath("tmp") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) err = c.SetPath("gcfg.go") - gtest.AssertNE(err, nil) - gtest.Assert(c.Get("name"), nil) + t.AssertNE(err, nil) + t.Assert(c.Get("name"), nil) }) } func TestCfg_SetViolenceCheck(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { c := gcfg.New("config.yml") c.SetViolenceCheck(true) - gtest.Assert(c.Get("name"), nil) + t.Assert(c.Get("name"), nil) }) } func TestCfg_AddPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { c := gcfg.New("config.yml") err := c.AddPath("tmp") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) err = c.AddPath("gcfg.go") - gtest.AssertNE(err, nil) - gtest.Assert(c.Get("name"), nil) + t.AssertNE(err, nil) + t.Assert(c.Get("name"), nil) }) } func TestCfg_FilePath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { c := gcfg.New("config.yml") path := c.FilePath("tmp") - gtest.Assert(path, "") + t.Assert(path, "") path = c.FilePath("tmp") - gtest.Assert(path, "") + t.Assert(path, "") }) } func TestCfg_Get(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var err error configPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err = gfile.Mkdir(configPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(configPath) defer gfile.Chdir(gfile.Pwd()) err = gfile.Chdir(configPath) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gfile.PutContents( gfile.Join(configPath, "config.yml"), "wrong config", ) - gtest.Assert(err, nil) + t.Assert(err, nil) c := gcfg.New("config.yml") - gtest.Assert(c.Get("name"), nil) - gtest.Assert(c.GetVar("name").Val(), nil) - gtest.Assert(c.Contains("name"), false) - gtest.Assert(c.GetMap("name"), nil) - gtest.Assert(c.GetArray("name"), nil) - gtest.Assert(c.GetString("name"), "") - gtest.Assert(c.GetStrings("name"), nil) - gtest.Assert(c.GetInterfaces("name"), nil) - gtest.Assert(c.GetBool("name"), false) - gtest.Assert(c.GetFloat32("name"), 0) - gtest.Assert(c.GetFloat64("name"), 0) - gtest.Assert(c.GetFloats("name"), nil) - gtest.Assert(c.GetInt("name"), 0) - gtest.Assert(c.GetInt8("name"), 0) - gtest.Assert(c.GetInt16("name"), 0) - gtest.Assert(c.GetInt32("name"), 0) - gtest.Assert(c.GetInt64("name"), 0) - gtest.Assert(c.GetInts("name"), nil) - gtest.Assert(c.GetUint("name"), 0) - gtest.Assert(c.GetUint8("name"), 0) - gtest.Assert(c.GetUint16("name"), 0) - gtest.Assert(c.GetUint32("name"), 0) - gtest.Assert(c.GetUint64("name"), 0) - gtest.Assert(c.GetTime("name").Format("2006-01-02"), "0001-01-01") - gtest.Assert(c.GetGTime("name"), nil) - gtest.Assert(c.GetDuration("name").String(), "0s") + t.Assert(c.Get("name"), nil) + t.Assert(c.GetVar("name").Val(), nil) + t.Assert(c.Contains("name"), false) + t.Assert(c.GetMap("name"), nil) + t.Assert(c.GetArray("name"), nil) + t.Assert(c.GetString("name"), "") + t.Assert(c.GetStrings("name"), nil) + t.Assert(c.GetInterfaces("name"), nil) + t.Assert(c.GetBool("name"), false) + t.Assert(c.GetFloat32("name"), 0) + t.Assert(c.GetFloat64("name"), 0) + t.Assert(c.GetFloats("name"), nil) + t.Assert(c.GetInt("name"), 0) + t.Assert(c.GetInt8("name"), 0) + t.Assert(c.GetInt16("name"), 0) + t.Assert(c.GetInt32("name"), 0) + t.Assert(c.GetInt64("name"), 0) + t.Assert(c.GetInts("name"), nil) + t.Assert(c.GetUint("name"), 0) + t.Assert(c.GetUint8("name"), 0) + t.Assert(c.GetUint16("name"), 0) + t.Assert(c.GetUint32("name"), 0) + t.Assert(c.GetUint64("name"), 0) + t.Assert(c.GetTime("name").Format("2006-01-02"), "0001-01-01") + t.Assert(c.GetGTime("name"), nil) + t.Assert(c.GetDuration("name").String(), "0s") name := struct { Name string }{} - gtest.Assert(c.GetStruct("name", &name) == nil, false) + t.Assert(c.GetStruct("name", &name) == nil, false) c.Clear() @@ -422,40 +422,40 @@ func TestCfg_Get(t *testing.T) { gfile.Join(configPath, "config.yml"), arr, ) - gtest.Assert(err, nil) - gtest.Assert(c.GetTime("time").Format("2006-01-02"), "2019-06-12") - gtest.Assert(c.GetGTime("time").Format("Y-m-d"), "2019-06-12") - gtest.Assert(c.GetDuration("time").String(), "0s") + t.Assert(err, nil) + t.Assert(c.GetTime("time").Format("2006-01-02"), "2019-06-12") + t.Assert(c.GetGTime("time").Format("Y-m-d"), "2019-06-12") + t.Assert(c.GetDuration("time").String(), "0s") err = c.GetStruct("person", &name) - gtest.Assert(err, nil) - gtest.Assert(name.Name, "gf") - gtest.Assert(c.GetFloats("floats") == nil, false) + t.Assert(err, nil) + t.Assert(name.Name, "gf") + t.Assert(c.GetFloats("floats") == nil, false) }) } func TestCfg_Instance(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gcfg.Instance("gf") != nil, true) + gtest.C(t, func(t *gtest.T) { + t.Assert(gcfg.Instance("gf") != nil, true) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { pwd := gfile.Pwd() gfile.Chdir(gfile.Join(gdebug.TestDataPath())) defer gfile.Chdir(pwd) - gtest.Assert(gcfg.Instance("c1") != nil, true) - gtest.Assert(gcfg.Instance("c1").Get("my-config"), "1") - gtest.Assert(gcfg.Instance("folder1/c1").Get("my-config"), "2") + t.Assert(gcfg.Instance("c1") != nil, true) + t.Assert(gcfg.Instance("c1").Get("my-config"), "1") + t.Assert(gcfg.Instance("folder1/c1").Get("my-config"), "2") }) } func TestCfg_Config(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gcfg.SetContent("gf", "config.yml") - gtest.Assert(gcfg.GetContent("config.yml"), "gf") + t.Assert(gcfg.GetContent("config.yml"), "gf") gcfg.SetContent("gf1", "config.yml") - gtest.Assert(gcfg.GetContent("config.yml"), "gf1") + t.Assert(gcfg.GetContent("config.yml"), "gf1") gcfg.RemoveContent("config.yml") gcfg.ClearContent() - gtest.Assert(gcfg.GetContent("name"), "") + t.Assert(gcfg.GetContent("name"), "") }) } diff --git a/os/gcmd/gcmd_z_unit_default_test.go b/os/gcmd/gcmd_z_unit_default_test.go index 227863227..16a278af7 100644 --- a/os/gcmd/gcmd_z_unit_default_test.go +++ b/os/gcmd/gcmd_z_unit_default_test.go @@ -19,32 +19,32 @@ import ( ) func Test_Default(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { os.Args = []string{"gf", "--force", "remove", "-fq", "-p=www", "path", "-n", "root"} - gtest.Assert(len(gcmd.GetArgAll()), 4) - gtest.Assert(gcmd.GetArg(1), "remove") - gtest.Assert(gcmd.GetArg(100, "test"), "test") - gtest.Assert(gcmd.GetOpt("n"), "") - gtest.Assert(gcmd.ContainsOpt("p"), true) - gtest.Assert(gcmd.ContainsOpt("n"), true) - gtest.Assert(gcmd.ContainsOpt("none"), false) - gtest.Assert(gcmd.GetOpt("none", "value"), "value") + t.Assert(len(gcmd.GetArgAll()), 4) + t.Assert(gcmd.GetArg(1), "remove") + t.Assert(gcmd.GetArg(100, "test"), "test") + t.Assert(gcmd.GetOpt("n"), "") + t.Assert(gcmd.ContainsOpt("p"), true) + t.Assert(gcmd.ContainsOpt("n"), true) + t.Assert(gcmd.ContainsOpt("none"), false) + t.Assert(gcmd.GetOpt("none", "value"), "value") }) } func Test_BuildOptions(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gcmd.BuildOptions(g.MapStrStr{ "n": "john", }) - gtest.Assert(s, "-n=john") + t.Assert(s, "-n=john") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gcmd.BuildOptions(g.MapStrStr{ "n": "john", }, "-test") - gtest.Assert(s, "-testn=john") + t.Assert(s, "-testn=john") }) } diff --git a/os/gcmd/gcmd_z_unit_parser_test.go b/os/gcmd/gcmd_z_unit_parser_test.go index 5c44b8010..4988c64be 100644 --- a/os/gcmd/gcmd_z_unit_parser_test.go +++ b/os/gcmd/gcmd_z_unit_parser_test.go @@ -20,7 +20,7 @@ import ( ) func Test_Parse(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { os.Args = []string{"gf", "--force", "remove", "-fq", "-p=www", "path", "-n", "root"} p, err := gcmd.Parse(map[string]bool{ "n, name": true, @@ -28,34 +28,34 @@ func Test_Parse(t *testing.T) { "f,force": false, "q,quiet": false, }) - gtest.Assert(err, nil) - gtest.Assert(len(p.GetArgAll()), 3) - gtest.Assert(p.GetArg(0), "gf") - gtest.Assert(p.GetArg(1), "remove") - gtest.Assert(p.GetArg(2), "path") - gtest.Assert(p.GetArgVar(2).String(), "path") + t.Assert(err, nil) + t.Assert(len(p.GetArgAll()), 3) + t.Assert(p.GetArg(0), "gf") + t.Assert(p.GetArg(1), "remove") + t.Assert(p.GetArg(2), "path") + t.Assert(p.GetArgVar(2).String(), "path") - gtest.Assert(len(p.GetOptAll()), 8) - gtest.Assert(p.GetOpt("n"), "root") - gtest.Assert(p.GetOpt("name"), "root") - gtest.Assert(p.GetOpt("p"), "www") - gtest.Assert(p.GetOpt("prefix"), "www") - gtest.Assert(p.GetOptVar("prefix").String(), "www") + t.Assert(len(p.GetOptAll()), 8) + t.Assert(p.GetOpt("n"), "root") + t.Assert(p.GetOpt("name"), "root") + t.Assert(p.GetOpt("p"), "www") + t.Assert(p.GetOpt("prefix"), "www") + t.Assert(p.GetOptVar("prefix").String(), "www") - gtest.Assert(p.ContainsOpt("n"), true) - gtest.Assert(p.ContainsOpt("name"), true) - gtest.Assert(p.ContainsOpt("p"), true) - gtest.Assert(p.ContainsOpt("prefix"), true) - gtest.Assert(p.ContainsOpt("f"), true) - gtest.Assert(p.ContainsOpt("force"), true) - gtest.Assert(p.ContainsOpt("q"), true) - gtest.Assert(p.ContainsOpt("quiet"), true) - gtest.Assert(p.ContainsOpt("none"), false) + t.Assert(p.ContainsOpt("n"), true) + t.Assert(p.ContainsOpt("name"), true) + t.Assert(p.ContainsOpt("p"), true) + t.Assert(p.ContainsOpt("prefix"), true) + t.Assert(p.ContainsOpt("f"), true) + t.Assert(p.ContainsOpt("force"), true) + t.Assert(p.ContainsOpt("q"), true) + t.Assert(p.ContainsOpt("quiet"), true) + t.Assert(p.ContainsOpt("none"), false) }) } func Test_ParseWithArgs(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p, err := gcmd.ParseWithArgs( []string{"gf", "--force", "remove", "-fq", "-p=www", "path", "-n", "root"}, map[string]bool{ @@ -64,34 +64,34 @@ func Test_ParseWithArgs(t *testing.T) { "f,force": false, "q,quiet": false, }) - gtest.Assert(err, nil) - gtest.Assert(len(p.GetArgAll()), 3) - gtest.Assert(p.GetArg(0), "gf") - gtest.Assert(p.GetArg(1), "remove") - gtest.Assert(p.GetArg(2), "path") - gtest.Assert(p.GetArgVar(2).String(), "path") + t.Assert(err, nil) + t.Assert(len(p.GetArgAll()), 3) + t.Assert(p.GetArg(0), "gf") + t.Assert(p.GetArg(1), "remove") + t.Assert(p.GetArg(2), "path") + t.Assert(p.GetArgVar(2).String(), "path") - gtest.Assert(len(p.GetOptAll()), 8) - gtest.Assert(p.GetOpt("n"), "root") - gtest.Assert(p.GetOpt("name"), "root") - gtest.Assert(p.GetOpt("p"), "www") - gtest.Assert(p.GetOpt("prefix"), "www") - gtest.Assert(p.GetOptVar("prefix").String(), "www") + t.Assert(len(p.GetOptAll()), 8) + t.Assert(p.GetOpt("n"), "root") + t.Assert(p.GetOpt("name"), "root") + t.Assert(p.GetOpt("p"), "www") + t.Assert(p.GetOpt("prefix"), "www") + t.Assert(p.GetOptVar("prefix").String(), "www") - gtest.Assert(p.ContainsOpt("n"), true) - gtest.Assert(p.ContainsOpt("name"), true) - gtest.Assert(p.ContainsOpt("p"), true) - gtest.Assert(p.ContainsOpt("prefix"), true) - gtest.Assert(p.ContainsOpt("f"), true) - gtest.Assert(p.ContainsOpt("force"), true) - gtest.Assert(p.ContainsOpt("q"), true) - gtest.Assert(p.ContainsOpt("quiet"), true) - gtest.Assert(p.ContainsOpt("none"), false) + t.Assert(p.ContainsOpt("n"), true) + t.Assert(p.ContainsOpt("name"), true) + t.Assert(p.ContainsOpt("p"), true) + t.Assert(p.ContainsOpt("prefix"), true) + t.Assert(p.ContainsOpt("f"), true) + t.Assert(p.ContainsOpt("force"), true) + t.Assert(p.ContainsOpt("q"), true) + t.Assert(p.ContainsOpt("quiet"), true) + t.Assert(p.ContainsOpt("none"), false) }) } func Test_Handler(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { p, err := gcmd.ParseWithArgs( []string{"gf", "--force", "remove", "-fq", "-p=www", "path", "-n", "root"}, map[string]bool{ @@ -100,37 +100,37 @@ func Test_Handler(t *testing.T) { "f,force": false, "q,quiet": false, }) - gtest.Assert(err, nil) + t.Assert(err, nil) array := garray.New() err = p.BindHandle("remove", func() { array.Append(1) }) - gtest.Assert(err, nil) + t.Assert(err, nil) err = p.BindHandle("remove", func() { array.Append(1) }) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) err = p.BindHandle("test", func() { array.Append(1) }) - gtest.Assert(err, nil) + t.Assert(err, nil) err = p.RunHandle("remove") - gtest.Assert(err, nil) - gtest.Assert(array.Len(), 1) + t.Assert(err, nil) + t.Assert(array.Len(), 1) err = p.RunHandle("none") - gtest.AssertNE(err, nil) - gtest.Assert(array.Len(), 1) + t.AssertNE(err, nil) + t.Assert(array.Len(), 1) err = p.RunHandle("test") - gtest.Assert(err, nil) - gtest.Assert(array.Len(), 2) + t.Assert(err, nil) + t.Assert(array.Len(), 2) err = p.AutoRun() - gtest.Assert(err, nil) - gtest.Assert(array.Len(), 3) + t.Assert(err, nil) + t.Assert(array.Len(), 3) }) } diff --git a/os/gcron/gcron_unit_1_test.go b/os/gcron/gcron_unit_1_test.go index e11bd4d98..01a31353e 100644 --- a/os/gcron/gcron_unit_1_test.go +++ b/os/gcron/gcron_unit_1_test.go @@ -16,7 +16,7 @@ import ( ) func TestCron_Add_Close(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) _, err1 := cron.Add("* * * * * *", func() { @@ -34,96 +34,96 @@ func TestCron_Add_Close(t *testing.T) { //glog.Println("cron3") array.Append(1) }) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.AssertNE(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(cron.Size(), 3) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.AssertNE(err3, nil) + t.Assert(err4, nil) + t.Assert(cron.Size(), 3) time.Sleep(1200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) time.Sleep(1200 * time.Millisecond) - gtest.Assert(array.Len(), 5) + t.Assert(array.Len(), 5) cron.Close() time.Sleep(1200 * time.Millisecond) fixedLength := array.Len() time.Sleep(1200 * time.Millisecond) - gtest.Assert(array.Len(), fixedLength) + t.Assert(array.Len(), fixedLength) }) } func TestCron_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() cron.Add("* * * * * *", func() {}, "add") //fmt.Println("start", time.Now()) cron.DelayAdd(time.Second, "* * * * * *", func() {}, "delay_add") - gtest.Assert(cron.Size(), 1) + t.Assert(cron.Size(), 1) time.Sleep(1200 * time.Millisecond) - gtest.Assert(cron.Size(), 2) + t.Assert(cron.Size(), 2) cron.Remove("delay_add") - gtest.Assert(cron.Size(), 1) + t.Assert(cron.Size(), 1) entry1 := cron.Search("add") entry2 := cron.Search("test-none") - gtest.AssertNE(entry1, nil) - gtest.Assert(entry2, nil) + t.AssertNE(entry1, nil) + t.Assert(entry2, nil) }) } func TestCron_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.Add("* * * * * *", func() { array.Append(1) }, "add") - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(1200 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) cron.Remove("add") - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(1200 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestCron_AddSingleton(t *testing.T) { // un used, can be removed - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() cron.Add("* * * * * *", func() {}, "add") cron.DelayAdd(time.Second, "* * * * * *", func() {}, "delay_add") - gtest.Assert(cron.Size(), 1) + t.Assert(cron.Size(), 1) time.Sleep(1200 * time.Millisecond) - gtest.Assert(cron.Size(), 2) + t.Assert(cron.Size(), 2) cron.Remove("delay_add") - gtest.Assert(cron.Size(), 1) + t.Assert(cron.Size(), 1) entry1 := cron.Search("add") entry2 := cron.Search("test-none") - gtest.AssertNE(entry1, nil) - gtest.Assert(entry2, nil) + t.AssertNE(entry1, nil) + t.Assert(entry2, nil) }) // keep this - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.AddSingleton("* * * * * *", func() { array.Append(1) time.Sleep(50 * time.Second) }) - gtest.Assert(cron.Size(), 1) + t.Assert(cron.Size(), 1) time.Sleep(3500 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestCron_AddOnce1(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.AddOnce("* * * * * *", func() { @@ -132,102 +132,102 @@ func TestCron_AddOnce1(t *testing.T) { cron.AddOnce("* * * * * *", func() { array.Append(1) }) - gtest.Assert(cron.Size(), 2) + t.Assert(cron.Size(), 2) time.Sleep(2500 * time.Millisecond) - gtest.Assert(array.Len(), 2) - gtest.Assert(cron.Size(), 0) + t.Assert(array.Len(), 2) + t.Assert(cron.Size(), 0) }) } func TestCron_AddOnce2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.AddOnce("@every 2s", func() { array.Append(1) }) - gtest.Assert(cron.Size(), 1) + t.Assert(cron.Size(), 1) time.Sleep(3000 * time.Millisecond) - gtest.Assert(array.Len(), 1) - gtest.Assert(cron.Size(), 0) + t.Assert(array.Len(), 1) + t.Assert(cron.Size(), 0) }) } func TestCron_AddTimes(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.AddTimes("* * * * * *", 2, func() { array.Append(1) }) time.Sleep(3500 * time.Millisecond) - gtest.Assert(array.Len(), 2) - gtest.Assert(cron.Size(), 0) + t.Assert(array.Len(), 2) + t.Assert(cron.Size(), 0) }) } func TestCron_DelayAdd(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.DelayAdd(500*time.Millisecond, "* * * * * *", func() { array.Append(1) }) - gtest.Assert(cron.Size(), 0) + t.Assert(cron.Size(), 0) time.Sleep(800 * time.Millisecond) - gtest.Assert(array.Len(), 0) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 0) + t.Assert(cron.Size(), 1) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 1) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 1) + t.Assert(cron.Size(), 1) }) } func TestCron_DelayAddSingleton(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.DelayAddSingleton(500*time.Millisecond, "* * * * * *", func() { array.Append(1) time.Sleep(10 * time.Second) }) - gtest.Assert(cron.Size(), 0) + t.Assert(cron.Size(), 0) time.Sleep(2200 * time.Millisecond) - gtest.Assert(array.Len(), 1) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 1) + t.Assert(cron.Size(), 1) }) } func TestCron_DelayAddOnce(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.DelayAddOnce(500*time.Millisecond, "* * * * * *", func() { array.Append(1) }) - gtest.Assert(cron.Size(), 0) + t.Assert(cron.Size(), 0) time.Sleep(800 * time.Millisecond) - gtest.Assert(array.Len(), 0) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 0) + t.Assert(cron.Size(), 1) time.Sleep(2200 * time.Millisecond) - gtest.Assert(array.Len(), 1) - gtest.Assert(cron.Size(), 0) + t.Assert(array.Len(), 1) + t.Assert(cron.Size(), 0) }) } func TestCron_DelayAddTimes(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.DelayAddTimes(500*time.Millisecond, "* * * * * *", 2, func() { array.Append(1) }) - gtest.Assert(cron.Size(), 0) + t.Assert(cron.Size(), 0) time.Sleep(800 * time.Millisecond) - gtest.Assert(array.Len(), 0) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 0) + t.Assert(cron.Size(), 1) time.Sleep(3000 * time.Millisecond) - gtest.Assert(array.Len(), 2) - gtest.Assert(cron.Size(), 0) + t.Assert(array.Len(), 2) + t.Assert(cron.Size(), 0) }) } diff --git a/os/gcron/gcron_unit_2_test.go b/os/gcron/gcron_unit_2_test.go index 5168fa0af..1432970c5 100644 --- a/os/gcron/gcron_unit_2_test.go +++ b/os/gcron/gcron_unit_2_test.go @@ -17,22 +17,22 @@ import ( ) func TestCron_Entry_Operations(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) cron.DelayAddTimes(500*time.Millisecond, "* * * * * *", 2, func() { glog.Println("add times") array.Append(1) }) - gtest.Assert(cron.Size(), 0) + t.Assert(cron.Size(), 0) time.Sleep(800 * time.Millisecond) - gtest.Assert(array.Len(), 0) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 0) + t.Assert(cron.Size(), 1) time.Sleep(3000 * time.Millisecond) - gtest.Assert(array.Len(), 2) - gtest.Assert(cron.Size(), 0) + t.Assert(array.Len(), 2) + t.Assert(cron.Size(), 0) }) cron := gcron.New() @@ -41,23 +41,23 @@ func TestCron_Entry_Operations(t *testing.T) { glog.Println("add") array.Append(1) }) - gtest.Assert(err1, nil) - gtest.Assert(array.Len(), 0) - gtest.Assert(cron.Size(), 1) + t.Assert(err1, nil) + t.Assert(array.Len(), 0) + t.Assert(cron.Size(), 1) time.Sleep(1200 * time.Millisecond) - gtest.Assert(array.Len(), 1) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 1) + t.Assert(cron.Size(), 1) entry.Stop() time.Sleep(2000 * time.Millisecond) - gtest.Assert(array.Len(), 1) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 1) + t.Assert(cron.Size(), 1) entry.Start() glog.Println("start") time.Sleep(1200 * time.Millisecond) - gtest.Assert(array.Len(), 2) - gtest.Assert(cron.Size(), 1) + t.Assert(array.Len(), 2) + t.Assert(cron.Size(), 1) entry.Close() time.Sleep(1200 * time.Millisecond) - gtest.Assert(cron.Size(), 0) + t.Assert(cron.Size(), 0) }) } diff --git a/os/genv/genv_test.go b/os/genv/genv_test.go index 747b0f854..5004911a7 100644 --- a/os/genv/genv_test.go +++ b/os/genv/genv_test.go @@ -17,71 +17,71 @@ import ( ) func Test_GEnv_All(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(os.Environ(), genv.All()) + gtest.C(t, func(t *gtest.T) { + t.Assert(os.Environ(), genv.All()) }) } func Test_GEnv_Map(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value := gconv.String(gtime.TimestampNano()) key := "TEST_ENV_" + value err := os.Setenv(key, "TEST") - gtest.Assert(err, nil) - gtest.Assert(genv.Map()[key], "TEST") + t.Assert(err, nil) + t.Assert(genv.Map()[key], "TEST") }) } func Test_GEnv_Get(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value := gconv.String(gtime.TimestampNano()) key := "TEST_ENV_" + value err := os.Setenv(key, "TEST") - gtest.Assert(err, nil) - gtest.AssertEQ(genv.Get(key), "TEST") + t.Assert(err, nil) + t.AssertEQ(genv.Get(key), "TEST") }) } func Test_GEnv_Contains(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value := gconv.String(gtime.TimestampNano()) key := "TEST_ENV_" + value err := os.Setenv(key, "TEST") - gtest.Assert(err, nil) - gtest.AssertEQ(genv.Contains(key), true) - gtest.AssertEQ(genv.Contains("none"), false) + t.Assert(err, nil) + t.AssertEQ(genv.Contains(key), true) + t.AssertEQ(genv.Contains("none"), false) }) } func Test_GEnv_Set(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value := gconv.String(gtime.TimestampNano()) key := "TEST_ENV_" + value err := genv.Set(key, "TEST") - gtest.Assert(err, nil) - gtest.AssertEQ(os.Getenv(key), "TEST") + t.Assert(err, nil) + t.AssertEQ(os.Getenv(key), "TEST") }) } func Test_GEnv_Build(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := genv.Build(map[string]string{ "k1": "v1", "k2": "v2", }) - gtest.AssertIN("k1=v1", s) - gtest.AssertIN("k2=v2", s) + t.AssertIN("k1=v1", s) + t.AssertIN("k2=v2", s) }) } func Test_GEnv_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value := gconv.String(gtime.TimestampNano()) key := "TEST_ENV_" + value err := os.Setenv(key, "TEST") - gtest.Assert(err, nil) + t.Assert(err, nil) err = genv.Remove(key) - gtest.Assert(err, nil) - gtest.AssertEQ(os.Getenv(key), "") + t.Assert(err, nil) + t.AssertEQ(os.Getenv(key), "") }) } diff --git a/os/gfcache/gfcache_z_unit_test.go b/os/gfcache/gfcache_z_unit_test.go index 753ddfde3..6d96b6a72 100755 --- a/os/gfcache/gfcache_z_unit_test.go +++ b/os/gfcache/gfcache_z_unit_test.go @@ -20,7 +20,7 @@ import ( ) func TestGetContents(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var f *os.File var err error @@ -50,11 +50,11 @@ func TestGetContents(t *testing.T) { } cache := gfcache.GetContents(f.Name(), 1) - gtest.Assert(cache, strTest) + t.Assert(cache, strTest) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var f *os.File var err error @@ -84,7 +84,7 @@ func TestGetContents(t *testing.T) { t.Error("write error", err) } - gtest.Assert(cache, "") + t.Assert(cache, "") time.Sleep(100 * time.Millisecond) } diff --git a/os/gfile/gfile_z_contents_test.go b/os/gfile/gfile_z_contents_test.go index 3f1ad0d99..11c90ce60 100644 --- a/os/gfile/gfile_z_contents_test.go +++ b/os/gfile/gfile_z_contents_test.go @@ -60,7 +60,7 @@ func testpath() string { } func Test_GetContents(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths string = "/testfile_t1.txt" @@ -68,14 +68,14 @@ func Test_GetContents(t *testing.T) { createTestFile(filepaths, "my name is jroam") defer delTestFiles(filepaths) - gtest.Assert(gfile.GetContents(testpath()+filepaths), "my name is jroam") - gtest.Assert(gfile.GetContents(""), "") + t.Assert(gfile.GetContents(testpath()+filepaths), "my name is jroam") + t.Assert(gfile.GetContents(""), "") }) } func Test_GetBinContents(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths1 string = "/testfile_t1.txt" // 文件存在时 filepaths2 string = testpath() + "/testfile_t1_no.txt" // 文件不存在时 @@ -85,19 +85,19 @@ func Test_GetBinContents(t *testing.T) { createTestFile(filepaths1, str1) defer delTestFiles(filepaths1) readcontent = gfile.GetBytes(testpath() + filepaths1) - gtest.Assert(readcontent, []byte(str1)) + t.Assert(readcontent, []byte(str1)) readcontent = gfile.GetBytes(filepaths2) - gtest.Assert(string(readcontent), "") + t.Assert(string(readcontent), "") - gtest.Assert(string(gfile.GetBytes(filepaths2)), "") + t.Assert(string(gfile.GetBytes(filepaths2)), "") }) } // 截断文件为指定的大小 func Test_Truncate(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths1 string = "/testfile_GetContentsyyui.txt" //文件存在时 err error @@ -106,25 +106,25 @@ func Test_Truncate(t *testing.T) { createTestFile(filepaths1, "abcdefghijkmln") defer delTestFiles(filepaths1) err = gfile.Truncate(testpath()+filepaths1, 10) - gtest.Assert(err, nil) + t.Assert(err, nil) //=========================检查修改文后的大小,是否与期望一致 files, err = os.Open(testpath() + filepaths1) defer files.Close() - gtest.Assert(err, nil) + t.Assert(err, nil) fileinfo, err2 := files.Stat() - gtest.Assert(err2, nil) - gtest.Assert(fileinfo.Size(), 10) + t.Assert(err2, nil) + t.Assert(fileinfo.Size(), 10) //====测试当为空时,是否报错 err = gfile.Truncate("", 10) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_PutContents(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths string = "/testfile_PutContents.txt" err error @@ -134,21 +134,21 @@ func Test_PutContents(t *testing.T) { defer delTestFiles(filepaths) err = gfile.PutContents(testpath()+filepaths, "test!") - gtest.Assert(err, nil) + t.Assert(err, nil) //==================判断是否真正写入 readcontent, err = ioutil.ReadFile(testpath() + filepaths) - gtest.Assert(err, nil) - gtest.Assert(string(readcontent), "test!") + t.Assert(err, nil) + t.Assert(string(readcontent), "test!") err = gfile.PutContents("", "test!") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_PutContentsAppend(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths string = "/testfile_PutContents.txt" err error @@ -158,22 +158,22 @@ func Test_PutContentsAppend(t *testing.T) { createTestFile(filepaths, "a") defer delTestFiles(filepaths) err = gfile.PutContentsAppend(testpath()+filepaths, "hello") - gtest.Assert(err, nil) + t.Assert(err, nil) //==================判断是否真正写入 readcontent, err = ioutil.ReadFile(testpath() + filepaths) - gtest.Assert(err, nil) - gtest.Assert(string(readcontent), "ahello") + t.Assert(err, nil) + t.Assert(string(readcontent), "ahello") err = gfile.PutContentsAppend("", "hello") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_PutBinContents(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths string = "/testfile_PutContents.txt" err error @@ -183,21 +183,21 @@ func Test_PutBinContents(t *testing.T) { defer delTestFiles(filepaths) err = gfile.PutBytes(testpath()+filepaths, []byte("test!!")) - gtest.Assert(err, nil) + t.Assert(err, nil) // 判断是否真正写入 readcontent, err = ioutil.ReadFile(testpath() + filepaths) - gtest.Assert(err, nil) - gtest.Assert(string(readcontent), "test!!") + t.Assert(err, nil) + t.Assert(string(readcontent), "test!!") err = gfile.PutBytes("", []byte("test!!")) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_PutBinContentsAppend(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths string = "/testfile_PutContents.txt" //原文件内容: yy err error @@ -206,21 +206,21 @@ func Test_PutBinContentsAppend(t *testing.T) { createTestFile(filepaths, "test!!") defer delTestFiles(filepaths) err = gfile.PutBytesAppend(testpath()+filepaths, []byte("word")) - gtest.Assert(err, nil) + t.Assert(err, nil) // 判断是否真正写入 readcontent, err = ioutil.ReadFile(testpath() + filepaths) - gtest.Assert(err, nil) - gtest.Assert(string(readcontent), "test!!word") + t.Assert(err, nil) + t.Assert(string(readcontent), "test!!word") err = gfile.PutBytesAppend("", []byte("word")) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_GetBinContentsByTwoOffsetsByPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths string = "/testfile_GetContents.txt" // 文件内容: abcdefghijk readcontent []byte @@ -230,17 +230,17 @@ func Test_GetBinContentsByTwoOffsetsByPath(t *testing.T) { defer delTestFiles(filepaths) readcontent = gfile.GetBytesByTwoOffsetsByPath(testpath()+filepaths, 2, 5) - gtest.Assert(string(readcontent), "cde") + t.Assert(string(readcontent), "cde") readcontent = gfile.GetBytesByTwoOffsetsByPath("", 2, 5) - gtest.Assert(len(readcontent), 0) + t.Assert(len(readcontent), 0) }) } func Test_GetNextCharOffsetByPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( filepaths string = "/testfile_GetContents.txt" // 文件内容: abcdefghijk localindex int64 @@ -248,48 +248,48 @@ func Test_GetNextCharOffsetByPath(t *testing.T) { createTestFile(filepaths, "abcdefghijk") defer delTestFiles(filepaths) localindex = gfile.GetNextCharOffsetByPath(testpath()+filepaths, 'd', 1) - gtest.Assert(localindex, 3) + t.Assert(localindex, 3) localindex = gfile.GetNextCharOffsetByPath("", 'd', 1) - gtest.Assert(localindex, -1) + t.Assert(localindex, -1) }) } func Test_GetNextCharOffset(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( localindex int64 ) reader := strings.NewReader("helloword") localindex = gfile.GetNextCharOffset(reader, 'w', 1) - gtest.Assert(localindex, 5) + t.Assert(localindex, 5) localindex = gfile.GetNextCharOffset(reader, 'j', 1) - gtest.Assert(localindex, -1) + t.Assert(localindex, -1) }) } func Test_GetBinContentsByTwoOffsets(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( reads []byte ) reader := strings.NewReader("helloword") reads = gfile.GetBytesByTwoOffsets(reader, 1, 3) - gtest.Assert(string(reads), "el") + t.Assert(string(reads), "el") reads = gfile.GetBytesByTwoOffsets(reader, 10, 30) - gtest.Assert(string(reads), "") + t.Assert(string(reads), "") }) } func Test_GetBinContentsTilChar(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( reads []byte indexs int64 @@ -297,16 +297,16 @@ func Test_GetBinContentsTilChar(t *testing.T) { reader := strings.NewReader("helloword") reads, _ = gfile.GetBytesTilChar(reader, 'w', 2) - gtest.Assert(string(reads), "llow") + t.Assert(string(reads), "llow") _, indexs = gfile.GetBytesTilChar(reader, 'w', 20) - gtest.Assert(indexs, -1) + t.Assert(indexs, -1) }) } func Test_GetBinContentsTilCharByPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( reads []byte indexs int64 @@ -317,27 +317,27 @@ func Test_GetBinContentsTilCharByPath(t *testing.T) { defer delTestFiles(filepaths) reads, _ = gfile.GetBytesTilCharByPath(testpath()+filepaths, 'c', 2) - gtest.Assert(string(reads), "c") + t.Assert(string(reads), "c") reads, _ = gfile.GetBytesTilCharByPath(testpath()+filepaths, 'y', 1) - gtest.Assert(string(reads), "") + t.Assert(string(reads), "") _, indexs = gfile.GetBytesTilCharByPath(testpath()+filepaths, 'x', 1) - gtest.Assert(indexs, -1) + t.Assert(indexs, -1) }) } func Test_Home(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( reads string err error ) reads, err = gfile.Home() - gtest.Assert(err, nil) - gtest.AssertNE(reads, "") + t.Assert(err, nil) + t.AssertNE(reads, "") }) } diff --git a/os/gfile/gfile_z_copy_test.go b/os/gfile/gfile_z_copy_test.go index 82588d57c..d45a096d1 100644 --- a/os/gfile/gfile_z_copy_test.go +++ b/os/gfile/gfile_z_copy_test.go @@ -14,7 +14,7 @@ import ( ) func Test_Copy(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths string = "/testfile_copyfile1.txt" topath string = "/testfile_copyfile2.txt" @@ -23,16 +23,16 @@ func Test_Copy(t *testing.T) { createTestFile(paths, "") defer delTestFiles(paths) - gtest.Assert(gfile.Copy(testpath()+paths, testpath()+topath), nil) + t.Assert(gfile.Copy(testpath()+paths, testpath()+topath), nil) defer delTestFiles(topath) - gtest.Assert(gfile.IsFile(testpath()+topath), true) - gtest.AssertNE(gfile.Copy("", ""), nil) + t.Assert(gfile.IsFile(testpath()+topath), true) + t.AssertNE(gfile.Copy("", ""), nil) }) } func Test_CopyFile(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths string = "/testfile_copyfile1.txt" topath string = "/testfile_copyfile2.txt" @@ -41,32 +41,32 @@ func Test_CopyFile(t *testing.T) { createTestFile(paths, "") defer delTestFiles(paths) - gtest.Assert(gfile.CopyFile(testpath()+paths, testpath()+topath), nil) + t.Assert(gfile.CopyFile(testpath()+paths, testpath()+topath), nil) defer delTestFiles(topath) - gtest.Assert(gfile.IsFile(testpath()+topath), true) - gtest.AssertNE(gfile.CopyFile("", ""), nil) + t.Assert(gfile.IsFile(testpath()+topath), true) + t.AssertNE(gfile.CopyFile("", ""), nil) }) // Content replacement. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { src := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) dst := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) srcContent := "1" dstContent := "1" gfile.PutContents(src, srcContent) gfile.PutContents(dst, dstContent) - gtest.Assert(gfile.GetContents(src), srcContent) - gtest.Assert(gfile.GetContents(dst), dstContent) + t.Assert(gfile.GetContents(src), srcContent) + t.Assert(gfile.GetContents(dst), dstContent) err := gfile.CopyFile(src, dst) - gtest.Assert(err, nil) - gtest.Assert(gfile.GetContents(src), srcContent) - gtest.Assert(gfile.GetContents(dst), srcContent) + t.Assert(err, nil) + t.Assert(gfile.GetContents(src), srcContent) + t.Assert(gfile.GetContents(dst), srcContent) }) } func Test_CopyDir(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( dirpath1 string = "/testcopydir1" dirpath2 string = "/testcopydir2" @@ -87,46 +87,46 @@ func Test_CopyDir(t *testing.T) { tofolder := testpath() + dirpath2 if gfile.IsDir(tofolder) { - gtest.Assert(gfile.Remove(tofolder), nil) - gtest.Assert(gfile.Remove(""), nil) + t.Assert(gfile.Remove(tofolder), nil) + t.Assert(gfile.Remove(""), nil) } - gtest.Assert(gfile.CopyDir(yfolder, tofolder), nil) + t.Assert(gfile.CopyDir(yfolder, tofolder), nil) defer delTestFiles(tofolder) // 检查复制后的旧文件夹是否真实存在 - gtest.Assert(gfile.IsDir(yfolder), true) + t.Assert(gfile.IsDir(yfolder), true) // 检查复制后的旧文件夹中的文件是否真实存在 for _, v := range havelist1 { - gtest.Assert(gfile.IsFile(yfolder+"/"+v), true) + t.Assert(gfile.IsFile(yfolder+"/"+v), true) } // 检查复制后的新文件夹是否真实存在 - gtest.Assert(gfile.IsDir(tofolder), true) + t.Assert(gfile.IsDir(tofolder), true) // 检查复制后的新文件夹中的文件是否真实存在 for _, v := range havelist1 { - gtest.Assert(gfile.IsFile(tofolder+"/"+v), true) + t.Assert(gfile.IsFile(tofolder+"/"+v), true) } - gtest.Assert(gfile.Remove(tofolder), nil) - gtest.Assert(gfile.Remove(""), nil) + t.Assert(gfile.Remove(tofolder), nil) + t.Assert(gfile.Remove(""), nil) }) // Content replacement. - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { src := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), gtime.TimestampNanoStr()) dst := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr(), gtime.TimestampNanoStr()) srcContent := "1" dstContent := "1" gfile.PutContents(src, srcContent) gfile.PutContents(dst, dstContent) - gtest.Assert(gfile.GetContents(src), srcContent) - gtest.Assert(gfile.GetContents(dst), dstContent) + t.Assert(gfile.GetContents(src), srcContent) + t.Assert(gfile.GetContents(dst), dstContent) err := gfile.CopyDir(gfile.Dir(src), gfile.Dir(dst)) - gtest.Assert(err, nil) - gtest.Assert(gfile.GetContents(src), srcContent) - gtest.Assert(gfile.GetContents(dst), srcContent) + t.Assert(err, nil) + t.Assert(gfile.GetContents(src), srcContent) + t.Assert(gfile.GetContents(dst), srcContent) }) } diff --git a/os/gfile/gfile_z_readline_test.go b/os/gfile/gfile_z_readline_test.go index 8fe537cf1..76e956250 100644 --- a/os/gfile/gfile_z_readline_test.go +++ b/os/gfile/gfile_z_readline_test.go @@ -15,17 +15,17 @@ import ( ) func Test_NotFound(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { teatFile := gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/error.log" callback := func(line string) { } err := gfile.ReadLines(teatFile, callback) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_ReadLines(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expectList := []string{"a", "b", "c", "d", "e"} getList := make([]string, 0) @@ -36,13 +36,13 @@ func Test_ReadLines(t *testing.T) { teatFile := gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" err := gfile.ReadLines(teatFile, callback) - gtest.AssertEQ(getList, expectList) - gtest.AssertEQ(err, nil) + t.AssertEQ(getList, expectList) + t.AssertEQ(err, nil) }) } func Test_ReadByteLines(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { expectList := [][]byte{[]byte("a"), []byte("b"), []byte("c"), []byte("d"), []byte("e")} getList := make([][]byte, 0) @@ -53,7 +53,7 @@ func Test_ReadByteLines(t *testing.T) { teatFile := gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata/readline/file.log" err := gfile.ReadByteLines(teatFile, callback) - gtest.AssertEQ(getList, expectList) - gtest.AssertEQ(err, nil) + t.AssertEQ(getList, expectList) + t.AssertEQ(err, nil) }) } diff --git a/os/gfile/gfile_z_scan_test.go b/os/gfile/gfile_z_scan_test.go index a164cc80a..386602687 100644 --- a/os/gfile/gfile_z_scan_test.go +++ b/os/gfile/gfile_z_scan_test.go @@ -17,36 +17,36 @@ import ( func Test_ScanDir(t *testing.T) { teatPath := gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { files, err := gfile.ScanDir(teatPath, "*", false) - gtest.Assert(err, nil) - gtest.AssertIN(teatPath+gfile.Separator+"dir1", files) - gtest.AssertIN(teatPath+gfile.Separator+"dir2", files) - gtest.AssertNE(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) + t.Assert(err, nil) + t.AssertIN(teatPath+gfile.Separator+"dir1", files) + t.AssertIN(teatPath+gfile.Separator+"dir2", files) + t.AssertNE(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { files, err := gfile.ScanDir(teatPath, "*", true) - gtest.Assert(err, nil) - gtest.AssertIN(teatPath+gfile.Separator+"dir1", files) - gtest.AssertIN(teatPath+gfile.Separator+"dir2", files) - gtest.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) - gtest.AssertIN(teatPath+gfile.Separator+"dir2"+gfile.Separator+"file2", files) + t.Assert(err, nil) + t.AssertIN(teatPath+gfile.Separator+"dir1", files) + t.AssertIN(teatPath+gfile.Separator+"dir2", files) + t.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) + t.AssertIN(teatPath+gfile.Separator+"dir2"+gfile.Separator+"file2", files) }) } func Test_ScanDirFile(t *testing.T) { teatPath := gfile.Dir(gdebug.CallerFilePath()) + gfile.Separator + "testdata" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { files, err := gfile.ScanDirFile(teatPath, "*", false) - gtest.Assert(err, nil) - gtest.Assert(len(files), 0) + t.Assert(err, nil) + t.Assert(len(files), 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { files, err := gfile.ScanDirFile(teatPath, "*", true) - gtest.Assert(err, nil) - gtest.AssertNI(teatPath+gfile.Separator+"dir1", files) - gtest.AssertNI(teatPath+gfile.Separator+"dir2", files) - gtest.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) - gtest.AssertIN(teatPath+gfile.Separator+"dir2"+gfile.Separator+"file2", files) + t.Assert(err, nil) + t.AssertNI(teatPath+gfile.Separator+"dir1", files) + t.AssertNI(teatPath+gfile.Separator+"dir2", files) + t.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) + t.AssertIN(teatPath+gfile.Separator+"dir2"+gfile.Separator+"file2", files) }) } diff --git a/os/gfile/gfile_z_search_test.go b/os/gfile/gfile_z_search_test.go index 0efb6cf17..cde8d5277 100644 --- a/os/gfile/gfile_z_search_test.go +++ b/os/gfile/gfile_z_search_test.go @@ -15,7 +15,7 @@ import ( ) func Test_Search(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfiless" paths2 string = "./testfile/dirfiles_no" @@ -31,28 +31,28 @@ func Test_Search(t *testing.T) { ypaths1 = paths1 tpath, err = gfile.Search(testpath() + paths1) - gtest.Assert(err, nil) + t.Assert(err, nil) tpath = filepath.ToSlash(tpath) // 自定义优先路径 tpath2, err = gfile.Search(testpath() + paths1) - gtest.Assert(err, nil) + t.Assert(err, nil) tpath2 = filepath.ToSlash(tpath2) tempstr = testpath() paths1 = tempstr + paths1 paths1 = filepath.ToSlash(paths1) - gtest.Assert(tpath, paths1) + t.Assert(tpath, paths1) - gtest.Assert(tpath2, tpath) + t.Assert(tpath2, tpath) // 测试给定目录 tpath2, err = gfile.Search(paths1, "testfiless") tpath2 = filepath.ToSlash(tpath2) tempss := filepath.ToSlash(paths1) - gtest.Assert(tpath2, tempss) + t.Assert(tpath2, tempss) // 测试当前目录 tempstr, _ = filepath.Abs("./") @@ -60,11 +60,11 @@ func Test_Search(t *testing.T) { paths1 = tempstr + ypaths1 paths1 = filepath.ToSlash(paths1) - gtest.Assert(tpath2, paths1) + t.Assert(tpath2, paths1) // 测试目录不存在时 _, err = gfile.Search(paths2) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } diff --git a/os/gfile/gfile_z_size_test.go b/os/gfile/gfile_z_size_test.go index 4d61fc412..c0ae9289c 100644 --- a/os/gfile/gfile_z_size_test.go +++ b/os/gfile/gfile_z_size_test.go @@ -14,7 +14,7 @@ import ( ) func Test_Size(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfile_t1.txt" sizes int64 @@ -24,40 +24,40 @@ func Test_Size(t *testing.T) { defer delTestFiles(paths1) sizes = gfile.Size(testpath() + paths1) - gtest.Assert(sizes, 14) + t.Assert(sizes, 14) sizes = gfile.Size("") - gtest.Assert(sizes, 0) + t.Assert(sizes, 0) }) } func Test_FormatSize(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gfile.FormatSize(0), "0.00B") - gtest.Assert(gfile.FormatSize(16), "16.00B") + gtest.C(t, func(t *gtest.T) { + t.Assert(gfile.FormatSize(0), "0.00B") + t.Assert(gfile.FormatSize(16), "16.00B") - gtest.Assert(gfile.FormatSize(1024), "1.00K") + t.Assert(gfile.FormatSize(1024), "1.00K") - gtest.Assert(gfile.FormatSize(16000000), "15.26M") + t.Assert(gfile.FormatSize(16000000), "15.26M") - gtest.Assert(gfile.FormatSize(1600000000), "1.49G") + t.Assert(gfile.FormatSize(1600000000), "1.49G") - gtest.Assert(gfile.FormatSize(9600000000000), "8.73T") - gtest.Assert(gfile.FormatSize(9600000000000000), "8.53P") + t.Assert(gfile.FormatSize(9600000000000), "8.73T") + t.Assert(gfile.FormatSize(9600000000000000), "8.53P") }) } func Test_ReadableSize(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfile_t1.txt" ) createTestFile(paths1, "abcdefghijklmn") defer delTestFiles(paths1) - gtest.Assert(gfile.ReadableSize(testpath()+paths1), "14.00B") - gtest.Assert(gfile.ReadableSize(""), "0.00B") + t.Assert(gfile.ReadableSize(testpath()+paths1), "14.00B") + t.Assert(gfile.ReadableSize(""), "0.00B") }) } diff --git a/os/gfile/gfile_z_test.go b/os/gfile/gfile_z_test.go index 3e67a46d0..ee8540188 100644 --- a/os/gfile/gfile_z_test.go +++ b/os/gfile/gfile_z_test.go @@ -20,45 +20,45 @@ import ( ) func Test_IsDir(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { paths := "/testfile" createDir(paths) defer delTestFiles(paths) - gtest.Assert(gfile.IsDir(testpath()+paths), true) - gtest.Assert(gfile.IsDir("./testfile2"), false) - gtest.Assert(gfile.IsDir("./testfile/tt.txt"), false) - gtest.Assert(gfile.IsDir(""), false) + t.Assert(gfile.IsDir(testpath()+paths), true) + t.Assert(gfile.IsDir("./testfile2"), false) + t.Assert(gfile.IsDir("./testfile/tt.txt"), false) + t.Assert(gfile.IsDir(""), false) }) } func Test_IsEmpty(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "/testdir_" + gconv.String(gtime.TimestampNano()) createDir(path) defer delTestFiles(path) - gtest.Assert(gfile.IsEmpty(testpath()+path), true) - gtest.Assert(gfile.IsEmpty(testpath()+path+gfile.Separator+"test.txt"), true) + t.Assert(gfile.IsEmpty(testpath()+path), true) + t.Assert(gfile.IsEmpty(testpath()+path+gfile.Separator+"test.txt"), true) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "/testfile_" + gconv.String(gtime.TimestampNano()) createTestFile(path, "") defer delTestFiles(path) - gtest.Assert(gfile.IsEmpty(testpath()+path), true) + t.Assert(gfile.IsEmpty(testpath()+path), true) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "/testfile_" + gconv.String(gtime.TimestampNano()) createTestFile(path, "1") defer delTestFiles(path) - gtest.Assert(gfile.IsEmpty(testpath()+path), false) + t.Assert(gfile.IsEmpty(testpath()+path), false) }) } func Test_Create(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( err error filepaths []string @@ -70,13 +70,13 @@ func Test_Create(t *testing.T) { fileobj, err = gfile.Create(testpath() + v) defer delTestFiles(v) fileobj.Close() - gtest.Assert(err, nil) + t.Assert(err, nil) } }) } func Test_Open(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( err error files []string @@ -98,9 +98,9 @@ func Test_Open(t *testing.T) { fileobj, err = gfile.Open(testpath() + v) fileobj.Close() if flags[k] { - gtest.Assert(err, nil) + t.Assert(err, nil) } else { - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) } } @@ -109,7 +109,7 @@ func Test_Open(t *testing.T) { } func Test_OpenFile(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( err error files []string @@ -131,9 +131,9 @@ func Test_OpenFile(t *testing.T) { fileobj, err = gfile.OpenFile(testpath()+v, os.O_RDWR, 0666) fileobj.Close() if flags[k] { - gtest.Assert(err, nil) + t.Assert(err, nil) } else { - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) } } @@ -142,7 +142,7 @@ func Test_OpenFile(t *testing.T) { } func Test_OpenWithFlag(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( err error files []string @@ -163,9 +163,9 @@ func Test_OpenWithFlag(t *testing.T) { fileobj, err = gfile.OpenWithFlag(testpath()+v, os.O_RDWR) fileobj.Close() if flags[k] { - gtest.Assert(err, nil) + t.Assert(err, nil) } else { - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) } } @@ -174,7 +174,7 @@ func Test_OpenWithFlag(t *testing.T) { } func Test_OpenWithFlagPerm(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( err error files []string @@ -194,9 +194,9 @@ func Test_OpenWithFlagPerm(t *testing.T) { fileobj, err = gfile.OpenWithFlagPerm(testpath()+v, os.O_RDWR, 666) fileobj.Close() if flags[k] { - gtest.Assert(err, nil) + t.Assert(err, nil) } else { - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) } } @@ -206,7 +206,7 @@ func Test_OpenWithFlagPerm(t *testing.T) { func Test_Exists(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( flag bool files []string @@ -226,9 +226,9 @@ func Test_Exists(t *testing.T) { for k, v := range files { flag = gfile.Exists(testpath() + v) if flags[k] { - gtest.Assert(flag, true) + t.Assert(flag, true) } else { - gtest.Assert(flag, false) + t.Assert(flag, false) } } @@ -237,16 +237,16 @@ func Test_Exists(t *testing.T) { } func Test_Pwd(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { paths, err := os.Getwd() - gtest.Assert(err, nil) - gtest.Assert(gfile.Pwd(), paths) + t.Assert(err, nil) + t.Assert(gfile.Pwd(), paths) }) } func Test_IsFile(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( flag bool files []string @@ -271,9 +271,9 @@ func Test_IsFile(t *testing.T) { for k, v := range files { flag = gfile.IsFile(testpath() + v) if flags[k] { - gtest.Assert(flag, true) + t.Assert(flag, true) } else { - gtest.Assert(flag, false) + t.Assert(flag, false) } } @@ -282,7 +282,7 @@ func Test_IsFile(t *testing.T) { } func Test_Info(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( err error paths string = "/testfile_t1.txt" @@ -293,18 +293,18 @@ func Test_Info(t *testing.T) { createTestFile(paths, "") defer delTestFiles(paths) files, err = gfile.Info(testpath() + paths) - gtest.Assert(err, nil) + t.Assert(err, nil) files2, err = os.Stat(testpath() + paths) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Assert(files, files2) + t.Assert(files, files2) }) } func Test_Move(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths string = "/ovetest" filepaths string = "/testfile_ttn1.txt" @@ -318,17 +318,17 @@ func Test_Move(t *testing.T) { yfile := testpath() + paths + filepaths tofile := testpath() + paths + topath - gtest.Assert(gfile.Move(yfile, tofile), nil) + t.Assert(gfile.Move(yfile, tofile), nil) // 检查移动后的文件是否真实存在 _, err := os.Stat(tofile) - gtest.Assert(os.IsNotExist(err), false) + t.Assert(os.IsNotExist(err), false) }) } func Test_Rename(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths string = "/testfiles" ypath string = "/testfilettm1.txt" @@ -341,17 +341,17 @@ func Test_Rename(t *testing.T) { ypath = testpath() + paths + ypath topath = testpath() + paths + topath - gtest.Assert(gfile.Rename(ypath, topath), nil) - gtest.Assert(gfile.IsFile(topath), true) + t.Assert(gfile.Rename(ypath, topath), nil) + t.Assert(gfile.IsFile(topath), true) - gtest.AssertNE(gfile.Rename("", ""), nil) + t.AssertNE(gfile.Rename("", ""), nil) }) } func Test_DirNames(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths string = "/testdirs" err error @@ -371,17 +371,17 @@ func Test_DirNames(t *testing.T) { readlist, err = gfile.DirNames(testpath() + paths) - gtest.Assert(err, nil) - gtest.AssertIN(readlist, havelist) + t.Assert(err, nil) + t.AssertIN(readlist, havelist) _, err = gfile.DirNames("") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_Glob(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths string = "/testfiles/*.txt" dirpath string = "/testfiles" @@ -407,29 +407,29 @@ func Test_Glob(t *testing.T) { defer delTestFiles(dirpath) resultlist, err = gfile.Glob(testpath()+paths, true) - gtest.Assert(err, nil) - gtest.Assert(resultlist, havelist1) + t.Assert(err, nil) + t.Assert(resultlist, havelist1) resultlist, err = gfile.Glob(testpath()+paths, false) - gtest.Assert(err, nil) - gtest.Assert(formatpaths(resultlist), formatpaths(havelist2)) + t.Assert(err, nil) + t.Assert(formatpaths(resultlist), formatpaths(havelist2)) _, err = gfile.Glob("", true) - gtest.Assert(err, nil) + t.Assert(err, nil) }) } func Test_Remove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths string = "/testfile_t1.txt" ) createTestFile(paths, "") - gtest.Assert(gfile.Remove(testpath()+paths), nil) + t.Assert(gfile.Remove(testpath()+paths), nil) - gtest.Assert(gfile.Remove(""), nil) + t.Assert(gfile.Remove(""), nil) defer delTestFiles(paths) @@ -437,7 +437,7 @@ func Test_Remove(t *testing.T) { } func Test_IsReadable(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfile_GetContents.txt" paths2 string = "./testfile_GetContents_no.txt" @@ -446,14 +446,14 @@ func Test_IsReadable(t *testing.T) { createTestFile(paths1, "") defer delTestFiles(paths1) - gtest.Assert(gfile.IsReadable(testpath()+paths1), true) - gtest.Assert(gfile.IsReadable(paths2), false) + t.Assert(gfile.IsReadable(testpath()+paths1), true) + t.Assert(gfile.IsReadable(paths2), false) }) } func Test_IsWritable(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfile_GetContents.txt" paths2 string = "./testfile_GetContents_no.txt" @@ -461,14 +461,14 @@ func Test_IsWritable(t *testing.T) { createTestFile(paths1, "") defer delTestFiles(paths1) - gtest.Assert(gfile.IsWritable(testpath()+paths1), true) - gtest.Assert(gfile.IsWritable(paths2), false) + t.Assert(gfile.IsWritable(testpath()+paths1), true) + t.Assert(gfile.IsWritable(paths2), false) }) } func Test_Chmod(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfile_GetContents.txt" paths2 string = "./testfile_GetContents_no.txt" @@ -476,15 +476,15 @@ func Test_Chmod(t *testing.T) { createTestFile(paths1, "") defer delTestFiles(paths1) - gtest.Assert(gfile.Chmod(testpath()+paths1, 0777), nil) - gtest.AssertNE(gfile.Chmod(paths2, 0777), nil) + t.Assert(gfile.Chmod(testpath()+paths1, 0777), nil) + t.AssertNE(gfile.Chmod(paths2, 0777), nil) }) } // 获取绝对目录地址 func Test_RealPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfile_files" readlPath string @@ -499,16 +499,16 @@ func Test_RealPath(t *testing.T) { tempstr, _ = filepath.Abs("./") - gtest.Assert(readlPath, tempstr) + t.Assert(readlPath, tempstr) - gtest.Assert(gfile.RealPath("./nodirs"), "") + t.Assert(gfile.RealPath("./nodirs"), "") }) } // 获取当前执行文件的目录 func Test_SelfPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string readlPath string @@ -521,13 +521,13 @@ func Test_SelfPath(t *testing.T) { paths1 = filepath.ToSlash(tempstr) paths1 = strings.Replace(paths1, "./", "/", 1) - gtest.Assert(readlPath, paths1) + t.Assert(readlPath, paths1) }) } func Test_SelfDir(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string readlPath string @@ -538,13 +538,13 @@ func Test_SelfDir(t *testing.T) { tempstr, _ = filepath.Abs(os.Args[0]) paths1 = filepath.Dir(tempstr) - gtest.Assert(readlPath, paths1) + t.Assert(readlPath, paths1) }) } func Test_Basename(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfilerr_GetContents.txt" readlPath string @@ -554,13 +554,13 @@ func Test_Basename(t *testing.T) { defer delTestFiles(paths1) readlPath = gfile.Basename(testpath() + paths1) - gtest.Assert(readlPath, "testfilerr_GetContents.txt") + t.Assert(readlPath, "testfilerr_GetContents.txt") }) } func Test_Dir(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfiless" readlPath string @@ -570,13 +570,13 @@ func Test_Dir(t *testing.T) { readlPath = gfile.Dir(testpath() + paths1) - gtest.Assert(readlPath, testpath()) + t.Assert(readlPath, testpath()) }) } func Test_Ext(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( paths1 string = "/testfile_GetContents.txt" dirpath1 = "/testdirs" @@ -587,35 +587,35 @@ func Test_Ext(t *testing.T) { createDir(dirpath1) defer delTestFiles(dirpath1) - gtest.Assert(gfile.Ext(testpath()+paths1), ".txt") - gtest.Assert(gfile.Ext(testpath()+dirpath1), "") + t.Assert(gfile.Ext(testpath()+paths1), ".txt") + t.Assert(gfile.Ext(testpath()+dirpath1), "") }) - gtest.Case(t, func() { - gtest.Assert(gfile.Ext("/var/www/test.js"), ".js") - gtest.Assert(gfile.Ext("/var/www/test.min.js"), ".js") - gtest.Assert(gfile.Ext("/var/www/test.js?1"), ".js") - gtest.Assert(gfile.Ext("/var/www/test.min.js?v1"), ".js") + gtest.C(t, func(t *gtest.T) { + t.Assert(gfile.Ext("/var/www/test.js"), ".js") + t.Assert(gfile.Ext("/var/www/test.min.js"), ".js") + t.Assert(gfile.Ext("/var/www/test.js?1"), ".js") + t.Assert(gfile.Ext("/var/www/test.min.js?v1"), ".js") }) } func Test_ExtName(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gfile.ExtName("/var/www/test.js"), "js") - gtest.Assert(gfile.ExtName("/var/www/test.min.js"), "js") - gtest.Assert(gfile.ExtName("/var/www/test.js?v=1"), "js") - gtest.Assert(gfile.ExtName("/var/www/test.min.js?v=1"), "js") + gtest.C(t, func(t *gtest.T) { + t.Assert(gfile.ExtName("/var/www/test.js"), "js") + t.Assert(gfile.ExtName("/var/www/test.min.js"), "js") + t.Assert(gfile.ExtName("/var/www/test.js?v=1"), "js") + t.Assert(gfile.ExtName("/var/www/test.min.js?v=1"), "js") }) } func Test_TempDir(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gfile.TempDir(), "/tmp") + gtest.C(t, func(t *gtest.T) { + t.Assert(gfile.TempDir(), "/tmp") }) } func Test_Mkdir(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( tpath string = "/testfile/createdir" err error @@ -624,19 +624,19 @@ func Test_Mkdir(t *testing.T) { defer delTestFiles("/testfile") err = gfile.Mkdir(testpath() + tpath) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gfile.Mkdir("") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) err = gfile.Mkdir(testpath() + tpath + "2/t1") - gtest.Assert(err, nil) + t.Assert(err, nil) }) } func Test_Stat(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( tpath1 = "/testfile_t1.txt" tpath2 = "./testfile_t1_no.txt" @@ -648,19 +648,19 @@ func Test_Stat(t *testing.T) { defer delTestFiles(tpath1) fileiofo, err = gfile.Stat(testpath() + tpath1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Assert(fileiofo.Size(), 1) + t.Assert(fileiofo.Size(), 1) _, err = gfile.Stat(tpath2) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_MainPkgPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { reads := gfile.MainPkgPath() - gtest.Assert(reads, "") + t.Assert(reads, "") }) } diff --git a/os/gfile/gfile_z_time_test.go b/os/gfile/gfile_z_time_test.go index 843c1ad1e..06508a610 100644 --- a/os/gfile/gfile_z_time_test.go +++ b/os/gfile/gfile_z_time_test.go @@ -16,7 +16,7 @@ import ( ) func Test_MTime(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( file1 = "/testfile_t1.txt" @@ -27,15 +27,15 @@ func Test_MTime(t *testing.T) { createTestFile(file1, "") defer delTestFiles(file1) fileobj, err = os.Stat(testpath() + file1) - gtest.Assert(err, nil) + t.Assert(err, nil) - gtest.Assert(gfile.MTime(testpath()+file1), fileobj.ModTime().Unix()) - gtest.Assert(gfile.MTime(""), 0) + t.Assert(gfile.MTime(testpath()+file1), fileobj.ModTime().Unix()) + t.Assert(gfile.MTime(""), 0) }) } func Test_MTimeMillisecond(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var ( file1 = "/testfile_t1.txt" err error @@ -45,13 +45,13 @@ func Test_MTimeMillisecond(t *testing.T) { createTestFile(file1, "") defer delTestFiles(file1) fileobj, err = os.Stat(testpath() + file1) - gtest.Assert(err, nil) + t.Assert(err, nil) time.Sleep(time.Millisecond * 100) - gtest.AssertGE( + t.AssertGE( gfile.MTimeMillisecond(testpath()+file1), fileobj.ModTime().UnixNano()/1000000, ) - gtest.Assert(gfile.MTimeMillisecond(""), 0) + t.Assert(gfile.MTimeMillisecond(""), 0) }) } diff --git a/os/gfpool/gfpool_z_unit_test.go b/os/gfpool/gfpool_z_unit_test.go index af3d11130..d3552d256 100644 --- a/os/gfpool/gfpool_z_unit_test.go +++ b/os/gfpool/gfpool_z_unit_test.go @@ -15,14 +15,14 @@ import ( func TestOpen(t *testing.T) { testFile := start("TestOpen.txt") - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { f, err := gfpool.Open(testFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - gtest.AssertEQ(err, nil) + t.AssertEQ(err, nil) f.Close() f2, err1 := gfpool.Open(testFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - gtest.AssertEQ(err1, nil) - gtest.AssertEQ(f, f2) + t.AssertEQ(err1, nil) + t.AssertEQ(f, f2) f2.Close() }) @@ -31,46 +31,46 @@ func TestOpen(t *testing.T) { // TestOpenErr test open file error func TestOpenErr(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { testErrFile := "errorPath" _, err := gfpool.Open(testErrFile, os.O_RDWR, 0666) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) // delete file error testFile := start("TestOpenDeleteErr.txt") pool := gfpool.New(testFile, os.O_RDWR, 0666) _, err1 := pool.File() - gtest.AssertEQ(err1, nil) + t.AssertEQ(err1, nil) stop(testFile) _, err1 = pool.File() - gtest.AssertNE(err1, nil) + t.AssertNE(err1, nil) // append mode delete file error and create again testFile = start("TestOpenCreateErr.txt") pool = gfpool.New(testFile, os.O_CREATE, 0666) _, err1 = pool.File() - gtest.AssertEQ(err1, nil) + t.AssertEQ(err1, nil) stop(testFile) _, err1 = pool.File() - gtest.AssertEQ(err1, nil) + t.AssertEQ(err1, nil) // append mode delete file error testFile = start("TestOpenAppendErr.txt") pool = gfpool.New(testFile, os.O_APPEND, 0666) _, err1 = pool.File() - gtest.AssertEQ(err1, nil) + t.AssertEQ(err1, nil) stop(testFile) _, err1 = pool.File() - gtest.AssertNE(err1, nil) + t.AssertNE(err1, nil) // trunc mode delete file error testFile = start("TestOpenTruncErr.txt") pool = gfpool.New(testFile, os.O_TRUNC, 0666) _, err1 = pool.File() - gtest.AssertEQ(err1, nil) + t.AssertEQ(err1, nil) stop(testFile) _, err1 = pool.File() - gtest.AssertNE(err1, nil) + t.AssertNE(err1, nil) }) } @@ -78,15 +78,15 @@ func TestOpenErr(t *testing.T) { func TestOpenExpire(t *testing.T) { testFile := start("TestOpenExpire.txt") - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { f, err := gfpool.Open(testFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666, 100*time.Millisecond) - gtest.AssertEQ(err, nil) + t.AssertEQ(err, nil) f.Close() time.Sleep(150 * time.Millisecond) f2, err1 := gfpool.Open(testFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666, 100*time.Millisecond) - gtest.AssertEQ(err1, nil) - //gtest.AssertNE(f, f2) + t.AssertEQ(err1, nil) + //t.AssertNE(f, f2) f2.Close() }) @@ -97,16 +97,16 @@ func TestOpenExpire(t *testing.T) { func TestNewPool(t *testing.T) { testFile := start("TestNewPool.txt") - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { f, err := gfpool.Open(testFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) - gtest.AssertEQ(err, nil) + t.AssertEQ(err, nil) f.Close() pool := gfpool.New(testFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f2, err1 := pool.File() // pool not equal - gtest.AssertEQ(err1, nil) - //gtest.AssertNE(f, f2) + t.AssertEQ(err1, nil) + //t.AssertNE(f, f2) f2.Close() pool.Close() diff --git a/os/gfsnotify/gfsnotify_z_unit_test.go b/os/gfsnotify/gfsnotify_z_unit_test.go index 5c920e682..a4640bda2 100644 --- a/os/gfsnotify/gfsnotify_z_unit_test.go +++ b/os/gfsnotify/gfsnotify_z_unit_test.go @@ -19,43 +19,43 @@ import ( ) func TestWatcher_AddOnce(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value := gtype.New() path := gfile.Join(gfile.TempDir(), gconv.String(gtime.TimestampNano())) err := gfile.PutContents(path, "init") - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) time.Sleep(100 * time.Millisecond) callback1, err := gfsnotify.AddOnce("mywatch", path, func(event *gfsnotify.Event) { value.Set(1) }) - gtest.Assert(err, nil) + t.Assert(err, nil) callback2, err := gfsnotify.AddOnce("mywatch", path, func(event *gfsnotify.Event) { value.Set(2) }) - gtest.Assert(err, nil) - gtest.Assert(callback2, nil) + t.Assert(err, nil) + t.Assert(callback2, nil) err = gfile.PutContents(path, "1") - gtest.Assert(err, nil) + t.Assert(err, nil) time.Sleep(100 * time.Millisecond) - gtest.Assert(value, 1) + t.Assert(value, 1) err = gfsnotify.RemoveCallback(callback1.Id) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gfile.PutContents(path, "2") - gtest.Assert(err, nil) + t.Assert(err, nil) time.Sleep(100 * time.Millisecond) - gtest.Assert(value, 1) + t.Assert(value, 1) }) } func TestWatcher_AddRemove(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path1 := gfile.TempDir() + gfile.Separator + gconv.String(gtime.TimestampNano()) path2 := gfile.TempDir() + gfile.Separator + gconv.String(gtime.TimestampNano()) + "2" gfile.PutContents(path1, "1") @@ -75,19 +75,19 @@ func TestWatcher_AddRemove(t *testing.T) { return } }) - gtest.Assert(err, nil) - gtest.AssertNE(callback, nil) + t.Assert(err, nil) + t.AssertNE(callback, nil) gfile.PutContents(path1, "2") time.Sleep(100 * time.Millisecond) - gtest.Assert(v.Val(), 2) + t.Assert(v.Val(), 2) gfile.Rename(path1, path2) time.Sleep(100 * time.Millisecond) - gtest.Assert(v.Val(), 3) + t.Assert(v.Val(), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path1 := gfile.TempDir() + gfile.Separator + gconv.String(gtime.TimestampNano()) gfile.PutContents(path1, "1") defer func() { @@ -104,25 +104,25 @@ func TestWatcher_AddRemove(t *testing.T) { return } }) - gtest.Assert(err, nil) - gtest.AssertNE(callback, nil) + t.Assert(err, nil) + t.AssertNE(callback, nil) gfile.PutContents(path1, "2") time.Sleep(100 * time.Millisecond) - gtest.Assert(v.Val(), 2) + t.Assert(v.Val(), 2) gfile.Remove(path1) time.Sleep(100 * time.Millisecond) - gtest.Assert(v.Val(), 4) + t.Assert(v.Val(), 4) gfile.PutContents(path1, "1") time.Sleep(100 * time.Millisecond) - gtest.Assert(v.Val(), 4) + t.Assert(v.Val(), 4) }) } func TestWatcher_Callback(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path1 := gfile.TempDir() + gfile.Separator + gconv.String(gtime.TimestampNano()) gfile.PutContents(path1, "1") defer func() { @@ -135,21 +135,21 @@ func TestWatcher_Callback(t *testing.T) { return } }) - gtest.Assert(err, nil) - gtest.AssertNE(callback, nil) + t.Assert(err, nil) + t.AssertNE(callback, nil) gfile.PutContents(path1, "2") time.Sleep(100 * time.Millisecond) - gtest.Assert(v.Val(), 2) + t.Assert(v.Val(), 2) v.Set(3) gfsnotify.RemoveCallback(callback.Id) gfile.PutContents(path1, "3") time.Sleep(100 * time.Millisecond) - gtest.Assert(v.Val(), 3) + t.Assert(v.Val(), 3) }) // multiple callbacks - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path1 := gfile.TempDir() + gfile.Separator + gconv.String(gtime.TimestampNano()) gfile.PutContents(path1, "1") defer func() { @@ -169,22 +169,22 @@ func TestWatcher_Callback(t *testing.T) { return } }) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.AssertNE(callback1, nil) - gtest.AssertNE(callback2, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.AssertNE(callback1, nil) + t.AssertNE(callback2, nil) gfile.PutContents(path1, "2") time.Sleep(100 * time.Millisecond) - gtest.Assert(v1.Val(), 2) - gtest.Assert(v2.Val(), 2) + t.Assert(v1.Val(), 2) + t.Assert(v2.Val(), 2) v1.Set(3) v2.Set(3) gfsnotify.RemoveCallback(callback1.Id) gfile.PutContents(path1, "3") time.Sleep(100 * time.Millisecond) - gtest.Assert(v1.Val(), 3) - gtest.Assert(v2.Val(), 2) + t.Assert(v1.Val(), 3) + t.Assert(v2.Val(), 2) }) } diff --git a/os/glog/glog_z_unit_basic_test.go b/os/glog/glog_z_unit_basic_test.go index ec26c1cfc..0f126ce69 100644 --- a/os/glog/glog_z_unit_basic_test.go +++ b/os/glog/glog_z_unit_basic_test.go @@ -14,68 +14,68 @@ import ( ) func Test_Print(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { w := bytes.NewBuffer(nil) l := NewWithWriter(w) l.Print(1, 2, 3) l.Println(1, 2, 3) l.Printf("%d %d %d", 1, 2, 3) - gtest.Assert(gstr.Count(w.String(), "["), 0) - gtest.Assert(gstr.Count(w.String(), "1 2 3"), 3) + t.Assert(gstr.Count(w.String(), "["), 0) + t.Assert(gstr.Count(w.String(), "1 2 3"), 3) }) } func Test_Debug(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { w := bytes.NewBuffer(nil) l := NewWithWriter(w) l.Debug(1, 2, 3) l.Debugf("%d %d %d", 1, 2, 3) - gtest.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_DEBU]), 2) - gtest.Assert(gstr.Count(w.String(), "1 2 3"), 2) + t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_DEBU]), 2) + t.Assert(gstr.Count(w.String(), "1 2 3"), 2) }) } func Test_Info(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { w := bytes.NewBuffer(nil) l := NewWithWriter(w) l.Info(1, 2, 3) l.Infof("%d %d %d", 1, 2, 3) - gtest.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_INFO]), 2) - gtest.Assert(gstr.Count(w.String(), "1 2 3"), 2) + t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_INFO]), 2) + t.Assert(gstr.Count(w.String(), "1 2 3"), 2) }) } func Test_Notice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { w := bytes.NewBuffer(nil) l := NewWithWriter(w) l.Notice(1, 2, 3) l.Noticef("%d %d %d", 1, 2, 3) - gtest.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_NOTI]), 2) - gtest.Assert(gstr.Count(w.String(), "1 2 3"), 2) + t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_NOTI]), 2) + t.Assert(gstr.Count(w.String(), "1 2 3"), 2) }) } func Test_Warning(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { w := bytes.NewBuffer(nil) l := NewWithWriter(w) l.Warning(1, 2, 3) l.Warningf("%d %d %d", 1, 2, 3) - gtest.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_WARN]), 2) - gtest.Assert(gstr.Count(w.String(), "1 2 3"), 2) + t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_WARN]), 2) + t.Assert(gstr.Count(w.String(), "1 2 3"), 2) }) } func Test_Error(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { w := bytes.NewBuffer(nil) l := NewWithWriter(w) l.Error(1, 2, 3) l.Errorf("%d %d %d", 1, 2, 3) - gtest.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_ERRO]), 2) - gtest.Assert(gstr.Count(w.String(), "1 2 3"), 2) + t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_ERRO]), 2) + t.Assert(gstr.Count(w.String(), "1 2 3"), 2) }) } diff --git a/os/glog/glog_z_unit_chaining_test.go b/os/glog/glog_z_unit_chaining_test.go index 827f44fbb..961278173 100644 --- a/os/glog/glog_z_unit_chaining_test.go +++ b/os/glog/glog_z_unit_chaining_test.go @@ -18,226 +18,226 @@ import ( ) func Test_To(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { w := bytes.NewBuffer(nil) To(w).Error(1, 2, 3) To(w).Errorf("%d %d %d", 1, 2, 3) - gtest.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_ERRO]), 2) - gtest.Assert(gstr.Count(w.String(), "1 2 3"), 2) + t.Assert(gstr.Count(w.String(), defaultLevelPrefixes[LEVEL_ERRO]), 2) + t.Assert(gstr.Count(w.String(), "1 2 3"), 2) }) } func Test_Path(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Stdout(false).Error(1, 2, 3) Path(path).File(file).Stdout(false).Errorf("%d %d %d", 1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 2) - gtest.Assert(gstr.Count(content, "1 2 3"), 2) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 2) + t.Assert(gstr.Count(content, "1 2 3"), 2) }) } func Test_Cat(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { cat := "category" path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Cat(cat).Stdout(false).Error(1, 2, 3) Path(path).File(file).Cat(cat).Stdout(false).Errorf("%d %d %d", 1, 2, 3) content := gfile.GetContents(gfile.Join(path, cat, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 2) - gtest.Assert(gstr.Count(content, "1 2 3"), 2) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 2) + t.Assert(gstr.Count(content, "1 2 3"), 2) }) } func Test_Level(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Level(LEVEL_PROD).Stdout(false).Debug(1, 2, 3) Path(path).File(file).Level(LEVEL_PROD).Stdout(false).Debug("%d %d %d", 1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 0) - gtest.Assert(gstr.Count(content, "1 2 3"), 0) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 0) + t.Assert(gstr.Count(content, "1 2 3"), 0) }) } func Test_Skip(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Skip(10).Stdout(false).Error(1, 2, 3) Path(path).File(file).Stdout(false).Errorf("%d %d %d", 1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 2) - gtest.Assert(gstr.Count(content, "1 2 3"), 2) - gtest.Assert(gstr.Count(content, "Stack"), 1) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 2) + t.Assert(gstr.Count(content, "1 2 3"), 2) + t.Assert(gstr.Count(content, "Stack"), 1) }) } func Test_Stack(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Stack(false).Stdout(false).Error(1, 2, 3) Path(path).File(file).Stdout(false).Errorf("%d %d %d", 1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 2) - gtest.Assert(gstr.Count(content, "1 2 3"), 2) - gtest.Assert(gstr.Count(content, "Stack"), 1) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 2) + t.Assert(gstr.Count(content, "1 2 3"), 2) + t.Assert(gstr.Count(content, "Stack"), 1) }) } func Test_StackWithFilter(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).StackWithFilter("none").Stdout(false).Error(1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1) - gtest.Assert(gstr.Count(content, "1 2 3"), 1) - gtest.Assert(gstr.Count(content, "Stack"), 1) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1) + t.Assert(gstr.Count(content, "1 2 3"), 1) + t.Assert(gstr.Count(content, "Stack"), 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).StackWithFilter("gogf").Stdout(false).Error(1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1) - gtest.Assert(gstr.Count(content, "1 2 3"), 1) - gtest.Assert(gstr.Count(content, "Stack"), 0) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1) + t.Assert(gstr.Count(content, "1 2 3"), 1) + t.Assert(gstr.Count(content, "Stack"), 0) }) } func Test_Header(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Header(true).Stdout(false).Error(1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1) - gtest.Assert(gstr.Count(content, "1 2 3"), 1) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1) + t.Assert(gstr.Count(content, "1 2 3"), 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Header(false).Stdout(false).Error(1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 0) - gtest.Assert(gstr.Count(content, "1 2 3"), 1) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 0) + t.Assert(gstr.Count(content, "1 2 3"), 1) }) } func Test_Line(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Line(true).Stdout(false).Debug(1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 1) - gtest.Assert(gstr.Count(content, "1 2 3"), 1) - gtest.Assert(gstr.Count(content, ".go"), 1) - gtest.Assert(gstr.Contains(content, gfile.Separator), true) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 1) + t.Assert(gstr.Count(content, "1 2 3"), 1) + t.Assert(gstr.Count(content, ".go"), 1) + t.Assert(gstr.Contains(content, gfile.Separator), true) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Line(false).Stdout(false).Debug(1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 1) - gtest.Assert(gstr.Count(content, "1 2 3"), 1) - gtest.Assert(gstr.Count(content, ".go"), 1) - gtest.Assert(gstr.Contains(content, gfile.Separator), false) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 1) + t.Assert(gstr.Count(content, "1 2 3"), 1) + t.Assert(gstr.Count(content, ".go"), 1) + t.Assert(gstr.Contains(content, gfile.Separator), false) }) } func Test_Async(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Async().Stdout(false).Debug(1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(content, "") + t.Assert(content, "") time.Sleep(200 * time.Millisecond) content = gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 1) - gtest.Assert(gstr.Count(content, "1 2 3"), 1) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 1) + t.Assert(gstr.Count(content, "1 2 3"), 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) err := gfile.Mkdir(path) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(path) Path(path).File(file).Async(false).Stdout(false).Debug(1, 2, 3) content := gfile.GetContents(gfile.Join(path, file)) - gtest.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 1) - gtest.Assert(gstr.Count(content, "1 2 3"), 1) + t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_DEBU]), 1) + t.Assert(gstr.Count(content, "1 2 3"), 1) }) } diff --git a/os/glog/glog_z_unit_config_test.go b/os/glog/glog_z_unit_config_test.go index ad07e819e..d23d1d59c 100644 --- a/os/glog/glog_z_unit_config_test.go +++ b/os/glog/glog_z_unit_config_test.go @@ -12,7 +12,7 @@ import ( ) func Test_SetConfigWithMap(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { l := New() m := map[string]interface{}{ "path": "/var/log", @@ -21,9 +21,9 @@ func Test_SetConfigWithMap(t *testing.T) { "StStatus": 0, } err := l.SetConfigWithMap(m) - gtest.Assert(err, nil) - gtest.Assert(l.config.Path, m["path"]) - gtest.Assert(l.config.Level, m["level"]) - gtest.Assert(l.config.StdoutPrint, m["stdout"]) + t.Assert(err, nil) + t.Assert(l.config.Path, m["path"]) + t.Assert(l.config.Level, m["level"]) + t.Assert(l.config.StdoutPrint, m["stdout"]) }) } diff --git a/os/glog/glog_z_unit_level_test.go b/os/glog/glog_z_unit_level_test.go index 388950519..3ceefaaf2 100644 --- a/os/glog/glog_z_unit_level_test.go +++ b/os/glog/glog_z_unit_level_test.go @@ -14,46 +14,46 @@ import ( ) func Test_LevelPrefix(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { l := New() - gtest.Assert(l.GetLevelPrefix(LEVEL_DEBU), defaultLevelPrefixes[LEVEL_DEBU]) - gtest.Assert(l.GetLevelPrefix(LEVEL_INFO), defaultLevelPrefixes[LEVEL_INFO]) - gtest.Assert(l.GetLevelPrefix(LEVEL_NOTI), defaultLevelPrefixes[LEVEL_NOTI]) - gtest.Assert(l.GetLevelPrefix(LEVEL_WARN), defaultLevelPrefixes[LEVEL_WARN]) - gtest.Assert(l.GetLevelPrefix(LEVEL_ERRO), defaultLevelPrefixes[LEVEL_ERRO]) - gtest.Assert(l.GetLevelPrefix(LEVEL_CRIT), defaultLevelPrefixes[LEVEL_CRIT]) + t.Assert(l.GetLevelPrefix(LEVEL_DEBU), defaultLevelPrefixes[LEVEL_DEBU]) + t.Assert(l.GetLevelPrefix(LEVEL_INFO), defaultLevelPrefixes[LEVEL_INFO]) + t.Assert(l.GetLevelPrefix(LEVEL_NOTI), defaultLevelPrefixes[LEVEL_NOTI]) + t.Assert(l.GetLevelPrefix(LEVEL_WARN), defaultLevelPrefixes[LEVEL_WARN]) + t.Assert(l.GetLevelPrefix(LEVEL_ERRO), defaultLevelPrefixes[LEVEL_ERRO]) + t.Assert(l.GetLevelPrefix(LEVEL_CRIT), defaultLevelPrefixes[LEVEL_CRIT]) l.SetLevelPrefix(LEVEL_DEBU, "debug") - gtest.Assert(l.GetLevelPrefix(LEVEL_DEBU), "debug") + t.Assert(l.GetLevelPrefix(LEVEL_DEBU), "debug") l.SetLevelPrefixes(map[int]string{ LEVEL_CRIT: "critical", }) - gtest.Assert(l.GetLevelPrefix(LEVEL_DEBU), "debug") - gtest.Assert(l.GetLevelPrefix(LEVEL_INFO), defaultLevelPrefixes[LEVEL_INFO]) - gtest.Assert(l.GetLevelPrefix(LEVEL_NOTI), defaultLevelPrefixes[LEVEL_NOTI]) - gtest.Assert(l.GetLevelPrefix(LEVEL_WARN), defaultLevelPrefixes[LEVEL_WARN]) - gtest.Assert(l.GetLevelPrefix(LEVEL_ERRO), defaultLevelPrefixes[LEVEL_ERRO]) - gtest.Assert(l.GetLevelPrefix(LEVEL_CRIT), "critical") + t.Assert(l.GetLevelPrefix(LEVEL_DEBU), "debug") + t.Assert(l.GetLevelPrefix(LEVEL_INFO), defaultLevelPrefixes[LEVEL_INFO]) + t.Assert(l.GetLevelPrefix(LEVEL_NOTI), defaultLevelPrefixes[LEVEL_NOTI]) + t.Assert(l.GetLevelPrefix(LEVEL_WARN), defaultLevelPrefixes[LEVEL_WARN]) + t.Assert(l.GetLevelPrefix(LEVEL_ERRO), defaultLevelPrefixes[LEVEL_ERRO]) + t.Assert(l.GetLevelPrefix(LEVEL_CRIT), "critical") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { buffer := bytes.NewBuffer(nil) l := New() l.SetWriter(buffer) l.Debug("test1") - gtest.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_DEBU]), true) + t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_DEBU]), true) buffer.Reset() l.SetLevelPrefix(LEVEL_DEBU, "debug") l.Debug("test2") - gtest.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_DEBU]), false) - gtest.Assert(gstr.Contains(buffer.String(), "debug"), true) + t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_DEBU]), false) + t.Assert(gstr.Contains(buffer.String(), "debug"), true) buffer.Reset() l.SetLevelPrefixes(map[int]string{ LEVEL_ERRO: "error", }) l.Error("test3") - gtest.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_ERRO]), false) - gtest.Assert(gstr.Contains(buffer.String(), "error"), true) + t.Assert(gstr.Contains(buffer.String(), defaultLevelPrefixes[LEVEL_ERRO]), false) + t.Assert(gstr.Contains(buffer.String(), "error"), true) }) } diff --git a/os/glog/glog_z_unit_rotate_test.go b/os/glog/glog_z_unit_rotate_test.go index 4d51ea816..451cfb414 100644 --- a/os/glog/glog_z_unit_rotate_test.go +++ b/os/glog/glog_z_unit_rotate_test.go @@ -18,7 +18,7 @@ import ( ) func Test_Rotate(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { l := glog.New() p := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err := l.SetConfigWithMap(g.Map{ @@ -31,7 +31,7 @@ func Test_Rotate(t *testing.T) { "RotateCompress": 9, "RotateInterval": time.Second, // For unit testing only. }) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(p) s := "1234567890abcdefg" @@ -42,15 +42,15 @@ func Test_Rotate(t *testing.T) { time.Sleep(time.Second * 3) files, err := gfile.ScanDirFile(p, "*.gz") - gtest.Assert(err, nil) - gtest.Assert(len(files), 2) + t.Assert(err, nil) + t.Assert(len(files), 2) content := gfile.GetContents(gfile.Join(p, "access.log")) - gtest.Assert(gstr.Count(content, s), 1) + t.Assert(gstr.Count(content, s), 1) time.Sleep(time.Second * 4) files, err = gfile.ScanDirFile(p, "*.gz") - gtest.Assert(err, nil) - gtest.Assert(len(files), 0) + t.Assert(err, nil) + t.Assert(len(files), 0) }) } diff --git a/os/gmlock/gmlock_unit_lock_test.go b/os/gmlock/gmlock_unit_lock_test.go index 480ea11b5..afb60d91c 100644 --- a/os/gmlock/gmlock_unit_lock_test.go +++ b/os/gmlock/gmlock_unit_lock_test.go @@ -16,7 +16,7 @@ import ( ) func Test_Locker_Lock(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLock" array := garray.New(true) go func() { @@ -32,15 +32,15 @@ func Test_Locker_Lock(t *testing.T) { gmlock.Unlock(key) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) gmlock.Remove(key) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLock" array := garray.New(true) lock := gmlock.New() @@ -57,18 +57,18 @@ func Test_Locker_Lock(t *testing.T) { lock.Unlock(key) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) lock.Clear() }) } func Test_Locker_TryLock(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testTryLock" array := garray.New(true) go func() { @@ -92,18 +92,18 @@ func Test_Locker_TryLock(t *testing.T) { } }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func Test_Locker_LockFunc(t *testing.T) { //no expire - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockFunc" array := garray.New(true) go func() { @@ -119,16 +119,16 @@ func Test_Locker_LockFunc(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) // + t.Assert(array.Len(), 1) // time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func Test_Locker_TryLockFunc(t *testing.T) { //no expire - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testTryLockFunc" array := garray.New(true) go func() { @@ -150,8 +150,8 @@ func Test_Locker_TryLockFunc(t *testing.T) { }) }() time.Sleep(150 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(400 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } diff --git a/os/gmlock/gmlock_unit_rlock_test.go b/os/gmlock/gmlock_unit_rlock_test.go index 66e60a31a..4d01bc930 100644 --- a/os/gmlock/gmlock_unit_rlock_test.go +++ b/os/gmlock/gmlock_unit_rlock_test.go @@ -17,7 +17,7 @@ import ( func Test_Locker_RLock(t *testing.T) { //RLock before Lock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testRLockBeforeLock" array := garray.New(true) go func() { @@ -33,13 +33,13 @@ func Test_Locker_RLock(t *testing.T) { gmlock.Unlock(key) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) //Lock before RLock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockBeforeRLock" array := garray.New(true) go func() { @@ -55,13 +55,13 @@ func Test_Locker_RLock(t *testing.T) { gmlock.RUnlock(key) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) //Lock before RLocks - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockBeforeRLocks" array := garray.New(true) go func() { @@ -85,15 +85,15 @@ func Test_Locker_RLock(t *testing.T) { gmlock.RUnlock(key) }() time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) }) } func Test_Locker_TryRLock(t *testing.T) { //Lock before TryRLock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockBeforeTryRLock" array := garray.New(true) go func() { @@ -110,13 +110,13 @@ func Test_Locker_TryRLock(t *testing.T) { } }() time.Sleep(150 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) //Lock before TryRLocks - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockBeforeTryRLocks" array := garray.New(true) go func() { @@ -140,15 +140,15 @@ func Test_Locker_TryRLock(t *testing.T) { } }() time.Sleep(150 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func Test_Locker_RLockFunc(t *testing.T) { //RLockFunc before Lock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testRLockFuncBeforeLock" array := garray.New(true) go func() { @@ -164,13 +164,13 @@ func Test_Locker_RLockFunc(t *testing.T) { gmlock.Unlock(key) }() time.Sleep(150 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) //Lock before RLockFunc - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockBeforeRLockFunc" array := garray.New(true) go func() { @@ -186,13 +186,13 @@ func Test_Locker_RLockFunc(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) //Lock before RLockFuncs - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockBeforeRLockFuncs" array := garray.New(true) go func() { @@ -216,15 +216,15 @@ func Test_Locker_RLockFunc(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) }) } func Test_Locker_TryRLockFunc(t *testing.T) { //Lock before TryRLockFunc - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockBeforeTryRLockFunc" array := garray.New(true) go func() { @@ -240,13 +240,13 @@ func Test_Locker_TryRLockFunc(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) //Lock before TryRLockFuncs - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { key := "testLockBeforeTryRLockFuncs" array := garray.New(true) go func() { @@ -268,8 +268,8 @@ func Test_Locker_TryRLockFunc(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } diff --git a/os/gmutex/gmutex_unit_test.go b/os/gmutex/gmutex_unit_test.go index 0560ae117..3afbfea90 100644 --- a/os/gmutex/gmutex_unit_test.go +++ b/os/gmutex/gmutex_unit_test.go @@ -16,7 +16,7 @@ import ( ) func Test_Mutex_RUnlock(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() for index := 0; index < 1000; index++ { go func() { @@ -26,21 +26,21 @@ func Test_Mutex_RUnlock(t *testing.T) { }() } time.Sleep(100 * time.Millisecond) - gtest.Assert(mu.IsRLocked(), true) - gtest.Assert(mu.IsLocked(), true) - gtest.Assert(mu.IsWLocked(), false) + t.Assert(mu.IsRLocked(), true) + t.Assert(mu.IsLocked(), true) + t.Assert(mu.IsWLocked(), false) for index := 0; index < 1000; index++ { go func() { mu.RUnlock() }() } time.Sleep(300 * time.Millisecond) - gtest.Assert(mu.IsRLocked(), false) + t.Assert(mu.IsRLocked(), false) }) //RLock before Lock - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() mu.RLock() go func() { @@ -50,16 +50,16 @@ func Test_Mutex_RUnlock(t *testing.T) { }() time.Sleep(100 * time.Millisecond) mu.RUnlock() - gtest.Assert(mu.IsRLocked(), false) + t.Assert(mu.IsRLocked(), false) time.Sleep(100 * time.Millisecond) - gtest.Assert(mu.IsLocked(), true) + t.Assert(mu.IsLocked(), true) time.Sleep(400 * time.Millisecond) - gtest.Assert(mu.IsLocked(), false) + t.Assert(mu.IsLocked(), false) }) } func Test_Mutex_IsLocked(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() go func() { mu.LockFunc(func() { @@ -67,12 +67,12 @@ func Test_Mutex_IsLocked(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(mu.IsLocked(), true) - gtest.Assert(mu.IsWLocked(), true) - gtest.Assert(mu.IsRLocked(), false) + t.Assert(mu.IsLocked(), true) + t.Assert(mu.IsWLocked(), true) + t.Assert(mu.IsRLocked(), false) time.Sleep(300 * time.Millisecond) - gtest.Assert(mu.IsLocked(), false) - gtest.Assert(mu.IsWLocked(), false) + t.Assert(mu.IsLocked(), false) + t.Assert(mu.IsWLocked(), false) go func() { mu.RLockFunc(func() { @@ -80,16 +80,16 @@ func Test_Mutex_IsLocked(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(mu.IsRLocked(), true) - gtest.Assert(mu.IsLocked(), true) - gtest.Assert(mu.IsWLocked(), false) + t.Assert(mu.IsRLocked(), true) + t.Assert(mu.IsLocked(), true) + t.Assert(mu.IsWLocked(), false) time.Sleep(300 * time.Millisecond) - gtest.Assert(mu.IsRLocked(), false) + t.Assert(mu.IsRLocked(), false) }) } func Test_Mutex_Unlock(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() array := garray.New(true) go func() { @@ -120,14 +120,14 @@ func Test_Mutex_Unlock(t *testing.T) { }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(400 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) }) } func Test_Mutex_LockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() array := garray.New(true) go func() { @@ -143,16 +143,16 @@ func Test_Mutex_LockFunc(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func Test_Mutex_TryLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() array := garray.New(true) go func() { @@ -174,16 +174,16 @@ func Test_Mutex_TryLockFunc(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func Test_Mutex_RLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() array := garray.New(true) go func() { @@ -200,14 +200,14 @@ func Test_Mutex_RLockFunc(t *testing.T) { }) }() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() array := garray.New(true) go func() { @@ -231,14 +231,14 @@ func Test_Mutex_RLockFunc(t *testing.T) { time.Sleep(100 * time.Millisecond) }) }() - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 3) + t.Assert(array.Len(), 3) }) } func Test_Mutex_TryRLockFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { mu := gmutex.New() array := garray.New(true) go func() { @@ -262,12 +262,12 @@ func Test_Mutex_TryRLockFunc(t *testing.T) { }() } time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(150 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(600 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(600 * time.Millisecond) - gtest.Assert(array.Len(), 1001) + t.Assert(array.Len(), 1001) }) } diff --git a/os/gres/gres_unit_1_test.go b/os/gres/gres_unit_1_test.go index dcf554136..bfb36a864 100644 --- a/os/gres/gres_unit_1_test.go +++ b/os/gres/gres_unit_1_test.go @@ -19,72 +19,72 @@ import ( ) func Test_PackToGoFile(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gdebug.CallerDirectory() + "/testdata/files" goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go" pkgName := "testdata" err := gres.PackToGoFile(srcPath, goFilePath, pkgName) - gtest.Assert(err, nil) + t.Assert(err, nil) }) } func Test_Pack(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gdebug.CallerDirectory() + "/testdata/files" data, err := gres.Pack(srcPath) - gtest.Assert(err, nil) + t.Assert(err, nil) r := gres.New() err = r.Add(string(data)) - gtest.Assert(err, nil) - gtest.Assert(r.Contains("files"), true) + t.Assert(err, nil) + t.Assert(r.Contains("files"), true) }) } func Test_PackToFile(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gdebug.CallerDirectory() + "/testdata/files" dstPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) err := gres.PackToFile(srcPath, dstPath) - gtest.Assert(err, nil) + t.Assert(err, nil) defer gfile.Remove(dstPath) r := gres.New() err = r.Load(dstPath) - gtest.Assert(err, nil) - gtest.Assert(r.Contains("files"), true) + t.Assert(err, nil) + t.Assert(r.Contains("files"), true) }) } func Test_PackMulti(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gdebug.CallerDirectory() + "/testdata/files" goFilePath := gdebug.CallerDirectory() + "/testdata/data/data.go" pkgName := "data" array, err := gfile.ScanDir(srcPath, "*", false) - gtest.Assert(err, nil) + t.Assert(err, nil) err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName) - gtest.Assert(err, nil) + t.Assert(err, nil) }) } func Test_PackWithPrefix1(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gdebug.CallerDirectory() + "/testdata/files" goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go" pkgName := "testdata" err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "www/gf-site/test") - gtest.Assert(err, nil) + t.Assert(err, nil) }) } func Test_PackWithPrefix2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { srcPath := gdebug.CallerDirectory() + "/testdata/files" goFilePath := gdebug.CallerDirectory() + "/testdata/testdata.go" pkgName := "testdata" err := gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test") - gtest.Assert(err, nil) + t.Assert(err, nil) }) } diff --git a/os/gres/gres_unit_2_test.go b/os/gres/gres_unit_2_test.go index b1cc7adfa..d4b01bb52 100644 --- a/os/gres/gres_unit_2_test.go +++ b/os/gres/gres_unit_2_test.go @@ -18,125 +18,125 @@ import ( func Test_Basic(t *testing.T) { gres.Dump() - gtest.Case(t, func() { - gtest.Assert(gres.Get("none"), nil) - gtest.Assert(gres.Contains("none"), false) - gtest.Assert(gres.Contains("dir1"), true) + gtest.C(t, func(t *gtest.T) { + t.Assert(gres.Get("none"), nil) + t.Assert(gres.Contains("none"), false) + t.Assert(gres.Contains("dir1"), true) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir1/test1" file := gres.Get(path) - gtest.AssertNE(file, nil) - gtest.Assert(file.Name(), path) + t.AssertNE(file, nil) + t.Assert(file.Name(), path) info := file.FileInfo() - gtest.AssertNE(info, nil) - gtest.Assert(info.IsDir(), false) - gtest.Assert(info.Name(), "test1") + t.AssertNE(info, nil) + t.Assert(info.IsDir(), false) + t.Assert(info.Name(), "test1") rc, err := file.Open() - gtest.Assert(err, nil) + t.Assert(err, nil) defer rc.Close() b := make([]byte, 5) n, err := rc.Read(b) - gtest.Assert(n, 5) - gtest.Assert(err, nil) - gtest.Assert(string(b), "test1") + t.Assert(n, 5) + t.Assert(err, nil) + t.Assert(string(b), "test1") - gtest.Assert(file.Content(), "test1 content") + t.Assert(file.Content(), "test1 content") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir2" file := gres.Get(path) - gtest.AssertNE(file, nil) - gtest.Assert(file.Name(), path) + t.AssertNE(file, nil) + t.Assert(file.Name(), path) info := file.FileInfo() - gtest.AssertNE(info, nil) - gtest.Assert(info.IsDir(), true) - gtest.Assert(info.Name(), "dir2") + t.AssertNE(info, nil) + t.Assert(info.IsDir(), true) + t.Assert(info.Name(), "dir2") rc, err := file.Open() - gtest.Assert(err, nil) + t.Assert(err, nil) defer rc.Close() - gtest.Assert(file.Content(), nil) + t.Assert(file.Content(), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir2/test2" file := gres.Get(path) - gtest.AssertNE(file, nil) - gtest.Assert(file.Name(), path) - gtest.Assert(file.Content(), "test2 content") + t.AssertNE(file, nil) + t.Assert(file.Name(), path) + t.Assert(file.Content(), "test2 content") }) } func Test_Get(t *testing.T) { gres.Dump() - gtest.Case(t, func() { - gtest.AssertNE(gres.Get("dir1/test1"), nil) + gtest.C(t, func(t *gtest.T) { + t.AssertNE(gres.Get("dir1/test1"), nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { file := gres.GetWithIndex("dir1", g.SliceStr{"test1"}) - gtest.AssertNE(file, nil) - gtest.Assert(file.Name(), "dir1/test1") + t.AssertNE(file, nil) + t.Assert(file.Name(), "dir1/test1") }) - gtest.Case(t, func() { - gtest.Assert(gres.GetContent("dir1"), "") - gtest.Assert(gres.GetContent("dir1/test1"), "test1 content") + gtest.C(t, func(t *gtest.T) { + t.Assert(gres.GetContent("dir1"), "") + t.Assert(gres.GetContent("dir1/test1"), "test1 content") }) } func Test_ScanDir(t *testing.T) { gres.Dump() - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir1" files := gres.ScanDir(path, "*", false) - gtest.AssertNE(files, nil) - gtest.Assert(len(files), 2) + t.AssertNE(files, nil) + t.Assert(len(files), 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir1" files := gres.ScanDir(path, "*", true) - gtest.AssertNE(files, nil) - gtest.Assert(len(files), 3) + t.AssertNE(files, nil) + t.Assert(len(files), 3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir1" files := gres.ScanDir(path, "*.*", true) - gtest.AssertNE(files, nil) - gtest.Assert(len(files), 1) - gtest.Assert(files[0].Name(), "dir1/sub/sub-test1.txt") - gtest.Assert(files[0].Content(), "sub-test1 content") + t.AssertNE(files, nil) + t.Assert(len(files), 1) + t.Assert(files[0].Name(), "dir1/sub/sub-test1.txt") + t.Assert(files[0].Content(), "sub-test1 content") }) } func Test_ScanDirFile(t *testing.T) { gres.Dump() - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir2" files := gres.ScanDirFile(path, "*", false) - gtest.AssertNE(files, nil) - gtest.Assert(len(files), 1) + t.AssertNE(files, nil) + t.Assert(len(files), 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir2" files := gres.ScanDirFile(path, "*", true) - gtest.AssertNE(files, nil) - gtest.Assert(len(files), 2) + t.AssertNE(files, nil) + t.Assert(len(files), 2) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { path := "dir2" files := gres.ScanDirFile(path, "*.*", true) - gtest.AssertNE(files, nil) - gtest.Assert(len(files), 1) - gtest.Assert(files[0].Name(), "dir2/sub/sub-test2.txt") - gtest.Assert(files[0].Content(), "sub-test2 content") + t.AssertNE(files, nil) + t.Assert(len(files), 1) + t.Assert(files[0].Name(), "dir2/sub/sub-test2.txt") + t.Assert(files[0].Content(), "sub-test2 content") }) } diff --git a/os/grpool/grpool_unit_test.go b/os/grpool/grpool_unit_test.go index 976a5078c..5aa9bd657 100644 --- a/os/grpool/grpool_unit_test.go +++ b/os/grpool/grpool_unit_test.go @@ -19,7 +19,7 @@ import ( ) func Test_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { wg := sync.WaitGroup{} array := garray.NewArray(true) size := 100 @@ -32,14 +32,14 @@ func Test_Basic(t *testing.T) { } wg.Wait() time.Sleep(100 * time.Millisecond) - gtest.Assert(array.Len(), size) - gtest.Assert(grpool.Jobs(), 0) - gtest.Assert(grpool.Size(), 0) + t.Assert(array.Len(), size) + t.Assert(grpool.Jobs(), 0) + t.Assert(grpool.Size(), 0) }) } func Test_Limit1(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { wg := sync.WaitGroup{} array := garray.NewArray(true) size := 100 @@ -52,12 +52,12 @@ func Test_Limit1(t *testing.T) { }) } wg.Wait() - gtest.Assert(array.Len(), size) + t.Assert(array.Len(), size) }) } func Test_Limit2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { wg := sync.WaitGroup{} array := garray.NewArray(true) size := 100 @@ -70,16 +70,16 @@ func Test_Limit2(t *testing.T) { }) } wg.Wait() - gtest.Assert(array.Len(), size) + t.Assert(array.Len(), size) }) } func Test_Limit3(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.NewArray(true) size := 1000 pool := grpool.New(100) - gtest.Assert(pool.Cap(), 100) + t.Assert(pool.Cap(), 100) for i := 0; i < size; i++ { pool.Add(func() { array.Append(1) @@ -87,16 +87,16 @@ func Test_Limit3(t *testing.T) { }) } time.Sleep(time.Second) - gtest.Assert(pool.Size(), 100) - gtest.Assert(pool.Jobs(), 900) - gtest.Assert(array.Len(), 100) + t.Assert(pool.Size(), 100) + t.Assert(pool.Jobs(), 900) + t.Assert(array.Len(), 100) pool.Close() time.Sleep(2 * time.Second) - gtest.Assert(pool.Size(), 0) - gtest.Assert(pool.Jobs(), 900) - gtest.Assert(array.Len(), 100) - gtest.Assert(pool.IsClosed(), true) - gtest.AssertNE(pool.Add(func() {}), nil) + t.Assert(pool.Size(), 0) + t.Assert(pool.Jobs(), 900) + t.Assert(array.Len(), 100) + t.Assert(pool.IsClosed(), true) + t.AssertNE(pool.Add(func() {}), nil) }) } diff --git a/os/gsession/gsession_unit_storage_file_test.go b/os/gsession/gsession_unit_storage_file_test.go index ede621efe..1efcf3cc4 100644 --- a/os/gsession/gsession_unit_storage_file_test.go +++ b/os/gsession/gsession_unit_storage_file_test.go @@ -19,7 +19,7 @@ func Test_StorageFile(t *testing.T) { storage := gsession.NewStorageFile() manager := gsession.New(time.Second, storage) sessionId := "" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New() defer s.Close() s.Set("k1", "v1") @@ -28,47 +28,47 @@ func Test_StorageFile(t *testing.T) { "k3": "v3", "k4": "v4", }) - gtest.Assert(s.IsDirty(), true) + t.Assert(s.IsDirty(), true) sessionId = s.Id() }) time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Get("k1"), "v1") - gtest.Assert(s.Get("k2"), "v2") - gtest.Assert(s.Get("k3"), "v3") - gtest.Assert(s.Get("k4"), "v4") - gtest.Assert(len(s.Map()), 4) - gtest.Assert(s.Map()["k1"], "v1") - gtest.Assert(s.Map()["k4"], "v4") - gtest.Assert(s.Id(), sessionId) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Contains("k1"), true) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k5"), false) + t.Assert(s.Get("k1"), "v1") + t.Assert(s.Get("k2"), "v2") + t.Assert(s.Get("k3"), "v3") + t.Assert(s.Get("k4"), "v4") + t.Assert(len(s.Map()), 4) + t.Assert(s.Map()["k1"], "v1") + t.Assert(s.Map()["k4"], "v4") + t.Assert(s.Id(), sessionId) + t.Assert(s.Size(), 4) + t.Assert(s.Contains("k1"), true) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k5"), false) s.Remove("k4") - gtest.Assert(s.Size(), 3) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k4"), false) + t.Assert(s.Size(), 3) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k4"), false) s.RemoveAll() - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Contains("k1"), false) - gtest.Assert(s.Contains("k2"), false) + t.Assert(s.Size(), 0) + t.Assert(s.Contains("k1"), false) + t.Assert(s.Contains("k2"), false) s.Sets(g.Map{ "k5": "v5", "k6": "v6", }) - gtest.Assert(s.Size(), 2) - gtest.Assert(s.Contains("k5"), true) - gtest.Assert(s.Contains("k6"), true) + t.Assert(s.Size(), 2) + t.Assert(s.Contains("k5"), true) + t.Assert(s.Contains("k6"), true) }) time.Sleep(1000 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Get("k5"), nil) - gtest.Assert(s.Get("k6"), nil) + t.Assert(s.Size(), 0) + t.Assert(s.Get("k5"), nil) + t.Assert(s.Get("k6"), nil) }) } diff --git a/os/gsession/gsession_unit_storage_memory_test.go b/os/gsession/gsession_unit_storage_memory_test.go index 6fe896594..e551855f0 100644 --- a/os/gsession/gsession_unit_storage_memory_test.go +++ b/os/gsession/gsession_unit_storage_memory_test.go @@ -19,7 +19,7 @@ func Test_StorageMemory(t *testing.T) { storage := gsession.NewStorageMemory() manager := gsession.New(time.Second, storage) sessionId := "" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New() defer s.Close() s.Set("k1", "v1") @@ -28,47 +28,47 @@ func Test_StorageMemory(t *testing.T) { "k3": "v3", "k4": "v4", }) - gtest.Assert(s.IsDirty(), true) + t.Assert(s.IsDirty(), true) sessionId = s.Id() }) time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Get("k1"), "v1") - gtest.Assert(s.Get("k2"), "v2") - gtest.Assert(s.Get("k3"), "v3") - gtest.Assert(s.Get("k4"), "v4") - gtest.Assert(len(s.Map()), 4) - gtest.Assert(s.Map()["k1"], "v1") - gtest.Assert(s.Map()["k4"], "v4") - gtest.Assert(s.Id(), sessionId) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Contains("k1"), true) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k5"), false) + t.Assert(s.Get("k1"), "v1") + t.Assert(s.Get("k2"), "v2") + t.Assert(s.Get("k3"), "v3") + t.Assert(s.Get("k4"), "v4") + t.Assert(len(s.Map()), 4) + t.Assert(s.Map()["k1"], "v1") + t.Assert(s.Map()["k4"], "v4") + t.Assert(s.Id(), sessionId) + t.Assert(s.Size(), 4) + t.Assert(s.Contains("k1"), true) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k5"), false) s.Remove("k4") - gtest.Assert(s.Size(), 3) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k4"), false) + t.Assert(s.Size(), 3) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k4"), false) s.RemoveAll() - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Contains("k1"), false) - gtest.Assert(s.Contains("k2"), false) + t.Assert(s.Size(), 0) + t.Assert(s.Contains("k1"), false) + t.Assert(s.Contains("k2"), false) s.Sets(g.Map{ "k5": "v5", "k6": "v6", }) - gtest.Assert(s.Size(), 2) - gtest.Assert(s.Contains("k5"), true) - gtest.Assert(s.Contains("k6"), true) + t.Assert(s.Size(), 2) + t.Assert(s.Contains("k5"), true) + t.Assert(s.Contains("k6"), true) }) time.Sleep(1000 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Get("k5"), nil) - gtest.Assert(s.Get("k6"), nil) + t.Assert(s.Size(), 0) + t.Assert(s.Get("k5"), nil) + t.Assert(s.Get("k6"), nil) }) } diff --git a/os/gsession/gsession_unit_storage_redis_hashtable_test.go b/os/gsession/gsession_unit_storage_redis_hashtable_test.go index 77b04e221..81c6f140a 100644 --- a/os/gsession/gsession_unit_storage_redis_hashtable_test.go +++ b/os/gsession/gsession_unit_storage_redis_hashtable_test.go @@ -18,12 +18,12 @@ import ( func Test_StorageRedisHashTable(t *testing.T) { redis, err := gredis.NewFromStr("127.0.0.1:6379,0") - gtest.Assert(err, nil) + t.Assert(err, nil) storage := gsession.NewStorageRedisHashTable(redis) manager := gsession.New(time.Second, storage) sessionId := "" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New() defer s.Close() s.Set("k1", "v1") @@ -32,59 +32,59 @@ func Test_StorageRedisHashTable(t *testing.T) { "k3": "v3", "k4": "v4", }) - gtest.Assert(s.IsDirty(), true) + t.Assert(s.IsDirty(), true) sessionId = s.Id() }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Get("k1"), "v1") - gtest.Assert(s.Get("k2"), "v2") - gtest.Assert(s.Get("k3"), "v3") - gtest.Assert(s.Get("k4"), "v4") - gtest.Assert(len(s.Map()), 4) - gtest.Assert(s.Map()["k1"], "v1") - gtest.Assert(s.Map()["k4"], "v4") - gtest.Assert(s.Id(), sessionId) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Contains("k1"), true) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k5"), false) + t.Assert(s.Get("k1"), "v1") + t.Assert(s.Get("k2"), "v2") + t.Assert(s.Get("k3"), "v3") + t.Assert(s.Get("k4"), "v4") + t.Assert(len(s.Map()), 4) + t.Assert(s.Map()["k1"], "v1") + t.Assert(s.Map()["k4"], "v4") + t.Assert(s.Id(), sessionId) + t.Assert(s.Size(), 4) + t.Assert(s.Contains("k1"), true) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k5"), false) s.Remove("k4") - gtest.Assert(s.Size(), 3) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k4"), false) + t.Assert(s.Size(), 3) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k4"), false) s.RemoveAll() - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Contains("k1"), false) - gtest.Assert(s.Contains("k2"), false) + t.Assert(s.Size(), 0) + t.Assert(s.Contains("k1"), false) + t.Assert(s.Contains("k2"), false) s.Sets(g.Map{ "k5": "v5", "k6": "v6", }) - gtest.Assert(s.Size(), 2) - gtest.Assert(s.Contains("k5"), true) - gtest.Assert(s.Contains("k6"), true) + t.Assert(s.Size(), 2) + t.Assert(s.Contains("k5"), true) + t.Assert(s.Contains("k6"), true) s.Close() }) time.Sleep(1500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Get("k5"), nil) - gtest.Assert(s.Get("k6"), nil) + t.Assert(s.Size(), 0) + t.Assert(s.Get("k5"), nil) + t.Assert(s.Get("k6"), nil) }) } func Test_StorageRedisHashTablePrefix(t *testing.T) { redis, err := gredis.NewFromStr("127.0.0.1:6379,0") - gtest.Assert(err, nil) + t.Assert(err, nil) prefix := "s_" storage := gsession.NewStorageRedisHashTable(redis, prefix) manager := gsession.New(time.Second, storage) sessionId := "" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New() defer s.Close() s.Set("k1", "v1") @@ -93,46 +93,46 @@ func Test_StorageRedisHashTablePrefix(t *testing.T) { "k3": "v3", "k4": "v4", }) - gtest.Assert(s.IsDirty(), true) + t.Assert(s.IsDirty(), true) sessionId = s.Id() }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Get("k1"), "v1") - gtest.Assert(s.Get("k2"), "v2") - gtest.Assert(s.Get("k3"), "v3") - gtest.Assert(s.Get("k4"), "v4") - gtest.Assert(len(s.Map()), 4) - gtest.Assert(s.Map()["k1"], "v1") - gtest.Assert(s.Map()["k4"], "v4") - gtest.Assert(s.Id(), sessionId) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Contains("k1"), true) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k5"), false) + t.Assert(s.Get("k1"), "v1") + t.Assert(s.Get("k2"), "v2") + t.Assert(s.Get("k3"), "v3") + t.Assert(s.Get("k4"), "v4") + t.Assert(len(s.Map()), 4) + t.Assert(s.Map()["k1"], "v1") + t.Assert(s.Map()["k4"], "v4") + t.Assert(s.Id(), sessionId) + t.Assert(s.Size(), 4) + t.Assert(s.Contains("k1"), true) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k5"), false) s.Remove("k4") - gtest.Assert(s.Size(), 3) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k4"), false) + t.Assert(s.Size(), 3) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k4"), false) s.RemoveAll() - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Contains("k1"), false) - gtest.Assert(s.Contains("k2"), false) + t.Assert(s.Size(), 0) + t.Assert(s.Contains("k1"), false) + t.Assert(s.Contains("k2"), false) s.Sets(g.Map{ "k5": "v5", "k6": "v6", }) - gtest.Assert(s.Size(), 2) - gtest.Assert(s.Contains("k5"), true) - gtest.Assert(s.Contains("k6"), true) + t.Assert(s.Size(), 2) + t.Assert(s.Contains("k5"), true) + t.Assert(s.Contains("k6"), true) s.Close() }) time.Sleep(1500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Get("k5"), nil) - gtest.Assert(s.Get("k6"), nil) + t.Assert(s.Size(), 0) + t.Assert(s.Get("k5"), nil) + t.Assert(s.Get("k6"), nil) }) } diff --git a/os/gsession/gsession_unit_storage_redis_test.go b/os/gsession/gsession_unit_storage_redis_test.go index 75f48027a..79f1aa61e 100644 --- a/os/gsession/gsession_unit_storage_redis_test.go +++ b/os/gsession/gsession_unit_storage_redis_test.go @@ -18,12 +18,12 @@ import ( func Test_StorageRedis(t *testing.T) { redis, err := gredis.NewFromStr("127.0.0.1:6379,0") - gtest.Assert(err, nil) + t.Assert(err, nil) storage := gsession.NewStorageRedis(redis) manager := gsession.New(time.Second, storage) sessionId := "" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New() defer s.Close() s.Set("k1", "v1") @@ -32,60 +32,60 @@ func Test_StorageRedis(t *testing.T) { "k3": "v3", "k4": "v4", }) - gtest.Assert(s.IsDirty(), true) + t.Assert(s.IsDirty(), true) sessionId = s.Id() }) time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Get("k1"), "v1") - gtest.Assert(s.Get("k2"), "v2") - gtest.Assert(s.Get("k3"), "v3") - gtest.Assert(s.Get("k4"), "v4") - gtest.Assert(len(s.Map()), 4) - gtest.Assert(s.Map()["k1"], "v1") - gtest.Assert(s.Map()["k4"], "v4") - gtest.Assert(s.Id(), sessionId) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Contains("k1"), true) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k5"), false) + t.Assert(s.Get("k1"), "v1") + t.Assert(s.Get("k2"), "v2") + t.Assert(s.Get("k3"), "v3") + t.Assert(s.Get("k4"), "v4") + t.Assert(len(s.Map()), 4) + t.Assert(s.Map()["k1"], "v1") + t.Assert(s.Map()["k4"], "v4") + t.Assert(s.Id(), sessionId) + t.Assert(s.Size(), 4) + t.Assert(s.Contains("k1"), true) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k5"), false) s.Remove("k4") - gtest.Assert(s.Size(), 3) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k4"), false) + t.Assert(s.Size(), 3) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k4"), false) s.RemoveAll() - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Contains("k1"), false) - gtest.Assert(s.Contains("k2"), false) + t.Assert(s.Size(), 0) + t.Assert(s.Contains("k1"), false) + t.Assert(s.Contains("k2"), false) s.Sets(g.Map{ "k5": "v5", "k6": "v6", }) - gtest.Assert(s.Size(), 2) - gtest.Assert(s.Contains("k5"), true) - gtest.Assert(s.Contains("k6"), true) + t.Assert(s.Size(), 2) + t.Assert(s.Contains("k5"), true) + t.Assert(s.Contains("k6"), true) }) time.Sleep(1000 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Get("k5"), nil) - gtest.Assert(s.Get("k6"), nil) + t.Assert(s.Size(), 0) + t.Assert(s.Get("k5"), nil) + t.Assert(s.Get("k6"), nil) }) } func Test_StorageRedisPrefix(t *testing.T) { redis, err := gredis.NewFromStr("127.0.0.1:6379,0") - gtest.Assert(err, nil) + t.Assert(err, nil) prefix := "s_" storage := gsession.NewStorageRedis(redis, prefix) manager := gsession.New(time.Second, storage) sessionId := "" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New() defer s.Close() s.Set("k1", "v1") @@ -94,47 +94,47 @@ func Test_StorageRedisPrefix(t *testing.T) { "k3": "v3", "k4": "v4", }) - gtest.Assert(s.IsDirty(), true) + t.Assert(s.IsDirty(), true) sessionId = s.Id() }) time.Sleep(500 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Get("k1"), "v1") - gtest.Assert(s.Get("k2"), "v2") - gtest.Assert(s.Get("k3"), "v3") - gtest.Assert(s.Get("k4"), "v4") - gtest.Assert(len(s.Map()), 4) - gtest.Assert(s.Map()["k1"], "v1") - gtest.Assert(s.Map()["k4"], "v4") - gtest.Assert(s.Id(), sessionId) - gtest.Assert(s.Size(), 4) - gtest.Assert(s.Contains("k1"), true) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k5"), false) + t.Assert(s.Get("k1"), "v1") + t.Assert(s.Get("k2"), "v2") + t.Assert(s.Get("k3"), "v3") + t.Assert(s.Get("k4"), "v4") + t.Assert(len(s.Map()), 4) + t.Assert(s.Map()["k1"], "v1") + t.Assert(s.Map()["k4"], "v4") + t.Assert(s.Id(), sessionId) + t.Assert(s.Size(), 4) + t.Assert(s.Contains("k1"), true) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k5"), false) s.Remove("k4") - gtest.Assert(s.Size(), 3) - gtest.Assert(s.Contains("k3"), true) - gtest.Assert(s.Contains("k4"), false) + t.Assert(s.Size(), 3) + t.Assert(s.Contains("k3"), true) + t.Assert(s.Contains("k4"), false) s.RemoveAll() - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Contains("k1"), false) - gtest.Assert(s.Contains("k2"), false) + t.Assert(s.Size(), 0) + t.Assert(s.Contains("k1"), false) + t.Assert(s.Contains("k2"), false) s.Sets(g.Map{ "k5": "v5", "k6": "v6", }) - gtest.Assert(s.Size(), 2) - gtest.Assert(s.Contains("k5"), true) - gtest.Assert(s.Contains("k6"), true) + t.Assert(s.Size(), 2) + t.Assert(s.Contains("k5"), true) + t.Assert(s.Contains("k6"), true) }) time.Sleep(1000 * time.Millisecond) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := manager.New(sessionId) - gtest.Assert(s.Size(), 0) - gtest.Assert(s.Get("k5"), nil) - gtest.Assert(s.Get("k6"), nil) + t.Assert(s.Size(), 0) + t.Assert(s.Get("k5"), nil) + t.Assert(s.Get("k6"), nil) }) } diff --git a/os/gsession/gsession_unit_test.go b/os/gsession/gsession_unit_test.go index d90f66f11..57e7c9205 100644 --- a/os/gsession/gsession_unit_test.go +++ b/os/gsession/gsession_unit_test.go @@ -13,10 +13,10 @@ import ( ) func Test_NewSessionId(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { id1 := NewSessionId() id2 := NewSessionId() - gtest.AssertNE(id1, id2) - gtest.Assert(len(id1), 18) + t.AssertNE(id1, id2) + t.Assert(len(id1), 18) }) } diff --git a/os/gspath/gspath_unit_test.go b/os/gspath/gspath_unit_test.go index a12a014c0..74b24b2e1 100644 --- a/os/gspath/gspath_unit_test.go +++ b/os/gspath/gspath_unit_test.go @@ -15,29 +15,29 @@ import ( ) func TestSPath_Api(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { pwd := gfile.Pwd() root := pwd gfile.Create(gfile.Join(root, "gf_tmp", "gf.txt")) defer gfile.Remove(gfile.Join(root, "gf_tmp")) fp, isDir := gspath.Search(root, "gf_tmp") - gtest.Assert(fp, gfile.Join(root, "gf_tmp")) - gtest.Assert(isDir, true) + t.Assert(fp, gfile.Join(root, "gf_tmp")) + t.Assert(isDir, true) fp, isDir = gspath.Search(root, "gf_tmp", "gf.txt") - gtest.Assert(fp, gfile.Join(root, "gf_tmp", "gf.txt")) - gtest.Assert(isDir, false) + t.Assert(fp, gfile.Join(root, "gf_tmp", "gf.txt")) + t.Assert(isDir, false) fp, isDir = gspath.SearchWithCache(root, "gf_tmp") - gtest.Assert(fp, gfile.Join(root, "gf_tmp")) - gtest.Assert(isDir, true) + t.Assert(fp, gfile.Join(root, "gf_tmp")) + t.Assert(isDir, true) fp, isDir = gspath.SearchWithCache(root, "gf_tmp", "gf.txt") - gtest.Assert(fp, gfile.Join(root, "gf_tmp", "gf.txt")) - gtest.Assert(isDir, false) + t.Assert(fp, gfile.Join(root, "gf_tmp", "gf.txt")) + t.Assert(isDir, false) }) } func TestSPath_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { pwd := gfile.Pwd() root := pwd @@ -45,69 +45,69 @@ func TestSPath_Basic(t *testing.T) { defer gfile.Remove(gfile.Join(root, "gf_tmp")) gsp := gspath.New(root, false) realPath, err := gsp.Add(gfile.Join(root, "gf_tmp")) - gtest.Assert(err, nil) - gtest.Assert(realPath, gfile.Join(root, "gf_tmp")) + t.Assert(err, nil) + t.Assert(realPath, gfile.Join(root, "gf_tmp")) realPath, err = gsp.Add("gf_tmp1") - gtest.Assert(err != nil, true) - gtest.Assert(realPath, "") + t.Assert(err != nil, true) + t.Assert(realPath, "") realPath, err = gsp.Add(gfile.Join(root, "gf_tmp", "gf.txt")) - gtest.Assert(err != nil, true) - gtest.Assert(realPath, "") + t.Assert(err != nil, true) + t.Assert(realPath, "") gsp.Remove("gf_tmp1") - gtest.Assert(gsp.Size(), 2) - gtest.Assert(len(gsp.Paths()), 2) - gtest.Assert(len(gsp.AllPaths()), 0) + t.Assert(gsp.Size(), 2) + t.Assert(len(gsp.Paths()), 2) + t.Assert(len(gsp.AllPaths()), 0) realPath, err = gsp.Set(gfile.Join(root, "gf_tmp1")) - gtest.Assert(err != nil, true) - gtest.Assert(realPath, "") + t.Assert(err != nil, true) + t.Assert(realPath, "") realPath, err = gsp.Set(gfile.Join(root, "gf_tmp", "gf.txt")) - gtest.AssertNE(err, nil) - gtest.Assert(realPath, "") + t.AssertNE(err, nil) + t.Assert(realPath, "") realPath, err = gsp.Set(root) - gtest.Assert(err, nil) - gtest.Assert(realPath, root) + t.Assert(err, nil) + t.Assert(realPath, root) fp, isDir := gsp.Search("gf_tmp") - gtest.Assert(fp, gfile.Join(root, "gf_tmp")) - gtest.Assert(isDir, true) + t.Assert(fp, gfile.Join(root, "gf_tmp")) + t.Assert(isDir, true) fp, isDir = gsp.Search("gf_tmp", "gf.txt") - gtest.Assert(fp, gfile.Join(root, "gf_tmp", "gf.txt")) - gtest.Assert(isDir, false) + t.Assert(fp, gfile.Join(root, "gf_tmp", "gf.txt")) + t.Assert(isDir, false) fp, isDir = gsp.Search("/", "gf.txt") - gtest.Assert(fp, root) - gtest.Assert(isDir, true) + t.Assert(fp, root) + t.Assert(isDir, true) gsp = gspath.New(root, true) realPath, err = gsp.Add(gfile.Join(root, "gf_tmp")) - gtest.Assert(err, nil) - gtest.Assert(realPath, gfile.Join(root, "gf_tmp")) + t.Assert(err, nil) + t.Assert(realPath, gfile.Join(root, "gf_tmp")) gfile.Mkdir(gfile.Join(root, "gf_tmp1")) gfile.Rename(gfile.Join(root, "gf_tmp1"), gfile.Join(root, "gf_tmp2")) gfile.Rename(gfile.Join(root, "gf_tmp2"), gfile.Join(root, "gf_tmp1")) defer gfile.Remove(gfile.Join(root, "gf_tmp1")) realPath, err = gsp.Add("gf_tmp1") - gtest.Assert(err != nil, false) - gtest.Assert(realPath, gfile.Join(root, "gf_tmp1")) + t.Assert(err != nil, false) + t.Assert(realPath, gfile.Join(root, "gf_tmp1")) realPath, err = gsp.Add("gf_tmp3") - gtest.Assert(err != nil, true) - gtest.Assert(realPath, "") + t.Assert(err != nil, true) + t.Assert(realPath, "") gsp.Remove(gfile.Join(root, "gf_tmp")) gsp.Remove(gfile.Join(root, "gf_tmp1")) gsp.Remove(gfile.Join(root, "gf_tmp3")) - gtest.Assert(gsp.Size(), 3) - gtest.Assert(len(gsp.Paths()), 3) + t.Assert(gsp.Size(), 3) + t.Assert(len(gsp.Paths()), 3) gsp.AllPaths() gsp.Set(root) fp, isDir = gsp.Search("gf_tmp") - gtest.Assert(fp, gfile.Join(root, "gf_tmp")) - gtest.Assert(isDir, true) + t.Assert(fp, gfile.Join(root, "gf_tmp")) + t.Assert(isDir, true) fp, isDir = gsp.Search("gf_tmp", "gf.txt") - gtest.Assert(fp, gfile.Join(root, "gf_tmp", "gf.txt")) - gtest.Assert(isDir, false) + t.Assert(fp, gfile.Join(root, "gf_tmp", "gf.txt")) + t.Assert(isDir, false) fp, isDir = gsp.Search("/", "gf.txt") - gtest.Assert(fp, pwd) - gtest.Assert(isDir, true) + t.Assert(fp, pwd) + t.Assert(isDir, true) }) } diff --git a/os/gtime/gtime_z_unit_basic_test.go b/os/gtime/gtime_z_unit_basic_test.go index 47c97773d..4b17b3065 100644 --- a/os/gtime/gtime_z_unit_basic_test.go +++ b/os/gtime/gtime_z_unit_basic_test.go @@ -15,77 +15,77 @@ import ( ) func Test_SetTimeZone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gtime.SetTimeZone("Asia/Shanghai") - gtest.Assert(time.Local.String(), "Asia/Shanghai") + t.Assert(time.Local.String(), "Asia/Shanghai") }) } func Test_Nanosecond(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { nanos := gtime.TimestampNano() timeTemp := time.Unix(0, nanos) - gtest.Assert(nanos, timeTemp.UnixNano()) + t.Assert(nanos, timeTemp.UnixNano()) }) } func Test_Microsecond(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { micros := gtime.TimestampMicro() timeTemp := time.Unix(0, micros*1e3) - gtest.Assert(micros, timeTemp.UnixNano()/1e3) + t.Assert(micros, timeTemp.UnixNano()/1e3) }) } func Test_Millisecond(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { millis := gtime.TimestampMilli() timeTemp := time.Unix(0, millis*1e6) - gtest.Assert(millis, timeTemp.UnixNano()/1e6) + t.Assert(millis, timeTemp.UnixNano()/1e6) }) } func Test_Second(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := gtime.Timestamp() timeTemp := time.Unix(s, 0) - gtest.Assert(s, timeTemp.Unix()) + t.Assert(s, timeTemp.Unix()) }) } func Test_Date(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gtime.Date(), time.Now().Format("2006-01-02")) + gtest.C(t, func(t *gtest.T) { + t.Assert(gtime.Date(), time.Now().Format("2006-01-02")) }) } func Test_Datetime(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { datetime := gtime.Datetime() timeTemp, err := gtime.StrToTime(datetime, "Y-m-d H:i:s") if err != nil { t.Error("test fail") } - gtest.Assert(datetime, timeTemp.Time.Format("2006-01-02 15:04:05")) + t.Assert(datetime, timeTemp.Time.Format("2006-01-02 15:04:05")) }) } func Test_ISO8601(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { iso8601 := gtime.ISO8601() - gtest.Assert(iso8601, gtime.Now().Format("c")) + t.Assert(iso8601, gtime.Now().Format("c")) }) } func Test_RFC822(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rfc822 := gtime.RFC822() - gtest.Assert(rfc822, gtime.Now().Format("r")) + t.Assert(rfc822, gtime.Now().Format("r")) }) } func Test_StrToTime(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //正常日期列表 //正则的原因,日期"06.01.02","2006.01","2006..01"无法覆盖gtime.go的百分百 var testDatetimes = []string{ @@ -108,7 +108,7 @@ func Test_StrToTime(t *testing.T) { if err != nil { t.Error("test fail") } - gtest.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") + t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") } //正常日期列表,时间00:00:00 @@ -123,7 +123,7 @@ func Test_StrToTime(t *testing.T) { if err != nil { t.Error("test fail") } - gtest.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 00:00:00") + t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 00:00:00") } //测试格式化formatToStdLayout @@ -148,7 +148,7 @@ func Test_StrToTime(t *testing.T) { if err != nil { t.Error("test fail") } - gtest.Assert(timeTemp.Time.Format("2006-01-02 15:04:05.000"), "2007-01-02 15:04:05.000") + t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05.000"), "2007-01-02 15:04:05.000") } //异常日期列表 @@ -174,7 +174,7 @@ func Test_StrToTime(t *testing.T) { } func Test_ConvertZone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //现行时间 nowUTC := time.Now().UTC() testZone := "America/Los_Angeles" @@ -191,12 +191,12 @@ func Test_ConvertZone(t *testing.T) { t2, err := time.ParseInLocation("2006-01-02 15:04:05", laStr, loc) //判断是否与现行时间匹配 - gtest.Assert(t2.UTC().Unix(), nowUTC.Unix()) + t.Assert(t2.UTC().Unix(), nowUTC.Unix()) }) //test err - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { //现行时间 nowUTC := time.Now().UTC() //t.Log(nowUTC.Unix()) @@ -221,21 +221,21 @@ func Test_ConvertZone(t *testing.T) { } func Test_StrToTimeFormat(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { }) } func Test_ParseTimeFromContent(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.ParseTimeFromContent("我是中文2006-01-02 15:04:05我也是中文", "Y-m-d H:i:s") - gtest.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") + t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") timeTemp1 := gtime.ParseTimeFromContent("我是中文2006-01-02 15:04:05我也是中文") - gtest.Assert(timeTemp1.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") + t.Assert(timeTemp1.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") timeTemp2 := gtime.ParseTimeFromContent("我是中文02.jan.2006 15:04:05我也是中文") - gtest.Assert(timeTemp2.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") + t.Assert(timeTemp2.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") //test err timeTempErr := gtime.ParseTimeFromContent("我是中文", "Y-m-d H:i:s") @@ -246,7 +246,7 @@ func Test_ParseTimeFromContent(t *testing.T) { } func Test_FuncCost(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gtime.FuncCost(func() { }) diff --git a/os/gtime/gtime_z_unit_format_test.go b/os/gtime/gtime_z_unit_format_test.go index 743aead20..80beae8a5 100644 --- a/os/gtime/gtime_z_unit_format_test.go +++ b/os/gtime/gtime_z_unit_format_test.go @@ -14,42 +14,42 @@ import ( ) func Test_Format(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp, err := gtime.StrToTime("2006-01-11 15:04:05", "Y-m-d H:i:s") timeTemp.ToZone("Asia/Shanghai") if err != nil { t.Error("test fail") } - gtest.Assert(timeTemp.Format("\\T\\i\\m\\e中文Y-m-j G:i:s.u\\"), "Time中文2006-01-11 15:04:05.000") + t.Assert(timeTemp.Format("\\T\\i\\m\\e中文Y-m-j G:i:s.u\\"), "Time中文2006-01-11 15:04:05.000") - gtest.Assert(timeTemp.Format("d D j l"), "11 Wed 11 Wednesday") + t.Assert(timeTemp.Format("d D j l"), "11 Wed 11 Wednesday") - gtest.Assert(timeTemp.Format("F m M n"), "January 01 Jan 1") + t.Assert(timeTemp.Format("F m M n"), "January 01 Jan 1") - gtest.Assert(timeTemp.Format("Y y"), "2006 06") + t.Assert(timeTemp.Format("Y y"), "2006 06") - gtest.Assert(timeTemp.Format("a A g G h H i s u .u"), "pm PM 3 15 03 15 04 05 000 .000") + t.Assert(timeTemp.Format("a A g G h H i s u .u"), "pm PM 3 15 03 15 04 05 000 .000") - gtest.Assert(timeTemp.Format("O P T"), "+0800 +08:00 CST") + t.Assert(timeTemp.Format("O P T"), "+0800 +08:00 CST") - gtest.Assert(timeTemp.Format("r"), "Wed, 11 Jan 06 15:04 CST") + t.Assert(timeTemp.Format("r"), "Wed, 11 Jan 06 15:04 CST") - gtest.Assert(timeTemp.Format("c"), "2006-01-11T15:04:05+08:00") + t.Assert(timeTemp.Format("c"), "2006-01-11T15:04:05+08:00") //补零 timeTemp1, err := gtime.StrToTime("2006-01-02 03:04:05", "Y-m-d H:i:s") if err != nil { t.Error("test fail") } - gtest.Assert(timeTemp1.Format("Y-m-d h:i:s"), "2006-01-02 03:04:05") + t.Assert(timeTemp1.Format("Y-m-d h:i:s"), "2006-01-02 03:04:05") //不补零 timeTemp2, err := gtime.StrToTime("2006-01-02 03:04:05", "Y-m-d H:i:s") if err != nil { t.Error("test fail") } - gtest.Assert(timeTemp2.Format("Y-n-j G:i:s"), "2006-1-2 3:04:05") + t.Assert(timeTemp2.Format("Y-n-j G:i:s"), "2006-1-2 3:04:05") - gtest.Assert(timeTemp2.Format("U"), "1136142245") + t.Assert(timeTemp2.Format("U"), "1136142245") // 测试数字型的星期 times := []map[string]string{ @@ -87,38 +87,38 @@ func Test_Format(t *testing.T) { for _, v := range times { t1, err1 := gtime.StrToTime(v["k"], "Y-m-d") - gtest.Assert(err1, nil) - gtest.Assert(t1.Format(v["f"]), v["r"]) + t.Assert(err1, nil) + t.Assert(t1.Format(v["f"]), v["r"]) } }) } func Test_Format_ZeroString(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp, err := gtime.StrToTime("0000-00-00 00:00:00") - gtest.AssertNE(err, nil) - gtest.Assert(timeTemp.String(), "") + t.AssertNE(err, nil) + t.Assert(timeTemp.String(), "") }) } func Test_FormatTo(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() - gtest.Assert(timeTemp.FormatTo("Y-m-01 00:00:01"), timeTemp.Time.Format("2006-01")+"-01 00:00:01") + t.Assert(timeTemp.FormatTo("Y-m-01 00:00:01"), timeTemp.Time.Format("2006-01")+"-01 00:00:01") }) } func Test_Layout(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() - gtest.Assert(timeTemp.Layout("2006-01-02 15:04:05"), timeTemp.Time.Format("2006-01-02 15:04:05")) + t.Assert(timeTemp.Layout("2006-01-02 15:04:05"), timeTemp.Time.Format("2006-01-02 15:04:05")) }) } func Test_LayoutTo(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() - gtest.Assert(timeTemp.LayoutTo("2006-01-02 00:00:00"), timeTemp.Time.Format("2006-01-02 00:00:00")) + t.Assert(timeTemp.LayoutTo("2006-01-02 00:00:00"), timeTemp.Time.Format("2006-01-02 00:00:00")) }) } diff --git a/os/gtime/gtime_z_unit_json_test.go b/os/gtime/gtime_z_unit_json_test.go index 9164a2398..39c0bde61 100644 --- a/os/gtime/gtime_z_unit_json_test.go +++ b/os/gtime/gtime_z_unit_json_test.go @@ -15,7 +15,7 @@ import ( func Test_Json_Pointer(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type T struct { Time *gtime.Time } @@ -23,42 +23,42 @@ func Test_Json_Pointer(t *testing.T) { s := "2006-01-02 15:04:05" t.Time = gtime.NewFromStr(s) j, err := json.Marshal(t) - gtest.Assert(err, nil) - gtest.Assert(j, `{"Time":"2006-01-02 15:04:05"}`) + t.Assert(err, nil) + t.Assert(j, `{"Time":"2006-01-02 15:04:05"}`) }) // Marshal nil - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type T struct { Time *gtime.Time } t := new(T) j, err := json.Marshal(t) - gtest.Assert(err, nil) - gtest.Assert(j, `{"Time":null}`) + t.Assert(err, nil) + t.Assert(j, `{"Time":null}`) }) // Marshal nil omitempty - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type T struct { Time *gtime.Time `json:"time,omitempty"` } t := new(T) j, err := json.Marshal(t) - gtest.Assert(err, nil) - gtest.Assert(j, `{}`) + t.Assert(err, nil) + t.Assert(j, `{}`) }) // Unmarshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t gtime.Time s := []byte(`"2006-01-02 15:04:05"`) err := json.Unmarshal(s, &t) - gtest.Assert(err, nil) - gtest.Assert(t.String(), "2006-01-02 15:04:05") + t.Assert(err, nil) + t.Assert(t.String(), "2006-01-02 15:04:05") }) } func Test_Json_Struct(t *testing.T) { // Marshal - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type T struct { Time gtime.Time } @@ -66,28 +66,28 @@ func Test_Json_Struct(t *testing.T) { s := "2006-01-02 15:04:05" t.Time = *gtime.NewFromStr(s) j, err := json.Marshal(t) - gtest.Assert(err, nil) - gtest.Assert(j, `{"Time":"2006-01-02 15:04:05"}`) + t.Assert(err, nil) + t.Assert(j, `{"Time":"2006-01-02 15:04:05"}`) }) // Marshal nil - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type T struct { Time gtime.Time } t := new(T) j, err := json.Marshal(t) - gtest.Assert(err, nil) - gtest.Assert(j, `{"Time":""}`) + t.Assert(err, nil) + t.Assert(j, `{"Time":""}`) }) // Marshal nil omitempty - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type T struct { Time gtime.Time `json:"time,omitempty"` } t := new(T) j, err := json.Marshal(t) - gtest.Assert(err, nil) - gtest.Assert(j, `{"time":""}`) + t.Assert(err, nil) + t.Assert(j, `{"time":""}`) }) } diff --git a/os/gtime/gtime_z_unit_time_test.go b/os/gtime/gtime_z_unit_time_test.go index c42d0e8dd..405e84d18 100644 --- a/os/gtime/gtime_z_unit_time_test.go +++ b/os/gtime/gtime_z_unit_time_test.go @@ -16,31 +16,31 @@ import ( ) func Test_New(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeNow := time.Now() timeTemp := gtime.New(timeNow) - gtest.Assert(timeTemp.Time.UnixNano(), timeNow.UnixNano()) + t.Assert(timeTemp.Time.UnixNano(), timeNow.UnixNano()) timeTemp1 := gtime.New() - gtest.Assert(timeTemp1.Time, time.Time{}) + t.Assert(timeTemp1.Time, time.Time{}) }) } func Test_Nil(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t *gtime.Time - gtest.Assert(t.String(), "") + t.Assert(t.String(), "") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var t gtime.Time - gtest.Assert(t.String(), "") + t.Assert(t.String(), "") }) } func Test_NewFromStr(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.NewFromStr("2006-01-02 15:04:05") - gtest.Assert(timeTemp.Format("Y-m-d H:i:s"), "2006-01-02 15:04:05") + t.Assert(timeTemp.Format("Y-m-d H:i:s"), "2006-01-02 15:04:05") timeTemp1 := gtime.NewFromStr("20060102") if timeTemp1 != nil { @@ -50,21 +50,21 @@ func Test_NewFromStr(t *testing.T) { } func Test_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { t1 := gtime.NewFromStr("2006-01-02 15:04:05") - gtest.Assert(t1.String(), "2006-01-02 15:04:05") - gtest.Assert(fmt.Sprintf("%s", t1), "2006-01-02 15:04:05") + t.Assert(t1.String(), "2006-01-02 15:04:05") + t.Assert(fmt.Sprintf("%s", t1), "2006-01-02 15:04:05") t2 := *t1 - gtest.Assert(t2.String(), "2006-01-02 15:04:05") - gtest.Assert(fmt.Sprintf("%s", t2), "{2006-01-02 15:04:05}") + t.Assert(t2.String(), "2006-01-02 15:04:05") + t.Assert(fmt.Sprintf("%s", t2), "{2006-01-02 15:04:05}") }) } func Test_NewFromStrFormat(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.NewFromStrFormat("2006-01-02 15:04:05", "Y-m-d H:i:s") - gtest.Assert(timeTemp.Format("Y-m-d H:i:s"), "2006-01-02 15:04:05") + t.Assert(timeTemp.Format("Y-m-d H:i:s"), "2006-01-02 15:04:05") timeTemp1 := gtime.NewFromStrFormat("2006-01-02 15:04:05", "aabbcc") if timeTemp1 != nil { @@ -72,19 +72,19 @@ func Test_NewFromStrFormat(t *testing.T) { } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { t1 := gtime.NewFromStrFormat("2019/2/1", "Y/n/j") - gtest.Assert(t1.Format("Y-m-d"), "2019-02-01") + t.Assert(t1.Format("Y-m-d"), "2019-02-01") t2 := gtime.NewFromStrFormat("2019/10/12", "Y/n/j") - gtest.Assert(t2.Format("Y-m-d"), "2019-10-12") + t.Assert(t2.Format("Y-m-d"), "2019-10-12") }) } func Test_NewFromStrLayout(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.NewFromStrLayout("2006-01-02 15:04:05", "2006-01-02 15:04:05") - gtest.Assert(timeTemp.Format("Y-m-d H:i:s"), "2006-01-02 15:04:05") + t.Assert(timeTemp.Format("Y-m-d H:i:s"), "2006-01-02 15:04:05") timeTemp1 := gtime.NewFromStrLayout("2006-01-02 15:04:05", "aabbcc") if timeTemp1 != nil { @@ -94,100 +94,100 @@ func Test_NewFromStrLayout(t *testing.T) { } func Test_NewFromTimeStamp(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.NewFromTimeStamp(1554459846000) - gtest.Assert(timeTemp.Format("Y-m-d H:i:s"), "2019-04-05 18:24:06") + t.Assert(timeTemp.Format("Y-m-d H:i:s"), "2019-04-05 18:24:06") timeTemp1 := gtime.NewFromTimeStamp(0) - gtest.Assert(timeTemp1.Format("Y-m-d H:i:s"), "0001-01-01 00:00:00") + t.Assert(timeTemp1.Format("Y-m-d H:i:s"), "0001-01-01 00:00:00") }) } func Test_Time_Second(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() - gtest.Assert(timeTemp.Second(), timeTemp.Time.Second()) + t.Assert(timeTemp.Second(), timeTemp.Time.Second()) }) } func Test_Time_Nanosecond(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() - gtest.Assert(timeTemp.Nanosecond(), timeTemp.Time.Nanosecond()) + t.Assert(timeTemp.Nanosecond(), timeTemp.Time.Nanosecond()) }) } func Test_Time_Microsecond(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() - gtest.Assert(timeTemp.Microsecond(), timeTemp.Time.Nanosecond()/1e3) + t.Assert(timeTemp.Microsecond(), timeTemp.Time.Nanosecond()/1e3) }) } func Test_Time_Millisecond(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() - gtest.Assert(timeTemp.Millisecond(), timeTemp.Time.Nanosecond()/1e6) + t.Assert(timeTemp.Millisecond(), timeTemp.Time.Nanosecond()/1e6) }) } func Test_Time_String(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() - gtest.Assert(timeTemp.String(), timeTemp.Time.Format("2006-01-02 15:04:05")) + t.Assert(timeTemp.String(), timeTemp.Time.Format("2006-01-02 15:04:05")) }) } func Test_Time_ISO8601(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { now := gtime.Now() - gtest.Assert(now.ISO8601(), now.Format("c")) + t.Assert(now.ISO8601(), now.Format("c")) }) } func Test_Time_RFC822(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { now := gtime.Now() - gtest.Assert(now.RFC822(), now.Format("r")) + t.Assert(now.RFC822(), now.Format("r")) }) } func Test_Clone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() timeTemp1 := timeTemp.Clone() - gtest.Assert(timeTemp.Time.Unix(), timeTemp1.Time.Unix()) + t.Assert(timeTemp.Time.Unix(), timeTemp1.Time.Unix()) }) } func Test_ToTime(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() timeTemp1 := timeTemp.Time - gtest.Assert(timeTemp.Time.UnixNano(), timeTemp1.UnixNano()) + t.Assert(timeTemp.Time.UnixNano(), timeTemp1.UnixNano()) }) } func Test_Add(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.NewFromStr("2006-01-02 15:04:05") timeTemp.Add(time.Second) - gtest.Assert(timeTemp.Format("Y-m-d H:i:s"), "2006-01-02 15:04:06") + t.Assert(timeTemp.Format("Y-m-d H:i:s"), "2006-01-02 15:04:06") }) } func Test_ToZone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() // timeTemp.ToZone("America/Los_Angeles") - gtest.Assert(timeTemp.Time.Location().String(), "America/Los_Angeles") + t.Assert(timeTemp.Time.Location().String(), "America/Los_Angeles") loc, err := time.LoadLocation("Asia/Shanghai") if err != nil { t.Error("test fail") } timeTemp.ToLocation(loc) - gtest.Assert(timeTemp.Time.Location().String(), "Asia/Shanghai") + t.Assert(timeTemp.Time.Location().String(), "Asia/Shanghai") timeTemp1, _ := timeTemp.ToZone("errZone") if timeTemp1 != nil { @@ -197,45 +197,45 @@ func Test_ToZone(t *testing.T) { } func Test_AddDate(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.NewFromStr("2006-01-02 15:04:05") timeTemp.AddDate(1, 2, 3) - gtest.Assert(timeTemp.Format("Y-m-d H:i:s"), "2007-03-05 15:04:05") + t.Assert(timeTemp.Format("Y-m-d H:i:s"), "2007-03-05 15:04:05") }) } func Test_UTC(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() timeTemp1 := timeTemp.Time timeTemp.UTC() - gtest.Assert(timeTemp.UnixNano(), timeTemp1.UTC().UnixNano()) + t.Assert(timeTemp.UnixNano(), timeTemp1.UTC().UnixNano()) }) } func Test_Local(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() timeTemp1 := timeTemp.Time timeTemp.Local() - gtest.Assert(timeTemp.UnixNano(), timeTemp1.Local().UnixNano()) + t.Assert(timeTemp.UnixNano(), timeTemp1.Local().UnixNano()) }) } func Test_Round(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() timeTemp1 := timeTemp.Time timeTemp.Round(time.Hour) - gtest.Assert(timeTemp.UnixNano(), timeTemp1.Round(time.Hour).UnixNano()) + t.Assert(timeTemp.UnixNano(), timeTemp1.Round(time.Hour).UnixNano()) }) } func Test_Truncate(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timeTemp := gtime.Now() timeTemp1 := timeTemp.Time timeTemp.Truncate(time.Hour) - gtest.Assert(timeTemp.UnixNano(), timeTemp1.Truncate(time.Hour).UnixNano()) + t.Assert(timeTemp.UnixNano(), timeTemp1.Truncate(time.Hour).UnixNano()) }) } diff --git a/os/gtimer/gtimer_z_unit_0_test.go b/os/gtimer/gtimer_z_unit_0_test.go index ae5c33072..b8615d731 100644 --- a/os/gtimer/gtimer_z_unit_0_test.go +++ b/os/gtimer/gtimer_z_unit_0_test.go @@ -18,123 +18,123 @@ import ( ) func TestSetTimeout(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.SetTimeout(200*time.Millisecond, func() { array.Append(1) }) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestSetInterval(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.SetInterval(200*time.Millisecond, func() { array.Append(1) }) time.Sleep(1100 * time.Millisecond) - gtest.Assert(array.Len(), 5) + t.Assert(array.Len(), 5) }) } func TestAddEntry(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.AddEntry(200*time.Millisecond, func() { array.Append(1) }, false, 2, gtimer.STATUS_READY) time.Sleep(1100 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func TestAddSingleton(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.AddSingleton(200*time.Millisecond, func() { array.Append(1) time.Sleep(10000 * time.Millisecond) }) time.Sleep(1100 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestAddTimes(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.AddTimes(200*time.Millisecond, 2, func() { array.Append(1) }) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func TestDelayAdd(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.DelayAdd(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestDelayAddEntry(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.DelayAddEntry(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }, false, 2, gtimer.STATUS_READY) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func TestDelayAddSingleton(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.DelayAddSingleton(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) time.Sleep(10000 * time.Millisecond) }) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestDelayAddOnce(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.DelayAddOnce(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestDelayAddTimes(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { array := garray.New(true) gtimer.DelayAddTimes(200*time.Millisecond, 200*time.Millisecond, 2, func() { array.Append(1) }) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } diff --git a/os/gtimer/gtimer_z_unit_1_test.go b/os/gtimer/gtimer_z_unit_1_test.go index e9a158032..1aadd161e 100644 --- a/os/gtimer/gtimer_z_unit_1_test.go +++ b/os/gtimer/gtimer_z_unit_1_test.go @@ -22,7 +22,7 @@ func New() *gtimer.Timer { } func TestTimer_Add_Close(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) //fmt.Println("start", time.Now()) @@ -39,42 +39,42 @@ func TestTimer_Add_Close(t *testing.T) { array.Append(1) }) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 5) + t.Assert(array.Len(), 5) timer.Close() time.Sleep(250 * time.Millisecond) fixedLength := array.Len() time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), fixedLength) + t.Assert(array.Len(), fixedLength) }) } func TestTimer_Start_Stop_Close(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.Add(200*time.Millisecond, func() { //glog.Println("add...") array.Append(1) }) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(300 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) timer.Stop() time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) timer.Start() time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) timer.Close() time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func TestTimer_AddSingleton(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.AddSingleton(200*time.Millisecond, func() { @@ -82,15 +82,15 @@ func TestTimer_AddSingleton(t *testing.T) { time.Sleep(10 * time.Second) }) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(500 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestTimer_AddOnce(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.AddOnce(200*time.Millisecond, func() { @@ -100,59 +100,59 @@ func TestTimer_AddOnce(t *testing.T) { array.Append(1) }) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) timer.Close() time.Sleep(250 * time.Millisecond) fixedLength := array.Len() time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), fixedLength) + t.Assert(array.Len(), fixedLength) }) } func TestTimer_AddTimes(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.AddTimes(200*time.Millisecond, 2, func() { array.Append(1) }) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func TestTimer_DelayAdd(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.DelayAdd(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestTimer_DelayAddEntry(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.DelayAddEntry(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }, false, 100, gtimer.STATUS_READY) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestTimer_DelayAddSingleton(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.DelayAddSingleton(200*time.Millisecond, 200*time.Millisecond, func() { @@ -160,72 +160,72 @@ func TestTimer_DelayAddSingleton(t *testing.T) { time.Sleep(10 * time.Second) }) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestTimer_DelayAddOnce(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.DelayAddOnce(200*time.Millisecond, 200*time.Millisecond, func() { array.Append(1) }) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(500 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestTimer_DelayAddTimes(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.DelayAddTimes(200*time.Millisecond, 500*time.Millisecond, 2, func() { array.Append(1) }) time.Sleep(200 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(600 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(600 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func TestTimer_AddLessThanInterval(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := gtimer.New(10, 100*time.Millisecond) array := garray.New(true) timer.Add(20*time.Millisecond, func() { array.Append(1) }) time.Sleep(50 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(110 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(110 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) }) } func TestTimer_AddLeveledEntry1(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) //glog.Println("start") @@ -234,15 +234,15 @@ func TestTimer_AddLeveledEntry1(t *testing.T) { array.Append(1) }) time.Sleep(1500 * time.Millisecond) - gtest.Assert(array.Len(), 0) + t.Assert(array.Len(), 0) time.Sleep(1300 * time.Millisecond) //glog.Println("check") - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } func TestTimer_Exit(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { timer := New() array := garray.New(true) timer.Add(200*time.Millisecond, func() { @@ -250,6 +250,6 @@ func TestTimer_Exit(t *testing.T) { gtimer.Exit() }) time.Sleep(1000 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) }) } diff --git a/os/gtimer/gtimer_z_unit_2_test.go b/os/gtimer/gtimer_z_unit_2_test.go index 6399d2426..7c34f357e 100644 --- a/os/gtimer/gtimer_z_unit_2_test.go +++ b/os/gtimer/gtimer_z_unit_2_test.go @@ -24,18 +24,18 @@ func TestEntry_Start_Stop_Close(t *testing.T) { array.Append(1) }) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) entry.Stop() time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) entry.Start() time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) entry.Close() time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) - gtest.Assert(entry.Status(), gtimer.STATUS_CLOSED) + t.Assert(entry.Status(), gtimer.STATUS_CLOSED) } func TestEntry_Singleton(t *testing.T) { @@ -45,14 +45,14 @@ func TestEntry_Singleton(t *testing.T) { array.Append(1) time.Sleep(10 * time.Second) }) - gtest.Assert(entry.IsSingleton(), false) + t.Assert(entry.IsSingleton(), false) entry.SetSingleton(true) - gtest.Assert(entry.IsSingleton(), true) + t.Assert(entry.IsSingleton(), true) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) time.Sleep(250 * time.Millisecond) - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) } func TestEntry_SetTimes(t *testing.T) { @@ -63,7 +63,7 @@ func TestEntry_SetTimes(t *testing.T) { }) entry.SetTimes(2) time.Sleep(1200 * time.Millisecond) - gtest.Assert(array.Len(), 2) + t.Assert(array.Len(), 2) } func TestEntry_Run(t *testing.T) { @@ -73,5 +73,5 @@ func TestEntry_Run(t *testing.T) { array.Append(1) }) entry.Run() - gtest.Assert(array.Len(), 1) + t.Assert(array.Len(), 1) } diff --git a/os/gview/gview_unit_basic_test.go b/os/gview/gview_unit_basic_test.go index fee64ae84..97eb62df6 100644 --- a/os/gview/gview_unit_basic_test.go +++ b/os/gview/gview_unit_basic_test.go @@ -28,7 +28,7 @@ func init() { } func Test_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { str := `hello {{.name}},version:{{.version}};hello {{GetName}},version:{{GetVersion}};{{.other}}` pwd := gfile.Pwd() view := gview.New() @@ -40,151 +40,151 @@ func Test_Basic(t *testing.T) { view.BindFunc("GetName", func() string { return "gf" }) view.BindFuncMap(gview.FuncMap{"GetVersion": func() string { return "1.7.0" }}) result, err := view.ParseContent(str, g.Map{"other": "that's all"}) - gtest.Assert(err != nil, false) - gtest.Assert(result, "hello gf,version:1.7.0;hello gf,version:1.7.0;that's all") + t.Assert(err != nil, false) + t.Assert(result, "hello gf,version:1.7.0;hello gf,version:1.7.0;that's all") //测试api方法 str = `hello {{.name}}` result, err = gview.ParseContent(str, g.Map{"name": "gf"}) - gtest.Assert(err != nil, false) - gtest.Assert(result, "hello gf") + t.Assert(err != nil, false) + t.Assert(result, "hello gf") //测试instance方法 result, err = gview.Instance().ParseContent(str, g.Map{"name": "gf"}) - gtest.Assert(err != nil, false) - gtest.Assert(result, "hello gf") + t.Assert(err != nil, false) + t.Assert(result, "hello gf") }) } func Test_Func(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { str := `{{eq 1 1}};{{eq 1 2}};{{eq "A" "B"}}` result, err := gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `true;false;false`) + t.Assert(err != nil, false) + t.Assert(result, `true;false;false`) str = `{{ne 1 2}};{{ne 1 1}};{{ne "A" "B"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `true;false;true`) + t.Assert(err != nil, false) + t.Assert(result, `true;false;true`) str = `{{lt 1 2}};{{lt 1 1}};{{lt 1 0}};{{lt "A" "B"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `true;false;false;true`) + t.Assert(err != nil, false) + t.Assert(result, `true;false;false;true`) str = `{{le 1 2}};{{le 1 1}};{{le 1 0}};{{le "A" "B"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `true;true;false;true`) + t.Assert(err != nil, false) + t.Assert(result, `true;true;false;true`) str = `{{gt 1 2}};{{gt 1 1}};{{gt 1 0}};{{gt "A" "B"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `false;false;true;false`) + t.Assert(err != nil, false) + t.Assert(result, `false;false;true;false`) str = `{{ge 1 2}};{{ge 1 1}};{{ge 1 0}};{{ge "A" "B"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `false;true;true;false`) + t.Assert(err != nil, false) + t.Assert(result, `false;true;true;false`) str = `{{"
测试
"|text}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `测试`) + t.Assert(err != nil, false) + t.Assert(result, `测试`) str = `{{"
测试
"|html}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `<div>测试</div>`) + t.Assert(err != nil, false) + t.Assert(result, `<div>测试</div>`) str = `{{"
测试
"|htmlencode}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `<div>测试</div>`) + t.Assert(err != nil, false) + t.Assert(result, `<div>测试</div>`) str = `{{"<div>测试</div>"|htmldecode}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `
测试
`) + t.Assert(err != nil, false) + t.Assert(result, `
测试
`) str = `{{"https://goframe.org"|url}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `https%3A%2F%2Fgoframe.org`) + t.Assert(err != nil, false) + t.Assert(result, `https%3A%2F%2Fgoframe.org`) str = `{{"https://goframe.org"|urlencode}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `https%3A%2F%2Fgoframe.org`) + t.Assert(err != nil, false) + t.Assert(result, `https%3A%2F%2Fgoframe.org`) str = `{{"https%3A%2F%2Fgoframe.org"|urldecode}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `https://goframe.org`) + t.Assert(err != nil, false) + t.Assert(result, `https://goframe.org`) str = `{{"https%3NA%2F%2Fgoframe.org"|urldecode}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(gstr.Contains(result, "invalid URL escape"), true) + t.Assert(err != nil, false) + t.Assert(gstr.Contains(result, "invalid URL escape"), true) str = `{{1540822968 | date "Y-m-d"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `2018-10-29`) + t.Assert(err != nil, false) + t.Assert(result, `2018-10-29`) str = `{{date "Y-m-d"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) + t.Assert(err != nil, false) str = `{{"我是中国人" | substr 2 -1}};{{"我是中国人" | substr 2 2}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `中国人;中国`) + t.Assert(err != nil, false) + t.Assert(result, `中国人;中国`) str = `{{"我是中国人" | strlimit 2 "..."}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `我是...`) + t.Assert(err != nil, false) + t.Assert(result, `我是...`) str = `{{"I'm中国人" | replace "I'm" "我是"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `我是中国人`) + t.Assert(err != nil, false) + t.Assert(result, `我是中国人`) str = `{{compare "A" "B"}};{{compare "1" "2"}};{{compare 2 1}};{{compare 1 1}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `-1;-1;1;0`) + t.Assert(err != nil, false) + t.Assert(result, `-1;-1;1;0`) str = `{{"热爱GF热爱生活" | hidestr 20 "*"}};{{"热爱GF热爱生活" | hidestr 50 "*"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `热爱GF*爱生活;热爱****生活`) + t.Assert(err != nil, false) + t.Assert(result, `热爱GF*爱生活;热爱****生活`) str = `{{"热爱GF热爱生活" | highlight "GF" "red"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `热爱GF热爱生活`) + t.Assert(err != nil, false) + t.Assert(result, `热爱GF热爱生活`) str = `{{"gf" | toupper}};{{"GF" | tolower}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err != nil, false) - gtest.Assert(result, `GF;gf`) + t.Assert(err != nil, false) + t.Assert(result, `GF;gf`) str = `{{concat "I" "Love" "GoFrame"}}` result, err = gview.ParseContent(str, nil) - gtest.Assert(err, nil) - gtest.Assert(result, `ILoveGoFrame`) + t.Assert(err, nil) + t.Assert(result, `ILoveGoFrame`) }) } func Test_FuncNl2Br(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { str := `{{"Go\nFrame" | nl2br}}` result, err := gview.ParseContent(str, nil) - gtest.Assert(err, nil) - gtest.Assert(result, `Go
Frame`) + t.Assert(err, nil) + t.Assert(result, `Go
Frame`) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "" for i := 0; i < 3000; i++ { s += "Go\nFrame\n中文" @@ -193,13 +193,13 @@ func Test_FuncNl2Br(t *testing.T) { result, err := gview.ParseContent(str, g.Map{ "content": s, }) - gtest.Assert(err, nil) - gtest.Assert(result, strings.Replace(s, "\n", "
", -1)) + t.Assert(err, nil) + t.Assert(result, strings.Replace(s, "\n", "
", -1)) }) } func Test_FuncInclude(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { header := `

HEADER

` main := `

hello gf

` footer := `

FOOTER

` @@ -219,11 +219,11 @@ func Test_FuncInclude(t *testing.T) { ioutil.WriteFile(templatePath+gfile.Separator+"layout.html", []byte(layout), 0644) view := gview.New(templatePath) result, err := view.Parse("notfound.html") - gtest.Assert(err != nil, true) - gtest.Assert(result, ``) + t.Assert(err != nil, true) + t.Assert(result, ``) result, err = view.Parse("layout.html") - gtest.Assert(err != nil, false) - gtest.Assert(result, `

HEADER

+ t.Assert(err != nil, false) + t.Assert(result, `

HEADER

hello gf

FOOTER

`) notfoundPath := templatePath + gfile.Separator + "template" + gfile.Separator + "notfound.html" @@ -231,34 +231,34 @@ func Test_FuncInclude(t *testing.T) { gfile.Create(notfoundPath) ioutil.WriteFile(notfoundPath, []byte("notfound"), 0644) result, err = view.Parse("notfound.html") - gtest.Assert(err != nil, true) - gtest.Assert(result, ``) + t.Assert(err != nil, true) + t.Assert(result, ``) }) } func Test_SetPath(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { view := gview.Instance("addpath") err := view.AddPath("tmp") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) err = view.AddPath("gview.go") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) os.Setenv("GF_GVIEW_PATH", "tmp") view = gview.Instance("setpath") err = view.SetPath("tmp") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) err = view.SetPath("gview.go") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) view = gview.New(gfile.Pwd()) err = view.SetPath("tmp") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) err = view.SetPath("gview.go") - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) os.Setenv("GF_GVIEW_PATH", "template") gfile.Mkdir(gfile.Pwd() + gfile.Separator + "template") @@ -267,17 +267,17 @@ func Test_SetPath(t *testing.T) { } func Test_ParseContent(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { str := `{{.name}}` view := gview.New() result, err := view.ParseContent(str, g.Map{"name": func() {}}) - gtest.Assert(err != nil, true) - gtest.Assert(result, ``) + t.Assert(err != nil, true) + t.Assert(result, ``) }) } func Test_HotReload(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { dirPath := gfile.Join( gfile.TempDir(), "testdata", @@ -288,7 +288,7 @@ func Test_HotReload(t *testing.T) { // Initialize data. err := gfile.PutContents(filePath, "test:{{.var}}") - gtest.Assert(err, nil) + t.Assert(err, nil) view := gview.New(dirPath) @@ -296,51 +296,51 @@ func Test_HotReload(t *testing.T) { result, err := view.Parse("test.html", g.Map{ "var": "1", }) - gtest.Assert(err, nil) - gtest.Assert(result, `test:1`) + t.Assert(err, nil) + t.Assert(result, `test:1`) // Update data. err = gfile.PutContents(filePath, "test2:{{.var}}") - gtest.Assert(err, nil) + t.Assert(err, nil) time.Sleep(100 * time.Millisecond) result, err = view.Parse("test.html", g.Map{ "var": "2", }) - gtest.Assert(err, nil) - gtest.Assert(result, `test2:2`) + t.Assert(err, nil) + t.Assert(result, `test2:2`) }) } func Test_XSS(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := gview.New() s := "
" r, err := v.ParseContent("{{.v}}", g.Map{ "v": s, }) - gtest.Assert(err, nil) - gtest.Assert(r, s) + t.Assert(err, nil) + t.Assert(r, s) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := gview.New() v.SetAutoEncode(true) s := "
" r, err := v.ParseContent("{{.v}}", g.Map{ "v": s, }) - gtest.Assert(err, nil) - gtest.Assert(r, ghtml.Entities(s)) + t.Assert(err, nil) + t.Assert(r, ghtml.Entities(s)) }) // Tag "if". - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { v := gview.New() v.SetAutoEncode(true) s := "
" r, err := v.ParseContent("{{if eq 1 1}}{{.v}}{{end}}", g.Map{ "v": s, }) - gtest.Assert(err, nil) - gtest.Assert(r, ghtml.Entities(s)) + t.Assert(err, nil) + t.Assert(r, ghtml.Entities(s)) }) } diff --git a/os/gview/gview_unit_config_test.go b/os/gview/gview_unit_config_test.go index 162873454..cb2e764c1 100644 --- a/os/gview/gview_unit_config_test.go +++ b/os/gview/gview_unit_config_test.go @@ -16,7 +16,7 @@ import ( ) func Test_Config(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { config := gview.Config{ Paths: []string{gfile.Join(gdebug.TestDataPath(), "config")}, Data: g.Map{ @@ -27,22 +27,22 @@ func Test_Config(t *testing.T) { } view := gview.New() err := view.SetConfig(config) - gtest.Assert(err, nil) + t.Assert(err, nil) str := `hello ${.name},version:${.version}` view.Assigns(g.Map{"version": "1.7.0"}) result, err := view.ParseContent(str, nil) - gtest.Assert(err, nil) - gtest.Assert(result, "hello gf,version:1.7.0") + t.Assert(err, nil) + t.Assert(result, "hello gf,version:1.7.0") result, err = view.ParseDefault() - gtest.Assert(err, nil) - gtest.Assert(result, "name:gf") + t.Assert(err, nil) + t.Assert(result, "name:gf") }) } func Test_ConfigWithMap(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { view := gview.New() err := view.SetConfigWithMap(g.Map{ "Paths": []string{gfile.Join(gdebug.TestDataPath(), "config")}, @@ -52,16 +52,16 @@ func Test_ConfigWithMap(t *testing.T) { "name": "gf", }, }) - gtest.Assert(err, nil) + t.Assert(err, nil) str := `hello ${.name},version:${.version}` view.Assigns(g.Map{"version": "1.7.0"}) result, err := view.ParseContent(str, nil) - gtest.Assert(err, nil) - gtest.Assert(result, "hello gf,version:1.7.0") + t.Assert(err, nil) + t.Assert(result, "hello gf,version:1.7.0") result, err = view.ParseDefault() - gtest.Assert(err, nil) - gtest.Assert(result, "name:gf") + t.Assert(err, nil) + t.Assert(result, "name:gf") }) } diff --git a/os/gview/gview_unit_i18n_test.go b/os/gview/gview_unit_i18n_test.go index 754de2640..2dbb3ce71 100644 --- a/os/gview/gview_unit_i18n_test.go +++ b/os/gview/gview_unit_i18n_test.go @@ -17,7 +17,7 @@ import ( ) func Test_I18n(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { content := `{{.name}} says "{#hello}{#world}!"` expect1 := `john says "你好世界!"` expect2 := `john says "こんにちは世界!"` @@ -29,24 +29,24 @@ func Test_I18n(t *testing.T) { result1, err := g.View().ParseContent(content, g.Map{ "name": "john", }) - gtest.Assert(err, nil) - gtest.Assert(result1, expect1) + t.Assert(err, nil) + t.Assert(result1, expect1) g.I18n().SetLanguage("ja") result2, err := g.View().ParseContent(content, g.Map{ "name": "john", }) - gtest.Assert(err, nil) - gtest.Assert(result2, expect2) + t.Assert(err, nil) + t.Assert(result2, expect2) g.I18n().SetLanguage("none") result3, err := g.View().ParseContent(content, g.Map{ "name": "john", }) - gtest.Assert(err, nil) - gtest.Assert(result3, expect3) + t.Assert(err, nil) + t.Assert(result3, expect3) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { content := `{{.name}} says "{#hello}{#world}!"` expect1 := `john says "你好世界!"` expect2 := `john says "こんにちは世界!"` @@ -58,21 +58,21 @@ func Test_I18n(t *testing.T) { "name": "john", "I18nLanguage": "zh-CN", }) - gtest.Assert(err, nil) - gtest.Assert(result1, expect1) + t.Assert(err, nil) + t.Assert(result1, expect1) result2, err := g.View().ParseContent(content, g.Map{ "name": "john", "I18nLanguage": "ja", }) - gtest.Assert(err, nil) - gtest.Assert(result2, expect2) + t.Assert(err, nil) + t.Assert(result2, expect2) result3, err := g.View().ParseContent(content, g.Map{ "name": "john", "I18nLanguage": "none", }) - gtest.Assert(err, nil) - gtest.Assert(result3, expect3) + t.Assert(err, nil) + t.Assert(result3, expect3) }) } diff --git a/test/gtest/gtest.go b/test/gtest/gtest.go index 2ffe21ed2..e5464b3b0 100644 --- a/test/gtest/gtest.go +++ b/test/gtest/gtest.go @@ -6,313 +6,3 @@ // Package gtest provides convenient test utilities for unit testing. package gtest - -import ( - "fmt" - "os" - "reflect" - "testing" - - "github.com/gogf/gf/debug/gdebug" - - "github.com/gogf/gf/util/gconv" -) - -const ( - gPATH_FILTER_KEY = "/test/gtest/gtest" -) - -// Case creates an unit test case. -// The parameter is the pointer to testing.T of stdlib (*testing.T). -// The parameter is the callback function for unit test case. -func Case(t *testing.T, f func()) { - defer func() { - if err := recover(); err != nil { - fmt.Fprintf(os.Stderr, "%v\n%s", err, gdebug.StackWithFilter(gPATH_FILTER_KEY)) - t.Fail() - } - }() - f() -} - -// Assert checks and EQUAL. -func Assert(value, expect interface{}) { - rvExpect := reflect.ValueOf(expect) - if isNil(value) { - value = nil - } - if rvExpect.Kind() == reflect.Map { - if err := compareMap(value, expect); err != nil { - panic(err) - } - return - } - strValue := gconv.String(value) - strExpect := gconv.String(expect) - if strValue != strExpect { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v == %v`, strValue, strExpect)) - } -} - -// AssertEQ checks and EQUAL, including their TYPES. -func AssertEQ(value, expect interface{}) { - // Value assert. - rvExpect := reflect.ValueOf(expect) - if isNil(value) { - value = nil - } - if rvExpect.Kind() == reflect.Map { - if err := compareMap(value, expect); err != nil { - panic(err) - } - return - } - strValue := gconv.String(value) - strExpect := gconv.String(expect) - if strValue != strExpect { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v == %v`, strValue, strExpect)) - } - // Type assert. - t1 := reflect.TypeOf(value) - t2 := reflect.TypeOf(expect) - if t1 != t2 { - panic(fmt.Sprintf(`[ASSERT] EXPECT TYPE %v[%v] == %v[%v]`, strValue, t1, strExpect, t2)) - } -} - -// AssertNE checks and NOT EQUAL. -func AssertNE(value, expect interface{}) { - rvExpect := reflect.ValueOf(expect) - if isNil(value) { - value = nil - } - if rvExpect.Kind() == reflect.Map { - if err := compareMap(value, expect); err == nil { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v != %v`, value, expect)) - } - return - } - strValue := gconv.String(value) - strExpect := gconv.String(expect) - if strValue == strExpect { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v != %v`, strValue, strExpect)) - } -} - -// AssertGT checks is GREATER THAN . -// Notice that, only string, integer and float types can be compared by AssertGT, -// others are invalid. -func AssertGT(value, expect interface{}) { - passed := false - switch reflect.ValueOf(expect).Kind() { - case reflect.String: - passed = gconv.String(value) > gconv.String(expect) - - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - passed = gconv.Int(value) > gconv.Int(expect) - - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - passed = gconv.Uint(value) > gconv.Uint(expect) - - case reflect.Float32, reflect.Float64: - passed = gconv.Float64(value) > gconv.Float64(expect) - } - if !passed { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v > %v`, value, expect)) - } -} - -// AssertGE checks is GREATER OR EQUAL THAN . -// Notice that, only string, integer and float types can be compared by AssertGTE, -// others are invalid. -func AssertGE(value, expect interface{}) { - passed := false - switch reflect.ValueOf(expect).Kind() { - case reflect.String: - passed = gconv.String(value) >= gconv.String(expect) - - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - passed = gconv.Int64(value) >= gconv.Int64(expect) - - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - passed = gconv.Uint64(value) >= gconv.Uint64(expect) - - case reflect.Float32, reflect.Float64: - passed = gconv.Float64(value) >= gconv.Float64(expect) - } - if !passed { - panic(fmt.Sprintf( - `[ASSERT] EXPECT %v(%v) >= %v(%v)`, - value, reflect.ValueOf(value).Kind(), - expect, reflect.ValueOf(expect).Kind(), - )) - } -} - -// AssertLT checks is LESS EQUAL THAN . -// Notice that, only string, integer and float types can be compared by AssertLT, -// others are invalid. -func AssertLT(value, expect interface{}) { - passed := false - switch reflect.ValueOf(expect).Kind() { - case reflect.String: - passed = gconv.String(value) < gconv.String(expect) - - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - passed = gconv.Int(value) < gconv.Int(expect) - - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - passed = gconv.Uint(value) < gconv.Uint(expect) - - case reflect.Float32, reflect.Float64: - passed = gconv.Float64(value) < gconv.Float64(expect) - } - if !passed { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v < %v`, value, expect)) - } -} - -// AssertLE checks is LESS OR EQUAL THAN . -// Notice that, only string, integer and float types can be compared by AssertLTE, -// others are invalid. -func AssertLE(value, expect interface{}) { - passed := false - switch reflect.ValueOf(expect).Kind() { - case reflect.String: - passed = gconv.String(value) <= gconv.String(expect) - - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - passed = gconv.Int(value) <= gconv.Int(expect) - - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - passed = gconv.Uint(value) <= gconv.Uint(expect) - - case reflect.Float32, reflect.Float64: - passed = gconv.Float64(value) <= gconv.Float64(expect) - } - if !passed { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v <= %v`, value, expect)) - } -} - -// AssertIN checks is IN . -// The should be a slice, -// but the can be a slice or a basic type variable. -// TODO map support. -func AssertIN(value, expect interface{}) { - passed := true - expectKind := reflect.ValueOf(expect).Kind() - switch expectKind { - case reflect.Slice, reflect.Array: - expectSlice := gconv.Strings(expect) - for _, v1 := range gconv.Strings(value) { - result := false - for _, v2 := range expectSlice { - if v1 == v2 { - result = true - break - } - } - if !result { - passed = false - break - } - } - default: - panic(fmt.Sprintf(`[ASSERT] INVALID EXPECT VALUE TYPE: %v`, expectKind)) - } - if !passed { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v IN %v`, value, expect)) - } -} - -// AssertNI checks is NOT IN . -// The should be a slice, -// but the can be a slice or a basic type variable. -// TODO map support. -func AssertNI(value, expect interface{}) { - passed := true - expectKind := reflect.ValueOf(expect).Kind() - switch expectKind { - case reflect.Slice, reflect.Array: - for _, v1 := range gconv.Strings(value) { - result := true - for _, v2 := range gconv.Strings(expect) { - if v1 == v2 { - result = false - break - } - } - if !result { - passed = false - break - } - } - default: - panic(fmt.Sprintf(`[ASSERT] INVALID EXPECT VALUE TYPE: %v`, expectKind)) - } - if !passed { - panic(fmt.Sprintf(`[ASSERT] EXPECT %v NOT IN %v`, value, expect)) - } -} - -// Error panics with given . -func Error(message ...interface{}) { - panic(fmt.Sprintf("[ERROR] %s", fmt.Sprint(message...))) -} - -// Fatal prints to stderr and exit the process. -func Fatal(message ...interface{}) { - fmt.Fprintf(os.Stderr, "[FATAL] %s\n%s", fmt.Sprint(message...), gdebug.StackWithFilter(gPATH_FILTER_KEY)) - os.Exit(1) -} - -// compareMap compares two maps, returns nil if they are equal, or else returns error. -func compareMap(value, expect interface{}) error { - rvValue := reflect.ValueOf(value) - rvExpect := reflect.ValueOf(expect) - if isNil(value) { - value = nil - } - if rvExpect.Kind() == reflect.Map { - if rvValue.Kind() == reflect.Map { - if rvExpect.Len() == rvValue.Len() { - // Turn two interface maps to the same type for comparison. - // Direct use of rvValue.MapIndex(key).Interface() will panic - // when the key types are inconsistent. - mValue := make(map[string]string) - mExpect := make(map[string]string) - ksValue := rvValue.MapKeys() - ksExpect := rvExpect.MapKeys() - for _, key := range ksValue { - mValue[gconv.String(key.Interface())] = gconv.String(rvValue.MapIndex(key).Interface()) - } - for _, key := range ksExpect { - mExpect[gconv.String(key.Interface())] = gconv.String(rvExpect.MapIndex(key).Interface()) - } - for k, v := range mExpect { - if v != mValue[k] { - return fmt.Errorf(`[ASSERT] EXPECT VALUE map["%v"]:%v == map["%v"]:%v`+ - "\nGIVEN : %v\nEXPECT: %v", k, mValue[k], k, v, mValue, mExpect) - } - } - } else { - return fmt.Errorf(`[ASSERT] EXPECT MAP LENGTH %d == %d`, rvValue.Len(), rvExpect.Len()) - } - } else { - return fmt.Errorf(`[ASSERT] EXPECT VALUE TO BE A MAP`) - } - } - return nil -} - -// isNil checks whether is nil. -func isNil(value interface{}) bool { - rv := reflect.ValueOf(value) - switch rv.Kind() { - case reflect.Slice, reflect.Array, reflect.Map, reflect.Ptr, reflect.Func: - return rv.IsNil() - default: - return value == nil - } -} diff --git a/test/gtest/gtest_t.go b/test/gtest/gtest_t.go new file mode 100644 index 000000000..b4b522cdd --- /dev/null +++ b/test/gtest/gtest_t.go @@ -0,0 +1,83 @@ +// Copyright 2018 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 gtest + +import ( + "testing" +) + +// T is the testing unit case management object. +type T struct { + T *testing.T +} + +// Assert checks and EQUAL. +func (t *T) Assert(value, expect interface{}) { + Assert(value, expect) +} + +// AssertEQ checks and EQUAL, including their TYPES. +func (t *T) AssertEQ(value, expect interface{}) { + AssertEQ(value, expect) +} + +// AssertNE checks and NOT EQUAL. +func (t *T) AssertNE(value, expect interface{}) { + AssertNE(value, expect) +} + +// AssertGT checks is GREATER THAN . +// Notice that, only string, integer and float types can be compared by AssertGT, +// others are invalid. +func (t *T) AssertGT(value, expect interface{}) { + AssertGT(value, expect) +} + +// AssertGE checks is GREATER OR EQUAL THAN . +// Notice that, only string, integer and float types can be compared by AssertGTE, +// others are invalid. +func (t *T) AssertGE(value, expect interface{}) { + AssertGE(value, expect) +} + +// AssertLT checks is LESS EQUAL THAN . +// Notice that, only string, integer and float types can be compared by AssertLT, +// others are invalid. +func (t *T) AssertLT(value, expect interface{}) { + AssertLT(value, expect) +} + +// AssertLE checks is LESS OR EQUAL THAN . +// Notice that, only string, integer and float types can be compared by AssertLTE, +// others are invalid. +func (t *T) AssertLE(value, expect interface{}) { + AssertLE(value, expect) +} + +// AssertIN checks is IN . +// The should be a slice, +// but the can be a slice or a basic type variable. +func (t *T) AssertIN(value, expect interface{}) { + AssertIN(value, expect) +} + +// AssertNI checks is NOT IN . +// The should be a slice, +// but the can be a slice or a basic type variable. +func (t *T) AssertNI(value, expect interface{}) { + AssertNI(value, expect) +} + +// Error panics with given . +func (t *T) Error(message ...interface{}) { + Error(message...) +} + +// Fatal prints to stderr and exit the process. +func (t *T) Fatal(message ...interface{}) { + Fatal(message...) +} diff --git a/test/gtest/gtest_util.go b/test/gtest/gtest_util.go new file mode 100644 index 000000000..ab1467f99 --- /dev/null +++ b/test/gtest/gtest_util.go @@ -0,0 +1,331 @@ +// Copyright 2018 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 gtest + +import ( + "fmt" + "os" + "reflect" + "testing" + + "github.com/gogf/gf/debug/gdebug" + + "github.com/gogf/gf/util/gconv" +) + +const ( + gPATH_FILTER_KEY = "/test/gtest/gtest" +) + +// C creates an unit testing case. +// The parameter is the pointer to testing.T of stdlib (*testing.T). +// The parameter is the callback function for unit test case. +func C(t *testing.T, f func(t *T)) { + defer func() { + if err := recover(); err != nil { + fmt.Fprintf(os.Stderr, "%v\n%s", err, gdebug.StackWithFilter(gPATH_FILTER_KEY)) + t.Fail() + } + }() + f(&T{t}) +} + +// Case creates an unit testing case. +// The parameter is the pointer to testing.T of stdlib (*testing.T). +// The parameter is the callback function for unit test case. +// Deprecated. +func Case(t *testing.T, f func()) { + defer func() { + if err := recover(); err != nil { + fmt.Fprintf(os.Stderr, "%v\n%s", err, gdebug.StackWithFilter(gPATH_FILTER_KEY)) + t.Fail() + } + }() + f() +} + +// Assert checks and EQUAL. +func Assert(value, expect interface{}) { + rvExpect := reflect.ValueOf(expect) + if isNil(value) { + value = nil + } + if rvExpect.Kind() == reflect.Map { + if err := compareMap(value, expect); err != nil { + panic(err) + } + return + } + strValue := gconv.String(value) + strExpect := gconv.String(expect) + if strValue != strExpect { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v == %v`, strValue, strExpect)) + } +} + +// AssertEQ checks and EQUAL, including their TYPES. +func AssertEQ(value, expect interface{}) { + // Value assert. + rvExpect := reflect.ValueOf(expect) + if isNil(value) { + value = nil + } + if rvExpect.Kind() == reflect.Map { + if err := compareMap(value, expect); err != nil { + panic(err) + } + return + } + strValue := gconv.String(value) + strExpect := gconv.String(expect) + if strValue != strExpect { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v == %v`, strValue, strExpect)) + } + // Type assert. + t1 := reflect.TypeOf(value) + t2 := reflect.TypeOf(expect) + if t1 != t2 { + panic(fmt.Sprintf(`[ASSERT] EXPECT TYPE %v[%v] == %v[%v]`, strValue, t1, strExpect, t2)) + } +} + +// AssertNE checks and NOT EQUAL. +func AssertNE(value, expect interface{}) { + rvExpect := reflect.ValueOf(expect) + if isNil(value) { + value = nil + } + if rvExpect.Kind() == reflect.Map { + if err := compareMap(value, expect); err == nil { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v != %v`, value, expect)) + } + return + } + strValue := gconv.String(value) + strExpect := gconv.String(expect) + if strValue == strExpect { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v != %v`, strValue, strExpect)) + } +} + +// AssertGT checks is GREATER THAN . +// Notice that, only string, integer and float types can be compared by AssertGT, +// others are invalid. +func AssertGT(value, expect interface{}) { + passed := false + switch reflect.ValueOf(expect).Kind() { + case reflect.String: + passed = gconv.String(value) > gconv.String(expect) + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + passed = gconv.Int(value) > gconv.Int(expect) + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + passed = gconv.Uint(value) > gconv.Uint(expect) + + case reflect.Float32, reflect.Float64: + passed = gconv.Float64(value) > gconv.Float64(expect) + } + if !passed { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v > %v`, value, expect)) + } +} + +// AssertGE checks is GREATER OR EQUAL THAN . +// Notice that, only string, integer and float types can be compared by AssertGTE, +// others are invalid. +func AssertGE(value, expect interface{}) { + passed := false + switch reflect.ValueOf(expect).Kind() { + case reflect.String: + passed = gconv.String(value) >= gconv.String(expect) + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + passed = gconv.Int64(value) >= gconv.Int64(expect) + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + passed = gconv.Uint64(value) >= gconv.Uint64(expect) + + case reflect.Float32, reflect.Float64: + passed = gconv.Float64(value) >= gconv.Float64(expect) + } + if !passed { + panic(fmt.Sprintf( + `[ASSERT] EXPECT %v(%v) >= %v(%v)`, + value, reflect.ValueOf(value).Kind(), + expect, reflect.ValueOf(expect).Kind(), + )) + } +} + +// AssertLT checks is LESS EQUAL THAN . +// Notice that, only string, integer and float types can be compared by AssertLT, +// others are invalid. +func AssertLT(value, expect interface{}) { + passed := false + switch reflect.ValueOf(expect).Kind() { + case reflect.String: + passed = gconv.String(value) < gconv.String(expect) + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + passed = gconv.Int(value) < gconv.Int(expect) + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + passed = gconv.Uint(value) < gconv.Uint(expect) + + case reflect.Float32, reflect.Float64: + passed = gconv.Float64(value) < gconv.Float64(expect) + } + if !passed { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v < %v`, value, expect)) + } +} + +// AssertLE checks is LESS OR EQUAL THAN . +// Notice that, only string, integer and float types can be compared by AssertLTE, +// others are invalid. +func AssertLE(value, expect interface{}) { + passed := false + switch reflect.ValueOf(expect).Kind() { + case reflect.String: + passed = gconv.String(value) <= gconv.String(expect) + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + passed = gconv.Int(value) <= gconv.Int(expect) + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + passed = gconv.Uint(value) <= gconv.Uint(expect) + + case reflect.Float32, reflect.Float64: + passed = gconv.Float64(value) <= gconv.Float64(expect) + } + if !passed { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v <= %v`, value, expect)) + } +} + +// AssertIN checks is IN . +// The should be a slice, +// but the can be a slice or a basic type variable. +// TODO map support. +func AssertIN(value, expect interface{}) { + passed := true + expectKind := reflect.ValueOf(expect).Kind() + switch expectKind { + case reflect.Slice, reflect.Array: + expectSlice := gconv.Strings(expect) + for _, v1 := range gconv.Strings(value) { + result := false + for _, v2 := range expectSlice { + if v1 == v2 { + result = true + break + } + } + if !result { + passed = false + break + } + } + default: + panic(fmt.Sprintf(`[ASSERT] INVALID EXPECT VALUE TYPE: %v`, expectKind)) + } + if !passed { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v IN %v`, value, expect)) + } +} + +// AssertNI checks is NOT IN . +// The should be a slice, +// but the can be a slice or a basic type variable. +// TODO map support. +func AssertNI(value, expect interface{}) { + passed := true + expectKind := reflect.ValueOf(expect).Kind() + switch expectKind { + case reflect.Slice, reflect.Array: + for _, v1 := range gconv.Strings(value) { + result := true + for _, v2 := range gconv.Strings(expect) { + if v1 == v2 { + result = false + break + } + } + if !result { + passed = false + break + } + } + default: + panic(fmt.Sprintf(`[ASSERT] INVALID EXPECT VALUE TYPE: %v`, expectKind)) + } + if !passed { + panic(fmt.Sprintf(`[ASSERT] EXPECT %v NOT IN %v`, value, expect)) + } +} + +// Error panics with given . +func Error(message ...interface{}) { + panic(fmt.Sprintf("[ERROR] %s", fmt.Sprint(message...))) +} + +// Fatal prints to stderr and exit the process. +func Fatal(message ...interface{}) { + fmt.Fprintf(os.Stderr, "[FATAL] %s\n%s", fmt.Sprint(message...), gdebug.StackWithFilter(gPATH_FILTER_KEY)) + os.Exit(1) +} + +// compareMap compares two maps, returns nil if they are equal, or else returns error. +func compareMap(value, expect interface{}) error { + rvValue := reflect.ValueOf(value) + rvExpect := reflect.ValueOf(expect) + if isNil(value) { + value = nil + } + if rvExpect.Kind() == reflect.Map { + if rvValue.Kind() == reflect.Map { + if rvExpect.Len() == rvValue.Len() { + // Turn two interface maps to the same type for comparison. + // Direct use of rvValue.MapIndex(key).Interface() will panic + // when the key types are inconsistent. + mValue := make(map[string]string) + mExpect := make(map[string]string) + ksValue := rvValue.MapKeys() + ksExpect := rvExpect.MapKeys() + for _, key := range ksValue { + mValue[gconv.String(key.Interface())] = gconv.String(rvValue.MapIndex(key).Interface()) + } + for _, key := range ksExpect { + mExpect[gconv.String(key.Interface())] = gconv.String(rvExpect.MapIndex(key).Interface()) + } + for k, v := range mExpect { + if v != mValue[k] { + return fmt.Errorf(`[ASSERT] EXPECT VALUE map["%v"]:%v == map["%v"]:%v`+ + "\nGIVEN : %v\nEXPECT: %v", k, mValue[k], k, v, mValue, mExpect) + } + } + } else { + return fmt.Errorf(`[ASSERT] EXPECT MAP LENGTH %d == %d`, rvValue.Len(), rvExpect.Len()) + } + } else { + return fmt.Errorf(`[ASSERT] EXPECT VALUE TO BE A MAP`) + } + } + return nil +} + +// isNil checks whether is nil. +func isNil(value interface{}) bool { + rv := reflect.ValueOf(value) + switch rv.Kind() { + case reflect.Slice, reflect.Array, reflect.Map, reflect.Ptr, reflect.Func: + return rv.IsNil() + default: + return value == nil + } +} diff --git a/test/gtest/gtest_test.go b/test/gtest/gtest_z_unit_test.go similarity index 50% rename from test/gtest/gtest_test.go rename to test/gtest/gtest_z_unit_test.go index b881de05d..0f5b756cd 100644 --- a/test/gtest/gtest_test.go +++ b/test/gtest/gtest_z_unit_test.go @@ -12,11 +12,20 @@ import ( "github.com/gogf/gf/test/gtest" ) -func TestCase(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(1, 1) - gtest.AssertNE(1, 0) - gtest.AssertEQ(float32(123.456), float32(123.456)) - gtest.AssertEQ(float64(123.456), float64(123.456)) +func TestC(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + t.Assert(1, 1) + t.AssertNE(1, 0) + t.AssertEQ(float32(123.456), float32(123.456)) + t.AssertEQ(float64(123.456), float64(123.456)) + }) +} + +func TestCase(t *testing.T) { + gtest.C(t, func(t *gtest.T) { + t.Assert(1, 1) + t.AssertNE(1, 0) + t.AssertEQ(float32(123.456), float32(123.456)) + t.AssertEQ(float64(123.456), float64(123.456)) }) } diff --git a/text/gregex/gregex_z_unit_test.go b/text/gregex/gregex_z_unit_test.go index ecee38d4f..a9b132b45 100644 --- a/text/gregex/gregex_z_unit_test.go +++ b/text/gregex/gregex_z_unit_test.go @@ -21,56 +21,56 @@ var ( ) func Test_Quote(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := `[foo]` //`\[foo\]` - gtest.Assert(gregex.Quote(s1), `\[foo\]`) + t.Assert(gregex.Quote(s1), `\[foo\]`) }) } func Test_Validate(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var s1 = `(.+):(\d+)` - gtest.Assert(gregex.Validate(s1), nil) + t.Assert(gregex.Validate(s1), nil) s1 = `((.+):(\d+)` - gtest.Assert(gregex.Validate(s1) == nil, false) + t.Assert(gregex.Validate(s1) == nil, false) }) } func Test_IsMatch(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var pattern = `(.+):(\d+)` s1 := []byte(`sfs:2323`) - gtest.Assert(gregex.IsMatch(pattern, s1), true) + t.Assert(gregex.IsMatch(pattern, s1), true) s1 = []byte(`sfs2323`) - gtest.Assert(gregex.IsMatch(pattern, s1), false) + t.Assert(gregex.IsMatch(pattern, s1), false) s1 = []byte(`sfs:`) - gtest.Assert(gregex.IsMatch(pattern, s1), false) + t.Assert(gregex.IsMatch(pattern, s1), false) // error pattern - gtest.Assert(gregex.IsMatch(PatternErr, s1), false) + t.Assert(gregex.IsMatch(PatternErr, s1), false) }) } func Test_IsMatchString(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var pattern = `(.+):(\d+)` s1 := `sfs:2323` - gtest.Assert(gregex.IsMatchString(pattern, s1), true) + t.Assert(gregex.IsMatchString(pattern, s1), true) s1 = `sfs2323` - gtest.Assert(gregex.IsMatchString(pattern, s1), false) + t.Assert(gregex.IsMatchString(pattern, s1), false) s1 = `sfs:` - gtest.Assert(gregex.IsMatchString(pattern, s1), false) + t.Assert(gregex.IsMatchString(pattern, s1), false) // error pattern - gtest.Assert(gregex.IsMatchString(PatternErr, s1), false) + t.Assert(gregex.IsMatchString(PatternErr, s1), false) }) } func Test_Match(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" wantSubs := "aaabb" s := "acbb" + wantSubs + "dd" subs, err := gregex.Match(re, []byte(s)) - gtest.Assert(err, nil) + t.Assert(err, nil) if string(subs[0]) != wantSubs { t.Fatalf("regex:%s,Match(%q)[0] = %q; want %q", re, s, subs[0], wantSubs) } @@ -79,17 +79,17 @@ func Test_Match(t *testing.T) { } // error pattern _, err = gregex.Match(PatternErr, []byte(s)) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_MatchString(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" wantSubs := "aaabb" s := "acbb" + wantSubs + "dd" subs, err := gregex.MatchString(re, s) - gtest.Assert(err, nil) + t.Assert(err, nil) if string(subs[0]) != wantSubs { t.Fatalf("regex:%s,Match(%q)[0] = %q; want %q", re, s, subs[0], wantSubs) } @@ -98,18 +98,18 @@ func Test_MatchString(t *testing.T) { } // error pattern _, err = gregex.MatchString(PatternErr, s) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_MatchAll(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" wantSubs := "aaabb" s := "acbb" + wantSubs + "dd" s = s + `其他的` + s subs, err := gregex.MatchAll(re, []byte(s)) - gtest.Assert(err, nil) + t.Assert(err, nil) if string(subs[0][0]) != wantSubs { t.Fatalf("regex:%s,Match(%q)[0] = %q; want %q", re, s, subs[0][0], wantSubs) } @@ -125,17 +125,17 @@ func Test_MatchAll(t *testing.T) { } // error pattern _, err = gregex.MatchAll(PatternErr, []byte(s)) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_MatchAllString(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" wantSubs := "aaabb" s := "acbb" + wantSubs + "dd" subs, err := gregex.MatchAllString(re, s+`其他的`+s) - gtest.Assert(err, nil) + t.Assert(err, nil) if string(subs[0][0]) != wantSubs { t.Fatalf("regex:%s,Match(%q)[0] = %q; want %q", re, s, subs[0][0], wantSubs) } @@ -151,48 +151,48 @@ func Test_MatchAllString(t *testing.T) { } // error pattern _, err = gregex.MatchAllString(PatternErr, s) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_Replace(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" wantSubs := "aaabb" replace := "12345" s := "acbb" + wantSubs + "dd" wanted := "acbb" + replace + "dd" replacedStr, err := gregex.Replace(re, []byte(replace), []byte(s)) - gtest.Assert(err, nil) + t.Assert(err, nil) if string(replacedStr) != wanted { t.Fatalf("regex:%s,old:%s; want %q", re, s, wanted) } // error pattern _, err = gregex.Replace(PatternErr, []byte(replace), []byte(s)) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_ReplaceString(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" wantSubs := "aaabb" replace := "12345" s := "acbb" + wantSubs + "dd" wanted := "acbb" + replace + "dd" replacedStr, err := gregex.ReplaceString(re, replace, s) - gtest.Assert(err, nil) + t.Assert(err, nil) if replacedStr != wanted { t.Fatalf("regex:%s,old:%s; want %q", re, s, wanted) } // error pattern _, err = gregex.ReplaceString(PatternErr, replace, s) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_ReplaceFun(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" wantSubs := "aaabb" //replace :="12345" @@ -205,7 +205,7 @@ func Test_ReplaceFun(t *testing.T) { } return []byte("[x" + string(s) + "y]") }) - gtest.Assert(err, nil) + t.Assert(err, nil) if string(replacedStr) != wanted { t.Fatalf("regex:%s,old:%s; want %q", re, s, wanted) } @@ -213,44 +213,44 @@ func Test_ReplaceFun(t *testing.T) { _, err = gregex.ReplaceFunc(PatternErr, []byte(s), func(s []byte) []byte { return []byte("") }) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_ReplaceFuncMatch(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := []byte("1234567890") p := `(\d{3})(\d{3})(.+)` s0, e0 := gregex.ReplaceFuncMatch(p, s, func(match [][]byte) []byte { return match[0] }) - gtest.Assert(e0, nil) - gtest.Assert(s0, s) + t.Assert(e0, nil) + t.Assert(s0, s) s1, e1 := gregex.ReplaceFuncMatch(p, s, func(match [][]byte) []byte { return match[1] }) - gtest.Assert(e1, nil) - gtest.Assert(s1, []byte("123")) + t.Assert(e1, nil) + t.Assert(s1, []byte("123")) s2, e2 := gregex.ReplaceFuncMatch(p, s, func(match [][]byte) []byte { return match[2] }) - gtest.Assert(e2, nil) - gtest.Assert(s2, []byte("456")) + t.Assert(e2, nil) + t.Assert(s2, []byte("456")) s3, e3 := gregex.ReplaceFuncMatch(p, s, func(match [][]byte) []byte { return match[3] }) - gtest.Assert(e3, nil) - gtest.Assert(s3, []byte("7890")) + t.Assert(e3, nil) + t.Assert(s3, []byte("7890")) // error pattern _, err := gregex.ReplaceFuncMatch(PatternErr, s, func(match [][]byte) []byte { return match[3] }) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_ReplaceStringFunc(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" wantSubs := "aaabb" //replace :="12345" @@ -263,7 +263,7 @@ func Test_ReplaceStringFunc(t *testing.T) { } return "[x" + s + "y]" }) - gtest.Assert(err, nil) + t.Assert(err, nil) if replacedStr != wanted { t.Fatalf("regex:%s,old:%s; want %q", re, s, wanted) } @@ -271,50 +271,50 @@ func Test_ReplaceStringFunc(t *testing.T) { _, err = gregex.ReplaceStringFunc(PatternErr, s, func(s string) string { return "" }) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_ReplaceStringFuncMatch(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "1234567890" p := `(\d{3})(\d{3})(.+)` s0, e0 := gregex.ReplaceStringFuncMatch(p, s, func(match []string) string { return match[0] }) - gtest.Assert(e0, nil) - gtest.Assert(s0, s) + t.Assert(e0, nil) + t.Assert(s0, s) s1, e1 := gregex.ReplaceStringFuncMatch(p, s, func(match []string) string { return match[1] }) - gtest.Assert(e1, nil) - gtest.Assert(s1, "123") + t.Assert(e1, nil) + t.Assert(s1, "123") s2, e2 := gregex.ReplaceStringFuncMatch(p, s, func(match []string) string { return match[2] }) - gtest.Assert(e2, nil) - gtest.Assert(s2, "456") + t.Assert(e2, nil) + t.Assert(s2, "456") s3, e3 := gregex.ReplaceStringFuncMatch(p, s, func(match []string) string { return match[3] }) - gtest.Assert(e3, nil) - gtest.Assert(s3, "7890") + t.Assert(e3, nil) + t.Assert(s3, "7890") // error pattern _, err := gregex.ReplaceStringFuncMatch(PatternErr, s, func(match []string) string { return "" }) - gtest.AssertNE(err, nil) + t.AssertNE(err, nil) }) } func Test_Split(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" matched := "aaabb" item0 := "acbb" item1 := "dd" s := item0 + matched + item1 - gtest.Assert(gregex.IsMatchString(re, matched), true) + t.Assert(gregex.IsMatchString(re, matched), true) items := gregex.Split(re, s) //split string with matched if items[0] != item0 { t.Fatalf("regex:%s,Split(%q) want %q", re, s, item0) @@ -324,20 +324,20 @@ func Test_Split(t *testing.T) { } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { re := "a(a+b+)b" notmatched := "aaxbb" item0 := "acbb" item1 := "dd" s := item0 + notmatched + item1 - gtest.Assert(gregex.IsMatchString(re, notmatched), false) + t.Assert(gregex.IsMatchString(re, notmatched), false) items := gregex.Split(re, s) //split string with notmatched then nosplitting if items[0] != s { t.Fatalf("regex:%s,Split(%q) want %q", re, s, item0) } // error pattern items = gregex.Split(PatternErr, s) - gtest.AssertEQ(items, nil) + t.AssertEQ(items, nil) }) } diff --git a/text/gstr/gstr_z_unit_basic_test.go b/text/gstr/gstr_z_unit_basic_test.go index 59e0de5e0..d283f3a5c 100644 --- a/text/gstr/gstr_z_unit_basic_test.go +++ b/text/gstr/gstr_z_unit_basic_test.go @@ -17,19 +17,19 @@ import ( ) func Test_Replace(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcdEFG乱入的中文abcdefg" - gtest.Assert(gstr.Replace(s1, "ab", "AB"), "ABcdEFG乱入的中文ABcdefg") - gtest.Assert(gstr.Replace(s1, "EF", "ef"), "abcdefG乱入的中文abcdefg") - gtest.Assert(gstr.Replace(s1, "MN", "mn"), s1) + t.Assert(gstr.Replace(s1, "ab", "AB"), "ABcdEFG乱入的中文ABcdefg") + t.Assert(gstr.Replace(s1, "EF", "ef"), "abcdefG乱入的中文abcdefg") + t.Assert(gstr.Replace(s1, "MN", "mn"), s1) - gtest.Assert(gstr.ReplaceByArray(s1, g.ArrayStr{ + t.Assert(gstr.ReplaceByArray(s1, g.ArrayStr{ "a", "A", "A", "-", "a", }), "-bcdEFG乱入的中文-bcdefg") - gtest.Assert(gstr.ReplaceByMap(s1, g.MapStrStr{ + t.Assert(gstr.ReplaceByMap(s1, g.MapStrStr{ "a": "A", "G": "g", }), "AbcdEFg乱入的中文Abcdefg") @@ -37,29 +37,29 @@ func Test_Replace(t *testing.T) { } func Test_ReplaceI_1(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcd乱入的中文ABCD" s2 := "a" - gtest.Assert(gstr.ReplaceI(s1, "ab", "aa"), "aacd乱入的中文aaCD") - gtest.Assert(gstr.ReplaceI(s1, "ab", "aa", 0), "abcd乱入的中文ABCD") - gtest.Assert(gstr.ReplaceI(s1, "ab", "aa", 1), "aacd乱入的中文ABCD") + t.Assert(gstr.ReplaceI(s1, "ab", "aa"), "aacd乱入的中文aaCD") + t.Assert(gstr.ReplaceI(s1, "ab", "aa", 0), "abcd乱入的中文ABCD") + t.Assert(gstr.ReplaceI(s1, "ab", "aa", 1), "aacd乱入的中文ABCD") - gtest.Assert(gstr.ReplaceI(s1, "abcd", "-"), "-乱入的中文-") - gtest.Assert(gstr.ReplaceI(s1, "abcd", "-", 1), "-乱入的中文ABCD") + t.Assert(gstr.ReplaceI(s1, "abcd", "-"), "-乱入的中文-") + t.Assert(gstr.ReplaceI(s1, "abcd", "-", 1), "-乱入的中文ABCD") - gtest.Assert(gstr.ReplaceI(s1, "abcd乱入的", ""), "中文ABCD") - gtest.Assert(gstr.ReplaceI(s1, "ABCD乱入的", ""), "中文ABCD") + t.Assert(gstr.ReplaceI(s1, "abcd乱入的", ""), "中文ABCD") + t.Assert(gstr.ReplaceI(s1, "ABCD乱入的", ""), "中文ABCD") - gtest.Assert(gstr.ReplaceI(s2, "A", "-"), "-") - gtest.Assert(gstr.ReplaceI(s2, "a", "-"), "-") + t.Assert(gstr.ReplaceI(s2, "A", "-"), "-") + t.Assert(gstr.ReplaceI(s2, "a", "-"), "-") - gtest.Assert(gstr.ReplaceIByArray(s1, g.ArrayStr{ + t.Assert(gstr.ReplaceIByArray(s1, g.ArrayStr{ "abcd乱入的", "-", "-", "=", "a", }), "=中文ABCD") - gtest.Assert(gstr.ReplaceIByMap(s1, g.MapStrStr{ + t.Assert(gstr.ReplaceIByMap(s1, g.MapStrStr{ "ab": "-", "CD": "=", }), "-=乱入的中文-=") @@ -67,133 +67,133 @@ func Test_ReplaceI_1(t *testing.T) { } func Test_ToLower(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcdEFG乱入的中文abcdefg" e1 := "abcdefg乱入的中文abcdefg" - gtest.Assert(gstr.ToLower(s1), e1) + t.Assert(gstr.ToLower(s1), e1) }) } func Test_ToUpper(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcdEFG乱入的中文abcdefg" e1 := "ABCDEFG乱入的中文ABCDEFG" - gtest.Assert(gstr.ToUpper(s1), e1) + t.Assert(gstr.ToUpper(s1), e1) }) } func Test_UcFirst(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcdEFG乱入的中文abcdefg" e1 := "AbcdEFG乱入的中文abcdefg" - gtest.Assert(gstr.UcFirst(""), "") - gtest.Assert(gstr.UcFirst(s1), e1) - gtest.Assert(gstr.UcFirst(e1), e1) + t.Assert(gstr.UcFirst(""), "") + t.Assert(gstr.UcFirst(s1), e1) + t.Assert(gstr.UcFirst(e1), e1) }) } func Test_LcFirst(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "AbcdEFG乱入的中文abcdefg" e1 := "abcdEFG乱入的中文abcdefg" - gtest.Assert(gstr.LcFirst(""), "") - gtest.Assert(gstr.LcFirst(s1), e1) - gtest.Assert(gstr.LcFirst(e1), e1) + t.Assert(gstr.LcFirst(""), "") + t.Assert(gstr.LcFirst(s1), e1) + t.Assert(gstr.LcFirst(e1), e1) }) } func Test_UcWords(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "我爱GF: i love go frame" e1 := "我爱GF: I Love Go Frame" - gtest.Assert(gstr.UcWords(s1), e1) + t.Assert(gstr.UcWords(s1), e1) }) } func Test_IsLetterLower(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.IsLetterLower('a'), true) - gtest.Assert(gstr.IsLetterLower('A'), false) - gtest.Assert(gstr.IsLetterLower('1'), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.IsLetterLower('a'), true) + t.Assert(gstr.IsLetterLower('A'), false) + t.Assert(gstr.IsLetterLower('1'), false) }) } func Test_IsLetterUpper(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.IsLetterUpper('a'), false) - gtest.Assert(gstr.IsLetterUpper('A'), true) - gtest.Assert(gstr.IsLetterUpper('1'), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.IsLetterUpper('a'), false) + t.Assert(gstr.IsLetterUpper('A'), true) + t.Assert(gstr.IsLetterUpper('1'), false) }) } func Test_IsNumeric(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.IsNumeric("1a我"), false) - gtest.Assert(gstr.IsNumeric("0123"), true) - gtest.Assert(gstr.IsNumeric("我是中国人"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.IsNumeric("1a我"), false) + t.Assert(gstr.IsNumeric("0123"), true) + t.Assert(gstr.IsNumeric("我是中国人"), false) }) } func Test_SubStr(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.SubStr("我爱GoFrame", 0), "我爱GoFrame") - gtest.Assert(gstr.SubStr("我爱GoFrame", 2), "GoFrame") - gtest.Assert(gstr.SubStr("我爱GoFrame", 2, 2), "Go") - gtest.Assert(gstr.SubStr("我爱GoFrame", -1, 30), "我爱GoFrame") - gtest.Assert(gstr.SubStr("我爱GoFrame", 30, 30), "") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.SubStr("我爱GoFrame", 0), "我爱GoFrame") + t.Assert(gstr.SubStr("我爱GoFrame", 2), "GoFrame") + t.Assert(gstr.SubStr("我爱GoFrame", 2, 2), "Go") + t.Assert(gstr.SubStr("我爱GoFrame", -1, 30), "我爱GoFrame") + t.Assert(gstr.SubStr("我爱GoFrame", 30, 30), "") }) } func Test_StrLimit(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.StrLimit("我爱GoFrame", 2), "我爱...") - gtest.Assert(gstr.StrLimit("我爱GoFrame", 2, ""), "我爱") - gtest.Assert(gstr.StrLimit("我爱GoFrame", 2, "**"), "我爱**") - gtest.Assert(gstr.StrLimit("我爱GoFrame", 4, ""), "我爱Go") - gtest.Assert(gstr.StrLimit("*", 4, ""), "*") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.StrLimit("我爱GoFrame", 2), "我爱...") + t.Assert(gstr.StrLimit("我爱GoFrame", 2, ""), "我爱") + t.Assert(gstr.StrLimit("我爱GoFrame", 2, "**"), "我爱**") + t.Assert(gstr.StrLimit("我爱GoFrame", 4, ""), "我爱Go") + t.Assert(gstr.StrLimit("*", 4, ""), "*") }) } func Test_HasPrefix(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.HasPrefix("我爱GoFrame", "我爱"), true) - gtest.Assert(gstr.HasPrefix("en我爱GoFrame", "我爱"), false) - gtest.Assert(gstr.HasPrefix("en我爱GoFrame", "en"), true) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.HasPrefix("我爱GoFrame", "我爱"), true) + t.Assert(gstr.HasPrefix("en我爱GoFrame", "我爱"), false) + t.Assert(gstr.HasPrefix("en我爱GoFrame", "en"), true) }) } func Test_HasSuffix(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.HasSuffix("我爱GoFrame", "GoFrame"), true) - gtest.Assert(gstr.HasSuffix("en我爱GoFrame", "a"), false) - gtest.Assert(gstr.HasSuffix("GoFrame很棒", "棒"), true) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.HasSuffix("我爱GoFrame", "GoFrame"), true) + t.Assert(gstr.HasSuffix("en我爱GoFrame", "a"), false) + t.Assert(gstr.HasSuffix("GoFrame很棒", "棒"), true) }) } func Test_Reverse(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Reverse("我爱123"), "321爱我") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Reverse("我爱123"), "321爱我") }) } func Test_NumberFormat(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.NumberFormat(1234567.8910, 2, ".", ","), "1,234,567.89") - gtest.Assert(gstr.NumberFormat(1234567.8910, 2, "#", "/"), "1/234/567#89") - gtest.Assert(gstr.NumberFormat(-1234567.8910, 2, "#", "/"), "-1/234/567#89") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.NumberFormat(1234567.8910, 2, ".", ","), "1,234,567.89") + t.Assert(gstr.NumberFormat(1234567.8910, 2, "#", "/"), "1/234/567#89") + t.Assert(gstr.NumberFormat(-1234567.8910, 2, "#", "/"), "-1/234/567#89") }) } func Test_ChunkSplit(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.ChunkSplit("1234", 1, "#"), "1#2#3#4#") - gtest.Assert(gstr.ChunkSplit("我爱123", 1, "#"), "我#爱#1#2#3#") - gtest.Assert(gstr.ChunkSplit("1234", 1, ""), "1\r\n2\r\n3\r\n4\r\n") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.ChunkSplit("1234", 1, "#"), "1#2#3#4#") + t.Assert(gstr.ChunkSplit("我爱123", 1, "#"), "我#爱#1#2#3#") + t.Assert(gstr.ChunkSplit("1234", 1, ""), "1\r\n2\r\n3\r\n4\r\n") }) } func Test_SplitAndTrim(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := ` 010 @@ -202,23 +202,23 @@ func Test_SplitAndTrim(t *testing.T) { ` a := gstr.SplitAndTrim(s, "\n", "0") - gtest.Assert(len(a), 2) - gtest.Assert(a[0], "1") - gtest.Assert(a[1], "2") + t.Assert(len(a), 2) + t.Assert(a[0], "1") + t.Assert(a[1], "2") }) } func Test_Fields(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Fields("我爱 Go Frame"), []string{ + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Fields("我爱 Go Frame"), []string{ "我爱", "Go", "Frame", }) }) } func Test_CountWords(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.CountWords("我爱 Go Go Go"), map[string]int{ + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.CountWords("我爱 Go Go Go"), map[string]int{ "Go": 3, "我爱": 1, }) @@ -226,15 +226,15 @@ func Test_CountWords(t *testing.T) { } func Test_CountChars(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.CountChars("我爱 Go Go Go"), map[string]int{ + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.CountChars("我爱 Go Go Go"), map[string]int{ " ": 3, "G": 3, "o": 3, "我": 1, "爱": 1, }) - gtest.Assert(gstr.CountChars("我爱 Go Go Go", true), map[string]int{ + t.Assert(gstr.CountChars("我爱 Go Go Go", true), map[string]int{ "G": 3, "o": 3, "我": 1, @@ -244,196 +244,196 @@ func Test_CountChars(t *testing.T) { } func Test_WordWrap(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.WordWrap("12 34", 2, "
"), "12
34") - gtest.Assert(gstr.WordWrap("12 34", 2, "\n"), "12\n34") - gtest.Assert(gstr.WordWrap("A very long woooooooooooooooooord. and something", 7, "
"), + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.WordWrap("12 34", 2, "
"), "12
34") + t.Assert(gstr.WordWrap("12 34", 2, "\n"), "12\n34") + t.Assert(gstr.WordWrap("A very long woooooooooooooooooord. and something", 7, "
"), "A very
long
woooooooooooooooooord.
and
something") }) } func Test_RuneLen(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.RuneLen("1234"), 4) - gtest.Assert(gstr.RuneLen("我爱GoFrame"), 9) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.RuneLen("1234"), 4) + t.Assert(gstr.RuneLen("我爱GoFrame"), 9) }) } func Test_Repeat(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Repeat("go", 3), "gogogo") - gtest.Assert(gstr.Repeat("好的", 3), "好的好的好的") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Repeat("go", 3), "gogogo") + t.Assert(gstr.Repeat("好的", 3), "好的好的好的") }) } func Test_Str(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Str("name@example.com", "@"), "@example.com") - gtest.Assert(gstr.Str("name@example.com", ""), "") - gtest.Assert(gstr.Str("name@example.com", "z"), "") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Str("name@example.com", "@"), "@example.com") + t.Assert(gstr.Str("name@example.com", ""), "") + t.Assert(gstr.Str("name@example.com", "z"), "") }) } func Test_Shuffle(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(len(gstr.Shuffle("123456")), 6) + gtest.C(t, func(t *gtest.T) { + t.Assert(len(gstr.Shuffle("123456")), 6) }) } func Test_Split(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Split("1.2", "."), []string{"1", "2"}) - gtest.Assert(gstr.Split("我爱 - GoFrame", " - "), []string{"我爱", "GoFrame"}) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Split("1.2", "."), []string{"1", "2"}) + t.Assert(gstr.Split("我爱 - GoFrame", " - "), []string{"我爱", "GoFrame"}) }) } func Test_Join(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Join([]string{"我爱", "GoFrame"}, " - "), "我爱 - GoFrame") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Join([]string{"我爱", "GoFrame"}, " - "), "我爱 - GoFrame") }) } func Test_Explode(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Explode(" - ", "我爱 - GoFrame"), []string{"我爱", "GoFrame"}) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Explode(" - ", "我爱 - GoFrame"), []string{"我爱", "GoFrame"}) }) } func Test_Implode(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Implode(" - ", []string{"我爱", "GoFrame"}), "我爱 - GoFrame") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Implode(" - ", []string{"我爱", "GoFrame"}), "我爱 - GoFrame") }) } func Test_Chr(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Chr(65), "A") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Chr(65), "A") }) } func Test_Ord(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Ord("A"), 65) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Ord("A"), 65) }) } func Test_HideStr(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.HideStr("15928008611", 40, "*"), "159****8611") - gtest.Assert(gstr.HideStr("john@kohg.cn", 40, "*"), "jo*n@kohg.cn") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.HideStr("15928008611", 40, "*"), "159****8611") + t.Assert(gstr.HideStr("john@kohg.cn", 40, "*"), "jo*n@kohg.cn") }) } func Test_Nl2Br(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Nl2Br("1\n2"), "1
2") - gtest.Assert(gstr.Nl2Br("1\r\n2"), "1
2") - gtest.Assert(gstr.Nl2Br("1\r\n2", true), "1
2") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Nl2Br("1\n2"), "1
2") + t.Assert(gstr.Nl2Br("1\r\n2"), "1
2") + t.Assert(gstr.Nl2Br("1\r\n2", true), "1
2") }) } func Test_AddSlashes(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.AddSlashes(`1'2"3\`), `1\'2\"3\\`) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.AddSlashes(`1'2"3\`), `1\'2\"3\\`) }) } func Test_StripSlashes(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.StripSlashes(`1\'2\"3\\`), `1'2"3\`) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.StripSlashes(`1\'2\"3\\`), `1'2"3\`) }) } func Test_QuoteMeta(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.QuoteMeta(`.\+*?[^]($)`), `\.\\\+\*\?\[\^\]\(\$\)`) - gtest.Assert(gstr.QuoteMeta(`.\+*中国?[^]($)`), `\.\\\+\*中国\?\[\^\]\(\$\)`) - gtest.Assert(gstr.QuoteMeta(`.''`, `'`), `.\'\'`) - gtest.Assert(gstr.QuoteMeta(`中国.''`, `'`), `中国.\'\'`) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.QuoteMeta(`.\+*?[^]($)`), `\.\\\+\*\?\[\^\]\(\$\)`) + t.Assert(gstr.QuoteMeta(`.\+*中国?[^]($)`), `\.\\\+\*中国\?\[\^\]\(\$\)`) + t.Assert(gstr.QuoteMeta(`.''`, `'`), `.\'\'`) + t.Assert(gstr.QuoteMeta(`中国.''`, `'`), `中国.\'\'`) }) } func Test_Count(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { 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) + t.Assert(gstr.Count(s, "0"), 0) + t.Assert(gstr.Count(s, "a"), 2) + t.Assert(gstr.Count(s, "b"), 1) + t.Assert(gstr.Count(s, "d"), 1) }) } func Test_CountI(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { 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) + t.Assert(gstr.CountI(s, "0"), 0) + t.Assert(gstr.CountI(s, "a"), 3) + t.Assert(gstr.CountI(s, "b"), 1) + t.Assert(gstr.CountI(s, "d"), 2) }) } func Test_Compare(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Compare("a", "b"), -1) - gtest.Assert(gstr.Compare("a", "a"), 0) - gtest.Assert(gstr.Compare("b", "a"), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Compare("a", "b"), -1) + t.Assert(gstr.Compare("a", "a"), 0) + t.Assert(gstr.Compare("b", "a"), 1) }) } func Test_Equal(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Equal("a", "A"), true) - gtest.Assert(gstr.Equal("a", "a"), true) - gtest.Assert(gstr.Equal("b", "a"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Equal("a", "A"), true) + t.Assert(gstr.Equal("a", "a"), true) + t.Assert(gstr.Equal("b", "a"), false) }) } func Test_Contains(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Contains("abc", "a"), true) - gtest.Assert(gstr.Contains("abc", "A"), false) - gtest.Assert(gstr.Contains("abc", "ab"), true) - gtest.Assert(gstr.Contains("abc", "abc"), true) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Contains("abc", "a"), true) + t.Assert(gstr.Contains("abc", "A"), false) + t.Assert(gstr.Contains("abc", "ab"), true) + t.Assert(gstr.Contains("abc", "abc"), true) }) } func Test_ContainsI(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.ContainsI("abc", "a"), true) - gtest.Assert(gstr.ContainsI("abc", "A"), true) - gtest.Assert(gstr.ContainsI("abc", "Ab"), true) - gtest.Assert(gstr.ContainsI("abc", "ABC"), true) - gtest.Assert(gstr.ContainsI("abc", "ABCD"), false) - gtest.Assert(gstr.ContainsI("abc", "D"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.ContainsI("abc", "a"), true) + t.Assert(gstr.ContainsI("abc", "A"), true) + t.Assert(gstr.ContainsI("abc", "Ab"), true) + t.Assert(gstr.ContainsI("abc", "ABC"), true) + t.Assert(gstr.ContainsI("abc", "ABCD"), false) + t.Assert(gstr.ContainsI("abc", "D"), false) }) } func Test_ContainsAny(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.ContainsAny("abc", "a"), true) - gtest.Assert(gstr.ContainsAny("abc", "cd"), true) - gtest.Assert(gstr.ContainsAny("abc", "de"), false) - gtest.Assert(gstr.ContainsAny("abc", "A"), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.ContainsAny("abc", "a"), true) + t.Assert(gstr.ContainsAny("abc", "cd"), true) + t.Assert(gstr.ContainsAny("abc", "de"), false) + t.Assert(gstr.ContainsAny("abc", "A"), false) }) } func Test_SearchArray(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a := g.SliceStr{"a", "b", "c"} - gtest.AssertEQ(gstr.SearchArray(a, "a"), 0) - gtest.AssertEQ(gstr.SearchArray(a, "b"), 1) - gtest.AssertEQ(gstr.SearchArray(a, "c"), 2) - gtest.AssertEQ(gstr.SearchArray(a, "d"), -1) + t.AssertEQ(gstr.SearchArray(a, "a"), 0) + t.AssertEQ(gstr.SearchArray(a, "b"), 1) + t.AssertEQ(gstr.SearchArray(a, "c"), 2) + t.AssertEQ(gstr.SearchArray(a, "d"), -1) }) } func Test_InArray(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { a := g.SliceStr{"a", "b", "c"} - gtest.AssertEQ(gstr.InArray(a, "a"), true) - gtest.AssertEQ(gstr.InArray(a, "b"), true) - gtest.AssertEQ(gstr.InArray(a, "c"), true) - gtest.AssertEQ(gstr.InArray(a, "d"), false) + t.AssertEQ(gstr.InArray(a, "a"), true) + t.AssertEQ(gstr.InArray(a, "b"), true) + t.AssertEQ(gstr.InArray(a, "c"), true) + t.AssertEQ(gstr.InArray(a, "d"), false) }) } diff --git a/text/gstr/gstr_z_unit_convert_test.go b/text/gstr/gstr_z_unit_convert_test.go index d5d1e3bd4..94f71cea0 100644 --- a/text/gstr/gstr_z_unit_convert_test.go +++ b/text/gstr/gstr_z_unit_convert_test.go @@ -16,7 +16,7 @@ import ( ) func Test_OctStr(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.OctStr(`\346\200\241`), "怡") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.OctStr(`\346\200\241`), "怡") }) } diff --git a/text/gstr/gstr_z_unit_domain_test.go b/text/gstr/gstr_z_unit_domain_test.go index e6797be2f..93ffb6a79 100644 --- a/text/gstr/gstr_z_unit_domain_test.go +++ b/text/gstr/gstr_z_unit_domain_test.go @@ -16,46 +16,46 @@ import ( ) func Test_IsSubDomain(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { main := "goframe.org" - gtest.Assert(gstr.IsSubDomain("goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.goframe.org:8080", main), true) - gtest.Assert(gstr.IsSubDomain("johng.cn", main), false) - gtest.Assert(gstr.IsSubDomain("s.johng.cn", main), false) - gtest.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false) + t.Assert(gstr.IsSubDomain("goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.s.goframe.org:8080", main), true) + t.Assert(gstr.IsSubDomain("johng.cn", main), false) + t.Assert(gstr.IsSubDomain("s.johng.cn", main), false) + t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { main := "*.goframe.org" - gtest.Assert(gstr.IsSubDomain("goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.goframe.org:80", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.goframe.org", main), false) - gtest.Assert(gstr.IsSubDomain("johng.cn", main), false) - gtest.Assert(gstr.IsSubDomain("s.johng.cn", main), false) - gtest.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false) + t.Assert(gstr.IsSubDomain("goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.goframe.org:80", main), true) + t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), false) + t.Assert(gstr.IsSubDomain("johng.cn", main), false) + t.Assert(gstr.IsSubDomain("s.johng.cn", main), false) + t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { main := "*.*.goframe.org" - gtest.Assert(gstr.IsSubDomain("goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.goframe.org:8000", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.s.goframe.org", main), false) - gtest.Assert(gstr.IsSubDomain("johng.cn", main), false) - gtest.Assert(gstr.IsSubDomain("s.johng.cn", main), false) - gtest.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false) + t.Assert(gstr.IsSubDomain("goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.s.goframe.org:8000", main), true) + t.Assert(gstr.IsSubDomain("s.s.s.goframe.org", main), false) + t.Assert(gstr.IsSubDomain("johng.cn", main), false) + t.Assert(gstr.IsSubDomain("s.johng.cn", main), false) + t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { main := "*.*.goframe.org:8080" - gtest.Assert(gstr.IsSubDomain("goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.goframe.org:8000", main), true) - gtest.Assert(gstr.IsSubDomain("s.s.s.goframe.org", main), false) - gtest.Assert(gstr.IsSubDomain("johng.cn", main), false) - gtest.Assert(gstr.IsSubDomain("s.johng.cn", main), false) - gtest.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false) + t.Assert(gstr.IsSubDomain("goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.s.goframe.org", main), true) + t.Assert(gstr.IsSubDomain("s.s.goframe.org:8000", main), true) + t.Assert(gstr.IsSubDomain("s.s.s.goframe.org", main), false) + t.Assert(gstr.IsSubDomain("johng.cn", main), false) + t.Assert(gstr.IsSubDomain("s.johng.cn", main), false) + t.Assert(gstr.IsSubDomain("s.s.johng.cn", main), false) }) } diff --git a/text/gstr/gstr_z_unit_parse_test.go b/text/gstr/gstr_z_unit_parse_test.go index 545716799..fed8ae01d 100644 --- a/text/gstr/gstr_z_unit_parse_test.go +++ b/text/gstr/gstr_z_unit_parse_test.go @@ -18,48 +18,48 @@ import ( ) func Test_Parse(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { // url - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "goframe.org/index?name=john&score=100" u, err := url.Parse(s) - gtest.Assert(err, nil) + t.Assert(err, nil) m, err := gstr.Parse(u.RawQuery) - gtest.Assert(err, nil) - gtest.Assert(m["name"], "john") - gtest.Assert(m["score"], "100") + t.Assert(err, nil) + t.Assert(m["name"], "john") + t.Assert(m["score"], "100") }) // name overwrite m, err := gstr.Parse("a=1&a=2") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "a": 2, }) // slice m, err = gstr.Parse("a[]=1&a[]=2") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "a": g.Slice{"1", "2"}, }) // map m, err = gstr.Parse("a=1&b=2&c=3") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "a": "1", "b": "2", "c": "3", }) m, err = gstr.Parse("a=1&a=2&c=3") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "a": "2", "c": "3", }) // map m, err = gstr.Parse("m[a]=1&m[b]=2&m[c]=3") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "m": g.Map{ "a": "1", "b": "2", @@ -67,8 +67,8 @@ func Test_Parse(t *testing.T) { }, }) m, err = gstr.Parse("m[a]=1&m[a]=2&m[b]=3") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "m": g.Map{ "a": "2", "b": "3", @@ -76,15 +76,15 @@ func Test_Parse(t *testing.T) { }) // map - slice m, err = gstr.Parse("m[a][]=1&m[a][]=2") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "m": g.Map{ "a": g.Slice{"1", "2"}, }, }) m, err = gstr.Parse("m[a][b][]=1&m[a][b][]=2") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "m": g.Map{ "a": g.Map{ "b": g.Slice{"1", "2"}, @@ -93,8 +93,8 @@ func Test_Parse(t *testing.T) { }) // map - complicated m, err = gstr.Parse("m[a1][b1][c1][d1]=1&m[a2][b2]=2&m[a3][b3][c3]=3") - gtest.Assert(err, nil) - gtest.Assert(m, g.Map{ + t.Assert(err, nil) + t.Assert(m, g.Map{ "m": g.Map{ "a1": g.Map{ "b1": g.Map{ diff --git a/text/gstr/gstr_z_unit_pos_test.go b/text/gstr/gstr_z_unit_pos_test.go index a8724e478..fdd4edecc 100644 --- a/text/gstr/gstr_z_unit_pos_test.go +++ b/text/gstr/gstr_z_unit_pos_test.go @@ -16,48 +16,48 @@ import ( ) func Test_Pos(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcdEFGabcdefg" - gtest.Assert(gstr.Pos(s1, "ab"), 0) - gtest.Assert(gstr.Pos(s1, "ab", 2), 7) - gtest.Assert(gstr.Pos(s1, "abd", 0), -1) - gtest.Assert(gstr.Pos(s1, "e", -4), 11) + t.Assert(gstr.Pos(s1, "ab"), 0) + t.Assert(gstr.Pos(s1, "ab", 2), 7) + t.Assert(gstr.Pos(s1, "abd", 0), -1) + t.Assert(gstr.Pos(s1, "e", -4), 11) }) } func Test_PosI(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcdEFGabcdefg" - gtest.Assert(gstr.PosI(s1, "zz"), -1) - gtest.Assert(gstr.PosI(s1, "ab"), 0) - gtest.Assert(gstr.PosI(s1, "ef", 2), 4) - gtest.Assert(gstr.PosI(s1, "abd", 0), -1) - gtest.Assert(gstr.PosI(s1, "E", -4), 11) + t.Assert(gstr.PosI(s1, "zz"), -1) + t.Assert(gstr.PosI(s1, "ab"), 0) + t.Assert(gstr.PosI(s1, "ef", 2), 4) + t.Assert(gstr.PosI(s1, "abd", 0), -1) + t.Assert(gstr.PosI(s1, "E", -4), 11) }) } func Test_PosR(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcdEFGabcdefg" s2 := "abcdEFGz1cdeab" - gtest.Assert(gstr.PosR(s1, "zz"), -1) - gtest.Assert(gstr.PosR(s1, "ab"), 7) - gtest.Assert(gstr.PosR(s2, "ab", -2), 0) - gtest.Assert(gstr.PosR(s1, "ef"), 11) - gtest.Assert(gstr.PosR(s1, "abd", 0), -1) - gtest.Assert(gstr.PosR(s1, "e", -4), -1) + t.Assert(gstr.PosR(s1, "zz"), -1) + t.Assert(gstr.PosR(s1, "ab"), 7) + t.Assert(gstr.PosR(s2, "ab", -2), 0) + t.Assert(gstr.PosR(s1, "ef"), 11) + t.Assert(gstr.PosR(s1, "abd", 0), -1) + t.Assert(gstr.PosR(s1, "e", -4), -1) }) } func Test_PosRI(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s1 := "abcdEFGabcdefg" s2 := "abcdEFGz1cdeab" - gtest.Assert(gstr.PosRI(s1, "zz"), -1) - gtest.Assert(gstr.PosRI(s1, "AB"), 7) - gtest.Assert(gstr.PosRI(s2, "AB", -2), 0) - gtest.Assert(gstr.PosRI(s1, "EF"), 11) - gtest.Assert(gstr.PosRI(s1, "abd", 0), -1) - gtest.Assert(gstr.PosRI(s1, "e", -5), 4) + t.Assert(gstr.PosRI(s1, "zz"), -1) + t.Assert(gstr.PosRI(s1, "AB"), 7) + t.Assert(gstr.PosRI(s2, "AB", -2), 0) + t.Assert(gstr.PosRI(s1, "EF"), 11) + t.Assert(gstr.PosRI(s1, "abd", 0), -1) + t.Assert(gstr.PosRI(s1, "e", -5), 4) }) } diff --git a/text/gstr/gstr_z_unit_trim_test.go b/text/gstr/gstr_z_unit_trim_test.go index a0f18bcff..d7f38f43a 100644 --- a/text/gstr/gstr_z_unit_trim_test.go +++ b/text/gstr/gstr_z_unit_trim_test.go @@ -16,53 +16,53 @@ import ( ) func Test_Trim(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.Trim(" 123456\n "), "123456") - gtest.Assert(gstr.Trim("#123456#;", "#;"), "123456") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.Trim(" 123456\n "), "123456") + t.Assert(gstr.Trim("#123456#;", "#;"), "123456") }) } func Test_TrimStr(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.TrimStr("gogo我爱gogo", "go"), "我爱") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.TrimStr("gogo我爱gogo", "go"), "我爱") }) - gtest.Case(t, func() { - gtest.Assert(gstr.TrimStr("啊我爱中国人啊", "啊"), "我爱中国人") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.TrimStr("啊我爱中国人啊", "啊"), "我爱中国人") }) } func Test_TrimRight(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.TrimRight(" 123456\n "), " 123456") - gtest.Assert(gstr.TrimRight("#123456#;", "#;"), "#123456") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.TrimRight(" 123456\n "), " 123456") + t.Assert(gstr.TrimRight("#123456#;", "#;"), "#123456") }) } func Test_TrimRightStr(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.TrimRightStr("gogo我爱gogo", "go"), "gogo我爱") - gtest.Assert(gstr.TrimRightStr("gogo我爱gogo", "go我爱gogo"), "go") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.TrimRightStr("gogo我爱gogo", "go"), "gogo我爱") + t.Assert(gstr.TrimRightStr("gogo我爱gogo", "go我爱gogo"), "go") }) - gtest.Case(t, func() { - gtest.Assert(gstr.TrimRightStr("我爱中国人", "人"), "我爱中国") - gtest.Assert(gstr.TrimRightStr("我爱中国人", "爱中国人"), "我") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.TrimRightStr("我爱中国人", "人"), "我爱中国") + t.Assert(gstr.TrimRightStr("我爱中国人", "爱中国人"), "我") }) } func Test_TrimLeft(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.TrimLeft(" \r123456\n "), "123456\n ") - gtest.Assert(gstr.TrimLeft("#;123456#;", "#;"), "123456#;") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.TrimLeft(" \r123456\n "), "123456\n ") + t.Assert(gstr.TrimLeft("#;123456#;", "#;"), "123456#;") }) } func Test_TrimLeftStr(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gstr.TrimLeftStr("gogo我爱gogo", "go"), "我爱gogo") - gtest.Assert(gstr.TrimLeftStr("gogo我爱gogo", "gogo我爱go"), "go") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.TrimLeftStr("gogo我爱gogo", "go"), "我爱gogo") + t.Assert(gstr.TrimLeftStr("gogo我爱gogo", "gogo我爱go"), "go") }) - gtest.Case(t, func() { - gtest.Assert(gstr.TrimLeftStr("我爱中国人", "我爱"), "中国人") - gtest.Assert(gstr.TrimLeftStr("我爱中国人", "我爱中国"), "人") + gtest.C(t, func(t *gtest.T) { + t.Assert(gstr.TrimLeftStr("我爱中国人", "我爱"), "中国人") + t.Assert(gstr.TrimLeftStr("我爱中国人", "我爱中国"), "人") }) } diff --git a/util/gconv/gconv_z_all_test.go b/util/gconv/gconv_z_all_test.go index 8a1f577bc..baca8c5c3 100644 --- a/util/gconv/gconv_z_all_test.go +++ b/util/gconv/gconv_z_all_test.go @@ -37,21 +37,21 @@ func (s1 S1) Error() string { } func Test_Bool_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.AssertEQ(gconv.Bool(i), false) - gtest.AssertEQ(gconv.Bool(false), false) - gtest.AssertEQ(gconv.Bool(nil), false) - gtest.AssertEQ(gconv.Bool(0), false) - gtest.AssertEQ(gconv.Bool("0"), false) - gtest.AssertEQ(gconv.Bool(""), false) - gtest.AssertEQ(gconv.Bool("false"), false) - gtest.AssertEQ(gconv.Bool("off"), false) - gtest.AssertEQ(gconv.Bool([]byte{}), false) - gtest.AssertEQ(gconv.Bool([]string{}), false) - gtest.AssertEQ(gconv.Bool([2]int{1, 2}), true) - gtest.AssertEQ(gconv.Bool([]interface{}{}), false) - gtest.AssertEQ(gconv.Bool([]map[int]int{}), false) + t.AssertEQ(gconv.Bool(i), false) + t.AssertEQ(gconv.Bool(false), false) + t.AssertEQ(gconv.Bool(nil), false) + t.AssertEQ(gconv.Bool(0), false) + t.AssertEQ(gconv.Bool("0"), false) + t.AssertEQ(gconv.Bool(""), false) + t.AssertEQ(gconv.Bool("false"), false) + t.AssertEQ(gconv.Bool("off"), false) + t.AssertEQ(gconv.Bool([]byte{}), false) + t.AssertEQ(gconv.Bool([]string{}), false) + t.AssertEQ(gconv.Bool([2]int{1, 2}), true) + t.AssertEQ(gconv.Bool([]interface{}{}), false) + t.AssertEQ(gconv.Bool([]map[int]int{}), false) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -59,34 +59,34 @@ func Test_Bool_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Bool(countryCapitalMap), true) + t.AssertEQ(gconv.Bool(countryCapitalMap), true) - gtest.AssertEQ(gconv.Bool("1"), true) - gtest.AssertEQ(gconv.Bool("on"), true) - gtest.AssertEQ(gconv.Bool(1), true) - gtest.AssertEQ(gconv.Bool(123.456), true) - gtest.AssertEQ(gconv.Bool(boolStruct{}), true) - gtest.AssertEQ(gconv.Bool(&boolStruct{}), true) + t.AssertEQ(gconv.Bool("1"), true) + t.AssertEQ(gconv.Bool("on"), true) + t.AssertEQ(gconv.Bool(1), true) + t.AssertEQ(gconv.Bool(123.456), true) + t.AssertEQ(gconv.Bool(boolStruct{}), true) + t.AssertEQ(gconv.Bool(&boolStruct{}), true) }) } func Test_Int_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.AssertEQ(gconv.Int(i), 0) - gtest.AssertEQ(gconv.Int(false), 0) - gtest.AssertEQ(gconv.Int(nil), 0) - gtest.Assert(gconv.Int(nil), 0) - gtest.AssertEQ(gconv.Int(0), 0) - gtest.AssertEQ(gconv.Int("0"), 0) - gtest.AssertEQ(gconv.Int(""), 0) - gtest.AssertEQ(gconv.Int("false"), 0) - gtest.AssertEQ(gconv.Int("off"), 0) - gtest.AssertEQ(gconv.Int([]byte{}), 0) - gtest.AssertEQ(gconv.Int([]string{}), 0) - gtest.AssertEQ(gconv.Int([2]int{1, 2}), 0) - gtest.AssertEQ(gconv.Int([]interface{}{}), 0) - gtest.AssertEQ(gconv.Int([]map[int]int{}), 0) + t.AssertEQ(gconv.Int(i), 0) + t.AssertEQ(gconv.Int(false), 0) + t.AssertEQ(gconv.Int(nil), 0) + t.Assert(gconv.Int(nil), 0) + t.AssertEQ(gconv.Int(0), 0) + t.AssertEQ(gconv.Int("0"), 0) + t.AssertEQ(gconv.Int(""), 0) + t.AssertEQ(gconv.Int("false"), 0) + t.AssertEQ(gconv.Int("off"), 0) + t.AssertEQ(gconv.Int([]byte{}), 0) + t.AssertEQ(gconv.Int([]string{}), 0) + t.AssertEQ(gconv.Int([2]int{1, 2}), 0) + t.AssertEQ(gconv.Int([]interface{}{}), 0) + t.AssertEQ(gconv.Int([]map[int]int{}), 0) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -94,33 +94,33 @@ func Test_Int_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Int(countryCapitalMap), 0) + t.AssertEQ(gconv.Int(countryCapitalMap), 0) - gtest.AssertEQ(gconv.Int("1"), 1) - gtest.AssertEQ(gconv.Int("on"), 0) - gtest.AssertEQ(gconv.Int(1), 1) - gtest.AssertEQ(gconv.Int(123.456), 123) - gtest.AssertEQ(gconv.Int(boolStruct{}), 0) - gtest.AssertEQ(gconv.Int(&boolStruct{}), 0) + t.AssertEQ(gconv.Int("1"), 1) + t.AssertEQ(gconv.Int("on"), 0) + t.AssertEQ(gconv.Int(1), 1) + t.AssertEQ(gconv.Int(123.456), 123) + t.AssertEQ(gconv.Int(boolStruct{}), 0) + t.AssertEQ(gconv.Int(&boolStruct{}), 0) }) } func Test_Int8_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.Assert(gconv.Int8(i), int8(0)) - gtest.AssertEQ(gconv.Int8(false), int8(0)) - gtest.AssertEQ(gconv.Int8(nil), int8(0)) - gtest.AssertEQ(gconv.Int8(0), int8(0)) - gtest.AssertEQ(gconv.Int8("0"), int8(0)) - gtest.AssertEQ(gconv.Int8(""), int8(0)) - gtest.AssertEQ(gconv.Int8("false"), int8(0)) - gtest.AssertEQ(gconv.Int8("off"), int8(0)) - gtest.AssertEQ(gconv.Int8([]byte{}), int8(0)) - gtest.AssertEQ(gconv.Int8([]string{}), int8(0)) - gtest.AssertEQ(gconv.Int8([2]int{1, 2}), int8(0)) - gtest.AssertEQ(gconv.Int8([]interface{}{}), int8(0)) - gtest.AssertEQ(gconv.Int8([]map[int]int{}), int8(0)) + t.Assert(gconv.Int8(i), int8(0)) + t.AssertEQ(gconv.Int8(false), int8(0)) + t.AssertEQ(gconv.Int8(nil), int8(0)) + t.AssertEQ(gconv.Int8(0), int8(0)) + t.AssertEQ(gconv.Int8("0"), int8(0)) + t.AssertEQ(gconv.Int8(""), int8(0)) + t.AssertEQ(gconv.Int8("false"), int8(0)) + t.AssertEQ(gconv.Int8("off"), int8(0)) + t.AssertEQ(gconv.Int8([]byte{}), int8(0)) + t.AssertEQ(gconv.Int8([]string{}), int8(0)) + t.AssertEQ(gconv.Int8([2]int{1, 2}), int8(0)) + t.AssertEQ(gconv.Int8([]interface{}{}), int8(0)) + t.AssertEQ(gconv.Int8([]map[int]int{}), int8(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -128,33 +128,33 @@ func Test_Int8_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Int8(countryCapitalMap), int8(0)) + t.AssertEQ(gconv.Int8(countryCapitalMap), int8(0)) - gtest.AssertEQ(gconv.Int8("1"), int8(1)) - gtest.AssertEQ(gconv.Int8("on"), int8(0)) - gtest.AssertEQ(gconv.Int8(int8(1)), int8(1)) - gtest.AssertEQ(gconv.Int8(123.456), int8(123)) - gtest.AssertEQ(gconv.Int8(boolStruct{}), int8(0)) - gtest.AssertEQ(gconv.Int8(&boolStruct{}), int8(0)) + t.AssertEQ(gconv.Int8("1"), int8(1)) + t.AssertEQ(gconv.Int8("on"), int8(0)) + t.AssertEQ(gconv.Int8(int8(1)), int8(1)) + t.AssertEQ(gconv.Int8(123.456), int8(123)) + t.AssertEQ(gconv.Int8(boolStruct{}), int8(0)) + t.AssertEQ(gconv.Int8(&boolStruct{}), int8(0)) }) } func Test_Int16_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.Assert(gconv.Int16(i), int16(0)) - gtest.AssertEQ(gconv.Int16(false), int16(0)) - gtest.AssertEQ(gconv.Int16(nil), int16(0)) - gtest.AssertEQ(gconv.Int16(0), int16(0)) - gtest.AssertEQ(gconv.Int16("0"), int16(0)) - gtest.AssertEQ(gconv.Int16(""), int16(0)) - gtest.AssertEQ(gconv.Int16("false"), int16(0)) - gtest.AssertEQ(gconv.Int16("off"), int16(0)) - gtest.AssertEQ(gconv.Int16([]byte{}), int16(0)) - gtest.AssertEQ(gconv.Int16([]string{}), int16(0)) - gtest.AssertEQ(gconv.Int16([2]int{1, 2}), int16(0)) - gtest.AssertEQ(gconv.Int16([]interface{}{}), int16(0)) - gtest.AssertEQ(gconv.Int16([]map[int]int{}), int16(0)) + t.Assert(gconv.Int16(i), int16(0)) + t.AssertEQ(gconv.Int16(false), int16(0)) + t.AssertEQ(gconv.Int16(nil), int16(0)) + t.AssertEQ(gconv.Int16(0), int16(0)) + t.AssertEQ(gconv.Int16("0"), int16(0)) + t.AssertEQ(gconv.Int16(""), int16(0)) + t.AssertEQ(gconv.Int16("false"), int16(0)) + t.AssertEQ(gconv.Int16("off"), int16(0)) + t.AssertEQ(gconv.Int16([]byte{}), int16(0)) + t.AssertEQ(gconv.Int16([]string{}), int16(0)) + t.AssertEQ(gconv.Int16([2]int{1, 2}), int16(0)) + t.AssertEQ(gconv.Int16([]interface{}{}), int16(0)) + t.AssertEQ(gconv.Int16([]map[int]int{}), int16(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -162,33 +162,33 @@ func Test_Int16_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Int16(countryCapitalMap), int16(0)) + t.AssertEQ(gconv.Int16(countryCapitalMap), int16(0)) - gtest.AssertEQ(gconv.Int16("1"), int16(1)) - gtest.AssertEQ(gconv.Int16("on"), int16(0)) - gtest.AssertEQ(gconv.Int16(int16(1)), int16(1)) - gtest.AssertEQ(gconv.Int16(123.456), int16(123)) - gtest.AssertEQ(gconv.Int16(boolStruct{}), int16(0)) - gtest.AssertEQ(gconv.Int16(&boolStruct{}), int16(0)) + t.AssertEQ(gconv.Int16("1"), int16(1)) + t.AssertEQ(gconv.Int16("on"), int16(0)) + t.AssertEQ(gconv.Int16(int16(1)), int16(1)) + t.AssertEQ(gconv.Int16(123.456), int16(123)) + t.AssertEQ(gconv.Int16(boolStruct{}), int16(0)) + t.AssertEQ(gconv.Int16(&boolStruct{}), int16(0)) }) } func Test_Int32_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.Assert(gconv.Int32(i), int32(0)) - gtest.AssertEQ(gconv.Int32(false), int32(0)) - gtest.AssertEQ(gconv.Int32(nil), int32(0)) - gtest.AssertEQ(gconv.Int32(0), int32(0)) - gtest.AssertEQ(gconv.Int32("0"), int32(0)) - gtest.AssertEQ(gconv.Int32(""), int32(0)) - gtest.AssertEQ(gconv.Int32("false"), int32(0)) - gtest.AssertEQ(gconv.Int32("off"), int32(0)) - gtest.AssertEQ(gconv.Int32([]byte{}), int32(0)) - gtest.AssertEQ(gconv.Int32([]string{}), int32(0)) - gtest.AssertEQ(gconv.Int32([2]int{1, 2}), int32(0)) - gtest.AssertEQ(gconv.Int32([]interface{}{}), int32(0)) - gtest.AssertEQ(gconv.Int32([]map[int]int{}), int32(0)) + t.Assert(gconv.Int32(i), int32(0)) + t.AssertEQ(gconv.Int32(false), int32(0)) + t.AssertEQ(gconv.Int32(nil), int32(0)) + t.AssertEQ(gconv.Int32(0), int32(0)) + t.AssertEQ(gconv.Int32("0"), int32(0)) + t.AssertEQ(gconv.Int32(""), int32(0)) + t.AssertEQ(gconv.Int32("false"), int32(0)) + t.AssertEQ(gconv.Int32("off"), int32(0)) + t.AssertEQ(gconv.Int32([]byte{}), int32(0)) + t.AssertEQ(gconv.Int32([]string{}), int32(0)) + t.AssertEQ(gconv.Int32([2]int{1, 2}), int32(0)) + t.AssertEQ(gconv.Int32([]interface{}{}), int32(0)) + t.AssertEQ(gconv.Int32([]map[int]int{}), int32(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -196,53 +196,53 @@ func Test_Int32_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Int32(countryCapitalMap), int32(0)) + t.AssertEQ(gconv.Int32(countryCapitalMap), int32(0)) - gtest.AssertEQ(gconv.Int32("1"), int32(1)) - gtest.AssertEQ(gconv.Int32("on"), int32(0)) - gtest.AssertEQ(gconv.Int32(int32(1)), int32(1)) - gtest.AssertEQ(gconv.Int32(123.456), int32(123)) - gtest.AssertEQ(gconv.Int32(boolStruct{}), int32(0)) - gtest.AssertEQ(gconv.Int32(&boolStruct{}), int32(0)) + t.AssertEQ(gconv.Int32("1"), int32(1)) + t.AssertEQ(gconv.Int32("on"), int32(0)) + t.AssertEQ(gconv.Int32(int32(1)), int32(1)) + t.AssertEQ(gconv.Int32(123.456), int32(123)) + t.AssertEQ(gconv.Int32(boolStruct{}), int32(0)) + t.AssertEQ(gconv.Int32(&boolStruct{}), int32(0)) }) } func Test_Int64_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.AssertEQ(gconv.Int64("0x00e"), int64(14)) - gtest.Assert(gconv.Int64("022"), int64(18)) + t.AssertEQ(gconv.Int64("0x00e"), int64(14)) + t.Assert(gconv.Int64("022"), int64(18)) - gtest.Assert(gconv.Int64(i), int64(0)) - gtest.Assert(gconv.Int64(true), 1) - gtest.Assert(gconv.Int64("1"), int64(1)) - gtest.Assert(gconv.Int64("0"), int64(0)) - gtest.Assert(gconv.Int64("X"), int64(0)) - gtest.Assert(gconv.Int64("x"), int64(0)) - gtest.Assert(gconv.Int64(int64(1)), int64(1)) - gtest.Assert(gconv.Int64(int(0)), int64(0)) - gtest.Assert(gconv.Int64(int8(0)), int64(0)) - gtest.Assert(gconv.Int64(int16(0)), int64(0)) - gtest.Assert(gconv.Int64(int32(0)), int64(0)) - gtest.Assert(gconv.Int64(uint64(0)), int64(0)) - gtest.Assert(gconv.Int64(uint32(0)), int64(0)) - gtest.Assert(gconv.Int64(uint16(0)), int64(0)) - gtest.Assert(gconv.Int64(uint8(0)), int64(0)) - gtest.Assert(gconv.Int64(uint(0)), int64(0)) - gtest.Assert(gconv.Int64(float32(0)), int64(0)) + t.Assert(gconv.Int64(i), int64(0)) + t.Assert(gconv.Int64(true), 1) + t.Assert(gconv.Int64("1"), int64(1)) + t.Assert(gconv.Int64("0"), int64(0)) + t.Assert(gconv.Int64("X"), int64(0)) + t.Assert(gconv.Int64("x"), int64(0)) + t.Assert(gconv.Int64(int64(1)), int64(1)) + t.Assert(gconv.Int64(int(0)), int64(0)) + t.Assert(gconv.Int64(int8(0)), int64(0)) + t.Assert(gconv.Int64(int16(0)), int64(0)) + t.Assert(gconv.Int64(int32(0)), int64(0)) + t.Assert(gconv.Int64(uint64(0)), int64(0)) + t.Assert(gconv.Int64(uint32(0)), int64(0)) + t.Assert(gconv.Int64(uint16(0)), int64(0)) + t.Assert(gconv.Int64(uint8(0)), int64(0)) + t.Assert(gconv.Int64(uint(0)), int64(0)) + t.Assert(gconv.Int64(float32(0)), int64(0)) - gtest.AssertEQ(gconv.Int64(false), int64(0)) - gtest.AssertEQ(gconv.Int64(nil), int64(0)) - gtest.AssertEQ(gconv.Int64(0), int64(0)) - gtest.AssertEQ(gconv.Int64("0"), int64(0)) - gtest.AssertEQ(gconv.Int64(""), int64(0)) - gtest.AssertEQ(gconv.Int64("false"), int64(0)) - gtest.AssertEQ(gconv.Int64("off"), int64(0)) - gtest.AssertEQ(gconv.Int64([]byte{}), int64(0)) - gtest.AssertEQ(gconv.Int64([]string{}), int64(0)) - gtest.AssertEQ(gconv.Int64([2]int{1, 2}), int64(0)) - gtest.AssertEQ(gconv.Int64([]interface{}{}), int64(0)) - gtest.AssertEQ(gconv.Int64([]map[int]int{}), int64(0)) + t.AssertEQ(gconv.Int64(false), int64(0)) + t.AssertEQ(gconv.Int64(nil), int64(0)) + t.AssertEQ(gconv.Int64(0), int64(0)) + t.AssertEQ(gconv.Int64("0"), int64(0)) + t.AssertEQ(gconv.Int64(""), int64(0)) + t.AssertEQ(gconv.Int64("false"), int64(0)) + t.AssertEQ(gconv.Int64("off"), int64(0)) + t.AssertEQ(gconv.Int64([]byte{}), int64(0)) + t.AssertEQ(gconv.Int64([]string{}), int64(0)) + t.AssertEQ(gconv.Int64([2]int{1, 2}), int64(0)) + t.AssertEQ(gconv.Int64([]interface{}{}), int64(0)) + t.AssertEQ(gconv.Int64([]map[int]int{}), int64(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -250,34 +250,34 @@ func Test_Int64_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Int64(countryCapitalMap), int64(0)) + t.AssertEQ(gconv.Int64(countryCapitalMap), int64(0)) - gtest.AssertEQ(gconv.Int64("1"), int64(1)) - gtest.AssertEQ(gconv.Int64("on"), int64(0)) - gtest.AssertEQ(gconv.Int64(int64(1)), int64(1)) - gtest.AssertEQ(gconv.Int64(123.456), int64(123)) - gtest.AssertEQ(gconv.Int64(boolStruct{}), int64(0)) - gtest.AssertEQ(gconv.Int64(&boolStruct{}), int64(0)) + t.AssertEQ(gconv.Int64("1"), int64(1)) + t.AssertEQ(gconv.Int64("on"), int64(0)) + t.AssertEQ(gconv.Int64(int64(1)), int64(1)) + t.AssertEQ(gconv.Int64(123.456), int64(123)) + t.AssertEQ(gconv.Int64(boolStruct{}), int64(0)) + t.AssertEQ(gconv.Int64(&boolStruct{}), int64(0)) }) } func Test_Uint_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.AssertEQ(gconv.Uint(i), uint(0)) - gtest.AssertEQ(gconv.Uint(false), uint(0)) - gtest.AssertEQ(gconv.Uint(nil), uint(0)) - gtest.Assert(gconv.Uint(nil), uint(0)) - gtest.AssertEQ(gconv.Uint(uint(0)), uint(0)) - gtest.AssertEQ(gconv.Uint("0"), uint(0)) - gtest.AssertEQ(gconv.Uint(""), uint(0)) - gtest.AssertEQ(gconv.Uint("false"), uint(0)) - gtest.AssertEQ(gconv.Uint("off"), uint(0)) - gtest.AssertEQ(gconv.Uint([]byte{}), uint(0)) - gtest.AssertEQ(gconv.Uint([]string{}), uint(0)) - gtest.AssertEQ(gconv.Uint([2]int{1, 2}), uint(0)) - gtest.AssertEQ(gconv.Uint([]interface{}{}), uint(0)) - gtest.AssertEQ(gconv.Uint([]map[int]int{}), uint(0)) + t.AssertEQ(gconv.Uint(i), uint(0)) + t.AssertEQ(gconv.Uint(false), uint(0)) + t.AssertEQ(gconv.Uint(nil), uint(0)) + t.Assert(gconv.Uint(nil), uint(0)) + t.AssertEQ(gconv.Uint(uint(0)), uint(0)) + t.AssertEQ(gconv.Uint("0"), uint(0)) + t.AssertEQ(gconv.Uint(""), uint(0)) + t.AssertEQ(gconv.Uint("false"), uint(0)) + t.AssertEQ(gconv.Uint("off"), uint(0)) + t.AssertEQ(gconv.Uint([]byte{}), uint(0)) + t.AssertEQ(gconv.Uint([]string{}), uint(0)) + t.AssertEQ(gconv.Uint([2]int{1, 2}), uint(0)) + t.AssertEQ(gconv.Uint([]interface{}{}), uint(0)) + t.AssertEQ(gconv.Uint([]map[int]int{}), uint(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -285,34 +285,34 @@ func Test_Uint_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Uint(countryCapitalMap), uint(0)) + t.AssertEQ(gconv.Uint(countryCapitalMap), uint(0)) - gtest.AssertEQ(gconv.Uint("1"), uint(1)) - gtest.AssertEQ(gconv.Uint("on"), uint(0)) - gtest.AssertEQ(gconv.Uint(1), uint(1)) - gtest.AssertEQ(gconv.Uint(123.456), uint(123)) - gtest.AssertEQ(gconv.Uint(boolStruct{}), uint(0)) - gtest.AssertEQ(gconv.Uint(&boolStruct{}), uint(0)) + t.AssertEQ(gconv.Uint("1"), uint(1)) + t.AssertEQ(gconv.Uint("on"), uint(0)) + t.AssertEQ(gconv.Uint(1), uint(1)) + t.AssertEQ(gconv.Uint(123.456), uint(123)) + t.AssertEQ(gconv.Uint(boolStruct{}), uint(0)) + t.AssertEQ(gconv.Uint(&boolStruct{}), uint(0)) }) } func Test_Uint8_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.Assert(gconv.Uint8(i), uint8(0)) - gtest.AssertEQ(gconv.Uint8(uint8(1)), uint8(1)) - gtest.AssertEQ(gconv.Uint8(false), uint8(0)) - gtest.AssertEQ(gconv.Uint8(nil), uint8(0)) - gtest.AssertEQ(gconv.Uint8(0), uint8(0)) - gtest.AssertEQ(gconv.Uint8("0"), uint8(0)) - gtest.AssertEQ(gconv.Uint8(""), uint8(0)) - gtest.AssertEQ(gconv.Uint8("false"), uint8(0)) - gtest.AssertEQ(gconv.Uint8("off"), uint8(0)) - gtest.AssertEQ(gconv.Uint8([]byte{}), uint8(0)) - gtest.AssertEQ(gconv.Uint8([]string{}), uint8(0)) - gtest.AssertEQ(gconv.Uint8([2]int{1, 2}), uint8(0)) - gtest.AssertEQ(gconv.Uint8([]interface{}{}), uint8(0)) - gtest.AssertEQ(gconv.Uint8([]map[int]int{}), uint8(0)) + t.Assert(gconv.Uint8(i), uint8(0)) + t.AssertEQ(gconv.Uint8(uint8(1)), uint8(1)) + t.AssertEQ(gconv.Uint8(false), uint8(0)) + t.AssertEQ(gconv.Uint8(nil), uint8(0)) + t.AssertEQ(gconv.Uint8(0), uint8(0)) + t.AssertEQ(gconv.Uint8("0"), uint8(0)) + t.AssertEQ(gconv.Uint8(""), uint8(0)) + t.AssertEQ(gconv.Uint8("false"), uint8(0)) + t.AssertEQ(gconv.Uint8("off"), uint8(0)) + t.AssertEQ(gconv.Uint8([]byte{}), uint8(0)) + t.AssertEQ(gconv.Uint8([]string{}), uint8(0)) + t.AssertEQ(gconv.Uint8([2]int{1, 2}), uint8(0)) + t.AssertEQ(gconv.Uint8([]interface{}{}), uint8(0)) + t.AssertEQ(gconv.Uint8([]map[int]int{}), uint8(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -320,34 +320,34 @@ func Test_Uint8_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Uint8(countryCapitalMap), uint8(0)) + t.AssertEQ(gconv.Uint8(countryCapitalMap), uint8(0)) - gtest.AssertEQ(gconv.Uint8("1"), uint8(1)) - gtest.AssertEQ(gconv.Uint8("on"), uint8(0)) - gtest.AssertEQ(gconv.Uint8(int8(1)), uint8(1)) - gtest.AssertEQ(gconv.Uint8(123.456), uint8(123)) - gtest.AssertEQ(gconv.Uint8(boolStruct{}), uint8(0)) - gtest.AssertEQ(gconv.Uint8(&boolStruct{}), uint8(0)) + t.AssertEQ(gconv.Uint8("1"), uint8(1)) + t.AssertEQ(gconv.Uint8("on"), uint8(0)) + t.AssertEQ(gconv.Uint8(int8(1)), uint8(1)) + t.AssertEQ(gconv.Uint8(123.456), uint8(123)) + t.AssertEQ(gconv.Uint8(boolStruct{}), uint8(0)) + t.AssertEQ(gconv.Uint8(&boolStruct{}), uint8(0)) }) } func Test_Uint16_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.Assert(gconv.Uint16(i), uint16(0)) - gtest.AssertEQ(gconv.Uint16(uint16(1)), uint16(1)) - gtest.AssertEQ(gconv.Uint16(false), uint16(0)) - gtest.AssertEQ(gconv.Uint16(nil), uint16(0)) - gtest.AssertEQ(gconv.Uint16(0), uint16(0)) - gtest.AssertEQ(gconv.Uint16("0"), uint16(0)) - gtest.AssertEQ(gconv.Uint16(""), uint16(0)) - gtest.AssertEQ(gconv.Uint16("false"), uint16(0)) - gtest.AssertEQ(gconv.Uint16("off"), uint16(0)) - gtest.AssertEQ(gconv.Uint16([]byte{}), uint16(0)) - gtest.AssertEQ(gconv.Uint16([]string{}), uint16(0)) - gtest.AssertEQ(gconv.Uint16([2]int{1, 2}), uint16(0)) - gtest.AssertEQ(gconv.Uint16([]interface{}{}), uint16(0)) - gtest.AssertEQ(gconv.Uint16([]map[int]int{}), uint16(0)) + t.Assert(gconv.Uint16(i), uint16(0)) + t.AssertEQ(gconv.Uint16(uint16(1)), uint16(1)) + t.AssertEQ(gconv.Uint16(false), uint16(0)) + t.AssertEQ(gconv.Uint16(nil), uint16(0)) + t.AssertEQ(gconv.Uint16(0), uint16(0)) + t.AssertEQ(gconv.Uint16("0"), uint16(0)) + t.AssertEQ(gconv.Uint16(""), uint16(0)) + t.AssertEQ(gconv.Uint16("false"), uint16(0)) + t.AssertEQ(gconv.Uint16("off"), uint16(0)) + t.AssertEQ(gconv.Uint16([]byte{}), uint16(0)) + t.AssertEQ(gconv.Uint16([]string{}), uint16(0)) + t.AssertEQ(gconv.Uint16([2]int{1, 2}), uint16(0)) + t.AssertEQ(gconv.Uint16([]interface{}{}), uint16(0)) + t.AssertEQ(gconv.Uint16([]map[int]int{}), uint16(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -355,34 +355,34 @@ func Test_Uint16_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Uint16(countryCapitalMap), uint16(0)) + t.AssertEQ(gconv.Uint16(countryCapitalMap), uint16(0)) - gtest.AssertEQ(gconv.Uint16("1"), uint16(1)) - gtest.AssertEQ(gconv.Uint16("on"), uint16(0)) - gtest.AssertEQ(gconv.Uint16(int16(1)), uint16(1)) - gtest.AssertEQ(gconv.Uint16(123.456), uint16(123)) - gtest.AssertEQ(gconv.Uint16(boolStruct{}), uint16(0)) - gtest.AssertEQ(gconv.Uint16(&boolStruct{}), uint16(0)) + t.AssertEQ(gconv.Uint16("1"), uint16(1)) + t.AssertEQ(gconv.Uint16("on"), uint16(0)) + t.AssertEQ(gconv.Uint16(int16(1)), uint16(1)) + t.AssertEQ(gconv.Uint16(123.456), uint16(123)) + t.AssertEQ(gconv.Uint16(boolStruct{}), uint16(0)) + t.AssertEQ(gconv.Uint16(&boolStruct{}), uint16(0)) }) } func Test_Uint32_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.Assert(gconv.Uint32(i), uint32(0)) - gtest.AssertEQ(gconv.Uint32(uint32(1)), uint32(1)) - gtest.AssertEQ(gconv.Uint32(false), uint32(0)) - gtest.AssertEQ(gconv.Uint32(nil), uint32(0)) - gtest.AssertEQ(gconv.Uint32(0), uint32(0)) - gtest.AssertEQ(gconv.Uint32("0"), uint32(0)) - gtest.AssertEQ(gconv.Uint32(""), uint32(0)) - gtest.AssertEQ(gconv.Uint32("false"), uint32(0)) - gtest.AssertEQ(gconv.Uint32("off"), uint32(0)) - gtest.AssertEQ(gconv.Uint32([]byte{}), uint32(0)) - gtest.AssertEQ(gconv.Uint32([]string{}), uint32(0)) - gtest.AssertEQ(gconv.Uint32([2]int{1, 2}), uint32(0)) - gtest.AssertEQ(gconv.Uint32([]interface{}{}), uint32(0)) - gtest.AssertEQ(gconv.Uint32([]map[int]int{}), uint32(0)) + t.Assert(gconv.Uint32(i), uint32(0)) + t.AssertEQ(gconv.Uint32(uint32(1)), uint32(1)) + t.AssertEQ(gconv.Uint32(false), uint32(0)) + t.AssertEQ(gconv.Uint32(nil), uint32(0)) + t.AssertEQ(gconv.Uint32(0), uint32(0)) + t.AssertEQ(gconv.Uint32("0"), uint32(0)) + t.AssertEQ(gconv.Uint32(""), uint32(0)) + t.AssertEQ(gconv.Uint32("false"), uint32(0)) + t.AssertEQ(gconv.Uint32("off"), uint32(0)) + t.AssertEQ(gconv.Uint32([]byte{}), uint32(0)) + t.AssertEQ(gconv.Uint32([]string{}), uint32(0)) + t.AssertEQ(gconv.Uint32([2]int{1, 2}), uint32(0)) + t.AssertEQ(gconv.Uint32([]interface{}{}), uint32(0)) + t.AssertEQ(gconv.Uint32([]map[int]int{}), uint32(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -390,53 +390,53 @@ func Test_Uint32_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Uint32(countryCapitalMap), uint32(0)) + t.AssertEQ(gconv.Uint32(countryCapitalMap), uint32(0)) - gtest.AssertEQ(gconv.Uint32("1"), uint32(1)) - gtest.AssertEQ(gconv.Uint32("on"), uint32(0)) - gtest.AssertEQ(gconv.Uint32(int32(1)), uint32(1)) - gtest.AssertEQ(gconv.Uint32(123.456), uint32(123)) - gtest.AssertEQ(gconv.Uint32(boolStruct{}), uint32(0)) - gtest.AssertEQ(gconv.Uint32(&boolStruct{}), uint32(0)) + t.AssertEQ(gconv.Uint32("1"), uint32(1)) + t.AssertEQ(gconv.Uint32("on"), uint32(0)) + t.AssertEQ(gconv.Uint32(int32(1)), uint32(1)) + t.AssertEQ(gconv.Uint32(123.456), uint32(123)) + t.AssertEQ(gconv.Uint32(boolStruct{}), uint32(0)) + t.AssertEQ(gconv.Uint32(&boolStruct{}), uint32(0)) }) } func Test_Uint64_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.AssertEQ(gconv.Uint64("0x00e"), uint64(14)) - gtest.Assert(gconv.Uint64("022"), uint64(18)) + t.AssertEQ(gconv.Uint64("0x00e"), uint64(14)) + t.Assert(gconv.Uint64("022"), uint64(18)) - gtest.AssertEQ(gconv.Uint64(i), uint64(0)) - gtest.AssertEQ(gconv.Uint64(true), uint64(1)) - gtest.Assert(gconv.Uint64("1"), int64(1)) - gtest.Assert(gconv.Uint64("0"), uint64(0)) - gtest.Assert(gconv.Uint64("X"), uint64(0)) - gtest.Assert(gconv.Uint64("x"), uint64(0)) - gtest.Assert(gconv.Uint64(int64(1)), uint64(1)) - gtest.Assert(gconv.Uint64(int(0)), uint64(0)) - gtest.Assert(gconv.Uint64(int8(0)), uint64(0)) - gtest.Assert(gconv.Uint64(int16(0)), uint64(0)) - gtest.Assert(gconv.Uint64(int32(0)), uint64(0)) - gtest.Assert(gconv.Uint64(uint64(0)), uint64(0)) - gtest.Assert(gconv.Uint64(uint32(0)), uint64(0)) - gtest.Assert(gconv.Uint64(uint16(0)), uint64(0)) - gtest.Assert(gconv.Uint64(uint8(0)), uint64(0)) - gtest.Assert(gconv.Uint64(uint(0)), uint64(0)) - gtest.Assert(gconv.Uint64(float32(0)), uint64(0)) + t.AssertEQ(gconv.Uint64(i), uint64(0)) + t.AssertEQ(gconv.Uint64(true), uint64(1)) + t.Assert(gconv.Uint64("1"), int64(1)) + t.Assert(gconv.Uint64("0"), uint64(0)) + t.Assert(gconv.Uint64("X"), uint64(0)) + t.Assert(gconv.Uint64("x"), uint64(0)) + t.Assert(gconv.Uint64(int64(1)), uint64(1)) + t.Assert(gconv.Uint64(int(0)), uint64(0)) + t.Assert(gconv.Uint64(int8(0)), uint64(0)) + t.Assert(gconv.Uint64(int16(0)), uint64(0)) + t.Assert(gconv.Uint64(int32(0)), uint64(0)) + t.Assert(gconv.Uint64(uint64(0)), uint64(0)) + t.Assert(gconv.Uint64(uint32(0)), uint64(0)) + t.Assert(gconv.Uint64(uint16(0)), uint64(0)) + t.Assert(gconv.Uint64(uint8(0)), uint64(0)) + t.Assert(gconv.Uint64(uint(0)), uint64(0)) + t.Assert(gconv.Uint64(float32(0)), uint64(0)) - gtest.AssertEQ(gconv.Uint64(false), uint64(0)) - gtest.AssertEQ(gconv.Uint64(nil), uint64(0)) - gtest.AssertEQ(gconv.Uint64(0), uint64(0)) - gtest.AssertEQ(gconv.Uint64("0"), uint64(0)) - gtest.AssertEQ(gconv.Uint64(""), uint64(0)) - gtest.AssertEQ(gconv.Uint64("false"), uint64(0)) - gtest.AssertEQ(gconv.Uint64("off"), uint64(0)) - gtest.AssertEQ(gconv.Uint64([]byte{}), uint64(0)) - gtest.AssertEQ(gconv.Uint64([]string{}), uint64(0)) - gtest.AssertEQ(gconv.Uint64([2]int{1, 2}), uint64(0)) - gtest.AssertEQ(gconv.Uint64([]interface{}{}), uint64(0)) - gtest.AssertEQ(gconv.Uint64([]map[int]int{}), uint64(0)) + t.AssertEQ(gconv.Uint64(false), uint64(0)) + t.AssertEQ(gconv.Uint64(nil), uint64(0)) + t.AssertEQ(gconv.Uint64(0), uint64(0)) + t.AssertEQ(gconv.Uint64("0"), uint64(0)) + t.AssertEQ(gconv.Uint64(""), uint64(0)) + t.AssertEQ(gconv.Uint64("false"), uint64(0)) + t.AssertEQ(gconv.Uint64("off"), uint64(0)) + t.AssertEQ(gconv.Uint64([]byte{}), uint64(0)) + t.AssertEQ(gconv.Uint64([]string{}), uint64(0)) + t.AssertEQ(gconv.Uint64([2]int{1, 2}), uint64(0)) + t.AssertEQ(gconv.Uint64([]interface{}{}), uint64(0)) + t.AssertEQ(gconv.Uint64([]map[int]int{}), uint64(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -444,33 +444,33 @@ func Test_Uint64_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Uint64(countryCapitalMap), uint64(0)) + t.AssertEQ(gconv.Uint64(countryCapitalMap), uint64(0)) - gtest.AssertEQ(gconv.Uint64("1"), uint64(1)) - gtest.AssertEQ(gconv.Uint64("on"), uint64(0)) - gtest.AssertEQ(gconv.Uint64(int64(1)), uint64(1)) - gtest.AssertEQ(gconv.Uint64(123.456), uint64(123)) - gtest.AssertEQ(gconv.Uint64(boolStruct{}), uint64(0)) - gtest.AssertEQ(gconv.Uint64(&boolStruct{}), uint64(0)) + t.AssertEQ(gconv.Uint64("1"), uint64(1)) + t.AssertEQ(gconv.Uint64("on"), uint64(0)) + t.AssertEQ(gconv.Uint64(int64(1)), uint64(1)) + t.AssertEQ(gconv.Uint64(123.456), uint64(123)) + t.AssertEQ(gconv.Uint64(boolStruct{}), uint64(0)) + t.AssertEQ(gconv.Uint64(&boolStruct{}), uint64(0)) }) } func Test_Float32_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.Assert(gconv.Float32(i), float32(0)) - gtest.AssertEQ(gconv.Float32(false), float32(0)) - gtest.AssertEQ(gconv.Float32(nil), float32(0)) - gtest.AssertEQ(gconv.Float32(0), float32(0)) - gtest.AssertEQ(gconv.Float32("0"), float32(0)) - gtest.AssertEQ(gconv.Float32(""), float32(0)) - gtest.AssertEQ(gconv.Float32("false"), float32(0)) - gtest.AssertEQ(gconv.Float32("off"), float32(0)) - gtest.AssertEQ(gconv.Float32([]byte{}), float32(0)) - gtest.AssertEQ(gconv.Float32([]string{}), float32(0)) - gtest.AssertEQ(gconv.Float32([2]int{1, 2}), float32(0)) - gtest.AssertEQ(gconv.Float32([]interface{}{}), float32(0)) - gtest.AssertEQ(gconv.Float32([]map[int]int{}), float32(0)) + t.Assert(gconv.Float32(i), float32(0)) + t.AssertEQ(gconv.Float32(false), float32(0)) + t.AssertEQ(gconv.Float32(nil), float32(0)) + t.AssertEQ(gconv.Float32(0), float32(0)) + t.AssertEQ(gconv.Float32("0"), float32(0)) + t.AssertEQ(gconv.Float32(""), float32(0)) + t.AssertEQ(gconv.Float32("false"), float32(0)) + t.AssertEQ(gconv.Float32("off"), float32(0)) + t.AssertEQ(gconv.Float32([]byte{}), float32(0)) + t.AssertEQ(gconv.Float32([]string{}), float32(0)) + t.AssertEQ(gconv.Float32([2]int{1, 2}), float32(0)) + t.AssertEQ(gconv.Float32([]interface{}{}), float32(0)) + t.AssertEQ(gconv.Float32([]map[int]int{}), float32(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -478,33 +478,33 @@ func Test_Float32_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Float32(countryCapitalMap), float32(0)) + t.AssertEQ(gconv.Float32(countryCapitalMap), float32(0)) - gtest.AssertEQ(gconv.Float32("1"), float32(1)) - gtest.AssertEQ(gconv.Float32("on"), float32(0)) - gtest.AssertEQ(gconv.Float32(float32(1)), float32(1)) - gtest.AssertEQ(gconv.Float32(123.456), float32(123.456)) - gtest.AssertEQ(gconv.Float32(boolStruct{}), float32(0)) - gtest.AssertEQ(gconv.Float32(&boolStruct{}), float32(0)) + t.AssertEQ(gconv.Float32("1"), float32(1)) + t.AssertEQ(gconv.Float32("on"), float32(0)) + t.AssertEQ(gconv.Float32(float32(1)), float32(1)) + t.AssertEQ(gconv.Float32(123.456), float32(123.456)) + t.AssertEQ(gconv.Float32(boolStruct{}), float32(0)) + t.AssertEQ(gconv.Float32(&boolStruct{}), float32(0)) }) } func Test_Float64_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.Assert(gconv.Float64(i), float64(0)) - gtest.AssertEQ(gconv.Float64(false), float64(0)) - gtest.AssertEQ(gconv.Float64(nil), float64(0)) - gtest.AssertEQ(gconv.Float64(0), float64(0)) - gtest.AssertEQ(gconv.Float64("0"), float64(0)) - gtest.AssertEQ(gconv.Float64(""), float64(0)) - gtest.AssertEQ(gconv.Float64("false"), float64(0)) - gtest.AssertEQ(gconv.Float64("off"), float64(0)) - gtest.AssertEQ(gconv.Float64([]byte{}), float64(0)) - gtest.AssertEQ(gconv.Float64([]string{}), float64(0)) - gtest.AssertEQ(gconv.Float64([2]int{1, 2}), float64(0)) - gtest.AssertEQ(gconv.Float64([]interface{}{}), float64(0)) - gtest.AssertEQ(gconv.Float64([]map[int]int{}), float64(0)) + t.Assert(gconv.Float64(i), float64(0)) + t.AssertEQ(gconv.Float64(false), float64(0)) + t.AssertEQ(gconv.Float64(nil), float64(0)) + t.AssertEQ(gconv.Float64(0), float64(0)) + t.AssertEQ(gconv.Float64("0"), float64(0)) + t.AssertEQ(gconv.Float64(""), float64(0)) + t.AssertEQ(gconv.Float64("false"), float64(0)) + t.AssertEQ(gconv.Float64("off"), float64(0)) + t.AssertEQ(gconv.Float64([]byte{}), float64(0)) + t.AssertEQ(gconv.Float64([]string{}), float64(0)) + t.AssertEQ(gconv.Float64([2]int{1, 2}), float64(0)) + t.AssertEQ(gconv.Float64([]interface{}{}), float64(0)) + t.AssertEQ(gconv.Float64([]map[int]int{}), float64(0)) var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -512,51 +512,51 @@ func Test_Float64_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.Float64(countryCapitalMap), float64(0)) + t.AssertEQ(gconv.Float64(countryCapitalMap), float64(0)) - gtest.AssertEQ(gconv.Float64("1"), float64(1)) - gtest.AssertEQ(gconv.Float64("on"), float64(0)) - gtest.AssertEQ(gconv.Float64(float64(1)), float64(1)) - gtest.AssertEQ(gconv.Float64(123.456), float64(123.456)) - gtest.AssertEQ(gconv.Float64(boolStruct{}), float64(0)) - gtest.AssertEQ(gconv.Float64(&boolStruct{}), float64(0)) + t.AssertEQ(gconv.Float64("1"), float64(1)) + t.AssertEQ(gconv.Float64("on"), float64(0)) + t.AssertEQ(gconv.Float64(float64(1)), float64(1)) + t.AssertEQ(gconv.Float64(123.456), float64(123.456)) + t.AssertEQ(gconv.Float64(boolStruct{}), float64(0)) + t.AssertEQ(gconv.Float64(&boolStruct{}), float64(0)) }) } func Test_String_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var s []rune - gtest.AssertEQ(gconv.String(s), "") + t.AssertEQ(gconv.String(s), "") var i interface{} = nil - gtest.AssertEQ(gconv.String(i), "") - gtest.AssertEQ(gconv.String("1"), "1") - gtest.AssertEQ(gconv.String("0"), string("0")) - gtest.Assert(gconv.String("X"), string("X")) - gtest.Assert(gconv.String("x"), string("x")) - gtest.Assert(gconv.String(int64(1)), uint64(1)) - gtest.Assert(gconv.String(int(0)), string("0")) - gtest.Assert(gconv.String(int8(0)), string("0")) - gtest.Assert(gconv.String(int16(0)), string("0")) - gtest.Assert(gconv.String(int32(0)), string("0")) - gtest.Assert(gconv.String(uint64(0)), string("0")) - gtest.Assert(gconv.String(uint32(0)), string("0")) - gtest.Assert(gconv.String(uint16(0)), string("0")) - gtest.Assert(gconv.String(uint8(0)), string("0")) - gtest.Assert(gconv.String(uint(0)), string("0")) - gtest.Assert(gconv.String(float32(0)), string("0")) - gtest.AssertEQ(gconv.String(true), "true") - gtest.AssertEQ(gconv.String(false), "false") - gtest.AssertEQ(gconv.String(nil), "") - gtest.AssertEQ(gconv.String(0), string("0")) - gtest.AssertEQ(gconv.String("0"), string("0")) - gtest.AssertEQ(gconv.String(""), "") - gtest.AssertEQ(gconv.String("false"), "false") - gtest.AssertEQ(gconv.String("off"), string("off")) - gtest.AssertEQ(gconv.String([]byte{}), "") - gtest.AssertEQ(gconv.String([]string{}), "[]") - gtest.AssertEQ(gconv.String([2]int{1, 2}), "[1,2]") - gtest.AssertEQ(gconv.String([]interface{}{}), "[]") - gtest.AssertEQ(gconv.String(map[int]int{}), "{}") + t.AssertEQ(gconv.String(i), "") + t.AssertEQ(gconv.String("1"), "1") + t.AssertEQ(gconv.String("0"), string("0")) + t.Assert(gconv.String("X"), string("X")) + t.Assert(gconv.String("x"), string("x")) + t.Assert(gconv.String(int64(1)), uint64(1)) + t.Assert(gconv.String(int(0)), string("0")) + t.Assert(gconv.String(int8(0)), string("0")) + t.Assert(gconv.String(int16(0)), string("0")) + t.Assert(gconv.String(int32(0)), string("0")) + t.Assert(gconv.String(uint64(0)), string("0")) + t.Assert(gconv.String(uint32(0)), string("0")) + t.Assert(gconv.String(uint16(0)), string("0")) + t.Assert(gconv.String(uint8(0)), string("0")) + t.Assert(gconv.String(uint(0)), string("0")) + t.Assert(gconv.String(float32(0)), string("0")) + t.AssertEQ(gconv.String(true), "true") + t.AssertEQ(gconv.String(false), "false") + t.AssertEQ(gconv.String(nil), "") + t.AssertEQ(gconv.String(0), string("0")) + t.AssertEQ(gconv.String("0"), string("0")) + t.AssertEQ(gconv.String(""), "") + t.AssertEQ(gconv.String("false"), "false") + t.AssertEQ(gconv.String("off"), string("off")) + t.AssertEQ(gconv.String([]byte{}), "") + t.AssertEQ(gconv.String([]string{}), "[]") + t.AssertEQ(gconv.String([2]int{1, 2}), "[1,2]") + t.AssertEQ(gconv.String([]interface{}{}), "[]") + t.AssertEQ(gconv.String(map[int]int{}), "{}") var countryCapitalMap = make(map[string]string) /* map插入key - value对,各个国家对应的首都 */ @@ -564,183 +564,183 @@ func Test_String_All(t *testing.T) { countryCapitalMap["Italy"] = "罗马" countryCapitalMap["Japan"] = "东京" countryCapitalMap["India "] = "新德里" - gtest.AssertEQ(gconv.String(countryCapitalMap), `{"France":"巴黎","India ":"新德里","Italy":"罗马","Japan":"东京"}`) - gtest.AssertEQ(gconv.String(int64(1)), "1") - gtest.AssertEQ(gconv.String(123.456), "123.456") - gtest.AssertEQ(gconv.String(boolStruct{}), "{}") - gtest.AssertEQ(gconv.String(&boolStruct{}), "{}") + t.AssertEQ(gconv.String(countryCapitalMap), `{"France":"巴黎","India ":"新德里","Italy":"罗马","Japan":"东京"}`) + t.AssertEQ(gconv.String(int64(1)), "1") + t.AssertEQ(gconv.String(123.456), "123.456") + t.AssertEQ(gconv.String(boolStruct{}), "{}") + t.AssertEQ(gconv.String(&boolStruct{}), "{}") var info apiString info = new(S) - gtest.AssertEQ(gconv.String(info), "22222") + t.AssertEQ(gconv.String(info), "22222") var errinfo apiError errinfo = new(S1) - gtest.AssertEQ(gconv.String(errinfo), "22222") + t.AssertEQ(gconv.String(errinfo), "22222") }) } func Test_Runes_All(t *testing.T) { - gtest.Case(t, func() { - gtest.AssertEQ(gconv.Runes("www"), []int32{119, 119, 119}) + gtest.C(t, func(t *gtest.T) { + t.AssertEQ(gconv.Runes("www"), []int32{119, 119, 119}) var s []rune - gtest.AssertEQ(gconv.Runes(s), nil) + t.AssertEQ(gconv.Runes(s), nil) }) } func Test_Rune_All(t *testing.T) { - gtest.Case(t, func() { - gtest.AssertEQ(gconv.Rune("www"), int32(0)) - gtest.AssertEQ(gconv.Rune(int32(0)), int32(0)) + gtest.C(t, func(t *gtest.T) { + t.AssertEQ(gconv.Rune("www"), int32(0)) + t.AssertEQ(gconv.Rune(int32(0)), int32(0)) var s []rune - gtest.AssertEQ(gconv.Rune(s), int32(0)) + t.AssertEQ(gconv.Rune(s), int32(0)) }) } func Test_Bytes_All(t *testing.T) { - gtest.Case(t, func() { - gtest.AssertEQ(gconv.Bytes(nil), nil) - gtest.AssertEQ(gconv.Bytes(int32(0)), []uint8{0, 0, 0, 0}) - gtest.AssertEQ(gconv.Bytes("s"), []uint8{115}) - gtest.AssertEQ(gconv.Bytes([]byte("s")), []uint8{115}) + gtest.C(t, func(t *gtest.T) { + t.AssertEQ(gconv.Bytes(nil), nil) + t.AssertEQ(gconv.Bytes(int32(0)), []uint8{0, 0, 0, 0}) + t.AssertEQ(gconv.Bytes("s"), []uint8{115}) + t.AssertEQ(gconv.Bytes([]byte("s")), []uint8{115}) }) } func Test_Byte_All(t *testing.T) { - gtest.Case(t, func() { - gtest.AssertEQ(gconv.Byte(uint8(0)), uint8(0)) - gtest.AssertEQ(gconv.Byte("s"), uint8(0)) - gtest.AssertEQ(gconv.Byte([]byte("s")), uint8(115)) + gtest.C(t, func(t *gtest.T) { + t.AssertEQ(gconv.Byte(uint8(0)), uint8(0)) + t.AssertEQ(gconv.Byte("s"), uint8(0)) + t.AssertEQ(gconv.Byte([]byte("s")), uint8(115)) }) } func Test_Convert_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.AssertEQ(gconv.Convert(i, "string"), "") - gtest.AssertEQ(gconv.Convert("1", "string"), "1") - gtest.Assert(gconv.Convert(int64(1), "int64"), int64(1)) - gtest.Assert(gconv.Convert(int(0), "int"), int(0)) - gtest.Assert(gconv.Convert(int8(0), "int8"), int8(0)) - gtest.Assert(gconv.Convert(int16(0), "int16"), int16(0)) - gtest.Assert(gconv.Convert(int32(0), "int32"), int32(0)) - gtest.Assert(gconv.Convert(uint64(0), "uint64"), uint64(0)) - gtest.Assert(gconv.Convert(uint32(0), "uint32"), uint32(0)) - gtest.Assert(gconv.Convert(uint16(0), "uint16"), uint16(0)) - gtest.Assert(gconv.Convert(uint8(0), "uint8"), uint8(0)) - gtest.Assert(gconv.Convert(uint(0), "uint"), uint(0)) - gtest.Assert(gconv.Convert(float32(0), "float32"), float32(0)) - gtest.Assert(gconv.Convert(float64(0), "float64"), float64(0)) - gtest.AssertEQ(gconv.Convert(true, "bool"), true) - gtest.AssertEQ(gconv.Convert([]byte{}, "[]byte"), []uint8{}) - gtest.AssertEQ(gconv.Convert([]string{}, "[]string"), []string{}) - gtest.AssertEQ(gconv.Convert([2]int{1, 2}, "[]int"), []int{0}) - gtest.AssertEQ(gconv.Convert("1989-01-02", "Time", "Y-m-d"), gconv.Time("1989-01-02", "Y-m-d")) - gtest.AssertEQ(gconv.Convert(1989, "Time"), gconv.Time("1970-01-01 08:33:09 +0800 CST")) - gtest.AssertEQ(gconv.Convert(gtime.Now(), "gtime.Time", 1), nil) - gtest.AssertEQ(gconv.Convert(1989, "gtime.Time"), *gconv.GTime("1970-01-01 08:33:09 +0800 CST")) - gtest.AssertEQ(gconv.Convert(gtime.Now(), "*gtime.Time", 1), nil) - gtest.AssertEQ(gconv.Convert(gtime.Now(), "GTime", 1), nil) - gtest.AssertEQ(gconv.Convert(1989, "*gtime.Time"), gconv.GTime(1989)) - gtest.AssertEQ(gconv.Convert(1989, "Duration"), time.Duration(int64(1989))) - gtest.AssertEQ(gconv.Convert("1989", "Duration"), time.Duration(int64(1989))) - gtest.AssertEQ(gconv.Convert("1989", ""), "1989") + t.AssertEQ(gconv.Convert(i, "string"), "") + t.AssertEQ(gconv.Convert("1", "string"), "1") + t.Assert(gconv.Convert(int64(1), "int64"), int64(1)) + t.Assert(gconv.Convert(int(0), "int"), int(0)) + t.Assert(gconv.Convert(int8(0), "int8"), int8(0)) + t.Assert(gconv.Convert(int16(0), "int16"), int16(0)) + t.Assert(gconv.Convert(int32(0), "int32"), int32(0)) + t.Assert(gconv.Convert(uint64(0), "uint64"), uint64(0)) + t.Assert(gconv.Convert(uint32(0), "uint32"), uint32(0)) + t.Assert(gconv.Convert(uint16(0), "uint16"), uint16(0)) + t.Assert(gconv.Convert(uint8(0), "uint8"), uint8(0)) + t.Assert(gconv.Convert(uint(0), "uint"), uint(0)) + t.Assert(gconv.Convert(float32(0), "float32"), float32(0)) + t.Assert(gconv.Convert(float64(0), "float64"), float64(0)) + t.AssertEQ(gconv.Convert(true, "bool"), true) + t.AssertEQ(gconv.Convert([]byte{}, "[]byte"), []uint8{}) + t.AssertEQ(gconv.Convert([]string{}, "[]string"), []string{}) + t.AssertEQ(gconv.Convert([2]int{1, 2}, "[]int"), []int{0}) + t.AssertEQ(gconv.Convert("1989-01-02", "Time", "Y-m-d"), gconv.Time("1989-01-02", "Y-m-d")) + t.AssertEQ(gconv.Convert(1989, "Time"), gconv.Time("1970-01-01 08:33:09 +0800 CST")) + t.AssertEQ(gconv.Convert(gtime.Now(), "gtime.Time", 1), nil) + t.AssertEQ(gconv.Convert(1989, "gtime.Time"), *gconv.GTime("1970-01-01 08:33:09 +0800 CST")) + t.AssertEQ(gconv.Convert(gtime.Now(), "*gtime.Time", 1), nil) + t.AssertEQ(gconv.Convert(gtime.Now(), "GTime", 1), nil) + t.AssertEQ(gconv.Convert(1989, "*gtime.Time"), gconv.GTime(1989)) + t.AssertEQ(gconv.Convert(1989, "Duration"), time.Duration(int64(1989))) + t.AssertEQ(gconv.Convert("1989", "Duration"), time.Duration(int64(1989))) + t.AssertEQ(gconv.Convert("1989", ""), "1989") }) } func Test_Time_All(t *testing.T) { - gtest.Case(t, func() { - gtest.AssertEQ(gconv.Duration(""), time.Duration(int64(0))) - gtest.AssertEQ(gconv.GTime(""), gtime.New()) + gtest.C(t, func(t *gtest.T) { + t.AssertEQ(gconv.Duration(""), time.Duration(int64(0))) + t.AssertEQ(gconv.GTime(""), gtime.New()) }) } func Test_Slice_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value := 123.456 - gtest.AssertEQ(gconv.Ints(value), []int{123}) - gtest.AssertEQ(gconv.Ints(nil), nil) - gtest.AssertEQ(gconv.Ints([]string{"1", "2"}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]int{}), []int{}) - gtest.AssertEQ(gconv.Ints([]int8{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]int16{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]int32{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]int64{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]uint{1}), []int{1}) - gtest.AssertEQ(gconv.Ints([]uint8{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]uint16{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]uint32{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]uint64{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]bool{true}), []int{1}) - gtest.AssertEQ(gconv.Ints([]float32{1, 2}), []int{1, 2}) - gtest.AssertEQ(gconv.Ints([]float64{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints(value), []int{123}) + t.AssertEQ(gconv.Ints(nil), nil) + t.AssertEQ(gconv.Ints([]string{"1", "2"}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]int{}), []int{}) + t.AssertEQ(gconv.Ints([]int8{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]int16{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]int32{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]int64{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]uint{1}), []int{1}) + t.AssertEQ(gconv.Ints([]uint8{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]uint16{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]uint32{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]uint64{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]bool{true}), []int{1}) + t.AssertEQ(gconv.Ints([]float32{1, 2}), []int{1, 2}) + t.AssertEQ(gconv.Ints([]float64{1, 2}), []int{1, 2}) var inter []interface{} = make([]interface{}, 2) - gtest.AssertEQ(gconv.Ints(inter), []int{0, 0}) + t.AssertEQ(gconv.Ints(inter), []int{0, 0}) - gtest.AssertEQ(gconv.Strings(value), []string{"123.456"}) - gtest.AssertEQ(gconv.Strings(nil), nil) - gtest.AssertEQ(gconv.Strings([]string{"1", "2"}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]int{1}), []string{"1"}) - gtest.AssertEQ(gconv.Strings([]int8{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]int16{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]int32{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]int64{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]uint{1}), []string{"1"}) - gtest.AssertEQ(gconv.Strings([]uint8{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]uint16{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]uint32{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]uint64{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]bool{true}), []string{"true"}) - gtest.AssertEQ(gconv.Strings([]float32{1, 2}), []string{"1", "2"}) - gtest.AssertEQ(gconv.Strings([]float64{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings(value), []string{"123.456"}) + t.AssertEQ(gconv.Strings(nil), nil) + t.AssertEQ(gconv.Strings([]string{"1", "2"}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]int{1}), []string{"1"}) + t.AssertEQ(gconv.Strings([]int8{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]int16{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]int32{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]int64{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]uint{1}), []string{"1"}) + t.AssertEQ(gconv.Strings([]uint8{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]uint16{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]uint32{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]uint64{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]bool{true}), []string{"true"}) + t.AssertEQ(gconv.Strings([]float32{1, 2}), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]float64{1, 2}), []string{"1", "2"}) var strer = make([]interface{}, 2) - gtest.AssertEQ(gconv.Strings(strer), []string{"", ""}) + t.AssertEQ(gconv.Strings(strer), []string{"", ""}) - gtest.AssertEQ(gconv.Floats(value), []float64{123.456}) - gtest.AssertEQ(gconv.Floats(nil), nil) - gtest.AssertEQ(gconv.Floats([]string{"1", "2"}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]int{1}), []float64{1}) - gtest.AssertEQ(gconv.Floats([]int8{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]int16{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]int32{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]int64{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]uint{1}), []float64{1}) - gtest.AssertEQ(gconv.Floats([]uint8{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]uint16{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]uint32{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]uint64{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]bool{true}), []float64{0}) - gtest.AssertEQ(gconv.Floats([]float32{1, 2}), []float64{1, 2}) - gtest.AssertEQ(gconv.Floats([]float64{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats(value), []float64{123.456}) + t.AssertEQ(gconv.Floats(nil), nil) + t.AssertEQ(gconv.Floats([]string{"1", "2"}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]int{1}), []float64{1}) + t.AssertEQ(gconv.Floats([]int8{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]int16{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]int32{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]int64{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]uint{1}), []float64{1}) + t.AssertEQ(gconv.Floats([]uint8{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]uint16{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]uint32{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]uint64{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]bool{true}), []float64{0}) + t.AssertEQ(gconv.Floats([]float32{1, 2}), []float64{1, 2}) + t.AssertEQ(gconv.Floats([]float64{1, 2}), []float64{1, 2}) var floer = make([]interface{}, 2) - gtest.AssertEQ(gconv.Floats(floer), []float64{0, 0}) + t.AssertEQ(gconv.Floats(floer), []float64{0, 0}) - gtest.AssertEQ(gconv.Interfaces(value), []interface{}{123.456}) - gtest.AssertEQ(gconv.Interfaces(nil), nil) - gtest.AssertEQ(gconv.Interfaces([]interface{}{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]string{"1"}), []interface{}{"1"}) - gtest.AssertEQ(gconv.Interfaces([]int{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]int8{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]int16{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]int32{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]int64{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]uint{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]uint8{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]uint16{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]uint32{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]uint64{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]bool{true}), []interface{}{true}) - gtest.AssertEQ(gconv.Interfaces([]float32{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([]float64{1}), []interface{}{1}) - gtest.AssertEQ(gconv.Interfaces([1]int{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces(value), []interface{}{123.456}) + t.AssertEQ(gconv.Interfaces(nil), nil) + t.AssertEQ(gconv.Interfaces([]interface{}{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]string{"1"}), []interface{}{"1"}) + t.AssertEQ(gconv.Interfaces([]int{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]int8{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]int16{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]int32{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]int64{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]uint{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]uint8{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]uint16{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]uint32{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]uint64{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]bool{true}), []interface{}{true}) + t.AssertEQ(gconv.Interfaces([]float32{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([]float64{1}), []interface{}{1}) + t.AssertEQ(gconv.Interfaces([1]int{1}), []interface{}{1}) type interSlice []int slices := interSlice{1} - gtest.AssertEQ(gconv.Interfaces(slices), []interface{}{1}) + t.AssertEQ(gconv.Interfaces(slices), []interface{}{1}) - gtest.AssertEQ(gconv.Maps(nil), nil) - gtest.AssertEQ(gconv.Maps([]map[string]interface{}{{"a": "1"}}), []map[string]interface{}{{"a": "1"}}) - gtest.AssertEQ(gconv.Maps(1223), []map[string]interface{}{nil}) - gtest.AssertEQ(gconv.Maps([]int{}), nil) + t.AssertEQ(gconv.Maps(nil), nil) + t.AssertEQ(gconv.Maps([]map[string]interface{}{{"a": "1"}}), []map[string]interface{}{{"a": "1"}}) + t.AssertEQ(gconv.Maps(1223), []map[string]interface{}{nil}) + t.AssertEQ(gconv.Maps([]int{}), nil) }) } @@ -751,14 +751,14 @@ func Test_Slice_PrivateAttribute_All(t *testing.T) { name string Ad []interface{} } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := &User{1, "john", []interface{}{2}} - gtest.Assert(gconv.Interfaces(user), g.Slice{1, []interface{}{2}}) + t.Assert(gconv.Interfaces(user), g.Slice{1, []interface{}{2}}) }) } func Test_Map_Basic_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m1 := map[string]string{ "k": "v", } @@ -768,39 +768,39 @@ func Test_Map_Basic_All(t *testing.T) { m3 := map[float64]float32{ 1.22: 3.1, } - gtest.Assert(gconv.Map(m1), g.Map{ + t.Assert(gconv.Map(m1), g.Map{ "k": "v", }) - gtest.Assert(gconv.Map(m2), g.Map{ + t.Assert(gconv.Map(m2), g.Map{ "3": "v", }) - gtest.Assert(gconv.Map(m3), g.Map{ + t.Assert(gconv.Map(m3), g.Map{ "1.22": "3.1", }) - gtest.AssertEQ(gconv.Map(nil), nil) - gtest.AssertEQ(gconv.Map(map[string]interface{}{"a": 1}), map[string]interface{}{"a": 1}) - gtest.AssertEQ(gconv.Map(map[int]interface{}{1: 1}), map[string]interface{}{"1": 1}) - gtest.AssertEQ(gconv.Map(map[uint]interface{}{1: 1}), map[string]interface{}{"1": 1}) - gtest.AssertEQ(gconv.Map(map[uint]string{1: "1"}), map[string]interface{}{"1": "1"}) + t.AssertEQ(gconv.Map(nil), nil) + t.AssertEQ(gconv.Map(map[string]interface{}{"a": 1}), map[string]interface{}{"a": 1}) + t.AssertEQ(gconv.Map(map[int]interface{}{1: 1}), map[string]interface{}{"1": 1}) + t.AssertEQ(gconv.Map(map[uint]interface{}{1: 1}), map[string]interface{}{"1": 1}) + t.AssertEQ(gconv.Map(map[uint]string{1: "1"}), map[string]interface{}{"1": "1"}) - gtest.AssertEQ(gconv.Map(map[interface{}]interface{}{"a": 1}), map[interface{}]interface{}{"a": 1}) - gtest.AssertEQ(gconv.Map(map[interface{}]string{"a": "1"}), map[interface{}]string{"a": "1"}) - gtest.AssertEQ(gconv.Map(map[interface{}]int{"a": 1}), map[interface{}]int{"a": 1}) - gtest.AssertEQ(gconv.Map(map[interface{}]uint{"a": 1}), map[interface{}]uint{"a": 1}) - gtest.AssertEQ(gconv.Map(map[interface{}]float32{"a": 1}), map[interface{}]float32{"a": 1}) - gtest.AssertEQ(gconv.Map(map[interface{}]float64{"a": 1}), map[interface{}]float64{"a": 1}) + t.AssertEQ(gconv.Map(map[interface{}]interface{}{"a": 1}), map[interface{}]interface{}{"a": 1}) + t.AssertEQ(gconv.Map(map[interface{}]string{"a": "1"}), map[interface{}]string{"a": "1"}) + t.AssertEQ(gconv.Map(map[interface{}]int{"a": 1}), map[interface{}]int{"a": 1}) + t.AssertEQ(gconv.Map(map[interface{}]uint{"a": 1}), map[interface{}]uint{"a": 1}) + t.AssertEQ(gconv.Map(map[interface{}]float32{"a": 1}), map[interface{}]float32{"a": 1}) + t.AssertEQ(gconv.Map(map[interface{}]float64{"a": 1}), map[interface{}]float64{"a": 1}) - gtest.AssertEQ(gconv.Map(map[string]bool{"a": true}), map[string]interface{}{"a": true}) - gtest.AssertEQ(gconv.Map(map[string]int{"a": 1}), map[string]interface{}{"a": 1}) - gtest.AssertEQ(gconv.Map(map[string]uint{"a": 1}), map[string]interface{}{"a": 1}) - gtest.AssertEQ(gconv.Map(map[string]float32{"a": 1}), map[string]interface{}{"a": 1}) - gtest.AssertEQ(gconv.Map(map[string]float64{"a": 1}), map[string]interface{}{"a": 1}) + t.AssertEQ(gconv.Map(map[string]bool{"a": true}), map[string]interface{}{"a": true}) + t.AssertEQ(gconv.Map(map[string]int{"a": 1}), map[string]interface{}{"a": 1}) + t.AssertEQ(gconv.Map(map[string]uint{"a": 1}), map[string]interface{}{"a": 1}) + t.AssertEQ(gconv.Map(map[string]float32{"a": 1}), map[string]interface{}{"a": 1}) + t.AssertEQ(gconv.Map(map[string]float64{"a": 1}), map[string]interface{}{"a": 1}) }) } func Test_Map_StructWithGconvTag_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -821,25 +821,25 @@ func Test_Map_StructWithGconvTag_All(t *testing.T) { user2 := &user1 map1 := gconv.Map(user1) map2 := gconv.Map(user2) - gtest.Assert(map1["Uid"], 100) - gtest.Assert(map1["Name"], "john") - gtest.Assert(map1["SiteUrl"], nil) - gtest.Assert(map1["NickName"], nil) - gtest.Assert(map1["nickname"], nil) - gtest.Assert(map1["password1"], "123") - gtest.Assert(map1["password2"], "456") - gtest.Assert(map2["Uid"], 100) - gtest.Assert(map2["Name"], "john") - gtest.Assert(map2["SiteUrl"], nil) - gtest.Assert(map2["NickName"], nil) - gtest.Assert(map2["nickname"], nil) - gtest.Assert(map2["password1"], "123") - gtest.Assert(map2["password2"], "456") + t.Assert(map1["Uid"], 100) + t.Assert(map1["Name"], "john") + t.Assert(map1["SiteUrl"], nil) + t.Assert(map1["NickName"], nil) + t.Assert(map1["nickname"], nil) + t.Assert(map1["password1"], "123") + t.Assert(map1["password2"], "456") + t.Assert(map2["Uid"], 100) + t.Assert(map2["Name"], "john") + t.Assert(map2["SiteUrl"], nil) + t.Assert(map2["NickName"], nil) + t.Assert(map2["nickname"], nil) + t.Assert(map2["password1"], "123") + t.Assert(map2["password2"], "456") }) } func Test_Map_StructWithJsonTag_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -876,21 +876,21 @@ func Test_Map_StructWithJsonTag_All(t *testing.T) { map1 := gconv.Map(user1, "json", "json2") map2 := gconv.Map(user2) map3 := gconv.Map(user3) - gtest.Assert(map1["Uid"], 100) - gtest.Assert(map1["Name"], "john") - gtest.Assert(map1["SiteUrl"], nil) - gtest.Assert(map1["NickName"], nil) - gtest.Assert(map1["nickname"], nil) - gtest.Assert(map1["password1"], "123") - gtest.Assert(map1["password2"], "456") - gtest.Assert(map2["Uid"], 100) - gtest.Assert(map2["Name"], "john") - gtest.Assert(map2["SiteUrl"], nil) - gtest.Assert(map2["NickName"], nil) - gtest.Assert(map2["nickname"], nil) - gtest.Assert(map2["password1"], "123") - gtest.Assert(map2["password2"], "456") - gtest.Assert(map3["NickName"], nil) + t.Assert(map1["Uid"], 100) + t.Assert(map1["Name"], "john") + t.Assert(map1["SiteUrl"], nil) + t.Assert(map1["NickName"], nil) + t.Assert(map1["nickname"], nil) + t.Assert(map1["password1"], "123") + t.Assert(map1["password2"], "456") + t.Assert(map2["Uid"], 100) + t.Assert(map2["Name"], "john") + t.Assert(map2["SiteUrl"], nil) + t.Assert(map2["NickName"], nil) + t.Assert(map2["nickname"], nil) + t.Assert(map2["password1"], "123") + t.Assert(map2["password2"], "456") + t.Assert(map3["NickName"], nil) }) } @@ -899,14 +899,14 @@ func Test_Map_PrivateAttribute_All(t *testing.T) { Id int name string } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := &User{1, "john"} - gtest.Assert(gconv.Map(user), g.Map{"Id": 1}) + t.Assert(gconv.Map(user), g.Map{"Id": 1}) }) } func Test_Map_StructInherit_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Ids struct { Id int `json:"id"` Uid int `json:"uid"` @@ -931,15 +931,15 @@ func Test_Map_StructInherit_All(t *testing.T) { user.S = &s m := gconv.MapDeep(user) - gtest.Assert(m["id"], user.Id) - gtest.Assert(m["nickname"], user.Nickname) - gtest.Assert(m["create_time"], user.CreateTime) - gtest.Assert(m["nickname2"], user.S) + t.Assert(m["id"], user.Id) + t.Assert(m["nickname"], user.Nickname) + t.Assert(m["create_time"], user.CreateTime) + t.Assert(m["nickname2"], user.S) }) } func Test_Struct_Basic1_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name int Result string @@ -1002,7 +1002,7 @@ func Test_Struct_Basic1_All(t *testing.T) { if err := gconv.Struct(params2, user); err != nil { gtest.Error(err) } - gtest.Assert(user, &User{ + t.Assert(user, &User{ Uid: 2, Name: "smith", Site_Url: "https://goframe.org", @@ -1015,7 +1015,7 @@ func Test_Struct_Basic1_All(t *testing.T) { // 使用默认映射规则绑定属性值到对象 func Test_Struct_Basic2_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -1034,7 +1034,7 @@ func Test_Struct_Basic2_All(t *testing.T) { if err := gconv.Struct(params, user); err != nil { gtest.Error(err) } - gtest.Assert(user, &User{ + t.Assert(user, &User{ Uid: 1, Name: "john", SiteUrl: "https://goframe.org", @@ -1046,7 +1046,7 @@ func Test_Struct_Basic2_All(t *testing.T) { // 带有指针的基础类型属性 func Test_Struct_Basic3_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name *string @@ -1059,14 +1059,14 @@ func Test_Struct_Basic3_All(t *testing.T) { if err := gconv.Struct(params, user); err != nil { gtest.Error(err) } - gtest.Assert(user.Uid, 1) - gtest.Assert(*user.Name, "john") + t.Assert(user.Uid, 1) + t.Assert(*user.Name, "john") }) } // slice类型属性的赋值 func Test_Struct_Attr_Slice_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []int } @@ -1075,7 +1075,7 @@ func Test_Struct_Attr_Slice_All(t *testing.T) { if err := gconv.Struct(g.Map{"Scores": scores}, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user, &User{ + t.Assert(user, &User{ Scores: []int{99, 100, 60, 140}, }) } @@ -1084,7 +1084,7 @@ func Test_Struct_Attr_Slice_All(t *testing.T) { // 属性为struct对象 func Test_Struct_Attr_Struct_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -1105,7 +1105,7 @@ func Test_Struct_Attr_Struct_All(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user, &User{ + t.Assert(user, &User{ Scores: Score{ Name: "john", Result: 100, @@ -1117,7 +1117,7 @@ func Test_Struct_Attr_Struct_All(t *testing.T) { // 属性为struct对象指针 func Test_Struct_Attr_Struct_Ptr_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -1138,7 +1138,7 @@ func Test_Struct_Attr_Struct_Ptr_All(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user.Scores, &Score{ + t.Assert(user.Scores, &Score{ Name: "john", Result: 100, }) @@ -1148,7 +1148,7 @@ func Test_Struct_Attr_Struct_Ptr_All(t *testing.T) { // 属性为struct对象slice func Test_Struct_Attr_Struct_Slice1_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -1169,7 +1169,7 @@ func Test_Struct_Attr_Struct_Slice1_All(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user.Scores, []Score{ + t.Assert(user.Scores, []Score{ { Name: "john", Result: 100, @@ -1181,7 +1181,7 @@ func Test_Struct_Attr_Struct_Slice1_All(t *testing.T) { // 属性为struct对象slice func Test_Struct_Attr_Struct_Slice2_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -1208,7 +1208,7 @@ func Test_Struct_Attr_Struct_Slice2_All(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user.Scores, []Score{ + t.Assert(user.Scores, []Score{ { Name: "john", Result: 100, @@ -1224,7 +1224,7 @@ func Test_Struct_Attr_Struct_Slice2_All(t *testing.T) { // 属性为struct对象slice ptr func Test_Struct_Attr_Struct_Slice_Ptr_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -1251,12 +1251,12 @@ func Test_Struct_Attr_Struct_Slice_Ptr_All(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(len(user.Scores), 2) - gtest.Assert(user.Scores[0], &Score{ + t.Assert(len(user.Scores), 2) + t.Assert(user.Scores[0], &Score{ Name: "john", Result: 100, }) - gtest.Assert(user.Scores[1], &Score{ + t.Assert(user.Scores[1], &Score{ Name: "smith", Result: 60, }) @@ -1269,17 +1269,17 @@ func Test_Struct_PrivateAttribute_All(t *testing.T) { Id int name string } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) err := gconv.Struct(g.Map{"id": 1, "name": "john"}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, 1) - gtest.Assert(user.name, "") + t.Assert(err, nil) + t.Assert(user.Id, 1) + t.Assert(user.name, "") }) } func Test_Struct_Deep_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Ids struct { Id int `json:"id"` Uid int `json:"uid"` @@ -1304,15 +1304,15 @@ func Test_Struct_Deep_All(t *testing.T) { } user := new(User) gconv.StructDeep(data, user) - gtest.Assert(user.Id, 100) - gtest.Assert(user.Uid, 101) - gtest.Assert(user.Nickname, "T1") - gtest.Assert(user.CreateTime, "2019") + t.Assert(user.Id, 100) + t.Assert(user.Uid, 101) + t.Assert(user.Nickname, "T1") + t.Assert(user.CreateTime, "2019") }) } func Test_Struct_Time_All(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime time.Time } @@ -1321,10 +1321,10 @@ func Test_Struct_Time_All(t *testing.T) { gconv.Struct(g.Map{ "create_time": now, }, user) - gtest.Assert(user.CreateTime.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.UTC().String(), now.UTC().String()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime *time.Time } @@ -1333,10 +1333,10 @@ func Test_Struct_Time_All(t *testing.T) { gconv.Struct(g.Map{ "create_time": &now, }, user) - gtest.Assert(user.CreateTime.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.UTC().String(), now.UTC().String()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime *gtime.Time } @@ -1345,10 +1345,10 @@ func Test_Struct_Time_All(t *testing.T) { gconv.Struct(g.Map{ "create_time": &now, }, user) - gtest.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime gtime.Time } @@ -1357,10 +1357,10 @@ func Test_Struct_Time_All(t *testing.T) { gconv.Struct(g.Map{ "create_time": &now, }, user) - gtest.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime gtime.Time } @@ -1369,6 +1369,6 @@ func Test_Struct_Time_All(t *testing.T) { gconv.Struct(g.Map{ "create_time": now, }, user) - gtest.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) }) } diff --git a/util/gconv/gconv_z_unit_basic_test.go b/util/gconv/gconv_z_unit_basic_test.go index 36495aa57..806c8b119 100644 --- a/util/gconv/gconv_z_unit_basic_test.go +++ b/util/gconv/gconv_z_unit_basic_test.go @@ -14,29 +14,29 @@ import ( ) func Test_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { f32 := float32(123.456) i64 := int64(1552578474888) - gtest.AssertEQ(gconv.Int(f32), int(123)) - gtest.AssertEQ(gconv.Int8(f32), int8(123)) - gtest.AssertEQ(gconv.Int16(f32), int16(123)) - gtest.AssertEQ(gconv.Int32(f32), int32(123)) - gtest.AssertEQ(gconv.Int64(f32), int64(123)) - gtest.AssertEQ(gconv.Int64(f32), int64(123)) - gtest.AssertEQ(gconv.Uint(f32), uint(123)) - gtest.AssertEQ(gconv.Uint8(f32), uint8(123)) - gtest.AssertEQ(gconv.Uint16(f32), uint16(123)) - gtest.AssertEQ(gconv.Uint32(f32), uint32(123)) - gtest.AssertEQ(gconv.Uint64(f32), uint64(123)) - gtest.AssertEQ(gconv.Float32(f32), float32(123.456)) - gtest.AssertEQ(gconv.Float64(i64), float64(i64)) - gtest.AssertEQ(gconv.Bool(f32), true) - gtest.AssertEQ(gconv.String(f32), "123.456") - gtest.AssertEQ(gconv.String(i64), "1552578474888") + t.AssertEQ(gconv.Int(f32), int(123)) + t.AssertEQ(gconv.Int8(f32), int8(123)) + t.AssertEQ(gconv.Int16(f32), int16(123)) + t.AssertEQ(gconv.Int32(f32), int32(123)) + t.AssertEQ(gconv.Int64(f32), int64(123)) + t.AssertEQ(gconv.Int64(f32), int64(123)) + t.AssertEQ(gconv.Uint(f32), uint(123)) + t.AssertEQ(gconv.Uint8(f32), uint8(123)) + t.AssertEQ(gconv.Uint16(f32), uint16(123)) + t.AssertEQ(gconv.Uint32(f32), uint32(123)) + t.AssertEQ(gconv.Uint64(f32), uint64(123)) + t.AssertEQ(gconv.Float32(f32), float32(123.456)) + t.AssertEQ(gconv.Float64(i64), float64(i64)) + t.AssertEQ(gconv.Bool(f32), true) + t.AssertEQ(gconv.String(f32), "123.456") + t.AssertEQ(gconv.String(i64), "1552578474888") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "-0xFF" - gtest.Assert(gconv.Int(s), int64(-0xFF)) + t.Assert(gconv.Int(s), int64(-0xFF)) }) } diff --git a/util/gconv/gconv_z_unit_bool_test.go b/util/gconv/gconv_z_unit_bool_test.go index 0f8e76f94..85eee9fcb 100644 --- a/util/gconv/gconv_z_unit_bool_test.go +++ b/util/gconv/gconv_z_unit_bool_test.go @@ -17,26 +17,26 @@ type boolStruct struct { } func Test_Bool(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { var i interface{} = nil - gtest.AssertEQ(gconv.Bool(i), false) - gtest.AssertEQ(gconv.Bool(false), false) - gtest.AssertEQ(gconv.Bool(nil), false) - gtest.AssertEQ(gconv.Bool(0), false) - gtest.AssertEQ(gconv.Bool("0"), false) - gtest.AssertEQ(gconv.Bool(""), false) - gtest.AssertEQ(gconv.Bool("false"), false) - gtest.AssertEQ(gconv.Bool("off"), false) - gtest.AssertEQ(gconv.Bool([]byte{}), false) - gtest.AssertEQ(gconv.Bool([]string{}), false) - gtest.AssertEQ(gconv.Bool([]interface{}{}), false) - gtest.AssertEQ(gconv.Bool([]map[int]int{}), false) + t.AssertEQ(gconv.Bool(i), false) + t.AssertEQ(gconv.Bool(false), false) + t.AssertEQ(gconv.Bool(nil), false) + t.AssertEQ(gconv.Bool(0), false) + t.AssertEQ(gconv.Bool("0"), false) + t.AssertEQ(gconv.Bool(""), false) + t.AssertEQ(gconv.Bool("false"), false) + t.AssertEQ(gconv.Bool("off"), false) + t.AssertEQ(gconv.Bool([]byte{}), false) + t.AssertEQ(gconv.Bool([]string{}), false) + t.AssertEQ(gconv.Bool([]interface{}{}), false) + t.AssertEQ(gconv.Bool([]map[int]int{}), false) - gtest.AssertEQ(gconv.Bool("1"), true) - gtest.AssertEQ(gconv.Bool("on"), true) - gtest.AssertEQ(gconv.Bool(1), true) - gtest.AssertEQ(gconv.Bool(123.456), true) - gtest.AssertEQ(gconv.Bool(boolStruct{}), true) - gtest.AssertEQ(gconv.Bool(&boolStruct{}), true) + t.AssertEQ(gconv.Bool("1"), true) + t.AssertEQ(gconv.Bool("on"), true) + t.AssertEQ(gconv.Bool(1), true) + t.AssertEQ(gconv.Bool(123.456), true) + t.AssertEQ(gconv.Bool(boolStruct{}), true) + t.AssertEQ(gconv.Bool(&boolStruct{}), true) }) } diff --git a/util/gconv/gconv_z_unit_map_test.go b/util/gconv/gconv_z_unit_map_test.go index 9d7075de2..5f4176c0e 100644 --- a/util/gconv/gconv_z_unit_map_test.go +++ b/util/gconv/gconv_z_unit_map_test.go @@ -15,7 +15,7 @@ import ( ) func Test_Map_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m1 := map[string]string{ "k": "v", } @@ -25,37 +25,37 @@ func Test_Map_Basic(t *testing.T) { m3 := map[float64]float32{ 1.22: 3.1, } - gtest.Assert(gconv.Map(m1), g.Map{ + t.Assert(gconv.Map(m1), g.Map{ "k": "v", }) - gtest.Assert(gconv.Map(m2), g.Map{ + t.Assert(gconv.Map(m2), g.Map{ "3": "v", }) - gtest.Assert(gconv.Map(m3), g.Map{ + t.Assert(gconv.Map(m3), g.Map{ "1.22": "3.1", }) }) } func Test_Map_Slice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { slice1 := g.Slice{"1", "2", "3", "4"} slice2 := g.Slice{"1", "2", "3"} slice3 := g.Slice{} - gtest.Assert(gconv.Map(slice1), g.Map{ + t.Assert(gconv.Map(slice1), g.Map{ "1": "2", "3": "4", }) - gtest.Assert(gconv.Map(slice2), g.Map{ + t.Assert(gconv.Map(slice2), g.Map{ "1": "2", "3": nil, }) - gtest.Assert(gconv.Map(slice3), g.Map{}) + t.Assert(gconv.Map(slice3), g.Map{}) }) } func Test_Map_StructWithGconvTag(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -74,26 +74,26 @@ func Test_Map_StructWithGconvTag(t *testing.T) { user2 := &user1 map1 := gconv.Map(user1) map2 := gconv.Map(user2) - gtest.Assert(map1["Uid"], 100) - gtest.Assert(map1["Name"], "john") - gtest.Assert(map1["SiteUrl"], nil) - gtest.Assert(map1["NickName"], nil) - gtest.Assert(map1["nickname"], nil) - gtest.Assert(map1["password1"], "123") - gtest.Assert(map1["password2"], "456") + t.Assert(map1["Uid"], 100) + t.Assert(map1["Name"], "john") + t.Assert(map1["SiteUrl"], nil) + t.Assert(map1["NickName"], nil) + t.Assert(map1["nickname"], nil) + t.Assert(map1["password1"], "123") + t.Assert(map1["password2"], "456") - gtest.Assert(map2["Uid"], 100) - gtest.Assert(map2["Name"], "john") - gtest.Assert(map2["SiteUrl"], nil) - gtest.Assert(map2["NickName"], nil) - gtest.Assert(map2["nickname"], nil) - gtest.Assert(map2["password1"], "123") - gtest.Assert(map2["password2"], "456") + t.Assert(map2["Uid"], 100) + t.Assert(map2["Name"], "john") + t.Assert(map2["SiteUrl"], nil) + t.Assert(map2["NickName"], nil) + t.Assert(map2["nickname"], nil) + t.Assert(map2["password1"], "123") + t.Assert(map2["password2"], "456") }) } func Test_Map_StructWithJsonTag(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -112,26 +112,26 @@ func Test_Map_StructWithJsonTag(t *testing.T) { user2 := &user1 map1 := gconv.Map(user1) map2 := gconv.Map(user2) - gtest.Assert(map1["Uid"], 100) - gtest.Assert(map1["Name"], "john") - gtest.Assert(map1["SiteUrl"], nil) - gtest.Assert(map1["NickName"], nil) - gtest.Assert(map1["nickname"], nil) - gtest.Assert(map1["password1"], "123") - gtest.Assert(map1["password2"], "456") + t.Assert(map1["Uid"], 100) + t.Assert(map1["Name"], "john") + t.Assert(map1["SiteUrl"], nil) + t.Assert(map1["NickName"], nil) + t.Assert(map1["nickname"], nil) + t.Assert(map1["password1"], "123") + t.Assert(map1["password2"], "456") - gtest.Assert(map2["Uid"], 100) - gtest.Assert(map2["Name"], "john") - gtest.Assert(map2["SiteUrl"], nil) - gtest.Assert(map2["NickName"], nil) - gtest.Assert(map2["nickname"], nil) - gtest.Assert(map2["password1"], "123") - gtest.Assert(map2["password2"], "456") + t.Assert(map2["Uid"], 100) + t.Assert(map2["Name"], "john") + t.Assert(map2["SiteUrl"], nil) + t.Assert(map2["NickName"], nil) + t.Assert(map2["nickname"], nil) + t.Assert(map2["password1"], "123") + t.Assert(map2["password2"], "456") }) } func Test_Map_StructWithCTag(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -150,21 +150,21 @@ func Test_Map_StructWithCTag(t *testing.T) { user2 := &user1 map1 := gconv.Map(user1) map2 := gconv.Map(user2) - gtest.Assert(map1["Uid"], 100) - gtest.Assert(map1["Name"], "john") - gtest.Assert(map1["SiteUrl"], nil) - gtest.Assert(map1["NickName"], nil) - gtest.Assert(map1["nickname"], nil) - gtest.Assert(map1["password1"], "123") - gtest.Assert(map1["password2"], "456") + t.Assert(map1["Uid"], 100) + t.Assert(map1["Name"], "john") + t.Assert(map1["SiteUrl"], nil) + t.Assert(map1["NickName"], nil) + t.Assert(map1["nickname"], nil) + t.Assert(map1["password1"], "123") + t.Assert(map1["password2"], "456") - gtest.Assert(map2["Uid"], 100) - gtest.Assert(map2["Name"], "john") - gtest.Assert(map2["SiteUrl"], nil) - gtest.Assert(map2["NickName"], nil) - gtest.Assert(map2["nickname"], nil) - gtest.Assert(map2["password1"], "123") - gtest.Assert(map2["password2"], "456") + t.Assert(map2["Uid"], 100) + t.Assert(map2["Name"], "john") + t.Assert(map2["SiteUrl"], nil) + t.Assert(map2["NickName"], nil) + t.Assert(map2["nickname"], nil) + t.Assert(map2["password1"], "123") + t.Assert(map2["password2"], "456") }) } @@ -173,9 +173,9 @@ func Test_Map_PrivateAttribute(t *testing.T) { Id int name string } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := &User{1, "john"} - gtest.Assert(gconv.Map(user), g.Map{"Id": 1}) + t.Assert(gconv.Map(user), g.Map{"Id": 1}) }) } @@ -194,25 +194,25 @@ func Test_Map_StructInherit(t *testing.T) { Password string `c:"password"` Nickname string `c:"nickname"` } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) user.Id = 100 user.Nickname = "john" user.CreateTime = "2019" m := gconv.Map(user) - gtest.Assert(m["id"], "") - gtest.Assert(m["nickname"], user.Nickname) - gtest.Assert(m["create_time"], "") + t.Assert(m["id"], "") + t.Assert(m["nickname"], user.Nickname) + t.Assert(m["create_time"], "") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) user.Id = 100 user.Nickname = "john" user.CreateTime = "2019" m := gconv.MapDeep(user) - gtest.Assert(m["id"], user.Id) - gtest.Assert(m["nickname"], user.Nickname) - gtest.Assert(m["create_time"], user.CreateTime) + t.Assert(m["id"], user.Id) + t.Assert(m["nickname"], user.Nickname) + t.Assert(m["create_time"], user.CreateTime) }) } @@ -227,37 +227,37 @@ func Test_MapToMap(t *testing.T) { "name": "john", }, } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string]User) err := gconv.MapToMap(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 1) - gtest.Assert(m["key"].Id, 1) - gtest.Assert(m["key"].Name, "john") + t.Assert(err, nil) + t.Assert(len(m), 1) + t.Assert(m["key"].Id, 1) + t.Assert(m["key"].Name, "john") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := (map[string]User)(nil) err := gconv.MapToMap(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 1) - gtest.Assert(m["key"].Id, 1) - gtest.Assert(m["key"].Name, "john") + t.Assert(err, nil) + t.Assert(len(m), 1) + t.Assert(m["key"].Id, 1) + t.Assert(m["key"].Name, "john") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string]*User) err := gconv.MapToMap(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 1) - gtest.Assert(m["key"].Id, 1) - gtest.Assert(m["key"].Name, "john") + t.Assert(err, nil) + t.Assert(len(m), 1) + t.Assert(m["key"].Id, 1) + t.Assert(m["key"].Name, "john") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := (map[string]*User)(nil) err := gconv.MapToMap(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 1) - gtest.Assert(m["key"].Id, 1) - gtest.Assert(m["key"].Name, "john") + t.Assert(err, nil) + t.Assert(len(m), 1) + t.Assert(m["key"].Id, 1) + t.Assert(m["key"].Name, "john") }) } @@ -280,21 +280,21 @@ func Test_MapToMapDeep(t *testing.T) { "name": "john", }, } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := (map[string]*User)(nil) err := gconv.MapToMap(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 1) - gtest.Assert(m["key"].Id, 0) - gtest.Assert(m["key"].Name, "john") + t.Assert(err, nil) + t.Assert(len(m), 1) + t.Assert(m["key"].Id, 0) + t.Assert(m["key"].Name, "john") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := (map[string]*User)(nil) err := gconv.MapToMapDeep(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 1) - gtest.Assert(m["key"].Id, 1) - gtest.Assert(m["key"].Name, "john") + t.Assert(err, nil) + t.Assert(len(m), 1) + t.Assert(m["key"].Id, 1) + t.Assert(m["key"].Name, "john") }) } @@ -313,45 +313,45 @@ func Test_MapToMaps1(t *testing.T) { g.Map{"id": 4, "name": "jim"}, }, } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string][]User) err := gconv.MapToMaps(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m["key1"][0].Id, 1) - gtest.Assert(m["key1"][1].Id, 2) - gtest.Assert(m["key2"][0].Id, 3) - gtest.Assert(m["key2"][1].Id, 4) + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m["key1"][0].Id, 1) + t.Assert(m["key1"][1].Id, 2) + t.Assert(m["key2"][0].Id, 3) + t.Assert(m["key2"][1].Id, 4) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := (map[string][]User)(nil) err := gconv.MapToMaps(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m["key1"][0].Id, 1) - gtest.Assert(m["key1"][1].Id, 2) - gtest.Assert(m["key2"][0].Id, 3) - gtest.Assert(m["key2"][1].Id, 4) + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m["key1"][0].Id, 1) + t.Assert(m["key1"][1].Id, 2) + t.Assert(m["key2"][0].Id, 3) + t.Assert(m["key2"][1].Id, 4) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string][]*User) err := gconv.MapToMaps(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m["key1"][0].Id, 1) - gtest.Assert(m["key1"][1].Id, 2) - gtest.Assert(m["key2"][0].Id, 3) - gtest.Assert(m["key2"][1].Id, 4) + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m["key1"][0].Id, 1) + t.Assert(m["key1"][1].Id, 2) + t.Assert(m["key2"][0].Id, 3) + t.Assert(m["key2"][1].Id, 4) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := (map[string][]*User)(nil) err := gconv.MapToMaps(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m["key1"][0].Id, 1) - gtest.Assert(m["key1"][1].Id, 2) - gtest.Assert(m["key2"][0].Id, 3) - gtest.Assert(m["key2"][1].Id, 4) + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m["key1"][0].Id, 1) + t.Assert(m["key1"][1].Id, 2) + t.Assert(m["key2"][0].Id, 3) + t.Assert(m["key2"][1].Id, 4) }) } @@ -370,35 +370,35 @@ func Test_MapToMaps2(t *testing.T) { g.Map{"id": 4, "name": "jim"}, }, } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[int][]User) err := gconv.MapToMaps(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m[100][0].Id, 1) - gtest.Assert(m[100][1].Id, 2) - gtest.Assert(m[200][0].Id, 3) - gtest.Assert(m[200][1].Id, 4) + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m[100][0].Id, 1) + t.Assert(m[100][1].Id, 2) + t.Assert(m[200][0].Id, 3) + t.Assert(m[200][1].Id, 4) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[int][]*User) err := gconv.MapToMaps(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m[100][0].Id, 1) - gtest.Assert(m[100][1].Id, 2) - gtest.Assert(m[200][0].Id, 3) - gtest.Assert(m[200][1].Id, 4) + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m[100][0].Id, 1) + t.Assert(m[100][1].Id, 2) + t.Assert(m[200][0].Id, 3) + t.Assert(m[200][1].Id, 4) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string][]*User) err := gconv.MapToMaps(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m["100"][0].Id, 1) - gtest.Assert(m["100"][1].Id, 2) - gtest.Assert(m["200"][0].Id, 3) - gtest.Assert(m["200"][1].Id, 4) + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m["100"][0].Id, 1) + t.Assert(m["100"][1].Id, 2) + t.Assert(m["200"][0].Id, 3) + t.Assert(m["200"][1].Id, 4) }) } @@ -425,32 +425,32 @@ func Test_MapToMapsDeep(t *testing.T) { g.Map{"id": 4, "name": "jim"}, }, } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string][]*User) err := gconv.MapToMaps(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m["100"][0].Id, 0) - gtest.Assert(m["100"][1].Id, 0) - gtest.Assert(m["100"][0].Name, "john") - gtest.Assert(m["100"][1].Name, "smith") - gtest.Assert(m["200"][0].Id, 0) - gtest.Assert(m["200"][1].Id, 0) - gtest.Assert(m["200"][0].Name, "green") - gtest.Assert(m["200"][1].Name, "jim") + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m["100"][0].Id, 0) + t.Assert(m["100"][1].Id, 0) + t.Assert(m["100"][0].Name, "john") + t.Assert(m["100"][1].Name, "smith") + t.Assert(m["200"][0].Id, 0) + t.Assert(m["200"][1].Id, 0) + t.Assert(m["200"][0].Name, "green") + t.Assert(m["200"][1].Name, "jim") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { m := make(map[string][]*User) err := gconv.MapToMapsDeep(params, &m) - gtest.Assert(err, nil) - gtest.Assert(len(m), 2) - gtest.Assert(m["100"][0].Id, 1) - gtest.Assert(m["100"][1].Id, 2) - gtest.Assert(m["100"][0].Name, "john") - gtest.Assert(m["100"][1].Name, "smith") - gtest.Assert(m["200"][0].Id, 3) - gtest.Assert(m["200"][1].Id, 4) - gtest.Assert(m["200"][0].Name, "green") - gtest.Assert(m["200"][1].Name, "jim") + t.Assert(err, nil) + t.Assert(len(m), 2) + t.Assert(m["100"][0].Id, 1) + t.Assert(m["100"][1].Id, 2) + t.Assert(m["100"][0].Name, "john") + t.Assert(m["100"][1].Name, "smith") + t.Assert(m["200"][0].Id, 3) + t.Assert(m["200"][1].Id, 4) + t.Assert(m["200"][0].Name, "green") + t.Assert(m["200"][1].Name, "jim") }) } diff --git a/util/gconv/gconv_z_unit_slice_test.go b/util/gconv/gconv_z_unit_slice_test.go index 4bc22fe16..8c23cb4fd 100644 --- a/util/gconv/gconv_z_unit_slice_test.go +++ b/util/gconv/gconv_z_unit_slice_test.go @@ -15,13 +15,13 @@ import ( ) func Test_Slice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { value := 123.456 - gtest.AssertEQ(gconv.Bytes("123"), []byte("123")) - gtest.AssertEQ(gconv.Strings(value), []string{"123.456"}) - gtest.AssertEQ(gconv.Ints(value), []int{123}) - gtest.AssertEQ(gconv.Floats(value), []float64{123.456}) - gtest.AssertEQ(gconv.Interfaces(value), []interface{}{123.456}) + t.AssertEQ(gconv.Bytes("123"), []byte("123")) + t.AssertEQ(gconv.Strings(value), []string{"123.456"}) + t.AssertEQ(gconv.Ints(value), []int{123}) + t.AssertEQ(gconv.Floats(value), []float64{123.456}) + t.AssertEQ(gconv.Interfaces(value), []interface{}{123.456}) }) } @@ -31,9 +31,9 @@ func Test_Slice_PrivateAttribute(t *testing.T) { Id int name string } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := &User{1, "john"} - gtest.Assert(gconv.Interfaces(user), g.Slice{1}) + t.Assert(gconv.Interfaces(user), g.Slice{1}) }) } @@ -47,39 +47,39 @@ func Test_Slice_Structs(t *testing.T) { Base } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { users := make([]User, 0) params := []g.Map{ {"id": 1, "name": "john", "age": 18}, {"id": 2, "name": "smith", "age": 20}, } err := gconv.Structs(params, &users) - gtest.Assert(err, nil) - gtest.Assert(len(users), 2) - gtest.Assert(users[0].Id, params[0]["id"]) - gtest.Assert(users[0].Name, params[0]["name"]) - gtest.Assert(users[0].Age, 0) + t.Assert(err, nil) + t.Assert(len(users), 2) + t.Assert(users[0].Id, params[0]["id"]) + t.Assert(users[0].Name, params[0]["name"]) + t.Assert(users[0].Age, 0) - gtest.Assert(users[1].Id, params[1]["id"]) - gtest.Assert(users[1].Name, params[1]["name"]) - gtest.Assert(users[1].Age, 0) + t.Assert(users[1].Id, params[1]["id"]) + t.Assert(users[1].Name, params[1]["name"]) + t.Assert(users[1].Age, 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { users := make([]User, 0) params := []g.Map{ {"id": 1, "name": "john", "age": 18}, {"id": 2, "name": "smith", "age": 20}, } err := gconv.StructsDeep(params, &users) - gtest.Assert(err, nil) - gtest.Assert(len(users), 2) - gtest.Assert(users[0].Id, params[0]["id"]) - gtest.Assert(users[0].Name, params[0]["name"]) - gtest.Assert(users[0].Age, params[0]["age"]) + t.Assert(err, nil) + t.Assert(len(users), 2) + t.Assert(users[0].Id, params[0]["id"]) + t.Assert(users[0].Name, params[0]["name"]) + t.Assert(users[0].Age, params[0]["age"]) - gtest.Assert(users[1].Id, params[1]["id"]) - gtest.Assert(users[1].Name, params[1]["name"]) - gtest.Assert(users[1].Age, params[1]["age"]) + t.Assert(users[1].Id, params[1]["id"]) + t.Assert(users[1].Name, params[1]["name"]) + t.Assert(users[1].Age, params[1]["age"]) }) } diff --git a/util/gconv/gconv_z_unit_string_test.go b/util/gconv/gconv_z_unit_string_test.go index 860ab5dc0..454f9b241 100644 --- a/util/gconv/gconv_z_unit_string_test.go +++ b/util/gconv/gconv_z_unit_string_test.go @@ -26,40 +26,40 @@ func (s *stringStruct1) String() string { } func Test_String(t *testing.T) { - gtest.Case(t, func() { - gtest.AssertEQ(gconv.String(int(123)), "123") - gtest.AssertEQ(gconv.String(int(-123)), "-123") - gtest.AssertEQ(gconv.String(int8(123)), "123") - gtest.AssertEQ(gconv.String(int8(-123)), "-123") - gtest.AssertEQ(gconv.String(int16(123)), "123") - gtest.AssertEQ(gconv.String(int16(-123)), "-123") - gtest.AssertEQ(gconv.String(int32(123)), "123") - gtest.AssertEQ(gconv.String(int32(-123)), "-123") - gtest.AssertEQ(gconv.String(int64(123)), "123") - gtest.AssertEQ(gconv.String(int64(-123)), "-123") - gtest.AssertEQ(gconv.String(int64(1552578474888)), "1552578474888") - gtest.AssertEQ(gconv.String(int64(-1552578474888)), "-1552578474888") + gtest.C(t, func(t *gtest.T) { + t.AssertEQ(gconv.String(int(123)), "123") + t.AssertEQ(gconv.String(int(-123)), "-123") + t.AssertEQ(gconv.String(int8(123)), "123") + t.AssertEQ(gconv.String(int8(-123)), "-123") + t.AssertEQ(gconv.String(int16(123)), "123") + t.AssertEQ(gconv.String(int16(-123)), "-123") + t.AssertEQ(gconv.String(int32(123)), "123") + t.AssertEQ(gconv.String(int32(-123)), "-123") + t.AssertEQ(gconv.String(int64(123)), "123") + t.AssertEQ(gconv.String(int64(-123)), "-123") + t.AssertEQ(gconv.String(int64(1552578474888)), "1552578474888") + t.AssertEQ(gconv.String(int64(-1552578474888)), "-1552578474888") - gtest.AssertEQ(gconv.String(uint(123)), "123") - gtest.AssertEQ(gconv.String(uint8(123)), "123") - gtest.AssertEQ(gconv.String(uint16(123)), "123") - gtest.AssertEQ(gconv.String(uint32(123)), "123") - gtest.AssertEQ(gconv.String(uint64(155257847488898765)), "155257847488898765") + t.AssertEQ(gconv.String(uint(123)), "123") + t.AssertEQ(gconv.String(uint8(123)), "123") + t.AssertEQ(gconv.String(uint16(123)), "123") + t.AssertEQ(gconv.String(uint32(123)), "123") + t.AssertEQ(gconv.String(uint64(155257847488898765)), "155257847488898765") - gtest.AssertEQ(gconv.String(float32(123.456)), "123.456") - gtest.AssertEQ(gconv.String(float32(-123.456)), "-123.456") - gtest.AssertEQ(gconv.String(float64(1552578474888.456)), "1552578474888.456") - gtest.AssertEQ(gconv.String(float64(-1552578474888.456)), "-1552578474888.456") + t.AssertEQ(gconv.String(float32(123.456)), "123.456") + t.AssertEQ(gconv.String(float32(-123.456)), "-123.456") + t.AssertEQ(gconv.String(float64(1552578474888.456)), "1552578474888.456") + t.AssertEQ(gconv.String(float64(-1552578474888.456)), "-1552578474888.456") - gtest.AssertEQ(gconv.String(true), "true") - gtest.AssertEQ(gconv.String(false), "false") + t.AssertEQ(gconv.String(true), "true") + t.AssertEQ(gconv.String(false), "false") - gtest.AssertEQ(gconv.String([]byte("bytes")), "bytes") + t.AssertEQ(gconv.String([]byte("bytes")), "bytes") - gtest.AssertEQ(gconv.String(stringStruct1{"john"}), `{"Name":"john"}`) - gtest.AssertEQ(gconv.String(&stringStruct1{"john"}), "john") + t.AssertEQ(gconv.String(stringStruct1{"john"}), `{"Name":"john"}`) + t.AssertEQ(gconv.String(&stringStruct1{"john"}), "john") - gtest.AssertEQ(gconv.String(stringStruct2{"john"}), `{"Name":"john"}`) - gtest.AssertEQ(gconv.String(&stringStruct2{"john"}), `{"Name":"john"}`) + t.AssertEQ(gconv.String(stringStruct2{"john"}), `{"Name":"john"}`) + t.AssertEQ(gconv.String(&stringStruct2{"john"}), `{"Name":"john"}`) }) } diff --git a/util/gconv/gconv_z_unit_struct_slice_test.go b/util/gconv/gconv_z_unit_struct_slice_test.go index 39be12750..71a3ac54c 100644 --- a/util/gconv/gconv_z_unit_struct_slice_test.go +++ b/util/gconv/gconv_z_unit_struct_slice_test.go @@ -15,84 +15,84 @@ import ( ) func Test_Struct_Slice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []int } user := new(User) array := g.Slice{1, 2, 3} err := gconv.Struct(g.Map{"scores": array}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Scores, array) + t.Assert(err, nil) + t.Assert(user.Scores, array) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []int32 } user := new(User) array := g.Slice{1, 2, 3} err := gconv.Struct(g.Map{"scores": array}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Scores, array) + t.Assert(err, nil) + t.Assert(user.Scores, array) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []int64 } user := new(User) array := g.Slice{1, 2, 3} err := gconv.Struct(g.Map{"scores": array}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Scores, array) + t.Assert(err, nil) + t.Assert(user.Scores, array) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []uint } user := new(User) array := g.Slice{1, 2, 3} err := gconv.Struct(g.Map{"scores": array}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Scores, array) + t.Assert(err, nil) + t.Assert(user.Scores, array) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []uint32 } user := new(User) array := g.Slice{1, 2, 3} err := gconv.Struct(g.Map{"scores": array}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Scores, array) + t.Assert(err, nil) + t.Assert(user.Scores, array) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []uint64 } user := new(User) array := g.Slice{1, 2, 3} err := gconv.Struct(g.Map{"scores": array}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Scores, array) + t.Assert(err, nil) + t.Assert(user.Scores, array) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []float32 } user := new(User) array := g.Slice{1, 2, 3} err := gconv.Struct(g.Map{"scores": array}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Scores, array) + t.Assert(err, nil) + t.Assert(user.Scores, array) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []float64 } user := new(User) array := g.Slice{1, 2, 3} err := gconv.Struct(g.Map{"scores": array}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Scores, array) + t.Assert(err, nil) + t.Assert(user.Scores, array) }) } diff --git a/util/gconv/gconv_z_unit_struct_test.go b/util/gconv/gconv_z_unit_struct_test.go index 767117b87..d5e65c2c6 100644 --- a/util/gconv/gconv_z_unit_struct_test.go +++ b/util/gconv/gconv_z_unit_struct_test.go @@ -18,7 +18,7 @@ import ( ) func Test_Struct_Basic1(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -40,7 +40,7 @@ func Test_Struct_Basic1(t *testing.T) { if err := gconv.Struct(params1, user); err != nil { gtest.Error(err) } - gtest.Assert(user, &User{ + t.Assert(user, &User{ Uid: 1, Name: "john", Site_Url: "https://goframe.org", @@ -62,7 +62,7 @@ func Test_Struct_Basic1(t *testing.T) { if err := gconv.Struct(params2, user); err != nil { gtest.Error(err) } - gtest.Assert(user, &User{ + t.Assert(user, &User{ Uid: 2, Name: "smith", Site_Url: "https://goframe.org", @@ -75,7 +75,7 @@ func Test_Struct_Basic1(t *testing.T) { // 使用默认映射规则绑定属性值到对象 func Test_Struct_Basic2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -94,7 +94,7 @@ func Test_Struct_Basic2(t *testing.T) { if err := gconv.Struct(params, user); err != nil { gtest.Error(err) } - gtest.Assert(user, &User{ + t.Assert(user, &User{ Uid: 1, Name: "john", SiteUrl: "https://goframe.org", @@ -106,7 +106,7 @@ func Test_Struct_Basic2(t *testing.T) { // 带有指针的基础类型属性 func Test_Struct_Basic3(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name *string @@ -119,14 +119,14 @@ func Test_Struct_Basic3(t *testing.T) { if err := gconv.Struct(params, user); err != nil { gtest.Error(err) } - gtest.Assert(user.Uid, 1) - gtest.Assert(*user.Name, "john") + t.Assert(user.Uid, 1) + t.Assert(*user.Name, "john") }) } // slice类型属性的赋值 func Test_Struct_Attr_Slice(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Scores []int } @@ -135,7 +135,7 @@ func Test_Struct_Attr_Slice(t *testing.T) { if err := gconv.Struct(g.Map{"Scores": scores}, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user, &User{ + t.Assert(user, &User{ Scores: []int{99, 100, 60, 140}, }) } @@ -144,7 +144,7 @@ func Test_Struct_Attr_Slice(t *testing.T) { // 属性为struct对象 func Test_Struct_Attr_Struct(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -165,7 +165,7 @@ func Test_Struct_Attr_Struct(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user, &User{ + t.Assert(user, &User{ Scores: Score{ Name: "john", Result: 100, @@ -177,7 +177,7 @@ func Test_Struct_Attr_Struct(t *testing.T) { // 属性为struct对象指针 func Test_Struct_Attr_Struct_Ptr(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -198,7 +198,7 @@ func Test_Struct_Attr_Struct_Ptr(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user.Scores, &Score{ + t.Assert(user.Scores, &Score{ Name: "john", Result: 100, }) @@ -208,7 +208,7 @@ func Test_Struct_Attr_Struct_Ptr(t *testing.T) { // 属性为struct对象slice func Test_Struct_Attr_Struct_Slice1(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -229,7 +229,7 @@ func Test_Struct_Attr_Struct_Slice1(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user.Scores, []Score{ + t.Assert(user.Scores, []Score{ { Name: "john", Result: 100, @@ -241,7 +241,7 @@ func Test_Struct_Attr_Struct_Slice1(t *testing.T) { // 属性为struct对象slice func Test_Struct_Attr_Struct_Slice2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -268,7 +268,7 @@ func Test_Struct_Attr_Struct_Slice2(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(user.Scores, []Score{ + t.Assert(user.Scores, []Score{ { Name: "john", Result: 100, @@ -284,7 +284,7 @@ func Test_Struct_Attr_Struct_Slice2(t *testing.T) { // 属性为struct对象slice ptr func Test_Struct_Attr_Struct_Slice_Ptr(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Score struct { Name string Result int @@ -311,12 +311,12 @@ func Test_Struct_Attr_Struct_Slice_Ptr(t *testing.T) { if err := gconv.Struct(scores, user); err != nil { gtest.Error(err) } else { - gtest.Assert(len(user.Scores), 2) - gtest.Assert(user.Scores[0], &Score{ + t.Assert(len(user.Scores), 2) + t.Assert(user.Scores[0], &Score{ Name: "john", Result: 100, }) - gtest.Assert(user.Scores[1], &Score{ + t.Assert(user.Scores[1], &Score{ Name: "smith", Result: 60, }) @@ -330,12 +330,12 @@ func Test_Struct_Attr_CustomType1(t *testing.T) { Id MyInt Name string } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) err := gconv.Struct(g.Map{"id": 1, "name": "john"}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, 1) - gtest.Assert(user.Name, "john") + t.Assert(err, nil) + t.Assert(user.Id, 1) + t.Assert(user.Name, "john") }) } @@ -345,12 +345,12 @@ func Test_Struct_Attr_CustomType2(t *testing.T) { Id []MyInt Name string } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) err := gconv.Struct(g.Map{"id": g.Slice{1, 2}, "name": "john"}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, g.Slice{1, 2}) - gtest.Assert(user.Name, "john") + t.Assert(err, nil) + t.Assert(user.Id, g.Slice{1, 2}) + t.Assert(user.Name, "john") }) } @@ -359,12 +359,12 @@ func Test_Struct_PrivateAttribute(t *testing.T) { Id int name string } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) err := gconv.Struct(g.Map{"id": 1, "name": "john"}, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, 1) - gtest.Assert(user.name, "") + t.Assert(err, nil) + t.Assert(user.Id, 1) + t.Assert(user.name, "") }) } @@ -377,7 +377,7 @@ func Test_StructDeep1(t *testing.T) { Name string Base } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) params := g.Map{ "id": 1, @@ -385,13 +385,13 @@ func Test_StructDeep1(t *testing.T) { "age": 18, } err := gconv.Struct(params, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, params["id"]) - gtest.Assert(user.Name, params["name"]) - gtest.Assert(user.Age, 0) + t.Assert(err, nil) + t.Assert(user.Id, params["id"]) + t.Assert(user.Name, params["name"]) + t.Assert(user.Age, 0) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) params := g.Map{ "id": 1, @@ -399,10 +399,10 @@ func Test_StructDeep1(t *testing.T) { "age": 18, } err := gconv.StructDeep(params, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, params["id"]) - gtest.Assert(user.Name, params["name"]) - gtest.Assert(user.Age, params["age"]) + t.Assert(err, nil) + t.Assert(user.Id, params["id"]) + t.Assert(user.Name, params["name"]) + t.Assert(user.Age, params["age"]) }) } @@ -424,35 +424,35 @@ func Test_StructDeep2(t *testing.T) { "uid": 10, "name": "john", } - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) err := gconv.Struct(params, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, 0) - gtest.Assert(user.Uid, 0) - gtest.Assert(user.Name, "john") + t.Assert(err, nil) + t.Assert(user.Id, 0) + t.Assert(user.Uid, 0) + t.Assert(user.Name, "john") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := new(User) err := gconv.StructDeep(params, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, 1) - gtest.Assert(user.Uid, 10) - gtest.Assert(user.Name, "john") + t.Assert(err, nil) + t.Assert(user.Id, 1) + t.Assert(user.Uid, 10) + t.Assert(user.Name, "john") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { user := (*User)(nil) err := gconv.StructDeep(params, &user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, 1) - gtest.Assert(user.Uid, 10) - gtest.Assert(user.Name, "john") + t.Assert(err, nil) + t.Assert(user.Id, 1) + t.Assert(user.Uid, 10) + t.Assert(user.Name, "john") }) } func Test_StructDeep3(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Ids struct { Id int `json:"id"` Uid int `json:"uid"` @@ -477,16 +477,16 @@ func Test_StructDeep3(t *testing.T) { } user := new(User) err := gconv.StructDeep(data, user) - gtest.Assert(err, nil) - gtest.Assert(user.Id, 100) - gtest.Assert(user.Uid, 101) - gtest.Assert(user.Nickname, "T1") - gtest.Assert(user.CreateTime, "2019") + t.Assert(err, nil) + t.Assert(user.Id, 100) + t.Assert(user.Uid, 101) + t.Assert(user.Nickname, "T1") + t.Assert(user.CreateTime, "2019") }) } func Test_Struct_Time(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime time.Time } @@ -495,10 +495,10 @@ func Test_Struct_Time(t *testing.T) { gconv.Struct(g.Map{ "create_time": now, }, user) - gtest.Assert(user.CreateTime.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.UTC().String(), now.UTC().String()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime *time.Time } @@ -507,10 +507,10 @@ func Test_Struct_Time(t *testing.T) { gconv.Struct(g.Map{ "create_time": &now, }, user) - gtest.Assert(user.CreateTime.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.UTC().String(), now.UTC().String()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime *gtime.Time } @@ -519,10 +519,10 @@ func Test_Struct_Time(t *testing.T) { gconv.Struct(g.Map{ "create_time": &now, }, user) - gtest.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime gtime.Time } @@ -531,10 +531,10 @@ func Test_Struct_Time(t *testing.T) { gconv.Struct(g.Map{ "create_time": &now, }, user) - gtest.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { CreateTime gtime.Time } @@ -543,13 +543,13 @@ func Test_Struct_Time(t *testing.T) { gconv.Struct(g.Map{ "create_time": now, }, user) - gtest.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) + t.Assert(user.CreateTime.Time.UTC().String(), now.UTC().String()) }) } // Auto create struct when given pointer. func Test_Struct_Create(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -560,12 +560,12 @@ func Test_Struct_Create(t *testing.T) { "Name": "john", } err := gconv.Struct(params, &user) - gtest.Assert(err, nil) - gtest.Assert(user.Uid, 1) - gtest.Assert(user.Name, "john") + t.Assert(err, nil) + t.Assert(user.Uid, 1) + t.Assert(user.Name, "john") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid int Name string @@ -576,13 +576,13 @@ func Test_Struct_Create(t *testing.T) { "Name": "john", } err := gconv.Struct(params, user) - gtest.AssertNE(err, nil) - gtest.Assert(user, nil) + t.AssertNE(err, nil) + t.Assert(user, nil) }) } func Test_Struct_Interface(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Uid interface{} Name interface{} @@ -593,14 +593,14 @@ func Test_Struct_Interface(t *testing.T) { "Name": nil, } err := gconv.Struct(params, &user) - gtest.Assert(err, nil) - gtest.Assert(user.Uid, 1) - gtest.Assert(user.Name, nil) + t.Assert(err, nil) + t.Assert(user.Uid, 1) + t.Assert(user.Name, nil) }) } func Test_Struct_NilAttribute(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Item struct { Title string `json:"title"` Key string `json:"key"` @@ -622,15 +622,15 @@ func Test_Struct_NilAttribute(t *testing.T) { "txt": "hello", "items": nil, }, m) - gtest.Assert(err, nil) - gtest.AssertNE(m.Me, nil) - gtest.Assert(m.Me["day"], "20009") - gtest.Assert(m.Items, nil) + t.Assert(err, nil) + t.AssertNE(m.Me, nil) + t.Assert(m.Me["day"], "20009") + t.Assert(m.Items, nil) }) } func Test_Struct_Complex(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type ApplyReportDetail struct { ApplyScore string `json:"apply_score"` ApplyCredibility string `json:"apply_credibility"` @@ -765,18 +765,18 @@ func Test_Struct_Complex(t *testing.T) { }` m := make(g.Map) err := json.Unmarshal([]byte(data), &m) - gtest.Assert(err, nil) + t.Assert(err, nil) model := new(XinYanModel) err = gconv.Struct(m, model) - gtest.Assert(err, nil) - gtest.Assert(model.ErrorCode, nil) - gtest.Assert(model.ErrorMsg, nil) - gtest.Assert(model.Success, true) - gtest.Assert(model.Data.IDName, "dd67a5943781369ddd7c594e231e9e70") - gtest.Assert(model.Data.TradeNo, "201704011507240100057329") - gtest.Assert(model.Data.ResultDetail.ApplyReportDetail.ApplyScore, "189") - gtest.Assert(model.Data.ResultDetail.BehaviorReportDetail.LoansSettleCount, "280") - gtest.Assert(model.Data.ResultDetail.CurrentReportDetail.LoansProductCount, "8") + t.Assert(err, nil) + t.Assert(model.ErrorCode, nil) + t.Assert(model.ErrorMsg, nil) + t.Assert(model.Success, true) + t.Assert(model.Data.IDName, "dd67a5943781369ddd7c594e231e9e70") + t.Assert(model.Data.TradeNo, "201704011507240100057329") + t.Assert(model.Data.ResultDetail.ApplyReportDetail.ApplyScore, "189") + t.Assert(model.Data.ResultDetail.BehaviorReportDetail.LoansSettleCount, "280") + t.Assert(model.Data.ResultDetail.CurrentReportDetail.LoansProductCount, "8") }) } diff --git a/util/gconv/gconv_z_unit_time_test.go b/util/gconv/gconv_z_unit_time_test.go index f439a4352..7f27375a6 100644 --- a/util/gconv/gconv_z_unit_time_test.go +++ b/util/gconv/gconv_z_unit_time_test.go @@ -16,10 +16,10 @@ import ( ) func Test_Time(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { t1 := "2011-10-10 01:02:03.456" - gtest.AssertEQ(gconv.GTime(t1), gtime.NewFromStr(t1)) - gtest.AssertEQ(gconv.Time(t1), gtime.NewFromStr(t1).Time) - gtest.AssertEQ(gconv.Duration(100), 100*time.Nanosecond) + t.AssertEQ(gconv.GTime(t1), gtime.NewFromStr(t1)) + t.AssertEQ(gconv.Time(t1), gtime.NewFromStr(t1).Time) + t.AssertEQ(gconv.Duration(100), 100*time.Nanosecond) }) } diff --git a/util/gconv/gconv_z_unit_unsafe_test.go b/util/gconv/gconv_z_unit_unsafe_test.go index e9ae03145..326d9a942 100644 --- a/util/gconv/gconv_z_unit_unsafe_test.go +++ b/util/gconv/gconv_z_unit_unsafe_test.go @@ -13,13 +13,13 @@ import ( ) func Test_Unsafe(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { s := "I love 小泽玛利亚" - gtest.AssertEQ(gconv.UnsafeStrToBytes(s), []byte(s)) + t.AssertEQ(gconv.UnsafeStrToBytes(s), []byte(s)) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { b := []byte("I love 小泽玛利亚") - gtest.AssertEQ(gconv.UnsafeBytesToStr(b), string(b)) + t.AssertEQ(gconv.UnsafeBytesToStr(b), string(b)) }) } diff --git a/util/gpage/gpage_unit_test.go b/util/gpage/gpage_unit_test.go index f1a6d9196..afa49c5f7 100644 --- a/util/gpage/gpage_unit_test.go +++ b/util/gpage/gpage_unit_test.go @@ -16,51 +16,51 @@ import ( ) func Test_New(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(9, 2, 1, `/user/list?page={.page}`) - gtest.Assert(page.TotalSize, 9) - gtest.Assert(page.TotalPage, 5) - gtest.Assert(page.CurrentPage, 1) + t.Assert(page.TotalSize, 9) + t.Assert(page.TotalPage, 5) + t.Assert(page.CurrentPage, 1) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(9, 2, 0, `/user/list?page={.page}`) - gtest.Assert(page.TotalSize, 9) - gtest.Assert(page.TotalPage, 5) - gtest.Assert(page.CurrentPage, 1) + t.Assert(page.TotalSize, 9) + t.Assert(page.TotalPage, 5) + t.Assert(page.CurrentPage, 1) }) } func Test_Basic(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(9, 2, 1, `/user/list?page={.page}`) - gtest.Assert(page.NextPage(), `
>`) - gtest.Assert(page.PrevPage(), `<`) - gtest.Assert(page.FirstPage(), `|<`) - gtest.Assert(page.LastPage(), `>|`) - gtest.Assert(page.PageBar(), `12345`) + t.Assert(page.NextPage(), `>`) + t.Assert(page.PrevPage(), `<`) + t.Assert(page.FirstPage(), `|<`) + t.Assert(page.LastPage(), `>|`) + t.Assert(page.PageBar(), `12345`) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(9, 2, 3, `/user/list?page={.page}`) - gtest.Assert(page.NextPage(), `>`) - gtest.Assert(page.PrevPage(), `<`) - gtest.Assert(page.FirstPage(), `|<`) - gtest.Assert(page.LastPage(), `>|`) - gtest.Assert(page.PageBar(), `12345`) + t.Assert(page.NextPage(), `>`) + t.Assert(page.PrevPage(), `<`) + t.Assert(page.FirstPage(), `|<`) + t.Assert(page.LastPage(), `>|`) + t.Assert(page.PageBar(), `12345`) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(9, 2, 5, `/user/list?page={.page}`) - gtest.Assert(page.NextPage(), `>`) - gtest.Assert(page.PrevPage(), `<`) - gtest.Assert(page.FirstPage(), `|<`) - gtest.Assert(page.LastPage(), `>|`) - gtest.Assert(page.PageBar(), `12345`) + t.Assert(page.NextPage(), `>`) + t.Assert(page.PrevPage(), `<`) + t.Assert(page.FirstPage(), `|<`) + t.Assert(page.LastPage(), `>|`) + t.Assert(page.PageBar(), `12345`) }) } func Test_CustomTag(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(5, 1, 2, `/user/list/{.page}`) page.PrevPageTag = "《" page.NextPageTag = "》" @@ -68,49 +68,49 @@ func Test_CustomTag(t *testing.T) { page.LastPageTag = "》|" page.PrevBarTag = "《《" page.NextBarTag = "》》" - gtest.Assert(page.NextPage(), ``) - gtest.Assert(page.PrevPage(), ``) - gtest.Assert(page.FirstPage(), `|《`) - gtest.Assert(page.LastPage(), `》|`) - gtest.Assert(page.PageBar(), `12345`) + t.Assert(page.NextPage(), ``) + t.Assert(page.PrevPage(), ``) + t.Assert(page.FirstPage(), `|《`) + t.Assert(page.LastPage(), `》|`) + t.Assert(page.PageBar(), `12345`) }) } func Test_CustomStyle(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(5, 1, 2, `/user/list/{.page}`) page.LinkStyle = "MyPageLink" page.SpanStyle = "MyPageSpan" page.SelectStyle = "MyPageSelect" - gtest.Assert(page.NextPage(), `>`) - gtest.Assert(page.PrevPage(), `<`) - gtest.Assert(page.FirstPage(), `|<`) - gtest.Assert(page.LastPage(), `>|`) - gtest.Assert(page.PageBar(), `12345`) - gtest.Assert(page.SelectBar(), ``) + t.Assert(page.NextPage(), `>`) + t.Assert(page.PrevPage(), `<`) + t.Assert(page.FirstPage(), `|<`) + t.Assert(page.LastPage(), `>|`) + t.Assert(page.PageBar(), `12345`) + t.Assert(page.SelectBar(), ``) }) } func Test_Ajax(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(5, 1, 2, `/user/list/{.page}`) page.AjaxActionName = "LoadPage" - gtest.Assert(page.NextPage(), `>`) - gtest.Assert(page.PrevPage(), `<`) - gtest.Assert(page.FirstPage(), `|<`) - gtest.Assert(page.LastPage(), `>|`) - gtest.Assert(page.PageBar(), `12345`) + t.Assert(page.NextPage(), `>`) + t.Assert(page.PrevPage(), `<`) + t.Assert(page.FirstPage(), `|<`) + t.Assert(page.LastPage(), `>|`) + t.Assert(page.PageBar(), `12345`) }) } func Test_PredefinedContent(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { page := gpage.New(5, 1, 2, `/user/list/{.page}`) page.AjaxActionName = "LoadPage" - gtest.Assert(page.GetContent(1), `上一页 2 下一页`) - gtest.Assert(page.GetContent(2), `首页<<上一页[第2页]下一页>>尾页页`) - gtest.Assert(page.GetContent(3), `首页上一页12345下一页尾页当前页2/5 共5条`) - gtest.Assert(page.GetContent(4), `首页上一页12345下一页尾页`) - gtest.Assert(page.GetContent(5), ``) + t.Assert(page.GetContent(1), `上一页 2 下一页`) + t.Assert(page.GetContent(2), `首页<<上一页[第2页]下一页>>尾页页`) + t.Assert(page.GetContent(3), `首页上一页12345下一页尾页当前页2/5 共5条`) + t.Assert(page.GetContent(4), `首页上一页12345下一页尾页`) + t.Assert(page.GetContent(5), ``) }) } diff --git a/util/grand/grand_z_unit_test.go b/util/grand/grand_z_unit_test.go index 340b9c57b..0be667eea 100644 --- a/util/grand/grand_z_unit_test.go +++ b/util/grand/grand_z_unit_test.go @@ -17,155 +17,155 @@ import ( ) func Test_Intn(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 1000000; i++ { n := grand.Intn(100) - gtest.AssertLT(n, 100) - gtest.AssertGE(n, 0) + t.AssertLT(n, 100) + t.AssertGE(n, 0) } for i := 0; i < 1000000; i++ { n := grand.Intn(-100) - gtest.AssertLE(n, 0) - gtest.Assert(n, -100) + t.AssertLE(n, 0) + t.Assert(n, -100) } }) } func Test_Meet(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(grand.Meet(100, 100), true) + t.Assert(grand.Meet(100, 100), true) } for i := 0; i < 100; i++ { - gtest.Assert(grand.Meet(0, 100), false) + t.Assert(grand.Meet(0, 100), false) } for i := 0; i < 100; i++ { - gtest.AssertIN(grand.Meet(50, 100), []bool{true, false}) + t.AssertIN(grand.Meet(50, 100), []bool{true, false}) } }) } func Test_MeetProb(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(grand.MeetProb(1), true) + t.Assert(grand.MeetProb(1), true) } for i := 0; i < 100; i++ { - gtest.Assert(grand.MeetProb(0), false) + t.Assert(grand.MeetProb(0), false) } for i := 0; i < 100; i++ { - gtest.AssertIN(grand.MeetProb(0.5), []bool{true, false}) + t.AssertIN(grand.MeetProb(0.5), []bool{true, false}) } }) } func Test_N(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(grand.N(1, 1), 1) + t.Assert(grand.N(1, 1), 1) } for i := 0; i < 100; i++ { - gtest.Assert(grand.N(0, 0), 0) + t.Assert(grand.N(0, 0), 0) } for i := 0; i < 100; i++ { - gtest.AssertIN(grand.N(1, 2), []int{1, 2}) + t.AssertIN(grand.N(1, 2), []int{1, 2}) } }) } func Test_Rand(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(grand.N(1, 1), 1) + t.Assert(grand.N(1, 1), 1) } for i := 0; i < 100; i++ { - gtest.Assert(grand.N(0, 0), 0) + t.Assert(grand.N(0, 0), 0) } for i := 0; i < 100; i++ { - gtest.AssertIN(grand.N(1, 2), []int{1, 2}) + t.AssertIN(grand.N(1, 2), []int{1, 2}) } for i := 0; i < 100; i++ { - gtest.AssertIN(grand.N(-1, 2), []int{-1, 0, 1, 2}) + t.AssertIN(grand.N(-1, 2), []int{-1, 0, 1, 2}) } }) } func Test_Str(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(len(grand.S(5)), 5) + t.Assert(len(grand.S(5)), 5) } }) } func Test_RandS(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(len(grand.S(5)), 5) + t.Assert(len(grand.S(5)), 5) } }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(len(grand.S(5, true)), 5) + t.Assert(len(grand.S(5, true)), 5) } }) } func Test_RandStr(t *testing.T) { str := "我爱GoFrame" - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 10; i++ { s := grand.Str(str, 100000) - gtest.Assert(gstr.Contains(s, "我"), true) - gtest.Assert(gstr.Contains(s, "爱"), true) - gtest.Assert(gstr.Contains(s, "G"), true) - gtest.Assert(gstr.Contains(s, "o"), true) - gtest.Assert(gstr.Contains(s, "F"), true) - gtest.Assert(gstr.Contains(s, "r"), true) - gtest.Assert(gstr.Contains(s, "a"), true) - gtest.Assert(gstr.Contains(s, "m"), true) - gtest.Assert(gstr.Contains(s, "e"), true) - gtest.Assert(gstr.Contains(s, "w"), false) + t.Assert(gstr.Contains(s, "我"), true) + t.Assert(gstr.Contains(s, "爱"), true) + t.Assert(gstr.Contains(s, "G"), true) + t.Assert(gstr.Contains(s, "o"), true) + t.Assert(gstr.Contains(s, "F"), true) + t.Assert(gstr.Contains(s, "r"), true) + t.Assert(gstr.Contains(s, "a"), true) + t.Assert(gstr.Contains(s, "m"), true) + t.Assert(gstr.Contains(s, "e"), true) + t.Assert(gstr.Contains(s, "w"), false) } }) } func Test_Digits(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(len(grand.Digits(5)), 5) + t.Assert(len(grand.Digits(5)), 5) } }) } func Test_RandDigits(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(len(grand.Digits(5)), 5) + t.Assert(len(grand.Digits(5)), 5) } }) } func Test_Letters(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(len(grand.Letters(5)), 5) + t.Assert(len(grand.Letters(5)), 5) } }) } func Test_RandLetters(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.Assert(len(grand.Letters(5)), 5) + t.Assert(len(grand.Letters(5)), 5) } }) } func Test_Perm(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { for i := 0; i < 100; i++ { - gtest.AssertIN(grand.Perm(5), []int{0, 1, 2, 3, 4}) + t.AssertIN(grand.Perm(5), []int{0, 1, 2, 3, 4}) } }) } diff --git a/util/gutil/gutil_z_comparator_z_unit_test.go b/util/gutil/gutil_z_comparator_z_unit_test.go index 3020574ea..428a7bda4 100755 --- a/util/gutil/gutil_z_comparator_z_unit_test.go +++ b/util/gutil/gutil_z_comparator_z_unit_test.go @@ -15,148 +15,148 @@ import ( func Test_ComparatorString(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorString(1, 1), 0) - gtest.Assert(gutil.ComparatorString(1, 2), -1) - gtest.Assert(gutil.ComparatorString(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorString(1, 1), 0) + t.Assert(gutil.ComparatorString(1, 2), -1) + t.Assert(gutil.ComparatorString(2, 1), 1) }) } func Test_ComparatorInt(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorInt(1, 1), 0) - gtest.Assert(gutil.ComparatorInt(1, 2), -1) - gtest.Assert(gutil.ComparatorInt(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorInt(1, 1), 0) + t.Assert(gutil.ComparatorInt(1, 2), -1) + t.Assert(gutil.ComparatorInt(2, 1), 1) }) } func Test_ComparatorInt8(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorInt8(1, 1), 0) - gtest.Assert(gutil.ComparatorInt8(1, 2), -1) - gtest.Assert(gutil.ComparatorInt8(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorInt8(1, 1), 0) + t.Assert(gutil.ComparatorInt8(1, 2), -1) + t.Assert(gutil.ComparatorInt8(2, 1), 1) }) } func Test_ComparatorInt16(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorInt16(1, 1), 0) - gtest.Assert(gutil.ComparatorInt16(1, 2), -1) - gtest.Assert(gutil.ComparatorInt16(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorInt16(1, 1), 0) + t.Assert(gutil.ComparatorInt16(1, 2), -1) + t.Assert(gutil.ComparatorInt16(2, 1), 1) }) } func Test_ComparatorInt32(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorInt32(1, 1), 0) - gtest.Assert(gutil.ComparatorInt32(1, 2), -1) - gtest.Assert(gutil.ComparatorInt32(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorInt32(1, 1), 0) + t.Assert(gutil.ComparatorInt32(1, 2), -1) + t.Assert(gutil.ComparatorInt32(2, 1), 1) }) } func Test_ComparatorInt64(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorInt64(1, 1), 0) - gtest.Assert(gutil.ComparatorInt64(1, 2), -1) - gtest.Assert(gutil.ComparatorInt64(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorInt64(1, 1), 0) + t.Assert(gutil.ComparatorInt64(1, 2), -1) + t.Assert(gutil.ComparatorInt64(2, 1), 1) }) } func Test_ComparatorUint(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorUint(1, 1), 0) - gtest.Assert(gutil.ComparatorUint(1, 2), -1) - gtest.Assert(gutil.ComparatorUint(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorUint(1, 1), 0) + t.Assert(gutil.ComparatorUint(1, 2), -1) + t.Assert(gutil.ComparatorUint(2, 1), 1) }) } func Test_ComparatorUint8(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorUint8(1, 1), 0) - gtest.Assert(gutil.ComparatorUint8(2, 6), 252) - gtest.Assert(gutil.ComparatorUint8(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorUint8(1, 1), 0) + t.Assert(gutil.ComparatorUint8(2, 6), 252) + t.Assert(gutil.ComparatorUint8(2, 1), 1) }) } func Test_ComparatorUint16(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorUint16(1, 1), 0) - gtest.Assert(gutil.ComparatorUint16(1, 2), 65535) - gtest.Assert(gutil.ComparatorUint16(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorUint16(1, 1), 0) + t.Assert(gutil.ComparatorUint16(1, 2), 65535) + t.Assert(gutil.ComparatorUint16(2, 1), 1) }) } func Test_ComparatorUint32(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorUint32(1, 1), 0) - gtest.Assert(gutil.ComparatorUint32(-1000, 2147483640), 2147482656) - gtest.Assert(gutil.ComparatorUint32(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorUint32(1, 1), 0) + t.Assert(gutil.ComparatorUint32(-1000, 2147483640), 2147482656) + t.Assert(gutil.ComparatorUint32(2, 1), 1) }) } func Test_ComparatorUint64(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorUint64(1, 1), 0) - gtest.Assert(gutil.ComparatorUint64(1, 2), -1) - gtest.Assert(gutil.ComparatorUint64(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorUint64(1, 1), 0) + t.Assert(gutil.ComparatorUint64(1, 2), -1) + t.Assert(gutil.ComparatorUint64(2, 1), 1) }) } func Test_ComparatorFloat32(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorFloat32(1, 1), 0) - gtest.Assert(gutil.ComparatorFloat32(1, 2), -1) - gtest.Assert(gutil.ComparatorFloat32(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorFloat32(1, 1), 0) + t.Assert(gutil.ComparatorFloat32(1, 2), -1) + t.Assert(gutil.ComparatorFloat32(2, 1), 1) }) } func Test_ComparatorFloat64(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorFloat64(1, 1), 0) - gtest.Assert(gutil.ComparatorFloat64(1, 2), -1) - gtest.Assert(gutil.ComparatorFloat64(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorFloat64(1, 1), 0) + t.Assert(gutil.ComparatorFloat64(1, 2), -1) + t.Assert(gutil.ComparatorFloat64(2, 1), 1) }) } func Test_ComparatorByte(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorByte(1, 1), 0) - gtest.Assert(gutil.ComparatorByte(1, 2), 255) - gtest.Assert(gutil.ComparatorByte(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorByte(1, 1), 0) + t.Assert(gutil.ComparatorByte(1, 2), 255) + t.Assert(gutil.ComparatorByte(2, 1), 1) }) } func Test_ComparatorRune(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.ComparatorRune(1, 1), 0) - gtest.Assert(gutil.ComparatorRune(1, 2), -1) - gtest.Assert(gutil.ComparatorRune(2, 1), 1) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.ComparatorRune(1, 1), 0) + t.Assert(gutil.ComparatorRune(1, 2), -1) + t.Assert(gutil.ComparatorRune(2, 1), 1) }) } func Test_ComparatorTime(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { j := gutil.ComparatorTime("2019-06-14", "2019-06-14") - gtest.Assert(j, 0) + t.Assert(j, 0) k := gutil.ComparatorTime("2019-06-15", "2019-06-14") - gtest.Assert(k, 1) + t.Assert(k, 1) l := gutil.ComparatorTime("2019-06-13", "2019-06-14") - gtest.Assert(l, -1) + t.Assert(l, -1) }) } diff --git a/util/gutil/gutil_z_unit_test.go b/util/gutil/gutil_z_unit_test.go index 248352e1e..c9b4a0ec5 100755 --- a/util/gutil/gutil_z_unit_test.go +++ b/util/gutil/gutil_z_unit_test.go @@ -14,51 +14,51 @@ import ( ) func Test_Dump(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gutil.Dump(map[int]int{ 100: 100, }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gutil.Dump(map[string]interface{}{"": func() {}}) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gutil.Dump([]byte("gutil Dump test")) }) } func Test_TryCatch(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gutil.TryCatch(func() { panic("gutil TryCatch test") }) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { gutil.TryCatch(func() { panic("gutil TryCatch test") }, func(err interface{}) { - gtest.Assert(err, "gutil TryCatch test") + t.Assert(err, "gutil TryCatch test") }) }) } func Test_IsEmpty(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(gutil.IsEmpty(1), false) + gtest.C(t, func(t *gtest.T) { + t.Assert(gutil.IsEmpty(1), false) }) } func Test_Throw(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { defer func() { - gtest.Assert(recover(), "gutil Throw test") + t.Assert(recover(), "gutil Throw test") }() gutil.Throw("gutil Throw test") diff --git a/util/guuid/guuid_z_unit_test.go b/util/guuid/guuid_z_unit_test.go index 39291ce28..5e6c36c0d 100755 --- a/util/guuid/guuid_z_unit_test.go +++ b/util/guuid/guuid_z_unit_test.go @@ -14,22 +14,22 @@ import ( ) func Test_Basic(t *testing.T) { - gtest.Case(t, func() { - gtest.Assert(len(guuid.New().String()), 36) + gtest.C(t, func(t *gtest.T) { + t.Assert(len(guuid.New().String()), 36) uuid, _ := guuid.NewUUID() - gtest.Assert(len(uuid.String()), 36) + t.Assert(len(uuid.String()), 36) uuid, _ = guuid.NewDCEGroup() - gtest.Assert(len(uuid.String()), 36) + t.Assert(len(uuid.String()), 36) uuid, _ = guuid.NewDCEPerson() - gtest.Assert(len(uuid.String()), 36) + t.Assert(len(uuid.String()), 36) uuid, _ = guuid.NewRandom() - gtest.Assert(len(uuid.String()), 36) + t.Assert(len(uuid.String()), 36) - gtest.Assert(len(guuid.NewMD5(guuid.UUID{}, []byte("")).String()), 36) - gtest.Assert(len(guuid.NewSHA1(guuid.UUID{}, []byte("")).String()), 36) + t.Assert(len(guuid.NewMD5(guuid.UUID{}, []byte("")).String()), 36) + t.Assert(len(guuid.NewSHA1(guuid.UUID{}, []byte("")).String()), 36) }) } diff --git a/util/gvalid/gvalid_unit_basic_all_test.go b/util/gvalid/gvalid_unit_basic_all_test.go index aa944b249..7c82547af 100755 --- a/util/gvalid/gvalid_unit_basic_all_test.go +++ b/util/gvalid/gvalid_unit_basic_all_test.go @@ -15,7 +15,7 @@ import ( ) func Test_Check(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "abc:6,16" val1 := 0 val2 := 7 @@ -23,9 +23,9 @@ func Test_Check(t *testing.T) { err1 := gvalid.Check(val1, rule, nil) err2 := gvalid.Check(val2, rule, nil) err3 := gvalid.Check(val3, rule, nil) - gtest.Assert(err1, "invalid rules:abc:6,16") - gtest.Assert(err2, "invalid rules:abc:6,16") - gtest.Assert(err3, "invalid rules:abc:6,16") + t.Assert(err1, "invalid rules:abc:6,16") + t.Assert(err2, "invalid rules:abc:6,16") + t.Assert(err3, "invalid rules:abc:6,16") }) } @@ -45,7 +45,7 @@ func Test_Required(t *testing.T) { } func Test_RequiredIf(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "required-if:100,200" val1 := "" val2 := "100" @@ -53,14 +53,14 @@ func Test_RequiredIf(t *testing.T) { err1 := gvalid.Check(val1, rule, nil) err2 := gvalid.Check(val2, rule, nil) err3 := gvalid.Check(val3, rule, nil) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) }) } func Test_RequiredUnless(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "required-unless:100,200" val1 := "" val2 := "100" @@ -68,14 +68,14 @@ func Test_RequiredUnless(t *testing.T) { err1 := gvalid.Check(val1, rule, nil) err2 := gvalid.Check(val2, rule, nil) err3 := gvalid.Check(val3, rule, nil) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) }) } func Test_RequiredWith(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "required-with:id,name" val1 := "" params1 := g.Map{ @@ -91,14 +91,14 @@ func Test_RequiredWith(t *testing.T) { err1 := gvalid.Check(val1, rule, nil, params1) err2 := gvalid.Check(val1, rule, nil, params2) err3 := gvalid.Check(val1, rule, nil, params3) - gtest.Assert(err1, nil) - gtest.AssertNE(err2, nil) - gtest.AssertNE(err3, nil) + t.Assert(err1, nil) + t.AssertNE(err2, nil) + t.AssertNE(err3, nil) }) } func Test_RequiredWithAll(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "required-with-all:id,name" val1 := "" params1 := g.Map{ @@ -114,14 +114,14 @@ func Test_RequiredWithAll(t *testing.T) { err1 := gvalid.Check(val1, rule, nil, params1) err2 := gvalid.Check(val1, rule, nil, params2) err3 := gvalid.Check(val1, rule, nil, params3) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.AssertNE(err3, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.AssertNE(err3, nil) }) } func Test_RequiredWithOut(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "required-without:id,name" val1 := "" params1 := g.Map{ @@ -137,14 +137,14 @@ func Test_RequiredWithOut(t *testing.T) { err1 := gvalid.Check(val1, rule, nil, params1) err2 := gvalid.Check(val1, rule, nil, params2) err3 := gvalid.Check(val1, rule, nil, params3) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) }) } func Test_RequiredWithOutAll(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "required-without-all:id,name" val1 := "" params1 := g.Map{ @@ -160,14 +160,14 @@ func Test_RequiredWithOutAll(t *testing.T) { err1 := gvalid.Check(val1, rule, nil, params1) err2 := gvalid.Check(val1, rule, nil, params2) err3 := gvalid.Check(val1, rule, nil, params3) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) }) } func Test_Date(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "date" val1 := "2010" val2 := "201011" @@ -181,17 +181,17 @@ func Test_Date(t *testing.T) { err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) err6 := gvalid.Check(val6, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) - gtest.Assert(err6, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) + t.Assert(err6, nil) }) } func Test_DateFormat(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { val1 := "2010" val2 := "201011" val3 := "2010.11" @@ -204,17 +204,17 @@ func Test_DateFormat(t *testing.T) { err4 := gvalid.Check(val4, "date-format:Ym-d", nil) err5 := gvalid.Check(val5, "date-format:Y~m~d", nil) err6 := gvalid.Check(val6, "date-format:Y~m~d", nil) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) - gtest.AssertNE(err6, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) + t.AssertNE(err6, nil) }) } func Test_Email(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "email" value1 := "m@johngcn" value2 := "m@www@johngcn" @@ -224,28 +224,28 @@ func Test_Email(t *testing.T) { err2 := gvalid.Check(value2, rule, nil) err3 := gvalid.Check(value3, rule, nil) err4 := gvalid.Check(value4, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) }) } func Test_Phone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { err1 := gvalid.Check("1361990897", "phone", nil) err2 := gvalid.Check("13619908979", "phone", nil) err3 := gvalid.Check("16719908979", "phone", nil) err4 := gvalid.Check("19719908989", "phone", nil) - gtest.AssertNE(err1.String(), nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) + t.AssertNE(err1.String(), nil) + t.Assert(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) }) } func Test_Telephone(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "telephone" val1 := "869265" val2 := "028-869265" @@ -257,16 +257,16 @@ func Test_Telephone(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) }) } func Test_Passport(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "passport" val1 := "123456" val2 := "a12345-6" @@ -278,16 +278,16 @@ func Test_Passport(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.AssertNE(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.AssertNE(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) }) } func Test_Password(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "password" val1 := "12345" val2 := "aaaaa" @@ -299,16 +299,16 @@ func Test_Password(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) }) } func Test_Password2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "password2" val1 := "12345" val2 := "Naaaa" @@ -324,18 +324,18 @@ func Test_Password2(t *testing.T) { err5 := gvalid.Check(val5, rule, nil) err6 := gvalid.Check(val6, rule, nil) err7 := gvalid.Check(val7, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.AssertNE(err3, nil) - gtest.AssertNE(err4, nil) - gtest.AssertNE(err5, nil) - gtest.Assert(err6, nil) - gtest.Assert(err7, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.AssertNE(err3, nil) + t.AssertNE(err4, nil) + t.AssertNE(err5, nil) + t.Assert(err6, nil) + t.Assert(err7, nil) }) } func Test_Password3(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "password3" val1 := "12345" val2 := "Naaaa" @@ -351,30 +351,30 @@ func Test_Password3(t *testing.T) { err5 := gvalid.Check(val5, rule, nil) err6 := gvalid.Check(val6, rule, nil) err7 := gvalid.Check(val7, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.AssertNE(err3, nil) - gtest.AssertNE(err4, nil) - gtest.AssertNE(err5, nil) - gtest.AssertNE(err6, nil) - gtest.Assert(err7, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.AssertNE(err3, nil) + t.AssertNE(err4, nil) + t.AssertNE(err5, nil) + t.AssertNE(err6, nil) + t.Assert(err7, nil) }) } func Test_Postcode(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "postcode" val1 := "12345" val2 := "610036" err1 := gvalid.Check(val1, rule, nil) err2 := gvalid.Check(val2, rule, nil) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) }) } func Test_IDNumber(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "id-number" val1 := "11111111111111" val2 := "1111111111111111" @@ -386,28 +386,28 @@ func Test_IDNumber(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.AssertNE(err3, nil) - gtest.AssertNE(err4, nil) - gtest.Assert(err5, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.AssertNE(err3, nil) + t.AssertNE(err4, nil) + t.Assert(err5, nil) }) } func Test_LuHn(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "luhn" val1 := "6230514630000424470" val2 := "6230514630000424473" err1 := gvalid.Check(val1, rule, nil) err2 := gvalid.Check(val2, rule, nil) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) }) } func Test_QQ(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "qq" val1 := "100" val2 := "1" @@ -419,11 +419,11 @@ func Test_QQ(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) }) } @@ -458,7 +458,7 @@ func Test_Ip(t *testing.T) { } func Test_IPv4(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "ipv4" val1 := "0.0.0" val2 := "0.0.0.0" @@ -470,16 +470,16 @@ func Test_IPv4(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) }) } func Test_IPv6(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "ipv6" val1 := "192.168.1.1" val2 := "CDCD:910A:2222:5498:8475:1111:3900:2020" @@ -491,16 +491,16 @@ func Test_IPv6(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) }) } func Test_MAC(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "mac" val1 := "192.168.1.1" val2 := "44-45-53-54-00-00" @@ -508,14 +508,14 @@ func Test_MAC(t *testing.T) { err1 := gvalid.Check(val1, rule, nil) err2 := gvalid.Check(val2, rule, nil) err3 := gvalid.Check(val3, rule, nil) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) }) } func Test_URL(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "url" val1 := "127.0.0.1" val2 := "https://www.baidu.com" @@ -525,15 +525,15 @@ func Test_URL(t *testing.T) { err2 := gvalid.Check(val2, rule, nil) err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) }) } func Test_Domain(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "domain" val1 := "localhost" val2 := "baidu.com" @@ -547,12 +547,12 @@ func Test_Domain(t *testing.T) { err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) err6 := gvalid.Check(val6, rule, nil) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) - gtest.Assert(err6, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) + t.Assert(err6, nil) }) } @@ -622,7 +622,7 @@ func Test_Between(t *testing.T) { } func Test_Min(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "min:100" val1 := "1" val2 := "99" @@ -634,20 +634,20 @@ func Test_Min(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.AssertNE(err5, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.AssertNE(err5, nil) rule2 := "min:a" err6 := gvalid.Check(val1, rule2, nil) - gtest.AssertNE(err6, nil) + t.AssertNE(err6, nil) }) } func Test_Max(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "max:100" val1 := "1" val2 := "99" @@ -659,20 +659,20 @@ func Test_Max(t *testing.T) { err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) - gtest.AssertNE(err4, nil) - gtest.AssertNE(err5, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) + t.AssertNE(err4, nil) + t.AssertNE(err5, nil) rule2 := "max:a" err6 := gvalid.Check(val1, rule2, nil) - gtest.AssertNE(err6, nil) + t.AssertNE(err6, nil) }) } func Test_Json(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "json" val1 := "" val2 := "." @@ -686,17 +686,17 @@ func Test_Json(t *testing.T) { err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) err6 := gvalid.Check(val6, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) - gtest.Assert(err6, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) + t.Assert(err6, nil) }) } func Test_Integer(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "integer" val1 := "" val2 := "1.0" @@ -710,17 +710,17 @@ func Test_Integer(t *testing.T) { err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) err6 := gvalid.Check(val6, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) - gtest.Assert(err6, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) + t.Assert(err6, nil) }) } func Test_Float(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "float" val1 := "" val2 := "a" @@ -734,17 +734,17 @@ func Test_Float(t *testing.T) { err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) err6 := gvalid.Check(val6, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) - gtest.Assert(err6, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) + t.Assert(err6, nil) }) } func Test_Boolean(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "boolean" val1 := "a" val2 := "-" @@ -758,17 +758,17 @@ func Test_Boolean(t *testing.T) { err4 := gvalid.Check(val4, rule, nil) err5 := gvalid.Check(val5, rule, nil) err6 := gvalid.Check(val6, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) - gtest.Assert(err5, nil) - gtest.Assert(err6, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) + t.Assert(err5, nil) + t.Assert(err6, nil) }) } func Test_Same(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "same:id" val1 := "100" params1 := g.Map{ @@ -784,14 +784,14 @@ func Test_Same(t *testing.T) { err1 := gvalid.Check(val1, rule, nil, params1) err2 := gvalid.Check(val1, rule, nil, params2) err3 := gvalid.Check(val1, rule, nil, params3) - gtest.AssertNE(err1, nil) - gtest.Assert(err2, nil) - gtest.Assert(err3, nil) + t.AssertNE(err1, nil) + t.Assert(err2, nil) + t.Assert(err3, nil) }) } func Test_Different(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "different:id" val1 := "100" params1 := g.Map{ @@ -807,14 +807,14 @@ func Test_Different(t *testing.T) { err1 := gvalid.Check(val1, rule, nil, params1) err2 := gvalid.Check(val1, rule, nil, params2) err3 := gvalid.Check(val1, rule, nil, params3) - gtest.Assert(err1, nil) - gtest.AssertNE(err2, nil) - gtest.AssertNE(err3, nil) + t.Assert(err1, nil) + t.AssertNE(err2, nil) + t.AssertNE(err3, nil) }) } func Test_In(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "in:100,200" val1 := "" val2 := "1" @@ -824,15 +824,15 @@ func Test_In(t *testing.T) { err2 := gvalid.Check(val2, rule, nil) err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) - gtest.Assert(err4, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) + t.Assert(err4, nil) }) } func Test_NotIn(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "not-in:100" val1 := "" val2 := "1" @@ -842,12 +842,12 @@ func Test_NotIn(t *testing.T) { err2 := gvalid.Check(val2, rule, nil) err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.AssertNE(err3, nil) - gtest.Assert(err4, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.AssertNE(err3, nil) + t.Assert(err4, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := "not-in:100,200" val1 := "" val2 := "1" @@ -857,10 +857,10 @@ func Test_NotIn(t *testing.T) { err2 := gvalid.Check(val2, rule, nil) err3 := gvalid.Check(val3, rule, nil) err4 := gvalid.Check(val4, rule, nil) - gtest.Assert(err1, nil) - gtest.Assert(err2, nil) - gtest.AssertNE(err3, nil) - gtest.AssertNE(err4, nil) + t.Assert(err1, nil) + t.Assert(err2, nil) + t.AssertNE(err3, nil) + t.AssertNE(err4, nil) }) } @@ -875,7 +875,7 @@ func Test_Regex1(t *testing.T) { } func Test_Regex2(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { rule := `required|min-length:6|regex:^data:image\/(jpeg|png);base64,` str1 := "" str2 := "data" @@ -883,11 +883,11 @@ func Test_Regex2(t *testing.T) { err1 := gvalid.Check(str1, rule, nil) err2 := gvalid.Check(str2, rule, nil) err3 := gvalid.Check(str3, rule, nil) - gtest.AssertNE(err1, nil) - gtest.AssertNE(err2, nil) - gtest.Assert(err3, nil) + t.AssertNE(err1, nil) + t.AssertNE(err2, nil) + t.Assert(err3, nil) - gtest.AssertNE(err1.Map()["required"], nil) - gtest.AssertNE(err2.Map()["min-length"], nil) + t.AssertNE(err1.Map()["required"], nil) + t.AssertNE(err2.Map()["min-length"], nil) }) } diff --git a/util/gvalid/gvalid_unit_checkmap_test.go b/util/gvalid/gvalid_unit_checkmap_test.go index 639a185f0..fd7cf395b 100755 --- a/util/gvalid/gvalid_unit_checkmap_test.go +++ b/util/gvalid/gvalid_unit_checkmap_test.go @@ -150,7 +150,7 @@ func Test_CheckMapWithNilAndNotRequiredField(t *testing.T) { } func Test_Sequence(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { params := map[string]interface{}{ "passport": "", "password": "123456", @@ -162,21 +162,21 @@ func Test_Sequence(t *testing.T) { "password2@required|length:6,16#", } err := gvalid.CheckMap(params, rules) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Map()), 2) - gtest.Assert(err.Map()["required"], "账号不能为空") - gtest.Assert(err.Map()["length"], "账号长度应当在6到16之间") - gtest.Assert(len(err.Maps()), 2) + t.AssertNE(err, nil) + t.Assert(len(err.Map()), 2) + t.Assert(err.Map()["required"], "账号不能为空") + t.Assert(err.Map()["length"], "账号长度应当在6到16之间") + t.Assert(len(err.Maps()), 2) - gtest.Assert(err.String(), "账号不能为空; 账号长度应当在6到16之间; 两次密码输入不相等") - gtest.Assert(err.Strings(), []string{"账号不能为空", "账号长度应当在6到16之间", "两次密码输入不相等"}) + t.Assert(err.String(), "账号不能为空; 账号长度应当在6到16之间; 两次密码输入不相等") + t.Assert(err.Strings(), []string{"账号不能为空", "账号长度应当在6到16之间", "两次密码输入不相等"}) k, m := err.FirstItem() - gtest.Assert(k, "passport") - gtest.Assert(m, err.Map()) + t.Assert(k, "passport") + t.Assert(m, err.Map()) r, s := err.FirstRule() - gtest.Assert(r, "required") - gtest.Assert(s, "账号不能为空") + t.Assert(r, "required") + t.Assert(s, "账号不能为空") }) } diff --git a/util/gvalid/gvalid_unit_checkstruct_test.go b/util/gvalid/gvalid_unit_checkstruct_test.go index 4219fca90..08b820040 100755 --- a/util/gvalid/gvalid_unit_checkstruct_test.go +++ b/util/gvalid/gvalid_unit_checkstruct_test.go @@ -16,7 +16,7 @@ import ( ) func Test_CheckStruct(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Object struct { Name string Age int @@ -34,10 +34,10 @@ func Test_CheckStruct(t *testing.T) { } obj := &Object{"john", 16} err := gvalid.CheckStruct(obj, rules, msgs) - gtest.Assert(err, nil) + t.Assert(err, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Object struct { Name string Age int @@ -55,14 +55,14 @@ func Test_CheckStruct(t *testing.T) { } obj := &Object{"john", 16} err := gvalid.CheckStruct(obj, rules, msgs) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Maps()), 2) - gtest.Assert(err.Maps()["Name"]["required"], "") - gtest.Assert(err.Maps()["Name"]["length"], "名称长度为6到16个字符") - gtest.Assert(err.Maps()["Age"]["between"], "年龄为18到30周岁") + t.AssertNE(err, nil) + t.Assert(len(err.Maps()), 2) + t.Assert(err.Maps()["Name"]["required"], "") + t.Assert(err.Maps()["Name"]["length"], "名称长度为6到16个字符") + t.Assert(err.Maps()["Age"]["between"], "年龄为18到30周岁") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Object struct { Name string Age int @@ -80,14 +80,14 @@ func Test_CheckStruct(t *testing.T) { } obj := &Object{"john", 16} err := gvalid.CheckStruct(obj, rules, msgs) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Maps()), 2) - gtest.Assert(err.Maps()["Name"]["required"], "") - gtest.Assert(err.Maps()["Name"]["length"], "名称长度为6到16个字符") - gtest.Assert(err.Maps()["Age"]["between"], "年龄为18到30周岁") + t.AssertNE(err, nil) + t.Assert(len(err.Maps()), 2) + t.Assert(err.Maps()["Name"]["required"], "") + t.Assert(err.Maps()["Name"]["length"], "名称长度为6到16个字符") + t.Assert(err.Maps()["Age"]["between"], "年龄为18到30周岁") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Object struct { Name string Age int @@ -105,49 +105,49 @@ func Test_CheckStruct(t *testing.T) { } obj := &Object{"john", 16} err := gvalid.CheckStruct(obj, rules, msgs) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Maps()), 2) - gtest.Assert(err.Maps()["Name"]["required"], "") - gtest.Assert(err.Maps()["Name"]["length"], "名称长度为6到16个字符") - gtest.Assert(err.Maps()["Age"]["between"], "年龄为18到30周岁") + t.AssertNE(err, nil) + t.Assert(len(err.Maps()), 2) + t.Assert(err.Maps()["Name"]["required"], "") + t.Assert(err.Maps()["Name"]["length"], "名称长度为6到16个字符") + t.Assert(err.Maps()["Age"]["between"], "年龄为18到30周岁") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type LoginRequest struct { Username string `json:"username" gvalid:"username@required#用户名不能为空"` Password string `json:"password" gvalid:"password@required#登录密码不能为空"` } var login LoginRequest err := gvalid.CheckStruct(login, nil) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Maps()), 2) - gtest.Assert(err.Maps()["username"]["required"], "用户名不能为空") - gtest.Assert(err.Maps()["password"]["required"], "登录密码不能为空") + t.AssertNE(err, nil) + t.Assert(len(err.Maps()), 2) + t.Assert(err.Maps()["username"]["required"], "用户名不能为空") + t.Assert(err.Maps()["password"]["required"], "登录密码不能为空") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type LoginRequest struct { Username string `json:"username" gvalid:"@required#用户名不能为空"` Password string `json:"password" gvalid:"@required#登录密码不能为空"` } var login LoginRequest err := gvalid.CheckStruct(login, nil) - gtest.Assert(err, nil) + t.Assert(err, nil) }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type LoginRequest struct { username string `json:"username" gvalid:"username@required#用户名不能为空"` Password string `json:"password" gvalid:"password@required#登录密码不能为空"` } var login LoginRequest err := gvalid.CheckStruct(login, nil) - gtest.AssertNE(err, nil) - gtest.Assert(err.Maps()["password"]["required"], "登录密码不能为空") + t.AssertNE(err, nil) + t.Assert(err.Maps()["password"]["required"], "登录密码不能为空") }) // gvalid tag - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int `gvalid:"uid@required|min:10#|ID不能为空"` Age int `gvalid:"age@required#年龄不能为空"` @@ -160,12 +160,12 @@ func Test_CheckStruct(t *testing.T) { Password: "123456", } err := gvalid.CheckStruct(user, nil) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Maps()), 1) - gtest.Assert(err.Maps()["uid"]["min"], "ID不能为空") + t.AssertNE(err, nil) + t.Assert(len(err.Maps()), 1) + t.Assert(err.Maps()["uid"]["min"], "ID不能为空") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int `gvalid:"uid@required|min:10#|ID不能为空"` Age int `gvalid:"age@required#年龄不能为空"` @@ -183,12 +183,12 @@ func Test_CheckStruct(t *testing.T) { } err := gvalid.CheckStruct(user, rules) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Maps()), 1) - gtest.Assert(err.Maps()["uid"]["min"], "ID不能为空") + t.AssertNE(err, nil) + t.Assert(len(err.Maps()), 1) + t.Assert(err.Maps()["uid"]["min"], "ID不能为空") }) - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int `gvalid:"uid@required|min:10#ID不能为空"` Age int `gvalid:"age@required#年龄不能为空"` @@ -201,12 +201,12 @@ func Test_CheckStruct(t *testing.T) { Password: "123456", } err := gvalid.CheckStruct(user, nil) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Maps()), 1) + t.AssertNE(err, nil) + t.Assert(len(err.Maps()), 1) }) // valid tag - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type User struct { Id int `valid:"uid@required|min:10#|ID不能为空"` Age int `valid:"age@required#年龄不能为空"` @@ -219,14 +219,14 @@ func Test_CheckStruct(t *testing.T) { Password: "123456", } err := gvalid.CheckStruct(user, nil) - gtest.AssertNE(err, nil) - gtest.Assert(len(err.Maps()), 1) - gtest.Assert(err.Maps()["uid"]["min"], "ID不能为空") + t.AssertNE(err, nil) + t.Assert(len(err.Maps()), 1) + t.Assert(err.Maps()["uid"]["min"], "ID不能为空") }) } func Test_CheckStruct_With_Inherit(t *testing.T) { - gtest.Case(t, func() { + gtest.C(t, func(t *gtest.T) { type Pass struct { Pass1 string `valid:"password1@required|same:password2#请输入您的密码|您两次输入的密码不一致"` Pass2 string `valid:"password2@required|same:password1#请再次输入您的密码|您两次输入的密码不一致"` @@ -244,9 +244,9 @@ func Test_CheckStruct_With_Inherit(t *testing.T) { }, } err := gvalid.CheckStruct(user, nil) - gtest.AssertNE(err, nil) - gtest.Assert(err.Maps()["name"], g.Map{"required": "请输入您的姓名"}) - gtest.Assert(err.Maps()["password1"], g.Map{"same": "您两次输入的密码不一致"}) - gtest.Assert(err.Maps()["password2"], g.Map{"same": "您两次输入的密码不一致"}) + t.AssertNE(err, nil) + t.Assert(err.Maps()["name"], g.Map{"required": "请输入您的姓名"}) + t.Assert(err.Maps()["password1"], g.Map{"same": "您两次输入的密码不一致"}) + t.Assert(err.Maps()["password2"], g.Map{"same": "您两次输入的密码不一致"}) }) } diff --git a/util/gvalid/gvalid_unit_customerror_test.go b/util/gvalid/gvalid_unit_customerror_test.go index 6dfd673bb..894d59d4f 100755 --- a/util/gvalid/gvalid_unit_customerror_test.go +++ b/util/gvalid/gvalid_unit_customerror_test.go @@ -22,7 +22,7 @@ func Test_Map(t *testing.T) { } err := gvalid.Check(val, rule, nil) - gtest.Assert(err.Map(), msg) + t.Assert(err.Map(), msg) } func Test_FirstString(t *testing.T) { @@ -31,7 +31,7 @@ func Test_FirstString(t *testing.T) { err := gvalid.Check(val, rule, nil) n := err.FirstString() - gtest.Assert(n, "IPv4地址格式不正确") + t.Assert(n, "IPv4地址格式不正确") } func Test_SetDefaultErrorMsgs(t *testing.T) { From 07e65c14a92617d9406b47f7bfb9fca3a3b66f2f Mon Sep 17 00:00:00 2001 From: John Date: Thu, 19 Mar 2020 23:53:03 +0800 Subject: [PATCH 7/9] improve unit testing cases --- .../garray_z_unit_normal_any_array_test.go | 18 +- .../garray_z_unit_normal_int_array_test.go | 18 +- .../garray_z_unit_normal_str_array_test.go | 18 +- container/glist/glist_z_unit_test.go | 695 ++++++++++-------- container/gmap/gmap_z_unit_any_any_test.go | 197 ++--- container/gmap/gmap_z_unit_int_any_test.go | 219 +++--- container/gmap/gmap_z_unit_int_int_test.go | 222 +++--- container/gmap/gmap_z_unit_int_str_test.go | 222 +++--- container/gmap/gmap_z_unit_list_map_test.go | 160 ++-- container/gmap/gmap_z_unit_str_any_test.go | 219 +++--- container/gmap/gmap_z_unit_str_int_test.go | 220 +++--- container/gmap/gmap_z_unit_str_str_test.go | 219 +++--- container/gmap/gmap_z_unit_tree_map_test.go | 114 +-- container/gqueue/gqueue_unit_test.go | 62 +- container/gset/gset_z_unit_any_test.go | 34 +- container/gset/gset_z_unit_int_test.go | 34 +- container/gset/gset_z_unit_str_test.go | 34 +- container/gtree/gtree_z_avl_tree_test.go | 58 +- container/gtree/gtree_z_b_tree_test.go | 57 +- container/gtype/z_unit_bool_test.go | 18 +- container/gtype/z_unit_byte_test.go | 10 +- container/gtype/z_unit_bytes_test.go | 10 +- container/gtype/z_unit_float32_test.go | 10 +- container/gtype/z_unit_float64_test.go | 10 +- container/gtype/z_unit_int32_test.go | 10 +- container/gtype/z_unit_int64_test.go | 10 +- container/gtype/z_unit_int_test.go | 10 +- container/gtype/z_unit_interface_test.go | 20 +- container/gtype/z_unit_string_test.go | 10 +- container/gtype/z_unit_uint32_test.go | 10 +- container/gtype/z_unit_uint64_test.go | 10 +- container/gtype/z_unit_uint_test.go | 10 +- database/gdb/gdb_unit_init_test.go | 6 +- database/gdb/gdb_unit_z_mysql_method_test.go | 31 +- database/gdb/gdb_unit_z_mysql_model_test.go | 2 +- encoding/gbinary/gbinary_z_be_test.go | 126 ++-- encoding/ghtml/ghtml_test.go | 28 +- .../gjson/gjson_z_unit_implements_test.go | 34 +- frame/gins/gins_z_unit_config_test.go | 190 +++-- frame/gins/gins_z_unit_database_test.go | 22 +- frame/gins/gins_z_unit_redis_test.go | 22 +- i18n/gi18n/gi18n_unit_test.go | 48 +- net/ghttp/ghttp_unit_websocket_test.go | 4 +- os/gcron/gcron_unit_2_test.go | 29 +- os/gres/testdata/data/data.go | 2 +- os/gres/testdata/testdata.go | 2 +- ...ssion_unit_storage_redis_hashtable_test.go | 8 +- .../gsession_unit_storage_redis_test.go | 4 +- os/gtime/gtime_z_unit_json_test.go | 34 +- os/gtime/gtime_z_unit_time_test.go | 8 +- os/gtimer/gtimer_z_unit_2_test.go | 94 +-- test/gtest/gtest_t.go | 2 +- text/gstr/gstr_z_unit_parse_test.go | 20 +- util/gvalid/gvalid_unit_customerror_test.go | 28 +- 54 files changed, 1966 insertions(+), 1746 deletions(-) diff --git a/container/garray/garray_z_unit_normal_any_array_test.go b/container/garray/garray_z_unit_normal_any_array_test.go index b656ad4fb..8984a8670 100644 --- a/container/garray/garray_z_unit_normal_any_array_test.go +++ b/container/garray/garray_z_unit_normal_any_array_test.go @@ -541,31 +541,31 @@ func TestArray_RemoveValue(t *testing.T) { } func TestArray_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Array *garray.Array } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`[1,2,3]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "array": g.Slice{1, 2, 3}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) }) } diff --git a/container/garray/garray_z_unit_normal_int_array_test.go b/container/garray/garray_z_unit_normal_int_array_test.go index db9bff224..6895ed433 100644 --- a/container/garray/garray_z_unit_normal_int_array_test.go +++ b/container/garray/garray_z_unit_normal_int_array_test.go @@ -576,31 +576,31 @@ func TestIntArray_RemoveValue(t *testing.T) { } func TestIntArray_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Array *garray.IntArray } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`[1,2,3]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "array": g.Slice{1, 2, 3}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) }) } diff --git a/container/garray/garray_z_unit_normal_str_array_test.go b/container/garray/garray_z_unit_normal_str_array_test.go index f1e1b8a6d..0791d0a6a 100644 --- a/container/garray/garray_z_unit_normal_str_array_test.go +++ b/container/garray/garray_z_unit_normal_str_array_test.go @@ -579,31 +579,31 @@ func TestStrArray_RemoveValue(t *testing.T) { } func TestStrArray_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Array *garray.StrArray } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`["1","2","3"]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"}) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "array": g.SliceStr{"1", "2", "3"}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"}) }) } diff --git a/container/glist/glist_z_unit_test.go b/container/glist/glist_z_unit_test.go index 49a249b2a..9d145d796 100644 --- a/container/glist/glist_z_unit_test.go +++ b/container/glist/glist_z_unit_test.go @@ -16,7 +16,7 @@ import ( ) // 检查链表长度 -func checkListLen(t *testing.T, l *List, len int) bool { +func checkListLen(t *gtest.T, l *List, len int) bool { if n := l.Len(); n != len { t.Errorf("l.Len() = %d, want %d", n, len) return false @@ -25,7 +25,7 @@ func checkListLen(t *testing.T, l *List, len int) bool { } // 检查指针地址 -func checkListPointers(t *testing.T, l *List, es []*Element) { +func checkListPointers(t *gtest.T, l *List, es []*Element) { if !checkListLen(t, l, len(es)) { return } @@ -80,87 +80,89 @@ func TestBasic(t *testing.T) { } func TestList(t *testing.T) { - l := New() - checkListPointers(t, l, []*Element{}) + gtest.C(t, func(t *gtest.T) { + l := New() + checkListPointers(t, l, []*Element{}) - // Single element list - e := l.PushFront("a") - checkListPointers(t, l, []*Element{e}) - l.MoveToFront(e) - checkListPointers(t, l, []*Element{e}) - l.MoveToBack(e) - checkListPointers(t, l, []*Element{e}) - l.Remove(e) - checkListPointers(t, l, []*Element{}) - - // Bigger list - e2 := l.PushFront(2) - e1 := l.PushFront(1) - e3 := l.PushBack(3) - e4 := l.PushBack("banana") - checkListPointers(t, l, []*Element{e1, e2, e3, e4}) - - l.Remove(e2) - checkListPointers(t, l, []*Element{e1, e3, e4}) - - l.MoveToFront(e3) // move from middle - checkListPointers(t, l, []*Element{e3, e1, e4}) - - l.MoveToFront(e1) - l.MoveToBack(e3) // move from middle - checkListPointers(t, l, []*Element{e1, e4, e3}) - - l.MoveToFront(e3) // move from back - checkListPointers(t, l, []*Element{e3, e1, e4}) - l.MoveToFront(e3) // should be no-op - checkListPointers(t, l, []*Element{e3, e1, e4}) - - l.MoveToBack(e3) // move from front - checkListPointers(t, l, []*Element{e1, e4, e3}) - l.MoveToBack(e3) // should be no-op - checkListPointers(t, l, []*Element{e1, e4, e3}) - - e2 = l.InsertBefore(e1, 2) // insert before front - checkListPointers(t, l, []*Element{e2, e1, e4, e3}) - l.Remove(e2) - e2 = l.InsertBefore(e4, 2) // insert before middle - checkListPointers(t, l, []*Element{e1, e2, e4, e3}) - l.Remove(e2) - e2 = l.InsertBefore(e3, 2) // insert before back - checkListPointers(t, l, []*Element{e1, e4, e2, e3}) - l.Remove(e2) - - e2 = l.InsertAfter(e1, 2) // insert after front - checkListPointers(t, l, []*Element{e1, e2, e4, e3}) - l.Remove(e2) - e2 = l.InsertAfter(e4, 2) // insert after middle - checkListPointers(t, l, []*Element{e1, e4, e2, e3}) - l.Remove(e2) - e2 = l.InsertAfter(e3, 2) // insert after back - checkListPointers(t, l, []*Element{e1, e4, e3, e2}) - l.Remove(e2) - - // Check standard iteration. - sum := 0 - for e := l.Front(); e != nil; e = e.Next() { - if i, ok := e.Value.(int); ok { - sum += i - } - } - if sum != 4 { - t.Errorf("sum over l = %d, want 4", sum) - } - - // Clear all elements by iterating - var next *Element - for e := l.Front(); e != nil; e = next { - next = e.Next() + // Single element list + e := l.PushFront("a") + checkListPointers(t, l, []*Element{e}) + l.MoveToFront(e) + checkListPointers(t, l, []*Element{e}) + l.MoveToBack(e) + checkListPointers(t, l, []*Element{e}) l.Remove(e) - } - checkListPointers(t, l, []*Element{}) + checkListPointers(t, l, []*Element{}) + + // Bigger list + e2 := l.PushFront(2) + e1 := l.PushFront(1) + e3 := l.PushBack(3) + e4 := l.PushBack("banana") + checkListPointers(t, l, []*Element{e1, e2, e3, e4}) + + l.Remove(e2) + checkListPointers(t, l, []*Element{e1, e3, e4}) + + l.MoveToFront(e3) // move from middle + checkListPointers(t, l, []*Element{e3, e1, e4}) + + l.MoveToFront(e1) + l.MoveToBack(e3) // move from middle + checkListPointers(t, l, []*Element{e1, e4, e3}) + + l.MoveToFront(e3) // move from back + checkListPointers(t, l, []*Element{e3, e1, e4}) + l.MoveToFront(e3) // should be no-op + checkListPointers(t, l, []*Element{e3, e1, e4}) + + l.MoveToBack(e3) // move from front + checkListPointers(t, l, []*Element{e1, e4, e3}) + l.MoveToBack(e3) // should be no-op + checkListPointers(t, l, []*Element{e1, e4, e3}) + + e2 = l.InsertBefore(e1, 2) // insert before front + checkListPointers(t, l, []*Element{e2, e1, e4, e3}) + l.Remove(e2) + e2 = l.InsertBefore(e4, 2) // insert before middle + checkListPointers(t, l, []*Element{e1, e2, e4, e3}) + l.Remove(e2) + e2 = l.InsertBefore(e3, 2) // insert before back + checkListPointers(t, l, []*Element{e1, e4, e2, e3}) + l.Remove(e2) + + e2 = l.InsertAfter(e1, 2) // insert after front + checkListPointers(t, l, []*Element{e1, e2, e4, e3}) + l.Remove(e2) + e2 = l.InsertAfter(e4, 2) // insert after middle + checkListPointers(t, l, []*Element{e1, e4, e2, e3}) + l.Remove(e2) + e2 = l.InsertAfter(e3, 2) // insert after back + checkListPointers(t, l, []*Element{e1, e4, e3, e2}) + l.Remove(e2) + + // Check standard iteration. + sum := 0 + for e := l.Front(); e != nil; e = e.Next() { + if i, ok := e.Value.(int); ok { + sum += i + } + } + if sum != 4 { + t.Errorf("sum over l = %d, want 4", sum) + } + + // Clear all elements by iterating + var next *Element + for e := l.Front(); e != nil; e = next { + next = e.Next() + l.Remove(e) + } + checkListPointers(t, l, []*Element{}) + }) } -func checkList(t *testing.T, l *List, es []interface{}) { +func checkList(t *gtest.T, l *List, es []interface{}) { if !checkListLen(t, l, len(es)) { return } @@ -193,60 +195,64 @@ func checkList(t *testing.T, l *List, es []interface{}) { } func TestExtending(t *testing.T) { - l1 := New() - l2 := New() + gtest.C(t, func(t *gtest.T) { + l1 := New() + l2 := New() - l1.PushBack(1) - l1.PushBack(2) - l1.PushBack(3) + l1.PushBack(1) + l1.PushBack(2) + l1.PushBack(3) - l2.PushBack(4) - l2.PushBack(5) + l2.PushBack(4) + l2.PushBack(5) - l3 := New() - l3.PushBackList(l1) - checkList(t, l3, []interface{}{1, 2, 3}) - l3.PushBackList(l2) - checkList(t, l3, []interface{}{1, 2, 3, 4, 5}) + l3 := New() + l3.PushBackList(l1) + checkList(t, l3, []interface{}{1, 2, 3}) + l3.PushBackList(l2) + checkList(t, l3, []interface{}{1, 2, 3, 4, 5}) - l3 = New() - l3.PushFrontList(l2) - checkList(t, l3, []interface{}{4, 5}) - l3.PushFrontList(l1) - checkList(t, l3, []interface{}{1, 2, 3, 4, 5}) + l3 = New() + l3.PushFrontList(l2) + checkList(t, l3, []interface{}{4, 5}) + l3.PushFrontList(l1) + checkList(t, l3, []interface{}{1, 2, 3, 4, 5}) - checkList(t, l1, []interface{}{1, 2, 3}) - checkList(t, l2, []interface{}{4, 5}) + checkList(t, l1, []interface{}{1, 2, 3}) + checkList(t, l2, []interface{}{4, 5}) - l3 = New() - l3.PushBackList(l1) - checkList(t, l3, []interface{}{1, 2, 3}) - l3.PushBackList(l3) - checkList(t, l3, []interface{}{1, 2, 3, 1, 2, 3}) + l3 = New() + l3.PushBackList(l1) + checkList(t, l3, []interface{}{1, 2, 3}) + l3.PushBackList(l3) + checkList(t, l3, []interface{}{1, 2, 3, 1, 2, 3}) - l3 = New() - l3.PushFrontList(l1) - checkList(t, l3, []interface{}{1, 2, 3}) - l3.PushFrontList(l3) - checkList(t, l3, []interface{}{1, 2, 3, 1, 2, 3}) + l3 = New() + l3.PushFrontList(l1) + checkList(t, l3, []interface{}{1, 2, 3}) + l3.PushFrontList(l3) + checkList(t, l3, []interface{}{1, 2, 3, 1, 2, 3}) - l3 = New() - l1.PushBackList(l3) - checkList(t, l1, []interface{}{1, 2, 3}) - l1.PushFrontList(l3) - checkList(t, l1, []interface{}{1, 2, 3}) + l3 = New() + l1.PushBackList(l3) + checkList(t, l1, []interface{}{1, 2, 3}) + l1.PushFrontList(l3) + checkList(t, l1, []interface{}{1, 2, 3}) + }) } func TestRemove(t *testing.T) { - l := New() - e1 := l.PushBack(1) - e2 := l.PushBack(2) - checkListPointers(t, l, []*Element{e1, e2}) - //e := l.Front() - //l.Remove(e) - //checkListPointers(t, l, []*Element{e2}) - //l.Remove(e) - //checkListPointers(t, l, []*Element{e2}) + gtest.C(t, func(t *gtest.T) { + l := New() + e1 := l.PushBack(1) + e2 := l.PushBack(2) + checkListPointers(t, l, []*Element{e1, e2}) + //e := l.Front() + //l.Remove(e) + //checkListPointers(t, l, []*Element{e2}) + //l.Remove(e) + //checkListPointers(t, l, []*Element{e2}) + }) } func TestIssue4103(t *testing.T) { @@ -289,122 +295,138 @@ func TestIssue6349(t *testing.T) { } func TestMove(t *testing.T) { - l := New() - e1 := l.PushBack(1) - e2 := l.PushBack(2) - e3 := l.PushBack(3) - e4 := l.PushBack(4) + gtest.C(t, func(t *gtest.T) { + l := New() + e1 := l.PushBack(1) + e2 := l.PushBack(2) + e3 := l.PushBack(3) + e4 := l.PushBack(4) - l.MoveAfter(e3, e3) - checkListPointers(t, l, []*Element{e1, e2, e3, e4}) - l.MoveBefore(e2, e2) - checkListPointers(t, l, []*Element{e1, e2, e3, e4}) + l.MoveAfter(e3, e3) + checkListPointers(t, l, []*Element{e1, e2, e3, e4}) + l.MoveBefore(e2, e2) + checkListPointers(t, l, []*Element{e1, e2, e3, e4}) - l.MoveAfter(e3, e2) - checkListPointers(t, l, []*Element{e1, e2, e3, e4}) - l.MoveBefore(e2, e3) - checkListPointers(t, l, []*Element{e1, e2, e3, e4}) + l.MoveAfter(e3, e2) + checkListPointers(t, l, []*Element{e1, e2, e3, e4}) + l.MoveBefore(e2, e3) + checkListPointers(t, l, []*Element{e1, e2, e3, e4}) - l.MoveBefore(e2, e4) - checkListPointers(t, l, []*Element{e1, e3, e2, e4}) - e2, e3 = e3, e2 + l.MoveBefore(e2, e4) + checkListPointers(t, l, []*Element{e1, e3, e2, e4}) + e2, e3 = e3, e2 - l.MoveBefore(e4, e1) - checkListPointers(t, l, []*Element{e4, e1, e2, e3}) - e1, e2, e3, e4 = e4, e1, e2, e3 + l.MoveBefore(e4, e1) + checkListPointers(t, l, []*Element{e4, e1, e2, e3}) + e1, e2, e3, e4 = e4, e1, e2, e3 - l.MoveAfter(e4, e1) - checkListPointers(t, l, []*Element{e1, e4, e2, e3}) - e2, e3, e4 = e4, e2, e3 + l.MoveAfter(e4, e1) + checkListPointers(t, l, []*Element{e1, e4, e2, e3}) + e2, e3, e4 = e4, e2, e3 - l.MoveAfter(e2, e3) - checkListPointers(t, l, []*Element{e1, e3, e2, e4}) - e2, e3 = e3, e2 + l.MoveAfter(e2, e3) + checkListPointers(t, l, []*Element{e1, e3, e2, e4}) + e2, e3 = e3, e2 + }) } // Test PushFront, PushBack, PushFrontList, PushBackList with uninitialized List func TestZeroList(t *testing.T) { - var l1 = New() - l1.PushFront(1) - checkList(t, l1, []interface{}{1}) + gtest.C(t, func(t *gtest.T) { + var l1 = New() + l1.PushFront(1) + checkList(t, l1, []interface{}{1}) - var l2 = New() - l2.PushBack(1) - checkList(t, l2, []interface{}{1}) + var l2 = New() + l2.PushBack(1) + checkList(t, l2, []interface{}{1}) - var l3 = New() - l3.PushFrontList(l1) - checkList(t, l3, []interface{}{1}) + var l3 = New() + l3.PushFrontList(l1) + checkList(t, l3, []interface{}{1}) - var l4 = New() - l4.PushBackList(l2) - checkList(t, l4, []interface{}{1}) + var l4 = New() + l4.PushBackList(l2) + checkList(t, l4, []interface{}{1}) + }) } // Test that a list l is not modified when calling InsertBefore with a mark that is not an element of l. func TestInsertBeforeUnknownMark(t *testing.T) { - l := New() - l.PushBack(1) - l.PushBack(2) - l.PushBack(3) - l.InsertBefore(new(Element), 1) - checkList(t, l, []interface{}{1, 2, 3}) + gtest.C(t, func(t *gtest.T) { + l := New() + l.PushBack(1) + l.PushBack(2) + l.PushBack(3) + l.InsertBefore(new(Element), 1) + checkList(t, l, []interface{}{1, 2, 3}) + }) } // Test that a list l is not modified when calling InsertAfter with a mark that is not an element of l. func TestInsertAfterUnknownMark(t *testing.T) { - l := New() - l.PushBack(1) - l.PushBack(2) - l.PushBack(3) - l.InsertAfter(new(Element), 1) - checkList(t, l, []interface{}{1, 2, 3}) + gtest.C(t, func(t *gtest.T) { + l := New() + l.PushBack(1) + l.PushBack(2) + l.PushBack(3) + l.InsertAfter(new(Element), 1) + checkList(t, l, []interface{}{1, 2, 3}) + }) } // Test that a list l is not modified when calling MoveAfter or MoveBefore with a mark that is not an element of l. func TestMoveUnknownMark(t *testing.T) { - l1 := New() - e1 := l1.PushBack(1) + gtest.C(t, func(t *gtest.T) { + l1 := New() + e1 := l1.PushBack(1) - l2 := New() - e2 := l2.PushBack(2) + l2 := New() + e2 := l2.PushBack(2) - l1.MoveAfter(e1, e2) - checkList(t, l1, []interface{}{1}) - checkList(t, l2, []interface{}{2}) + l1.MoveAfter(e1, e2) + checkList(t, l1, []interface{}{1}) + checkList(t, l2, []interface{}{2}) - l1.MoveBefore(e1, e2) - checkList(t, l1, []interface{}{1}) - checkList(t, l2, []interface{}{2}) + l1.MoveBefore(e1, e2) + checkList(t, l1, []interface{}{1}) + checkList(t, l2, []interface{}{2}) + }) } func TestList_RemoveAll(t *testing.T) { - l := New() - l.PushBack(1) - l.RemoveAll() - checkList(t, l, []interface{}{}) - l.PushBack(2) - checkList(t, l, []interface{}{2}) + gtest.C(t, func(t *gtest.T) { + l := New() + l.PushBack(1) + l.RemoveAll() + checkList(t, l, []interface{}{}) + l.PushBack(2) + checkList(t, l, []interface{}{2}) + }) } func TestList_PushFronts(t *testing.T) { - l := New() - a1 := []interface{}{1, 2} - l.PushFronts(a1) - checkList(t, l, []interface{}{2, 1}) - a1 = []interface{}{3, 4, 5} - l.PushFronts(a1) - checkList(t, l, []interface{}{5, 4, 3, 2, 1}) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2} + l.PushFronts(a1) + checkList(t, l, []interface{}{2, 1}) + a1 = []interface{}{3, 4, 5} + l.PushFronts(a1) + checkList(t, l, []interface{}{5, 4, 3, 2, 1}) + }) } func TestList_PushBacks(t *testing.T) { - l := New() - a1 := []interface{}{1, 2} - l.PushBacks(a1) - checkList(t, l, []interface{}{1, 2}) - a1 = []interface{}{3, 4, 5} - l.PushBacks(a1) - checkList(t, l, []interface{}{1, 2, 3, 4, 5}) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2} + l.PushBacks(a1) + checkList(t, l, []interface{}{1, 2}) + a1 = []interface{}{3, 4, 5} + l.PushBacks(a1) + checkList(t, l, []interface{}{1, 2, 3, 4, 5}) + }) } func TestList_PopBacks(t *testing.T) { @@ -423,165 +445,190 @@ func TestList_PopBacks(t *testing.T) { } func TestList_PopFronts(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - i1 := l.PopFronts(2) - t.Assert(i1, []interface{}{4, 3}) - t.Assert(l.Len(), 2) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + i1 := l.PopFronts(2) + t.Assert(i1, []interface{}{4, 3}) + t.Assert(l.Len(), 2) + }) } func TestList_PopBackAll(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - i1 := l.PopBackAll() - t.Assert(i1, []interface{}{1, 2, 3, 4}) - t.Assert(l.Len(), 0) - + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + i1 := l.PopBackAll() + t.Assert(i1, []interface{}{1, 2, 3, 4}) + t.Assert(l.Len(), 0) + }) } func TestList_PopFrontAll(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - i1 := l.PopFrontAll() - t.Assert(i1, []interface{}{4, 3, 2, 1}) - t.Assert(l.Len(), 0) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + i1 := l.PopFrontAll() + t.Assert(i1, []interface{}{4, 3, 2, 1}) + t.Assert(l.Len(), 0) + }) } func TestList_FrontAll(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - i1 := l.FrontAll() - t.Assert(i1, []interface{}{4, 3, 2, 1}) - t.Assert(l.Len(), 4) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + i1 := l.FrontAll() + t.Assert(i1, []interface{}{4, 3, 2, 1}) + t.Assert(l.Len(), 4) + }) } func TestList_BackAll(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - i1 := l.BackAll() - t.Assert(i1, []interface{}{1, 2, 3, 4}) - t.Assert(l.Len(), 4) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + i1 := l.BackAll() + t.Assert(i1, []interface{}{1, 2, 3, 4}) + t.Assert(l.Len(), 4) + }) } func TestList_FrontValue(t *testing.T) { - l := New() - l2 := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - i1 := l.FrontValue() - t.Assert(gconv.Int(i1), 4) - t.Assert(l.Len(), 4) + gtest.C(t, func(t *gtest.T) { + l := New() + l2 := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + i1 := l.FrontValue() + t.Assert(gconv.Int(i1), 4) + t.Assert(l.Len(), 4) - i1 = l2.FrontValue() - t.Assert(i1, nil) + i1 = l2.FrontValue() + t.Assert(i1, nil) + }) } func TestList_BackValue(t *testing.T) { - l := New() - l2 := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - i1 := l.BackValue() - t.Assert(gconv.Int(i1), 1) - t.Assert(l.Len(), 4) - - i1 = l2.FrontValue() - t.Assert(i1, nil) + gtest.C(t, func(t *gtest.T) { + l := New() + l2 := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + i1 := l.BackValue() + t.Assert(gconv.Int(i1), 1) + t.Assert(l.Len(), 4) + i1 = l2.FrontValue() + t.Assert(i1, nil) + }) } func TestList_Back(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - e1 := l.Back() - t.Assert(e1.Value, 1) - t.Assert(l.Len(), 4) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + e1 := l.Back() + t.Assert(e1.Value, 1) + t.Assert(l.Len(), 4) + }) } func TestList_Size(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - t.Assert(l.Size(), 4) - l.PopFront() - t.Assert(l.Size(), 3) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + t.Assert(l.Size(), 4) + l.PopFront() + t.Assert(l.Size(), 3) + }) } func TestList_Removes(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - e1 := l.Back() - l.Removes([]*Element{e1}) - t.Assert(l.Len(), 3) - - e2 := l.Back() - l.Removes([]*Element{e2}) - t.Assert(l.Len(), 2) - checkList(t, l, []interface{}{4, 3}) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + e1 := l.Back() + l.Removes([]*Element{e1}) + t.Assert(l.Len(), 3) + e2 := l.Back() + l.Removes([]*Element{e2}) + t.Assert(l.Len(), 2) + checkList(t, l, []interface{}{4, 3}) + }) } func TestList_Clear(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - l.Clear() - t.Assert(l.Len(), 0) + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + l.Clear() + t.Assert(l.Len(), 0) + }) } func TestList_IteratorAsc(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 5, 6, 3, 4} - l.PushFronts(a1) - e1 := l.Back() - fun1 := func(e *Element) bool { - if gconv.Int(e1.Value) > 2 { - return true + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 5, 6, 3, 4} + l.PushFronts(a1) + e1 := l.Back() + fun1 := func(e *Element) bool { + if gconv.Int(e1.Value) > 2 { + return true + } + return false } - return false - } - checkList(t, l, []interface{}{4, 3, 6, 5, 2, 1}) - l.IteratorAsc(fun1) - checkList(t, l, []interface{}{4, 3, 6, 5, 2, 1}) + checkList(t, l, []interface{}{4, 3, 6, 5, 2, 1}) + l.IteratorAsc(fun1) + checkList(t, l, []interface{}{4, 3, 6, 5, 2, 1}) + }) } func TestList_IteratorDesc(t *testing.T) { - l := New() - a1 := []interface{}{1, 2, 3, 4} - l.PushFronts(a1) - e1 := l.Back() - fun1 := func(e *Element) bool { - if gconv.Int(e1.Value) > 6 { - return true + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{1, 2, 3, 4} + l.PushFronts(a1) + e1 := l.Back() + fun1 := func(e *Element) bool { + if gconv.Int(e1.Value) > 6 { + return true + } + return false } - return false - } - l.IteratorDesc(fun1) - t.Assert(l.Len(), 4) - checkList(t, l, []interface{}{4, 3, 2, 1}) + l.IteratorDesc(fun1) + t.Assert(l.Len(), 4) + checkList(t, l, []interface{}{4, 3, 2, 1}) + }) } func TestList_Iterator(t *testing.T) { - l := New() - a1 := []interface{}{"a", "b", "c", "d", "e"} - l.PushFronts(a1) - e1 := l.Back() - fun1 := func(e *Element) bool { - if gconv.String(e1.Value) > "c" { - return true + gtest.C(t, func(t *gtest.T) { + l := New() + a1 := []interface{}{"a", "b", "c", "d", "e"} + l.PushFronts(a1) + e1 := l.Back() + fun1 := func(e *Element) bool { + if gconv.String(e1.Value) > "c" { + return true + } + return false } - return false - } - checkList(t, l, []interface{}{"e", "d", "c", "b", "a"}) - l.Iterator(fun1) - checkList(t, l, []interface{}{"e", "d", "c", "b", "a"}) + checkList(t, l, []interface{}{"e", "d", "c", "b", "a"}) + l.Iterator(fun1) + checkList(t, l, []interface{}{"e", "d", "c", "b", "a"}) + }) } func TestList_Join(t *testing.T) { @@ -634,30 +681,30 @@ func TestList_Json(t *testing.T) { } func TestList_UnmarshalValue(t *testing.T) { - type T struct { + type TList struct { Name string List *List } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var tlist *TList err := gconv.Struct(map[string]interface{}{ "name": "john", "list": []byte(`[1,2,3]`), - }, &t) + }, &tlist) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.List.FrontAll(), []interface{}{1, 2, 3}) + t.Assert(tlist.Name, "john") + t.Assert(tlist.List.FrontAll(), []interface{}{1, 2, 3}) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var tlist *TList err := gconv.Struct(map[string]interface{}{ "name": "john", "list": []interface{}{1, 2, 3}, - }, &t) + }, &tlist) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.List.FrontAll(), []interface{}{1, 2, 3}) + t.Assert(tlist.Name, "john") + t.Assert(tlist.List.FrontAll(), []interface{}{1, 2, 3}) }) } diff --git a/container/gmap/gmap_z_unit_any_any_test.go b/container/gmap/gmap_z_unit_any_any_test.go index ba6e2bf58..37520c728 100644 --- a/container/gmap/gmap_z_unit_any_any_test.go +++ b/container/gmap/gmap_z_unit_any_any_test.go @@ -55,61 +55,68 @@ func Test_AnyAnyMap_Basic(t *testing.T) { } func Test_AnyAnyMap_Set_Fun(t *testing.T) { - m := gmap.NewAnyAnyMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewAnyAnyMap() - m.GetOrSetFunc(1, getAny) - m.GetOrSetFuncLock(2, getAny) - t.Assert(m.Get(1), 123) - t.Assert(m.Get(2), 123) + m.GetOrSetFunc(1, getAny) + m.GetOrSetFuncLock(2, getAny) + t.Assert(m.Get(1), 123) + t.Assert(m.Get(2), 123) - t.Assert(m.SetIfNotExistFunc(1, getAny), false) - t.Assert(m.SetIfNotExistFunc(3, getAny), true) + t.Assert(m.SetIfNotExistFunc(1, getAny), false) + t.Assert(m.SetIfNotExistFunc(3, getAny), true) - t.Assert(m.SetIfNotExistFuncLock(2, getAny), false) - t.Assert(m.SetIfNotExistFuncLock(4, getAny), true) + t.Assert(m.SetIfNotExistFuncLock(2, getAny), false) + t.Assert(m.SetIfNotExistFuncLock(4, getAny), true) + }) } func Test_AnyAnyMap_Batch(t *testing.T) { - m := gmap.NewAnyAnyMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewAnyAnyMap() - m.Sets(map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) - t.Assert(m.Map(), map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) - m.Removes([]interface{}{1, 2}) - t.Assert(m.Map(), map[interface{}]interface{}{3: 3}) + m.Sets(map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, 2: "2", 3: 3}) + m.Removes([]interface{}{1, 2}) + t.Assert(m.Map(), map[interface{}]interface{}{3: 3}) + }) } func Test_AnyAnyMap_Iterator(t *testing.T) { - expect := map[interface{}]interface{}{1: 1, 2: "2"} - m := gmap.NewAnyAnyMapFrom(expect) - m.Iterator(func(k interface{}, v interface{}) bool { - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + expect := map[interface{}]interface{}{1: 1, 2: "2"} + m := gmap.NewAnyAnyMapFrom(expect) + m.Iterator(func(k interface{}, v interface{}) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k interface{}, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k interface{}, v interface{}) bool { + j++ + return false + }) + t.Assert(i, "2") + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k interface{}, v interface{}) bool { - i++ - return true - }) - m.Iterator(func(k interface{}, v interface{}) bool { - j++ - return false - }) - t.Assert(i, "2") - t.Assert(j, 1) - } func Test_AnyAnyMap_Lock(t *testing.T) { - expect := map[interface{}]interface{}{1: 1, 2: "2"} - m := gmap.NewAnyAnyMapFrom(expect) - m.LockFunc(func(m map[interface{}]interface{}) { - t.Assert(m, expect) - }) - m.RLockFunc(func(m map[interface{}]interface{}) { - t.Assert(m, expect) + gtest.C(t, func(t *gtest.T) { + expect := map[interface{}]interface{}{1: 1, 2: "2"} + m := gmap.NewAnyAnyMapFrom(expect) + m.LockFunc(func(m map[interface{}]interface{}) { + t.Assert(m, expect) + }) + m.RLockFunc(func(m map[interface{}]interface{}) { + t.Assert(m, expect) + }) }) } @@ -130,53 +137,61 @@ func Test_AnyAnyMap_Clone(t *testing.T) { } func Test_AnyAnyMap_Merge(t *testing.T) { - m1 := gmap.NewAnyAnyMap() - m2 := gmap.NewAnyAnyMap() - m1.Set(1, 1) - m2.Set(2, "2") - m1.Merge(m2) - t.Assert(m1.Map(), map[interface{}]interface{}{1: 1, 2: "2"}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.NewAnyAnyMap() + m2 := gmap.NewAnyAnyMap() + m1.Set(1, 1) + m2.Set(2, "2") + m1.Merge(m2) + t.Assert(m1.Map(), map[interface{}]interface{}{1: 1, 2: "2"}) + }) } func Test_AnyAnyMap_Map(t *testing.T) { - m := gmap.NewAnyAnyMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - data := m.Map() - t.Assert(data[1], 0) - t.Assert(data[2], 2) - data[3] = 3 - t.Assert(m.Get(3), 3) - m.Set(4, 4) - t.Assert(data[4], 4) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewAnyAnyMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + data := m.Map() + t.Assert(data[1], 0) + t.Assert(data[2], 2) + data[3] = 3 + t.Assert(m.Get(3), 3) + m.Set(4, 4) + t.Assert(data[4], 4) + }) } func Test_AnyAnyMap_MapCopy(t *testing.T) { - m := gmap.NewAnyAnyMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - data := m.MapCopy() - t.Assert(data[1], 0) - t.Assert(data[2], 2) - data[3] = 3 - t.Assert(m.Get(3), nil) - m.Set(4, 4) - t.Assert(data[4], nil) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewAnyAnyMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + data := m.MapCopy() + t.Assert(data[1], 0) + t.Assert(data[2], 2) + data[3] = 3 + t.Assert(m.Get(3), nil) + m.Set(4, 4) + t.Assert(data[4], nil) + }) } func Test_AnyAnyMap_FilterEmpty(t *testing.T) { - m := gmap.NewAnyAnyMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - m.FilterEmpty() - t.Assert(m.Get(1), nil) - t.Assert(m.Get(2), 2) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewAnyAnyMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + m.FilterEmpty() + t.Assert(m.Get(1), nil) + t.Assert(m.Get(2), 2) + }) } func Test_AnyAnyMap_Json(t *testing.T) { @@ -277,37 +292,37 @@ func Test_AnyAnyMap_Pops(t *testing.T) { } func TestAnyAnyMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.Map } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":"v1","k2":"v2"}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), "v1") - t.Assert(t.Map.Get("k2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), "v1") + t.Assert(v.Map.Get("k2"), "v2") }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.Map{ "k1": "v1", "k2": "v2", }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), "v1") - t.Assert(t.Map.Get("k2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), "v1") + t.Assert(v.Map.Get("k2"), "v2") }) } diff --git a/container/gmap/gmap_z_unit_int_any_test.go b/container/gmap/gmap_z_unit_int_any_test.go index 4c8efb98a..9bf922ed7 100644 --- a/container/gmap/gmap_z_unit_int_any_test.go +++ b/container/gmap/gmap_z_unit_int_any_test.go @@ -56,124 +56,141 @@ func Test_IntAnyMap_Basic(t *testing.T) { }) } func Test_IntAnyMap_Set_Fun(t *testing.T) { - m := gmap.NewIntAnyMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntAnyMap() - m.GetOrSetFunc(1, getAny) - m.GetOrSetFuncLock(2, getAny) - t.Assert(m.Get(1), 123) - t.Assert(m.Get(2), 123) + m.GetOrSetFunc(1, getAny) + m.GetOrSetFuncLock(2, getAny) + t.Assert(m.Get(1), 123) + t.Assert(m.Get(2), 123) - t.Assert(m.SetIfNotExistFunc(1, getAny), false) - t.Assert(m.SetIfNotExistFunc(3, getAny), true) - - t.Assert(m.SetIfNotExistFuncLock(2, getAny), false) - t.Assert(m.SetIfNotExistFuncLock(4, getAny), true) + t.Assert(m.SetIfNotExistFunc(1, getAny), false) + t.Assert(m.SetIfNotExistFunc(3, getAny), true) + t.Assert(m.SetIfNotExistFuncLock(2, getAny), false) + t.Assert(m.SetIfNotExistFuncLock(4, getAny), true) + }) } func Test_IntAnyMap_Batch(t *testing.T) { - m := gmap.NewIntAnyMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntAnyMap() - m.Sets(map[int]interface{}{1: 1, 2: "2", 3: 3}) - t.Assert(m.Map(), map[int]interface{}{1: 1, 2: "2", 3: 3}) - m.Removes([]int{1, 2}) - t.Assert(m.Map(), map[int]interface{}{3: 3}) + m.Sets(map[int]interface{}{1: 1, 2: "2", 3: 3}) + t.Assert(m.Map(), map[int]interface{}{1: 1, 2: "2", 3: 3}) + m.Removes([]int{1, 2}) + t.Assert(m.Map(), map[int]interface{}{3: 3}) + }) } func Test_IntAnyMap_Iterator(t *testing.T) { - expect := map[int]interface{}{1: 1, 2: "2"} - m := gmap.NewIntAnyMapFrom(expect) - m.Iterator(func(k int, v interface{}) bool { - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + expect := map[int]interface{}{1: 1, 2: "2"} + m := gmap.NewIntAnyMapFrom(expect) + m.Iterator(func(k int, v interface{}) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k int, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k int, v interface{}) bool { + j++ + return false + }) + t.Assert(i, "2") + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k int, v interface{}) bool { - i++ - return true - }) - m.Iterator(func(k int, v interface{}) bool { - j++ - return false - }) - t.Assert(i, "2") - t.Assert(j, 1) } func Test_IntAnyMap_Lock(t *testing.T) { - expect := map[int]interface{}{1: 1, 2: "2"} - m := gmap.NewIntAnyMapFrom(expect) - m.LockFunc(func(m map[int]interface{}) { - t.Assert(m, expect) - }) - m.RLockFunc(func(m map[int]interface{}) { - t.Assert(m, expect) + gtest.C(t, func(t *gtest.T) { + expect := map[int]interface{}{1: 1, 2: "2"} + m := gmap.NewIntAnyMapFrom(expect) + m.LockFunc(func(m map[int]interface{}) { + t.Assert(m, expect) + }) + m.RLockFunc(func(m map[int]interface{}) { + t.Assert(m, expect) + }) }) } func Test_IntAnyMap_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewIntAnyMapFrom(map[int]interface{}{1: 1, 2: "2"}) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewIntAnyMapFrom(map[int]interface{}{1: 1, 2: "2"}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove(2) - //修改clone map,原 map 不影响 - t.AssertIN(2, m.Keys()) + m_clone.Remove(2) + //修改clone map,原 map 不影响 + t.AssertIN(2, m.Keys()) + }) } func Test_IntAnyMap_Merge(t *testing.T) { - m1 := gmap.NewIntAnyMap() - m2 := gmap.NewIntAnyMap() - m1.Set(1, 1) - m2.Set(2, "2") - m1.Merge(m2) - t.Assert(m1.Map(), map[int]interface{}{1: 1, 2: "2"}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.NewIntAnyMap() + m2 := gmap.NewIntAnyMap() + m1.Set(1, 1) + m2.Set(2, "2") + m1.Merge(m2) + t.Assert(m1.Map(), map[int]interface{}{1: 1, 2: "2"}) + }) } func Test_IntAnyMap_Map(t *testing.T) { - m := gmap.NewIntAnyMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - data := m.Map() - t.Assert(data[1], 0) - t.Assert(data[2], 2) - data[3] = 3 - t.Assert(m.Get(3), 3) - m.Set(4, 4) - t.Assert(data[4], 4) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntAnyMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + data := m.Map() + t.Assert(data[1], 0) + t.Assert(data[2], 2) + data[3] = 3 + t.Assert(m.Get(3), 3) + m.Set(4, 4) + t.Assert(data[4], 4) + }) } func Test_IntAnyMap_MapCopy(t *testing.T) { - m := gmap.NewIntAnyMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - data := m.MapCopy() - t.Assert(data[1], 0) - t.Assert(data[2], 2) - data[3] = 3 - t.Assert(m.Get(3), nil) - m.Set(4, 4) - t.Assert(data[4], nil) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntAnyMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + data := m.MapCopy() + t.Assert(data[1], 0) + t.Assert(data[2], 2) + data[3] = 3 + t.Assert(m.Get(3), nil) + m.Set(4, 4) + t.Assert(data[4], nil) + }) } func Test_IntAnyMap_FilterEmpty(t *testing.T) { - m := gmap.NewIntAnyMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Size(), 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - m.FilterEmpty() - t.Assert(m.Size(), 1) - t.Assert(m.Get(2), 2) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntAnyMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Size(), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + m.FilterEmpty() + t.Assert(m.Size(), 1) + t.Assert(m.Get(2), 2) + }) } func Test_IntAnyMap_Json(t *testing.T) { @@ -260,37 +277,37 @@ func Test_IntAnyMap_Pops(t *testing.T) { } func TestIntAnyMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.IntAnyMap } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"1":"v1","2":"v2"}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get(1), "v1") - t.Assert(t.Map.Get(2), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get(1), "v1") + t.Assert(v.Map.Get(2), "v2") }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.MapIntAny{ 1: "v1", 2: "v2", }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get(1), "v1") - t.Assert(t.Map.Get(2), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get(1), "v1") + t.Assert(v.Map.Get(2), "v2") }) } diff --git a/container/gmap/gmap_z_unit_int_int_test.go b/container/gmap/gmap_z_unit_int_int_test.go index 719916107..5a37ddcc2 100644 --- a/container/gmap/gmap_z_unit_int_int_test.go +++ b/container/gmap/gmap_z_unit_int_int_test.go @@ -56,127 +56,143 @@ func Test_IntIntMap_Basic(t *testing.T) { }) } func Test_IntIntMap_Set_Fun(t *testing.T) { - m := gmap.NewIntIntMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntIntMap() - m.GetOrSetFunc(1, getInt) - m.GetOrSetFuncLock(2, getInt) - t.Assert(m.Get(1), 123) - t.Assert(m.Get(2), 123) - t.Assert(m.SetIfNotExistFunc(1, getInt), false) - t.Assert(m.SetIfNotExistFunc(3, getInt), true) - - t.Assert(m.SetIfNotExistFuncLock(2, getInt), false) - t.Assert(m.SetIfNotExistFuncLock(4, getInt), true) + m.GetOrSetFunc(1, getInt) + m.GetOrSetFuncLock(2, getInt) + t.Assert(m.Get(1), 123) + t.Assert(m.Get(2), 123) + t.Assert(m.SetIfNotExistFunc(1, getInt), false) + t.Assert(m.SetIfNotExistFunc(3, getInt), true) + t.Assert(m.SetIfNotExistFuncLock(2, getInt), false) + t.Assert(m.SetIfNotExistFuncLock(4, getInt), true) + }) } func Test_IntIntMap_Batch(t *testing.T) { - m := gmap.NewIntIntMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntIntMap() - m.Sets(map[int]int{1: 1, 2: 2, 3: 3}) - m.Iterator(intIntCallBack) - t.Assert(m.Map(), map[int]int{1: 1, 2: 2, 3: 3}) - m.Removes([]int{1, 2}) - t.Assert(m.Map(), map[int]int{3: 3}) + m.Sets(map[int]int{1: 1, 2: 2, 3: 3}) + m.Iterator(intIntCallBack) + t.Assert(m.Map(), map[int]int{1: 1, 2: 2, 3: 3}) + m.Removes([]int{1, 2}) + t.Assert(m.Map(), map[int]int{3: 3}) + }) } func Test_IntIntMap_Iterator(t *testing.T) { - expect := map[int]int{1: 1, 2: 2} - m := gmap.NewIntIntMapFrom(expect) - m.Iterator(func(k int, v int) bool { - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + expect := map[int]int{1: 1, 2: 2} + m := gmap.NewIntIntMapFrom(expect) + m.Iterator(func(k int, v int) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k int, v int) bool { + i++ + return true + }) + m.Iterator(func(k int, v int) bool { + j++ + return false + }) + t.Assert(i, 2) + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k int, v int) bool { - i++ - return true - }) - m.Iterator(func(k int, v int) bool { - j++ - return false - }) - t.Assert(i, 2) - t.Assert(j, 1) } func Test_IntIntMap_Lock(t *testing.T) { - expect := map[int]int{1: 1, 2: 2} - m := gmap.NewIntIntMapFrom(expect) - m.LockFunc(func(m map[int]int) { - t.Assert(m, expect) + gtest.C(t, func(t *gtest.T) { + expect := map[int]int{1: 1, 2: 2} + m := gmap.NewIntIntMapFrom(expect) + m.LockFunc(func(m map[int]int) { + t.Assert(m, expect) + }) + m.RLockFunc(func(m map[int]int) { + t.Assert(m, expect) + }) }) - m.RLockFunc(func(m map[int]int) { - t.Assert(m, expect) - }) - } func Test_IntIntMap_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewIntIntMapFrom(map[int]int{1: 1, 2: 2}) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewIntIntMapFrom(map[int]int{1: 1, 2: 2}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove(2) - //修改clone map,原 map 不影响 - t.AssertIN(2, m.Keys()) + m_clone.Remove(2) + //修改clone map,原 map 不影响 + t.AssertIN(2, m.Keys()) + }) } func Test_IntIntMap_Merge(t *testing.T) { - m1 := gmap.NewIntIntMap() - m2 := gmap.NewIntIntMap() - m1.Set(1, 1) - m2.Set(2, 2) - m1.Merge(m2) - t.Assert(m1.Map(), map[int]int{1: 1, 2: 2}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.NewIntIntMap() + m2 := gmap.NewIntIntMap() + m1.Set(1, 1) + m2.Set(2, 2) + m1.Merge(m2) + t.Assert(m1.Map(), map[int]int{1: 1, 2: 2}) + }) } func Test_IntIntMap_Map(t *testing.T) { - m := gmap.NewIntIntMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - data := m.Map() - t.Assert(data[1], 0) - t.Assert(data[2], 2) - data[3] = 3 - t.Assert(m.Get(3), 3) - m.Set(4, 4) - t.Assert(data[4], 4) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntIntMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + data := m.Map() + t.Assert(data[1], 0) + t.Assert(data[2], 2) + data[3] = 3 + t.Assert(m.Get(3), 3) + m.Set(4, 4) + t.Assert(data[4], 4) + }) } func Test_IntIntMap_MapCopy(t *testing.T) { - m := gmap.NewIntIntMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - data := m.MapCopy() - t.Assert(data[1], 0) - t.Assert(data[2], 2) - data[3] = 3 - t.Assert(m.Get(3), 0) - m.Set(4, 4) - t.Assert(data[4], 0) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntIntMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + data := m.MapCopy() + t.Assert(data[1], 0) + t.Assert(data[2], 2) + data[3] = 3 + t.Assert(m.Get(3), 0) + m.Set(4, 4) + t.Assert(data[4], 0) + }) } func Test_IntIntMap_FilterEmpty(t *testing.T) { - m := gmap.NewIntIntMap() - m.Set(1, 0) - m.Set(2, 2) - t.Assert(m.Size(), 2) - t.Assert(m.Get(1), 0) - t.Assert(m.Get(2), 2) - m.FilterEmpty() - t.Assert(m.Size(), 1) - t.Assert(m.Get(2), 2) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntIntMap() + m.Set(1, 0) + m.Set(2, 2) + t.Assert(m.Size(), 2) + t.Assert(m.Get(1), 0) + t.Assert(m.Get(2), 2) + m.FilterEmpty() + t.Assert(m.Size(), 1) + t.Assert(m.Get(2), 2) + }) } func Test_IntIntMap_Json(t *testing.T) { @@ -263,37 +279,37 @@ func Test_IntIntMap_Pops(t *testing.T) { } func TestIntIntMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.IntIntMap } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"1":1,"2":2}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get(1), "1") - t.Assert(t.Map.Get(2), "2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get(1), "1") + t.Assert(v.Map.Get(2), "2") }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.MapIntAny{ 1: 1, 2: 2, }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get(1), "1") - t.Assert(t.Map.Get(2), "2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get(1), "1") + t.Assert(v.Map.Get(2), "2") }) } diff --git a/container/gmap/gmap_z_unit_int_str_test.go b/container/gmap/gmap_z_unit_int_str_test.go index 489ed525f..47622c24b 100644 --- a/container/gmap/gmap_z_unit_int_str_test.go +++ b/container/gmap/gmap_z_unit_int_str_test.go @@ -61,123 +61,137 @@ func Test_IntStrMap_Basic(t *testing.T) { }) } func Test_IntStrMap_Set_Fun(t *testing.T) { - m := gmap.NewIntStrMap() - - m.GetOrSetFunc(1, getStr) - m.GetOrSetFuncLock(2, getStr) - t.Assert(m.Get(1), "z") - t.Assert(m.Get(2), "z") - t.Assert(m.SetIfNotExistFunc(1, getStr), false) - t.Assert(m.SetIfNotExistFunc(3, getStr), true) - - t.Assert(m.SetIfNotExistFuncLock(2, getStr), false) - t.Assert(m.SetIfNotExistFuncLock(4, getStr), true) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntStrMap() + m.GetOrSetFunc(1, getStr) + m.GetOrSetFuncLock(2, getStr) + t.Assert(m.Get(1), "z") + t.Assert(m.Get(2), "z") + t.Assert(m.SetIfNotExistFunc(1, getStr), false) + t.Assert(m.SetIfNotExistFunc(3, getStr), true) + t.Assert(m.SetIfNotExistFuncLock(2, getStr), false) + t.Assert(m.SetIfNotExistFuncLock(4, getStr), true) + }) } func Test_IntStrMap_Batch(t *testing.T) { - m := gmap.NewIntStrMap() - - m.Sets(map[int]string{1: "a", 2: "b", 3: "c"}) - t.Assert(m.Map(), map[int]string{1: "a", 2: "b", 3: "c"}) - m.Removes([]int{1, 2}) - t.Assert(m.Map(), map[int]interface{}{3: "c"}) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntStrMap() + m.Sets(map[int]string{1: "a", 2: "b", 3: "c"}) + t.Assert(m.Map(), map[int]string{1: "a", 2: "b", 3: "c"}) + m.Removes([]int{1, 2}) + t.Assert(m.Map(), map[int]interface{}{3: "c"}) + }) } func Test_IntStrMap_Iterator(t *testing.T) { - expect := map[int]string{1: "a", 2: "b"} - m := gmap.NewIntStrMapFrom(expect) - m.Iterator(func(k int, v string) bool { - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + expect := map[int]string{1: "a", 2: "b"} + m := gmap.NewIntStrMapFrom(expect) + m.Iterator(func(k int, v string) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k int, v string) bool { + i++ + return true + }) + m.Iterator(func(k int, v string) bool { + j++ + return false + }) + t.Assert(i, 2) + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k int, v string) bool { - i++ - return true - }) - m.Iterator(func(k int, v string) bool { - j++ - return false - }) - t.Assert(i, 2) - t.Assert(j, 1) } func Test_IntStrMap_Lock(t *testing.T) { - - expect := map[int]string{1: "a", 2: "b", 3: "c"} - m := gmap.NewIntStrMapFrom(expect) - m.LockFunc(func(m map[int]string) { - t.Assert(m, expect) + gtest.C(t, func(t *gtest.T) { + expect := map[int]string{1: "a", 2: "b", 3: "c"} + m := gmap.NewIntStrMapFrom(expect) + m.LockFunc(func(m map[int]string) { + t.Assert(m, expect) + }) + m.RLockFunc(func(m map[int]string) { + t.Assert(m, expect) + }) }) - m.RLockFunc(func(m map[int]string) { - t.Assert(m, expect) - }) - } + func Test_IntStrMap_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewIntStrMapFrom(map[int]string{1: "a", 2: "b", 3: "c"}) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewIntStrMapFrom(map[int]string{1: "a", 2: "b", 3: "c"}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove(2) - //修改clone map,原 map 不影响 - t.AssertIN(2, m.Keys()) + m_clone.Remove(2) + //修改clone map,原 map 不影响 + t.AssertIN(2, m.Keys()) + }) } func Test_IntStrMap_Merge(t *testing.T) { - m1 := gmap.NewIntStrMap() - m2 := gmap.NewIntStrMap() - m1.Set(1, "a") - m2.Set(2, "b") - m1.Merge(m2) - t.Assert(m1.Map(), map[int]string{1: "a", 2: "b"}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.NewIntStrMap() + m2 := gmap.NewIntStrMap() + m1.Set(1, "a") + m2.Set(2, "b") + m1.Merge(m2) + t.Assert(m1.Map(), map[int]string{1: "a", 2: "b"}) + }) } func Test_IntStrMap_Map(t *testing.T) { - m := gmap.NewIntStrMap() - m.Set(1, "0") - m.Set(2, "2") - t.Assert(m.Get(1), "0") - t.Assert(m.Get(2), "2") - data := m.Map() - t.Assert(data[1], "0") - t.Assert(data[2], "2") - data[3] = "3" - t.Assert(m.Get(3), "3") - m.Set(4, "4") - t.Assert(data[4], "4") + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntStrMap() + m.Set(1, "0") + m.Set(2, "2") + t.Assert(m.Get(1), "0") + t.Assert(m.Get(2), "2") + data := m.Map() + t.Assert(data[1], "0") + t.Assert(data[2], "2") + data[3] = "3" + t.Assert(m.Get(3), "3") + m.Set(4, "4") + t.Assert(data[4], "4") + }) } func Test_IntStrMap_MapCopy(t *testing.T) { - m := gmap.NewIntStrMap() - m.Set(1, "0") - m.Set(2, "2") - t.Assert(m.Get(1), "0") - t.Assert(m.Get(2), "2") - data := m.MapCopy() - t.Assert(data[1], "0") - t.Assert(data[2], "2") - data[3] = "3" - t.Assert(m.Get(3), "") - m.Set(4, "4") - t.Assert(data[4], "") + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntStrMap() + m.Set(1, "0") + m.Set(2, "2") + t.Assert(m.Get(1), "0") + t.Assert(m.Get(2), "2") + data := m.MapCopy() + t.Assert(data[1], "0") + t.Assert(data[2], "2") + data[3] = "3" + t.Assert(m.Get(3), "") + m.Set(4, "4") + t.Assert(data[4], "") + }) } func Test_IntStrMap_FilterEmpty(t *testing.T) { - m := gmap.NewIntStrMap() - m.Set(1, "") - m.Set(2, "2") - t.Assert(m.Size(), 2) - t.Assert(m.Get(2), "2") - m.FilterEmpty() - t.Assert(m.Size(), 1) - t.Assert(m.Get(2), "2") + gtest.C(t, func(t *gtest.T) { + m := gmap.NewIntStrMap() + m.Set(1, "") + m.Set(2, "2") + t.Assert(m.Size(), 2) + t.Assert(m.Get(2), "2") + m.FilterEmpty() + t.Assert(m.Size(), 1) + t.Assert(m.Get(2), "2") + }) } func Test_IntStrMap_Json(t *testing.T) { @@ -264,37 +278,37 @@ func Test_IntStrMap_Pops(t *testing.T) { } func TestIntStrMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.IntStrMap } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"1":"v1","2":"v2"}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get(1), "v1") - t.Assert(t.Map.Get(2), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get(1), "v1") + t.Assert(v.Map.Get(2), "v2") }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.MapIntAny{ 1: "v1", 2: "v2", }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get(1), "v1") - t.Assert(t.Map.Get(2), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get(1), "v1") + t.Assert(v.Map.Get(2), "v2") }) } diff --git a/container/gmap/gmap_z_unit_list_map_test.go b/container/gmap/gmap_z_unit_list_map_test.go index bc3ea2b59..ec8feb4c2 100644 --- a/container/gmap/gmap_z_unit_list_map_test.go +++ b/container/gmap/gmap_z_unit_list_map_test.go @@ -52,86 +52,100 @@ func Test_ListMap_Basic(t *testing.T) { }) } func Test_ListMap_Set_Fun(t *testing.T) { - m := gmap.NewListMap() - m.GetOrSetFunc("fun", getValue) - m.GetOrSetFuncLock("funlock", getValue) - t.Assert(m.Get("funlock"), 3) - t.Assert(m.Get("fun"), 3) - m.GetOrSetFunc("fun", getValue) - t.Assert(m.SetIfNotExistFunc("fun", getValue), false) - t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewListMap() + m.GetOrSetFunc("fun", getValue) + m.GetOrSetFuncLock("funlock", getValue) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) + m.GetOrSetFunc("fun", getValue) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + }) } func Test_ListMap_Batch(t *testing.T) { - m := gmap.NewListMap() - m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - m.Removes([]interface{}{"key1", 1}) - t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewListMap() + m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + m.Removes([]interface{}{"key1", 1}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + }) } func Test_ListMap_Iterator(t *testing.T) { - expect := map[interface{}]interface{}{1: 1, "key1": "val1"} + gtest.C(t, func(t *gtest.T) { + expect := map[interface{}]interface{}{1: 1, "key1": "val1"} - m := gmap.NewListMapFrom(expect) - m.Iterator(func(k interface{}, v interface{}) bool { - t.Assert(expect[k], v) - return true + m := gmap.NewListMapFrom(expect) + m.Iterator(func(k interface{}, v interface{}) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k interface{}, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k interface{}, v interface{}) bool { + j++ + return false + }) + t.Assert(i, 2) + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k interface{}, v interface{}) bool { - i++ - return true - }) - m.Iterator(func(k interface{}, v interface{}) bool { - j++ - return false - }) - t.Assert(i, 2) - t.Assert(j, 1) } func Test_ListMap_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewListMapFrom(map[interface{}]interface{}{1: 1, "key1": "val1"}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewListMapFrom(map[interface{}]interface{}{1: 1, "key1": "val1"}) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove("key1") - //修改clone map,原 map 不影响 - t.AssertIN("key1", m.Keys()) + m_clone.Remove("key1") + //修改clone map,原 map 不影响 + t.AssertIN("key1", m.Keys()) + }) } func Test_ListMap_Basic_Merge(t *testing.T) { - m1 := gmap.NewListMap() - m2 := gmap.NewListMap() - m1.Set("key1", "val1") - m2.Set("key2", "val2") - m1.Merge(m2) - t.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.NewListMap() + m2 := gmap.NewListMap() + m1.Set("key1", "val1") + m2.Set("key2", "val2") + m1.Merge(m2) + t.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"}) + }) } func Test_ListMap_Order(t *testing.T) { - m := gmap.NewListMap() - m.Set("k1", "v1") - m.Set("k2", "v2") - m.Set("k3", "v3") - t.Assert(m.Keys(), g.Slice{"k1", "k2", "k3"}) - t.Assert(m.Values(), g.Slice{"v1", "v2", "v3"}) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewListMap() + m.Set("k1", "v1") + m.Set("k2", "v2") + m.Set("k3", "v3") + t.Assert(m.Keys(), g.Slice{"k1", "k2", "k3"}) + t.Assert(m.Values(), g.Slice{"v1", "v2", "v3"}) + }) } func Test_ListMap_FilterEmpty(t *testing.T) { - m := gmap.NewListMap() - m.Set(1, "") - m.Set(2, "2") - t.Assert(m.Size(), 2) - t.Assert(m.Get(2), "2") - m.FilterEmpty() - t.Assert(m.Size(), 1) - t.Assert(m.Get(2), "2") + gtest.C(t, func(t *gtest.T) { + m := gmap.NewListMap() + m.Set(1, "") + m.Set(2, "2") + t.Assert(m.Size(), 2) + t.Assert(m.Get(2), "2") + m.FilterEmpty() + t.Assert(m.Size(), 1) + t.Assert(m.Get(2), "2") + }) } func Test_ListMap_Json(t *testing.T) { @@ -233,37 +247,37 @@ func Test_ListMap_Pops(t *testing.T) { } func TestListMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.ListMap } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"1":"v1","2":"v2"}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("1"), "v1") - t.Assert(t.Map.Get("2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("1"), "v1") + t.Assert(v.Map.Get("2"), "v2") }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.MapIntAny{ 1: "v1", 2: "v2", }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("1"), "v1") - t.Assert(t.Map.Get("2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("1"), "v1") + t.Assert(v.Map.Get("2"), "v2") }) } diff --git a/container/gmap/gmap_z_unit_str_any_test.go b/container/gmap/gmap_z_unit_str_any_test.go index f8b5468d0..04965342f 100644 --- a/container/gmap/gmap_z_unit_str_any_test.go +++ b/container/gmap/gmap_z_unit_str_any_test.go @@ -54,124 +54,141 @@ func Test_StrAnyMap_Basic(t *testing.T) { }) } func Test_StrAnyMap_Set_Fun(t *testing.T) { - m := gmap.NewStrAnyMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrAnyMap() - m.GetOrSetFunc("a", getAny) - m.GetOrSetFuncLock("b", getAny) - t.Assert(m.Get("a"), 123) - t.Assert(m.Get("b"), 123) - t.Assert(m.SetIfNotExistFunc("a", getAny), false) - t.Assert(m.SetIfNotExistFunc("c", getAny), true) - - t.Assert(m.SetIfNotExistFuncLock("b", getAny), false) - t.Assert(m.SetIfNotExistFuncLock("d", getAny), true) + m.GetOrSetFunc("a", getAny) + m.GetOrSetFuncLock("b", getAny) + t.Assert(m.Get("a"), 123) + t.Assert(m.Get("b"), 123) + t.Assert(m.SetIfNotExistFunc("a", getAny), false) + t.Assert(m.SetIfNotExistFunc("c", getAny), true) + t.Assert(m.SetIfNotExistFuncLock("b", getAny), false) + t.Assert(m.SetIfNotExistFuncLock("d", getAny), true) + }) } func Test_StrAnyMap_Batch(t *testing.T) { - m := gmap.NewStrAnyMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrAnyMap() - m.Sets(map[string]interface{}{"a": 1, "b": "2", "c": 3}) - t.Assert(m.Map(), map[string]interface{}{"a": 1, "b": "2", "c": 3}) - m.Removes([]string{"a", "b"}) - t.Assert(m.Map(), map[string]interface{}{"c": 3}) + m.Sets(map[string]interface{}{"a": 1, "b": "2", "c": 3}) + t.Assert(m.Map(), map[string]interface{}{"a": 1, "b": "2", "c": 3}) + m.Removes([]string{"a", "b"}) + t.Assert(m.Map(), map[string]interface{}{"c": 3}) + }) } func Test_StrAnyMap_Iterator(t *testing.T) { - expect := map[string]interface{}{"a": true, "b": false} - m := gmap.NewStrAnyMapFrom(expect) - m.Iterator(func(k string, v interface{}) bool { - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + expect := map[string]interface{}{"a": true, "b": false} + m := gmap.NewStrAnyMapFrom(expect) + m.Iterator(func(k string, v interface{}) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k string, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k string, v interface{}) bool { + j++ + return false + }) + t.Assert(i, 2) + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k string, v interface{}) bool { - i++ - return true - }) - m.Iterator(func(k string, v interface{}) bool { - j++ - return false - }) - t.Assert(i, 2) - t.Assert(j, 1) } func Test_StrAnyMap_Lock(t *testing.T) { - expect := map[string]interface{}{"a": true, "b": false} + gtest.C(t, func(t *gtest.T) { + expect := map[string]interface{}{"a": true, "b": false} - m := gmap.NewStrAnyMapFrom(expect) - m.LockFunc(func(m map[string]interface{}) { - t.Assert(m, expect) - }) - m.RLockFunc(func(m map[string]interface{}) { - t.Assert(m, expect) + m := gmap.NewStrAnyMapFrom(expect) + m.LockFunc(func(m map[string]interface{}) { + t.Assert(m, expect) + }) + m.RLockFunc(func(m map[string]interface{}) { + t.Assert(m, expect) + }) }) } func Test_StrAnyMap_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewStrAnyMapFrom(map[string]interface{}{"a": 1, "b": "2"}) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewStrAnyMapFrom(map[string]interface{}{"a": 1, "b": "2"}) - m_clone := m.Clone() - m.Remove("a") - //修改原 map,clone 后的 map 不影响 - t.AssertIN("a", m_clone.Keys()) + m_clone := m.Clone() + m.Remove("a") + //修改原 map,clone 后的 map 不影响 + t.AssertIN("a", m_clone.Keys()) - m_clone.Remove("b") - //修改clone map,原 map 不影响 - t.AssertIN("b", m.Keys()) + m_clone.Remove("b") + //修改clone map,原 map 不影响 + t.AssertIN("b", m.Keys()) + }) } func Test_StrAnyMap_Merge(t *testing.T) { - m1 := gmap.NewStrAnyMap() - m2 := gmap.NewStrAnyMap() - m1.Set("a", 1) - m2.Set("b", "2") - m1.Merge(m2) - t.Assert(m1.Map(), map[string]interface{}{"a": 1, "b": "2"}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.NewStrAnyMap() + m2 := gmap.NewStrAnyMap() + m1.Set("a", 1) + m2.Set("b", "2") + m1.Merge(m2) + t.Assert(m1.Map(), map[string]interface{}{"a": 1, "b": "2"}) + }) } func Test_StrAnyMap_Map(t *testing.T) { - m := gmap.NewStrAnyMap() - m.Set("1", 1) - m.Set("2", 2) - t.Assert(m.Get("1"), 1) - t.Assert(m.Get("2"), 2) - data := m.Map() - t.Assert(data["1"], 1) - t.Assert(data["2"], 2) - data["3"] = 3 - t.Assert(m.Get("3"), 3) - m.Set("4", 4) - t.Assert(data["4"], 4) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrAnyMap() + m.Set("1", 1) + m.Set("2", 2) + t.Assert(m.Get("1"), 1) + t.Assert(m.Get("2"), 2) + data := m.Map() + t.Assert(data["1"], 1) + t.Assert(data["2"], 2) + data["3"] = 3 + t.Assert(m.Get("3"), 3) + m.Set("4", 4) + t.Assert(data["4"], 4) + }) } func Test_StrAnyMap_MapCopy(t *testing.T) { - m := gmap.NewStrAnyMap() - m.Set("1", 1) - m.Set("2", 2) - t.Assert(m.Get("1"), 1) - t.Assert(m.Get("2"), 2) - data := m.MapCopy() - t.Assert(data["1"], 1) - t.Assert(data["2"], 2) - data["3"] = 3 - t.Assert(m.Get("3"), nil) - m.Set("4", 4) - t.Assert(data["4"], nil) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrAnyMap() + m.Set("1", 1) + m.Set("2", 2) + t.Assert(m.Get("1"), 1) + t.Assert(m.Get("2"), 2) + data := m.MapCopy() + t.Assert(data["1"], 1) + t.Assert(data["2"], 2) + data["3"] = 3 + t.Assert(m.Get("3"), nil) + m.Set("4", 4) + t.Assert(data["4"], nil) + }) } func Test_StrAnyMap_FilterEmpty(t *testing.T) { - m := gmap.NewStrAnyMap() - m.Set("1", 0) - m.Set("2", 2) - t.Assert(m.Size(), 2) - t.Assert(m.Get("1"), 0) - t.Assert(m.Get("2"), 2) - m.FilterEmpty() - t.Assert(m.Size(), 1) - t.Assert(m.Get("2"), 2) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrAnyMap() + m.Set("1", 0) + m.Set("2", 2) + t.Assert(m.Size(), 2) + t.Assert(m.Get("1"), 0) + t.Assert(m.Get("2"), 2) + m.FilterEmpty() + t.Assert(m.Size(), 1) + t.Assert(m.Get("2"), 2) + }) } func Test_StrAnyMap_Json(t *testing.T) { @@ -272,37 +289,37 @@ func Test_StrAnyMap_Pops(t *testing.T) { } func TestStrAnyMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.StrAnyMap } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":"v1","k2":"v2"}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), "v1") - t.Assert(t.Map.Get("k2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), "v1") + t.Assert(v.Map.Get("k2"), "v2") }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.Map{ "k1": "v1", "k2": "v2", }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), "v1") - t.Assert(t.Map.Get("k2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), "v1") + t.Assert(v.Map.Get("k2"), "v2") }) } diff --git a/container/gmap/gmap_z_unit_str_int_test.go b/container/gmap/gmap_z_unit_str_int_test.go index fc713aa1a..b20f23040 100644 --- a/container/gmap/gmap_z_unit_str_int_test.go +++ b/container/gmap/gmap_z_unit_str_int_test.go @@ -56,125 +56,141 @@ func Test_StrIntMap_Basic(t *testing.T) { }) } func Test_StrIntMap_Set_Fun(t *testing.T) { - m := gmap.NewStrIntMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrIntMap() - m.GetOrSetFunc("a", getInt) - m.GetOrSetFuncLock("b", getInt) - t.Assert(m.Get("a"), 123) - t.Assert(m.Get("b"), 123) - t.Assert(m.SetIfNotExistFunc("a", getInt), false) - t.Assert(m.SetIfNotExistFunc("c", getInt), true) - - t.Assert(m.SetIfNotExistFuncLock("b", getInt), false) - t.Assert(m.SetIfNotExistFuncLock("d", getInt), true) + m.GetOrSetFunc("a", getInt) + m.GetOrSetFuncLock("b", getInt) + t.Assert(m.Get("a"), 123) + t.Assert(m.Get("b"), 123) + t.Assert(m.SetIfNotExistFunc("a", getInt), false) + t.Assert(m.SetIfNotExistFunc("c", getInt), true) + t.Assert(m.SetIfNotExistFuncLock("b", getInt), false) + t.Assert(m.SetIfNotExistFuncLock("d", getInt), true) + }) } func Test_StrIntMap_Batch(t *testing.T) { - m := gmap.NewStrIntMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrIntMap() - m.Sets(map[string]int{"a": 1, "b": 2, "c": 3}) - t.Assert(m.Map(), map[string]int{"a": 1, "b": 2, "c": 3}) - m.Removes([]string{"a", "b"}) - t.Assert(m.Map(), map[string]int{"c": 3}) + m.Sets(map[string]int{"a": 1, "b": 2, "c": 3}) + t.Assert(m.Map(), map[string]int{"a": 1, "b": 2, "c": 3}) + m.Removes([]string{"a", "b"}) + t.Assert(m.Map(), map[string]int{"c": 3}) + }) } func Test_StrIntMap_Iterator(t *testing.T) { - expect := map[string]int{"a": 1, "b": 2} - m := gmap.NewStrIntMapFrom(expect) - m.Iterator(func(k string, v int) bool { - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + expect := map[string]int{"a": 1, "b": 2} + m := gmap.NewStrIntMapFrom(expect) + m.Iterator(func(k string, v int) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k string, v int) bool { + i++ + return true + }) + m.Iterator(func(k string, v int) bool { + j++ + return false + }) + t.Assert(i, 2) + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k string, v int) bool { - i++ - return true - }) - m.Iterator(func(k string, v int) bool { - j++ - return false - }) - t.Assert(i, 2) - t.Assert(j, 1) - } func Test_StrIntMap_Lock(t *testing.T) { - expect := map[string]int{"a": 1, "b": 2} + gtest.C(t, func(t *gtest.T) { + expect := map[string]int{"a": 1, "b": 2} - m := gmap.NewStrIntMapFrom(expect) - m.LockFunc(func(m map[string]int) { - t.Assert(m, expect) - }) - m.RLockFunc(func(m map[string]int) { - t.Assert(m, expect) + m := gmap.NewStrIntMapFrom(expect) + m.LockFunc(func(m map[string]int) { + t.Assert(m, expect) + }) + m.RLockFunc(func(m map[string]int) { + t.Assert(m, expect) + }) }) } func Test_StrIntMap_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewStrIntMapFrom(map[string]int{"a": 1, "b": 2, "c": 3}) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewStrIntMapFrom(map[string]int{"a": 1, "b": 2, "c": 3}) - m_clone := m.Clone() - m.Remove("a") - //修改原 map,clone 后的 map 不影响 - t.AssertIN("a", m_clone.Keys()) + m_clone := m.Clone() + m.Remove("a") + //修改原 map,clone 后的 map 不影响 + t.AssertIN("a", m_clone.Keys()) - m_clone.Remove("b") - //修改clone map,原 map 不影响 - t.AssertIN("b", m.Keys()) + m_clone.Remove("b") + //修改clone map,原 map 不影响 + t.AssertIN("b", m.Keys()) + }) } func Test_StrIntMap_Merge(t *testing.T) { - m1 := gmap.NewStrIntMap() - m2 := gmap.NewStrIntMap() - m1.Set("a", 1) - m2.Set("b", 2) - m1.Merge(m2) - t.Assert(m1.Map(), map[string]int{"a": 1, "b": 2}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.NewStrIntMap() + m2 := gmap.NewStrIntMap() + m1.Set("a", 1) + m2.Set("b", 2) + m1.Merge(m2) + t.Assert(m1.Map(), map[string]int{"a": 1, "b": 2}) + }) } func Test_StrIntMap_Map(t *testing.T) { - m := gmap.NewStrIntMap() - m.Set("1", 1) - m.Set("2", 2) - t.Assert(m.Get("1"), 1) - t.Assert(m.Get("2"), 2) - data := m.Map() - t.Assert(data["1"], 1) - t.Assert(data["2"], 2) - data["3"] = 3 - t.Assert(m.Get("3"), 3) - m.Set("4", 4) - t.Assert(data["4"], 4) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrIntMap() + m.Set("1", 1) + m.Set("2", 2) + t.Assert(m.Get("1"), 1) + t.Assert(m.Get("2"), 2) + data := m.Map() + t.Assert(data["1"], 1) + t.Assert(data["2"], 2) + data["3"] = 3 + t.Assert(m.Get("3"), 3) + m.Set("4", 4) + t.Assert(data["4"], 4) + }) } func Test_StrIntMap_MapCopy(t *testing.T) { - m := gmap.NewStrIntMap() - m.Set("1", 1) - m.Set("2", 2) - t.Assert(m.Get("1"), 1) - t.Assert(m.Get("2"), 2) - data := m.MapCopy() - t.Assert(data["1"], 1) - t.Assert(data["2"], 2) - data["3"] = 3 - t.Assert(m.Get("3"), 0) - m.Set("4", 4) - t.Assert(data["4"], 0) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrIntMap() + m.Set("1", 1) + m.Set("2", 2) + t.Assert(m.Get("1"), 1) + t.Assert(m.Get("2"), 2) + data := m.MapCopy() + t.Assert(data["1"], 1) + t.Assert(data["2"], 2) + data["3"] = 3 + t.Assert(m.Get("3"), 0) + m.Set("4", 4) + t.Assert(data["4"], 0) + }) } func Test_StrIntMap_FilterEmpty(t *testing.T) { - m := gmap.NewStrIntMap() - m.Set("1", 0) - m.Set("2", 2) - t.Assert(m.Size(), 2) - t.Assert(m.Get("1"), 0) - t.Assert(m.Get("2"), 2) - m.FilterEmpty() - t.Assert(m.Size(), 1) - t.Assert(m.Get("2"), 2) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrIntMap() + m.Set("1", 0) + m.Set("2", 2) + t.Assert(m.Size(), 2) + t.Assert(m.Get("1"), 0) + t.Assert(m.Get("2"), 2) + m.FilterEmpty() + t.Assert(m.Size(), 1) + t.Assert(m.Get("2"), 2) + }) } func Test_StrIntMap_Json(t *testing.T) { @@ -275,37 +291,37 @@ func Test_StrIntMap_Pops(t *testing.T) { } func TestStrIntMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.StrIntMap } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":1,"k2":2}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), 1) - t.Assert(t.Map.Get("k2"), 2) + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), 1) + t.Assert(v.Map.Get("k2"), 2) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.Map{ "k1": 1, "k2": 2, }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), 1) - t.Assert(t.Map.Get("k2"), 2) + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), 1) + t.Assert(v.Map.Get("k2"), 2) }) } diff --git a/container/gmap/gmap_z_unit_str_str_test.go b/container/gmap/gmap_z_unit_str_str_test.go index 1a3ca665b..f18ecc98e 100644 --- a/container/gmap/gmap_z_unit_str_str_test.go +++ b/container/gmap/gmap_z_unit_str_str_test.go @@ -55,123 +55,140 @@ func Test_StrStrMap_Basic(t *testing.T) { }) } func Test_StrStrMap_Set_Fun(t *testing.T) { - m := gmap.NewStrStrMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrStrMap() - m.GetOrSetFunc("a", getStr) - m.GetOrSetFuncLock("b", getStr) - t.Assert(m.Get("a"), "z") - t.Assert(m.Get("b"), "z") - t.Assert(m.SetIfNotExistFunc("a", getStr), false) - t.Assert(m.SetIfNotExistFunc("c", getStr), true) - - t.Assert(m.SetIfNotExistFuncLock("b", getStr), false) - t.Assert(m.SetIfNotExistFuncLock("d", getStr), true) + m.GetOrSetFunc("a", getStr) + m.GetOrSetFuncLock("b", getStr) + t.Assert(m.Get("a"), "z") + t.Assert(m.Get("b"), "z") + t.Assert(m.SetIfNotExistFunc("a", getStr), false) + t.Assert(m.SetIfNotExistFunc("c", getStr), true) + t.Assert(m.SetIfNotExistFuncLock("b", getStr), false) + t.Assert(m.SetIfNotExistFuncLock("d", getStr), true) + }) } func Test_StrStrMap_Batch(t *testing.T) { - m := gmap.NewStrStrMap() + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrStrMap() - m.Sets(map[string]string{"a": "a", "b": "b", "c": "c"}) - t.Assert(m.Map(), map[string]string{"a": "a", "b": "b", "c": "c"}) - m.Removes([]string{"a", "b"}) - t.Assert(m.Map(), map[string]string{"c": "c"}) + m.Sets(map[string]string{"a": "a", "b": "b", "c": "c"}) + t.Assert(m.Map(), map[string]string{"a": "a", "b": "b", "c": "c"}) + m.Removes([]string{"a", "b"}) + t.Assert(m.Map(), map[string]string{"c": "c"}) + }) } func Test_StrStrMap_Iterator(t *testing.T) { - expect := map[string]string{"a": "a", "b": "b"} - m := gmap.NewStrStrMapFrom(expect) - m.Iterator(func(k string, v string) bool { - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + expect := map[string]string{"a": "a", "b": "b"} + m := gmap.NewStrStrMapFrom(expect) + m.Iterator(func(k string, v string) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k string, v string) bool { + i++ + return true + }) + m.Iterator(func(k string, v string) bool { + j++ + return false + }) + t.Assert(i, 2) + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k string, v string) bool { - i++ - return true - }) - m.Iterator(func(k string, v string) bool { - j++ - return false - }) - t.Assert(i, 2) - t.Assert(j, 1) } func Test_StrStrMap_Lock(t *testing.T) { - expect := map[string]string{"a": "a", "b": "b"} + gtest.C(t, func(t *gtest.T) { + expect := map[string]string{"a": "a", "b": "b"} - m := gmap.NewStrStrMapFrom(expect) - m.LockFunc(func(m map[string]string) { - t.Assert(m, expect) - }) - m.RLockFunc(func(m map[string]string) { - t.Assert(m, expect) + m := gmap.NewStrStrMapFrom(expect) + m.LockFunc(func(m map[string]string) { + t.Assert(m, expect) + }) + m.RLockFunc(func(m map[string]string) { + t.Assert(m, expect) + }) }) } func Test_StrStrMap_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewStrStrMapFrom(map[string]string{"a": "a", "b": "b", "c": "c"}) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewStrStrMapFrom(map[string]string{"a": "a", "b": "b", "c": "c"}) - m_clone := m.Clone() - m.Remove("a") - //修改原 map,clone 后的 map 不影响 - t.AssertIN("a", m_clone.Keys()) + m_clone := m.Clone() + m.Remove("a") + //修改原 map,clone 后的 map 不影响 + t.AssertIN("a", m_clone.Keys()) - m_clone.Remove("b") - //修改clone map,原 map 不影响 - t.AssertIN("b", m.Keys()) + m_clone.Remove("b") + //修改clone map,原 map 不影响 + t.AssertIN("b", m.Keys()) + }) } func Test_StrStrMap_Merge(t *testing.T) { - m1 := gmap.NewStrStrMap() - m2 := gmap.NewStrStrMap() - m1.Set("a", "a") - m2.Set("b", "b") - m1.Merge(m2) - t.Assert(m1.Map(), map[string]string{"a": "a", "b": "b"}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.NewStrStrMap() + m2 := gmap.NewStrStrMap() + m1.Set("a", "a") + m2.Set("b", "b") + m1.Merge(m2) + t.Assert(m1.Map(), map[string]string{"a": "a", "b": "b"}) + }) } func Test_StrStrMap_Map(t *testing.T) { - m := gmap.NewStrStrMap() - m.Set("1", "1") - m.Set("2", "2") - t.Assert(m.Get("1"), "1") - t.Assert(m.Get("2"), "2") - data := m.Map() - t.Assert(data["1"], "1") - t.Assert(data["2"], "2") - data["3"] = "3" - t.Assert(m.Get("3"), "3") - m.Set("4", "4") - t.Assert(data["4"], "4") + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrStrMap() + m.Set("1", "1") + m.Set("2", "2") + t.Assert(m.Get("1"), "1") + t.Assert(m.Get("2"), "2") + data := m.Map() + t.Assert(data["1"], "1") + t.Assert(data["2"], "2") + data["3"] = "3" + t.Assert(m.Get("3"), "3") + m.Set("4", "4") + t.Assert(data["4"], "4") + }) } func Test_StrStrMap_MapCopy(t *testing.T) { - m := gmap.NewStrStrMap() - m.Set("1", "1") - m.Set("2", "2") - t.Assert(m.Get("1"), "1") - t.Assert(m.Get("2"), "2") - data := m.MapCopy() - t.Assert(data["1"], "1") - t.Assert(data["2"], "2") - data["3"] = "3" - t.Assert(m.Get("3"), "") - m.Set("4", "4") - t.Assert(data["4"], "") + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrStrMap() + m.Set("1", "1") + m.Set("2", "2") + t.Assert(m.Get("1"), "1") + t.Assert(m.Get("2"), "2") + data := m.MapCopy() + t.Assert(data["1"], "1") + t.Assert(data["2"], "2") + data["3"] = "3" + t.Assert(m.Get("3"), "") + m.Set("4", "4") + t.Assert(data["4"], "") + }) } func Test_StrStrMap_FilterEmpty(t *testing.T) { - m := gmap.NewStrStrMap() - m.Set("1", "") - m.Set("2", "2") - t.Assert(m.Size(), 2) - t.Assert(m.Get("1"), "") - t.Assert(m.Get("2"), "2") - m.FilterEmpty() - t.Assert(m.Size(), 1) - t.Assert(m.Get("2"), "2") + gtest.C(t, func(t *gtest.T) { + m := gmap.NewStrStrMap() + m.Set("1", "") + m.Set("2", "2") + t.Assert(m.Size(), 2) + t.Assert(m.Get("1"), "") + t.Assert(m.Get("2"), "2") + m.FilterEmpty() + t.Assert(m.Size(), 1) + t.Assert(m.Get("2"), "2") + }) } func Test_StrStrMap_Json(t *testing.T) { @@ -272,37 +289,37 @@ func Test_StrStrMap_Pops(t *testing.T) { } func TestStrStrMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.StrStrMap } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":"v1","k2":"v2"}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), "v1") - t.Assert(t.Map.Get("k2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), "v1") + t.Assert(v.Map.Get("k2"), "v2") }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.Map{ "k1": "v1", "k2": "v2", }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), "v1") - t.Assert(t.Map.Get("k2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), "v1") + t.Assert(v.Map.Get("k2"), "v2") }) } diff --git a/container/gmap/gmap_z_unit_tree_map_test.go b/container/gmap/gmap_z_unit_tree_map_test.go index a1658c174..ae7ff082c 100644 --- a/container/gmap/gmap_z_unit_tree_map_test.go +++ b/container/gmap/gmap_z_unit_tree_map_test.go @@ -52,57 +52,65 @@ func Test_TreeMap_Basic(t *testing.T) { }) } func Test_TreeMap_Set_Fun(t *testing.T) { - m := gmap.NewTreeMap(gutil.ComparatorString) - m.GetOrSetFunc("fun", getValue) - m.GetOrSetFuncLock("funlock", getValue) - t.Assert(m.Get("funlock"), 3) - t.Assert(m.Get("fun"), 3) - m.GetOrSetFunc("fun", getValue) - t.Assert(m.SetIfNotExistFunc("fun", getValue), false) - t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewTreeMap(gutil.ComparatorString) + m.GetOrSetFunc("fun", getValue) + m.GetOrSetFuncLock("funlock", getValue) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) + m.GetOrSetFunc("fun", getValue) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + }) } func Test_TreeMap_Batch(t *testing.T) { - m := gmap.NewTreeMap(gutil.ComparatorString) - m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - m.Removes([]interface{}{"key1", 1}) - t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + gtest.C(t, func(t *gtest.T) { + m := gmap.NewTreeMap(gutil.ComparatorString) + m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + m.Removes([]interface{}{"key1", 1}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + }) } func Test_TreeMap_Iterator(t *testing.T) { - expect := map[interface{}]interface{}{1: 1, "key1": "val1"} + gtest.C(t, func(t *gtest.T) { + expect := map[interface{}]interface{}{1: 1, "key1": "val1"} - m := gmap.NewTreeMapFrom(gutil.ComparatorString, expect) - m.Iterator(func(k interface{}, v interface{}) bool { - t.Assert(expect[k], v) - return true + m := gmap.NewTreeMapFrom(gutil.ComparatorString, expect) + m.Iterator(func(k interface{}, v interface{}) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k interface{}, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k interface{}, v interface{}) bool { + j++ + return false + }) + t.Assert(i, 2) + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k interface{}, v interface{}) bool { - i++ - return true - }) - m.Iterator(func(k interface{}, v interface{}) bool { - j++ - return false - }) - t.Assert(i, 2) - t.Assert(j, 1) } func Test_TreeMap_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewTreeMapFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewTreeMapFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove("key1") - //修改clone map,原 map 不影响 - t.AssertIN("key1", m.Keys()) + m_clone.Remove("key1") + //修改clone map,原 map 不影响 + t.AssertIN("key1", m.Keys()) + }) } func Test_TreeMap_Json(t *testing.T) { @@ -150,37 +158,37 @@ func Test_TreeMap_Json(t *testing.T) { } func TestTreeMap_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Map *gmap.TreeMap } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": []byte(`{"k1":"v1","k2":"v2"}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), "v1") - t.Assert(t.Map.Get("k2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), "v1") + t.Assert(v.Map.Get("k2"), "v2") }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "map": g.Map{ "k1": "v1", "k2": "v2", }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Map.Size(), 2) - t.Assert(t.Map.Get("k1"), "v1") - t.Assert(t.Map.Get("k2"), "v2") + t.Assert(v.Name, "john") + t.Assert(v.Map.Size(), 2) + t.Assert(v.Map.Get("k1"), "v1") + t.Assert(v.Map.Get("k2"), "v2") }) } diff --git a/container/gqueue/gqueue_unit_test.go b/container/gqueue/gqueue_unit_test.go index 854008b3a..cc4d75b6b 100644 --- a/container/gqueue/gqueue_unit_test.go +++ b/container/gqueue/gqueue_unit_test.go @@ -17,41 +17,49 @@ import ( ) func TestQueue_Len(t *testing.T) { - max := 100 - for n := 10; n < max; n++ { - q1 := gqueue.New(max) - for i := 0; i < max; i++ { - q1.Push(i) + gtest.C(t, func(t *gtest.T) { + max := 100 + for n := 10; n < max; n++ { + q1 := gqueue.New(max) + for i := 0; i < max; i++ { + q1.Push(i) + } + t.Assert(q1.Len(), max) + t.Assert(q1.Size(), max) } - t.Assert(q1.Len(), max) - t.Assert(q1.Size(), max) - } + }) } func TestQueue_Basic(t *testing.T) { - q := gqueue.New() - for i := 0; i < 100; i++ { - q.Push(i) - } - t.Assert(q.Pop(), 0) - t.Assert(q.Pop(), 1) + gtest.C(t, func(t *gtest.T) { + q := gqueue.New() + for i := 0; i < 100; i++ { + q.Push(i) + } + t.Assert(q.Pop(), 0) + t.Assert(q.Pop(), 1) + }) } func TestQueue_Pop(t *testing.T) { - q1 := gqueue.New() - q1.Push(1) - q1.Push(2) - q1.Push(3) - q1.Push(4) - i1 := q1.Pop() - t.Assert(i1, 1) + gtest.C(t, func(t *gtest.T) { + q1 := gqueue.New() + q1.Push(1) + q1.Push(2) + q1.Push(3) + q1.Push(4) + i1 := q1.Pop() + t.Assert(i1, 1) + }) } func TestQueue_Close(t *testing.T) { - q1 := gqueue.New() - q1.Push(1) - q1.Push(2) - time.Sleep(time.Millisecond) - t.Assert(q1.Len(), 2) - q1.Close() + gtest.C(t, func(t *gtest.T) { + q1 := gqueue.New() + q1.Push(1) + q1.Push(2) + time.Sleep(time.Millisecond) + t.Assert(q1.Len(), 2) + q1.Close() + }) } diff --git a/container/gset/gset_z_unit_any_test.go b/container/gset/gset_z_unit_any_test.go index a42751232..3ca5d9aa2 100644 --- a/container/gset/gset_z_unit_any_test.go +++ b/container/gset/gset_z_unit_any_test.go @@ -365,38 +365,38 @@ func TestSet_AddIfNotExistFunc(t *testing.T) { } func TestSet_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Set *gset.Set } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "set": []byte(`["k1","k2","k3"]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Set.Size(), 3) - t.Assert(t.Set.Contains("k1"), true) - t.Assert(t.Set.Contains("k2"), true) - t.Assert(t.Set.Contains("k3"), true) - t.Assert(t.Set.Contains("k4"), false) + t.Assert(v.Name, "john") + t.Assert(v.Set.Size(), 3) + t.Assert(v.Set.Contains("k1"), true) + t.Assert(v.Set.Contains("k2"), true) + t.Assert(v.Set.Contains("k3"), true) + t.Assert(v.Set.Contains("k4"), false) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "set": g.Slice{"k1", "k2", "k3"}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Set.Size(), 3) - t.Assert(t.Set.Contains("k1"), true) - t.Assert(t.Set.Contains("k2"), true) - t.Assert(t.Set.Contains("k3"), true) - t.Assert(t.Set.Contains("k4"), false) + t.Assert(v.Name, "john") + t.Assert(v.Set.Size(), 3) + t.Assert(v.Set.Contains("k1"), true) + t.Assert(v.Set.Contains("k2"), true) + t.Assert(v.Set.Contains("k3"), true) + t.Assert(v.Set.Contains("k4"), false) }) } diff --git a/container/gset/gset_z_unit_int_test.go b/container/gset/gset_z_unit_int_test.go index 8e5e17bd8..ee36c7805 100644 --- a/container/gset/gset_z_unit_int_test.go +++ b/container/gset/gset_z_unit_int_test.go @@ -328,38 +328,38 @@ func TestIntSet_AddIfNotExistFunc(t *testing.T) { } func TestIntSet_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Set *gset.IntSet } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "set": []byte(`[1,2,3]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Set.Size(), 3) - t.Assert(t.Set.Contains(1), true) - t.Assert(t.Set.Contains(2), true) - t.Assert(t.Set.Contains(3), true) - t.Assert(t.Set.Contains(4), false) + t.Assert(v.Name, "john") + t.Assert(v.Set.Size(), 3) + t.Assert(v.Set.Contains(1), true) + t.Assert(v.Set.Contains(2), true) + t.Assert(v.Set.Contains(3), true) + t.Assert(v.Set.Contains(4), false) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "set": g.Slice{1, 2, 3}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Set.Size(), 3) - t.Assert(t.Set.Contains(1), true) - t.Assert(t.Set.Contains(2), true) - t.Assert(t.Set.Contains(3), true) - t.Assert(t.Set.Contains(4), false) + t.Assert(v.Name, "john") + t.Assert(v.Set.Size(), 3) + t.Assert(v.Set.Contains(1), true) + t.Assert(v.Set.Contains(2), true) + t.Assert(v.Set.Contains(3), true) + t.Assert(v.Set.Contains(4), false) }) } diff --git a/container/gset/gset_z_unit_str_test.go b/container/gset/gset_z_unit_str_test.go index d178dce4a..7f0fbb3a6 100644 --- a/container/gset/gset_z_unit_str_test.go +++ b/container/gset/gset_z_unit_str_test.go @@ -364,38 +364,38 @@ func TestStrSet_AddIfNotExistFunc(t *testing.T) { } func TestStrSet_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Set *gset.StrSet } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "set": []byte(`["1","2","3"]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Set.Size(), 3) - t.Assert(t.Set.Contains("1"), true) - t.Assert(t.Set.Contains("2"), true) - t.Assert(t.Set.Contains("3"), true) - t.Assert(t.Set.Contains("4"), false) + t.Assert(v.Name, "john") + t.Assert(v.Set.Size(), 3) + t.Assert(v.Set.Contains("1"), true) + t.Assert(v.Set.Contains("2"), true) + t.Assert(v.Set.Contains("3"), true) + t.Assert(v.Set.Contains("4"), false) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "set": g.SliceStr{"1", "2", "3"}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Set.Size(), 3) - t.Assert(t.Set.Contains("1"), true) - t.Assert(t.Set.Contains("2"), true) - t.Assert(t.Set.Contains("3"), true) - t.Assert(t.Set.Contains("4"), false) + t.Assert(v.Name, "john") + t.Assert(v.Set.Size(), 3) + t.Assert(v.Set.Contains("1"), true) + t.Assert(v.Set.Contains("2"), true) + t.Assert(v.Set.Contains("3"), true) + t.Assert(v.Set.Contains("4"), false) }) } diff --git a/container/gtree/gtree_z_avl_tree_test.go b/container/gtree/gtree_z_avl_tree_test.go index 2eb3a4224..aa5b0b981 100644 --- a/container/gtree/gtree_z_avl_tree_test.go +++ b/container/gtree/gtree_z_avl_tree_test.go @@ -99,14 +99,17 @@ func Test_AVLTree_Get_Set_Var(t *testing.T) { } func Test_AVLTree_Batch(t *testing.T) { - m := gtree.NewAVLTree(gutil.ComparatorString) - m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - m.Removes([]interface{}{"key1", 1}) - t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + gtest.C(t, func(t *gtest.T) { + m := gtree.NewAVLTree(gutil.ComparatorString) + m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + m.Removes([]interface{}{"key1", 1}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + }) } func Test_AVLTree_Iterator(t *testing.T) { + keys := []string{"1", "key1", "key2", "key3", "key4"} keyLen := len(keys) index := 0 @@ -114,18 +117,21 @@ func Test_AVLTree_Iterator(t *testing.T) { expect := map[interface{}]interface{}{"key4": "val4", 1: 1, "key1": "val1", "key2": "val2", "key3": "val3"} m := gtree.NewAVLTreeFrom(gutil.ComparatorString, expect) - m.Iterator(func(k interface{}, v interface{}) bool { - t.Assert(k, keys[index]) - index++ - t.Assert(expect[k], v) - return true - }) - m.IteratorDesc(func(k interface{}, v interface{}) bool { - index-- - t.Assert(k, keys[index]) - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + m.Iterator(func(k interface{}, v interface{}) bool { + t.Assert(k, keys[index]) + index++ + t.Assert(expect[k], v) + return true + }) + + m.IteratorDesc(func(k interface{}, v interface{}) bool { + index-- + t.Assert(k, keys[index]) + t.Assert(expect[k], v) + return true + }) }) m.Print() @@ -197,16 +203,18 @@ func Test_AVLTree_IteratorFrom(t *testing.T) { } func Test_AVLTree_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gtree.NewAVLTreeFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gtree.NewAVLTreeFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove("key1") - //修改clone map,原 map 不影响 - t.AssertIN("key1", m.Keys()) + m_clone.Remove("key1") + //修改clone map,原 map 不影响 + t.AssertIN("key1", m.Keys()) + }) } func Test_AVLTree_LRNode(t *testing.T) { diff --git a/container/gtree/gtree_z_b_tree_test.go b/container/gtree/gtree_z_b_tree_test.go index 76197292a..469226de2 100644 --- a/container/gtree/gtree_z_b_tree_test.go +++ b/container/gtree/gtree_z_b_tree_test.go @@ -94,11 +94,13 @@ func Test_BTree_Get_Set_Var(t *testing.T) { } func Test_BTree_Batch(t *testing.T) { - m := gtree.NewBTree(3, gutil.ComparatorString) - m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - m.Removes([]interface{}{"key1", 1}) - t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + gtest.C(t, func(t *gtest.T) { + m := gtree.NewBTree(3, gutil.ComparatorString) + m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + m.Removes([]interface{}{"key1", 1}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + }) } func Test_BTree_Iterator(t *testing.T) { @@ -109,18 +111,21 @@ func Test_BTree_Iterator(t *testing.T) { expect := map[interface{}]interface{}{"key4": "val4", 1: 1, "key1": "val1", "key2": "val2", "key3": "val3"} m := gtree.NewBTreeFrom(3, gutil.ComparatorString, expect) - m.Iterator(func(k interface{}, v interface{}) bool { - t.Assert(k, keys[index]) - index++ - t.Assert(expect[k], v) - return true - }) - m.IteratorDesc(func(k interface{}, v interface{}) bool { - index-- - t.Assert(k, keys[index]) - t.Assert(expect[k], v) - return true + gtest.C(t, func(t *gtest.T) { + m.Iterator(func(k interface{}, v interface{}) bool { + t.Assert(k, keys[index]) + index++ + t.Assert(expect[k], v) + return true + }) + + m.IteratorDesc(func(k interface{}, v interface{}) bool { + index-- + t.Assert(k, keys[index]) + t.Assert(expect[k], v) + return true + }) }) m.Print() @@ -191,16 +196,18 @@ func Test_BTree_IteratorFrom(t *testing.T) { } func Test_BTree_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gtree.NewBTreeFrom(3, gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gtree.NewBTreeFrom(3, gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove("key1") - //修改clone map,原 map 不影响 - t.AssertIN("key1", m.Keys()) + m_clone.Remove("key1") + //修改clone map,原 map 不影响 + t.AssertIN("key1", m.Keys()) + }) } func Test_BTree_LRNode(t *testing.T) { diff --git a/container/gtype/z_unit_bool_test.go b/container/gtype/z_unit_bool_test.go index 1ea796791..2c38694be 100644 --- a/container/gtype/z_unit_bool_test.go +++ b/container/gtype/z_unit_bool_test.go @@ -98,28 +98,28 @@ func Test_Bool_JSON(t *testing.T) { } func Test_Bool_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Bool } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "true", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), true) + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), true) }) gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "false", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), false) + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), false) }) } diff --git a/container/gtype/z_unit_byte_test.go b/container/gtype/z_unit_byte_test.go index f6dd88505..24f17f6ba 100644 --- a/container/gtype/z_unit_byte_test.go +++ b/container/gtype/z_unit_byte_test.go @@ -60,18 +60,18 @@ func Test_Byte_JSON(t *testing.T) { } func Test_Byte_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Byte } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "2", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "2") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "2") }) } diff --git a/container/gtype/z_unit_bytes_test.go b/container/gtype/z_unit_bytes_test.go index 1100800b7..f34fa670d 100644 --- a/container/gtype/z_unit_bytes_test.go +++ b/container/gtype/z_unit_bytes_test.go @@ -46,18 +46,18 @@ func Test_Bytes_JSON(t *testing.T) { } func Test_Bytes_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Bytes } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_float32_test.go b/container/gtype/z_unit_float32_test.go index 82c866ccd..178bc45ff 100644 --- a/container/gtype/z_unit_float32_test.go +++ b/container/gtype/z_unit_float32_test.go @@ -47,18 +47,18 @@ func Test_Float32_JSON(t *testing.T) { } func Test_Float32_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Float32 } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123.456", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123.456") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123.456") }) } diff --git a/container/gtype/z_unit_float64_test.go b/container/gtype/z_unit_float64_test.go index deec6de15..cfbb12aac 100644 --- a/container/gtype/z_unit_float64_test.go +++ b/container/gtype/z_unit_float64_test.go @@ -45,18 +45,18 @@ func Test_Float64_JSON(t *testing.T) { } func Test_Float64_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Float64 } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123.456", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123.456") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123.456") }) } diff --git a/container/gtype/z_unit_int32_test.go b/container/gtype/z_unit_int32_test.go index 3fba55d04..37d63fb89 100644 --- a/container/gtype/z_unit_int32_test.go +++ b/container/gtype/z_unit_int32_test.go @@ -58,18 +58,18 @@ func Test_Int32_JSON(t *testing.T) { } func Test_Int32_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Int32 } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_int64_test.go b/container/gtype/z_unit_int64_test.go index 5fc1e8560..db69a43dc 100644 --- a/container/gtype/z_unit_int64_test.go +++ b/container/gtype/z_unit_int64_test.go @@ -57,18 +57,18 @@ func Test_Int64_JSON(t *testing.T) { } func Test_Int64_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Int64 } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_int_test.go b/container/gtype/z_unit_int_test.go index d56322464..94fe2df54 100644 --- a/container/gtype/z_unit_int_test.go +++ b/container/gtype/z_unit_int_test.go @@ -57,18 +57,18 @@ func Test_Int_JSON(t *testing.T) { } func Test_Int_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Int } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_interface_test.go b/container/gtype/z_unit_interface_test.go index 2f39de61f..1b0413af6 100644 --- a/container/gtype/z_unit_interface_test.go +++ b/container/gtype/z_unit_interface_test.go @@ -16,12 +16,12 @@ import ( func Test_Interface(t *testing.T) { gtest.C(t, func(t *gtest.T) { - t := Temp{Name: "gf", Age: 18} - t1 := Temp{Name: "gf", Age: 19} - i := gtype.New(t) + t1 := Temp{Name: "gf", Age: 18} + t2 := Temp{Name: "gf", Age: 19} + i := gtype.New(t1) iClone := i.Clone() - t.AssertEQ(iClone.Set(t1), t) - t.AssertEQ(iClone.Val().(Temp), t1) + t.AssertEQ(iClone.Set(t2), t1) + t.AssertEQ(iClone.Val().(Temp), t2) //空参测试 i1 := gtype.New() @@ -47,18 +47,18 @@ func Test_Interface_JSON(t *testing.T) { } func Test_Interface_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Var *gtype.Interface } gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_string_test.go b/container/gtype/z_unit_string_test.go index a2cc47b50..1dbd455b9 100644 --- a/container/gtype/z_unit_string_test.go +++ b/container/gtype/z_unit_string_test.go @@ -45,18 +45,18 @@ func Test_String_JSON(t *testing.T) { } func Test_String_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Var *gtype.String } gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_uint32_test.go b/container/gtype/z_unit_uint32_test.go index 177e2c0dd..9ea1483b0 100644 --- a/container/gtype/z_unit_uint32_test.go +++ b/container/gtype/z_unit_uint32_test.go @@ -57,18 +57,18 @@ func Test_Uint32_JSON(t *testing.T) { } func Test_Uint32_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Var *gtype.Uint32 } gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_uint64_test.go b/container/gtype/z_unit_uint64_test.go index dee3c861b..5e65b3bd9 100644 --- a/container/gtype/z_unit_uint64_test.go +++ b/container/gtype/z_unit_uint64_test.go @@ -62,18 +62,18 @@ func Test_Uint64_JSON(t *testing.T) { } func Test_Uint64_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Var *gtype.Uint64 } gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/container/gtype/z_unit_uint_test.go b/container/gtype/z_unit_uint_test.go index 7f8d42083..a5984ee73 100644 --- a/container/gtype/z_unit_uint_test.go +++ b/container/gtype/z_unit_uint_test.go @@ -56,18 +56,18 @@ func Test_Uint_JSON(t *testing.T) { } func Test_Uint_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Var *gtype.Uint } gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "123", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.Val(), "123") + t.Assert(v.Name, "john") + t.Assert(v.Var.Val(), "123") }) } diff --git a/database/gdb/gdb_unit_init_test.go b/database/gdb/gdb_unit_init_test.go index 8f29f2f82..24f1bd3df 100644 --- a/database/gdb/gdb_unit_init_test.go +++ b/database/gdb/gdb_unit_init_test.go @@ -195,11 +195,11 @@ func createInitTableWithDb(db gdb.DB, table ...string) (name string) { } result, err := db.BatchInsert(name, array.Slice()) - t.Assert(err, nil) + gtest.Assert(err, nil) n, e := result.RowsAffected() - t.Assert(e, nil) - t.Assert(n, SIZE) + gtest.Assert(e, nil) + gtest.Assert(n, SIZE) return } diff --git a/database/gdb/gdb_unit_z_mysql_method_test.go b/database/gdb/gdb_unit_z_mysql_method_test.go index 148cd6f1f..3b3138f1c 100644 --- a/database/gdb/gdb_unit_z_mysql_method_test.go +++ b/database/gdb/gdb_unit_z_mysql_method_test.go @@ -635,13 +635,13 @@ func Test_DB_Time(t *testing.T) { }) gtest.C(t, func(t *gtest.T) { - t := time.Now() + t1 := time.Now() result, err := db.Insert(table, g.Map{ "id": 300, "passport": "t300", "password": "123456", "nickname": "T300", - "create_time": &t, + "create_time": &t1, }) if err != nil { gtest.Error(err) @@ -662,11 +662,10 @@ func Test_DB_Time(t *testing.T) { } func Test_DB_ToJson(t *testing.T) { - table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - t.Assert(err, nil) + gtest.Assert(err, nil) gtest.C(t, func(t *gtest.T) { result, err := db.Table(table).Fields("*").Where("id =? ", 1).Select() @@ -737,11 +736,10 @@ func Test_DB_ToJson(t *testing.T) { } func Test_DB_ToXml(t *testing.T) { - table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - t.Assert(err, nil) + gtest.Assert(err, nil) gtest.C(t, func(t *gtest.T) { record, err := db.Table(table).Fields("*").Where("id = ?", 1).One() @@ -807,7 +805,7 @@ func Test_DB_ToStringMap(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - t.Assert(err, nil) + gtest.Assert(err, nil) gtest.C(t, func(t *gtest.T) { id := "1" result, err := db.Table(table).Fields("*").Where("id = ?", 1).Select() @@ -843,7 +841,7 @@ func Test_DB_ToIntMap(t *testing.T) { table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - t.Assert(err, nil) + gtest.Assert(err, nil) gtest.C(t, func(t *gtest.T) { id := 1 @@ -876,11 +874,10 @@ func Test_DB_ToIntMap(t *testing.T) { } func Test_DB_ToUintMap(t *testing.T) { - table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - t.Assert(err, nil) + gtest.Assert(err, nil) gtest.C(t, func(t *gtest.T) { id := 1 @@ -914,11 +911,10 @@ func Test_DB_ToUintMap(t *testing.T) { } func Test_DB_ToStringRecord(t *testing.T) { - table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - t.Assert(err, nil) + gtest.Assert(err, nil) gtest.C(t, func(t *gtest.T) { id := 1 @@ -953,11 +949,10 @@ func Test_DB_ToStringRecord(t *testing.T) { } func Test_DB_ToIntRecord(t *testing.T) { - table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - t.Assert(err, nil) + gtest.Assert(err, nil) gtest.C(t, func(t *gtest.T) { id := 1 @@ -991,11 +986,10 @@ func Test_DB_ToIntRecord(t *testing.T) { } func Test_DB_ToUintRecord(t *testing.T) { - table := createInitTable() defer dropTable(table) _, err := db.Update(table, "create_time='2010-10-10 00:00:01'", "id=?", 1) - t.Assert(err, nil) + gtest.Assert(err, nil) gtest.C(t, func(t *gtest.T) { id := 1 @@ -1030,7 +1024,6 @@ func Test_DB_ToUintRecord(t *testing.T) { func Test_DB_TableField(t *testing.T) { name := "field_test" dropTable(name) - defer dropTable(name) _, err := db.Exec(fmt.Sprintf(` CREATE TABLE %s ( @@ -1069,7 +1062,7 @@ func Test_DB_TableField(t *testing.T) { if err != nil { gtest.Fatal(err) } else { - t.Assert(n, 1) + gtest.Assert(n, 1) } result, err := db.Table(name).Fields("*").Where("field_int = ?", 2).Select() @@ -1077,7 +1070,7 @@ func Test_DB_TableField(t *testing.T) { gtest.Fatal(err) } - t.Assert(result[0], data) + gtest.Assert(result[0], data) } func Test_DB_Prefix(t *testing.T) { diff --git a/database/gdb/gdb_unit_z_mysql_model_test.go b/database/gdb/gdb_unit_z_mysql_model_test.go index 3a90f6592..37adfbb05 100644 --- a/database/gdb/gdb_unit_z_mysql_model_test.go +++ b/database/gdb/gdb_unit_z_mysql_model_test.go @@ -1515,7 +1515,7 @@ func Test_Model_Offset(t *testing.T) { t.Assert(err, nil) t.Assert(len(result), 2) t.Assert(result[0]["id"], 6) - t.Assert(result[1]["id"], 7) + tgit.Assert(result[1]["id"], 7) } func Test_Model_ForPage(t *testing.T) { diff --git a/encoding/gbinary/gbinary_z_be_test.go b/encoding/gbinary/gbinary_z_be_test.go index 533811be0..509424c62 100644 --- a/encoding/gbinary/gbinary_z_be_test.go +++ b/encoding/gbinary/gbinary_z_be_test.go @@ -14,71 +14,75 @@ import ( ) func Test_BeEncodeAndBeDecode(t *testing.T) { - for k, v := range testData { - ve := gbinary.BeEncode(v) - ve1 := gbinary.BeEncodeByLength(len(ve), v) + gtest.C(t, func(t *gtest.T) { + for k, v := range testData { + ve := gbinary.BeEncode(v) + ve1 := gbinary.BeEncodeByLength(len(ve), v) - //t.Logf("%s:%v, encoded:%v\n", k, v, ve) - switch v.(type) { - case int: - t.Assert(gbinary.BeDecodeToInt(ve), v) - t.Assert(gbinary.BeDecodeToInt(ve1), v) - case int8: - t.Assert(gbinary.BeDecodeToInt8(ve), v) - t.Assert(gbinary.BeDecodeToInt8(ve1), v) - case int16: - t.Assert(gbinary.BeDecodeToInt16(ve), v) - t.Assert(gbinary.BeDecodeToInt16(ve1), v) - case int32: - t.Assert(gbinary.BeDecodeToInt32(ve), v) - t.Assert(gbinary.BeDecodeToInt32(ve1), v) - case int64: - t.Assert(gbinary.BeDecodeToInt64(ve), v) - t.Assert(gbinary.BeDecodeToInt64(ve1), v) - case uint: - t.Assert(gbinary.BeDecodeToUint(ve), v) - t.Assert(gbinary.BeDecodeToUint(ve1), v) - case uint8: - t.Assert(gbinary.BeDecodeToUint8(ve), v) - t.Assert(gbinary.BeDecodeToUint8(ve1), v) - case uint16: - t.Assert(gbinary.BeDecodeToUint16(ve1), v) - t.Assert(gbinary.BeDecodeToUint16(ve), v) - case uint32: - t.Assert(gbinary.BeDecodeToUint32(ve1), v) - t.Assert(gbinary.BeDecodeToUint32(ve), v) - case uint64: - t.Assert(gbinary.BeDecodeToUint64(ve), v) - t.Assert(gbinary.BeDecodeToUint64(ve1), v) - case bool: - t.Assert(gbinary.BeDecodeToBool(ve), v) - t.Assert(gbinary.BeDecodeToBool(ve1), v) - case string: - t.Assert(gbinary.BeDecodeToString(ve), v) - t.Assert(gbinary.BeDecodeToString(ve1), v) - case float32: - t.Assert(gbinary.BeDecodeToFloat32(ve), v) - t.Assert(gbinary.BeDecodeToFloat32(ve1), v) - case float64: - t.Assert(gbinary.BeDecodeToFloat64(ve), v) - t.Assert(gbinary.BeDecodeToFloat64(ve1), v) - default: - if v == nil { - continue + //t.Logf("%s:%v, encoded:%v\n", k, v, ve) + switch v.(type) { + case int: + t.Assert(gbinary.BeDecodeToInt(ve), v) + t.Assert(gbinary.BeDecodeToInt(ve1), v) + case int8: + t.Assert(gbinary.BeDecodeToInt8(ve), v) + t.Assert(gbinary.BeDecodeToInt8(ve1), v) + case int16: + t.Assert(gbinary.BeDecodeToInt16(ve), v) + t.Assert(gbinary.BeDecodeToInt16(ve1), v) + case int32: + t.Assert(gbinary.BeDecodeToInt32(ve), v) + t.Assert(gbinary.BeDecodeToInt32(ve1), v) + case int64: + t.Assert(gbinary.BeDecodeToInt64(ve), v) + t.Assert(gbinary.BeDecodeToInt64(ve1), v) + case uint: + t.Assert(gbinary.BeDecodeToUint(ve), v) + t.Assert(gbinary.BeDecodeToUint(ve1), v) + case uint8: + t.Assert(gbinary.BeDecodeToUint8(ve), v) + t.Assert(gbinary.BeDecodeToUint8(ve1), v) + case uint16: + t.Assert(gbinary.BeDecodeToUint16(ve1), v) + t.Assert(gbinary.BeDecodeToUint16(ve), v) + case uint32: + t.Assert(gbinary.BeDecodeToUint32(ve1), v) + t.Assert(gbinary.BeDecodeToUint32(ve), v) + case uint64: + t.Assert(gbinary.BeDecodeToUint64(ve), v) + t.Assert(gbinary.BeDecodeToUint64(ve1), v) + case bool: + t.Assert(gbinary.BeDecodeToBool(ve), v) + t.Assert(gbinary.BeDecodeToBool(ve1), v) + case string: + t.Assert(gbinary.BeDecodeToString(ve), v) + t.Assert(gbinary.BeDecodeToString(ve1), v) + case float32: + t.Assert(gbinary.BeDecodeToFloat32(ve), v) + t.Assert(gbinary.BeDecodeToFloat32(ve1), v) + case float64: + t.Assert(gbinary.BeDecodeToFloat64(ve), v) + t.Assert(gbinary.BeDecodeToFloat64(ve1), v) + default: + if v == nil { + continue + } + res := make([]byte, len(ve)) + err := gbinary.BeDecode(ve, res) + if err != nil { + t.Errorf("test data: %s, %v, error:%v", k, v, err) + } + t.Assert(res, v) } - res := make([]byte, len(ve)) - err := gbinary.BeDecode(ve, res) - if err != nil { - t.Errorf("test data: %s, %v, error:%v", k, v, err) - } - t.Assert(res, v) } - } + }) } func Test_BeEncodeStruct(t *testing.T) { - user := User{"wenzi1", 999, "www.baidu.com"} - ve := gbinary.BeEncode(user) - s := gbinary.BeDecodeToString(ve) - t.Assert(string(s), s) + gtest.C(t, func(t *gtest.T) { + user := User{"wenzi1", 999, "www.baidu.com"} + ve := gbinary.BeEncode(user) + s := gbinary.BeDecodeToString(ve) + t.Assert(string(s), s) + }) } diff --git a/encoding/ghtml/ghtml_test.go b/encoding/ghtml/ghtml_test.go index 0b7f43421..bbc29fb7e 100644 --- a/encoding/ghtml/ghtml_test.go +++ b/encoding/ghtml/ghtml_test.go @@ -13,21 +13,27 @@ import ( ) func TestStripTags(t *testing.T) { - src := `

Test paragraph.

Other text` - dst := `Test paragraph. Other text` - t.Assert(ghtml.StripTags(src), dst) + gtest.C(t, func(t *gtest.T) { + src := `

Test paragraph.

Other text` + dst := `Test paragraph. Other text` + t.Assert(ghtml.StripTags(src), dst) + }) } func TestEntities(t *testing.T) { - src := `A 'quote' "is" bold` - dst := `A 'quote' "is" <b>bold</b>` - t.Assert(ghtml.Entities(src), dst) - t.Assert(ghtml.EntitiesDecode(dst), src) + gtest.C(t, func(t *gtest.T) { + src := `A 'quote' "is" bold` + dst := `A 'quote' "is" <b>bold</b>` + t.Assert(ghtml.Entities(src), dst) + t.Assert(ghtml.EntitiesDecode(dst), src) + }) } func TestSpecialChars(t *testing.T) { - src := `A 'quote' "is" bold` - dst := `A 'quote' "is" <b>bold</b>` - t.Assert(ghtml.SpecialChars(src), dst) - t.Assert(ghtml.SpecialCharsDecode(dst), src) + gtest.C(t, func(t *gtest.T) { + src := `A 'quote' "is" bold` + dst := `A 'quote' "is" <b>bold</b>` + t.Assert(ghtml.SpecialChars(src), dst) + t.Assert(ghtml.SpecialCharsDecode(dst), src) + }) } diff --git a/encoding/gjson/gjson_z_unit_implements_test.go b/encoding/gjson/gjson_z_unit_implements_test.go index 0944857fa..2e125ea34 100644 --- a/encoding/gjson/gjson_z_unit_implements_test.go +++ b/encoding/gjson/gjson_z_unit_implements_test.go @@ -31,28 +31,28 @@ func TestJson_UnmarshalJSON(t *testing.T) { } func TestJson_UnmarshalValue(t *testing.T) { - type T struct { + type Var struct { Name string Json *gjson.Json } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "json": []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Json.Get("n"), "123456789") - t.Assert(t.Json.Get("m"), g.Map{"k": "v"}) - t.Assert(t.Json.Get("m.k"), "v") - t.Assert(t.Json.Get("a"), g.Slice{1, 2, 3}) - t.Assert(t.Json.Get("a.1"), 2) + t.Assert(v.Name, "john") + t.Assert(v.Json.Get("n"), "123456789") + t.Assert(v.Json.Get("m"), g.Map{"k": "v"}) + t.Assert(v.Json.Get("m.k"), "v") + t.Assert(v.Json.Get("a"), g.Slice{1, 2, 3}) + t.Assert(v.Json.Get("a.1"), 2) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *Var err := gconv.Struct(g.Map{ "name": "john", "json": g.Map{ @@ -60,13 +60,13 @@ func TestJson_UnmarshalValue(t *testing.T) { "m": g.Map{"k": "v"}, "a": g.Slice{1, 2, 3}, }, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Json.Get("n"), "123456789") - t.Assert(t.Json.Get("m"), g.Map{"k": "v"}) - t.Assert(t.Json.Get("m.k"), "v") - t.Assert(t.Json.Get("a"), g.Slice{1, 2, 3}) - t.Assert(t.Json.Get("a.1"), 2) + t.Assert(v.Name, "john") + t.Assert(v.Json.Get("n"), "123456789") + t.Assert(v.Json.Get("m"), g.Map{"k": "v"}) + t.Assert(v.Json.Get("m.k"), "v") + t.Assert(v.Json.Get("a"), g.Slice{1, 2, 3}) + t.Assert(v.Json.Get("a.1"), 2) }) } diff --git a/frame/gins/gins_z_unit_config_test.go b/frame/gins/gins_z_unit_config_test.go index 0beb16ed3..0ba1cc54d 100644 --- a/frame/gins/gins_z_unit_config_test.go +++ b/frame/gins/gins_z_unit_config_test.go @@ -88,116 +88,112 @@ func Test_Config2(t *testing.T) { func Test_Config3(t *testing.T) { gtest.C(t, func(t *gtest.T) { - gtest.C(t, func(t *gtest.T) { - var err error - dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) - err = gfile.Mkdir(dirPath) - t.Assert(err, nil) - defer gfile.Remove(dirPath) + var err error + dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) + err = gfile.Mkdir(dirPath) + t.Assert(err, nil) + defer gfile.Remove(dirPath) - name := "test.toml" - err = gfile.PutContents(gfile.Join(dirPath, name), configContent) - t.Assert(err, nil) + name := "test.toml" + err = gfile.PutContents(gfile.Join(dirPath, name), configContent) + t.Assert(err, nil) - err = gins.Config("test").AddPath(dirPath) - t.Assert(err, nil) + err = gins.Config("test").AddPath(dirPath) + t.Assert(err, nil) - defer gins.Config("test").Clear() - gins.Config("test").SetFileName("test.toml") + defer gins.Config("test").Clear() + gins.Config("test").SetFileName("test.toml") - t.Assert(gins.Config("test").Get("test"), "v=1") - t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") - t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") - }) - // for gfsnotify callbacks to refresh cache of config file - time.Sleep(500 * time.Millisecond) - - gtest.C(t, func(t *gtest.T) { - var err error - dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) - err = gfile.Mkdir(dirPath) - t.Assert(err, nil) - defer gfile.Remove(dirPath) - - name := "config/test.toml" - err = gfile.PutContents(gfile.Join(dirPath, name), configContent) - t.Assert(err, nil) - - err = gins.Config("test").AddPath(dirPath) - t.Assert(err, nil) - - defer gins.Config("test").Clear() - gins.Config("test").SetFileName("test.toml") - - t.Assert(gins.Config("test").Get("test"), "v=1") - t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") - t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") - }) - // for gfsnotify callbacks to refresh cache of config file for next unit testing case. - time.Sleep(500 * time.Millisecond) + t.Assert(gins.Config("test").Get("test"), "v=1") + t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") }) + // for gfsnotify callbacks to refresh cache of config file + time.Sleep(500 * time.Millisecond) + + gtest.C(t, func(t *gtest.T) { + var err error + dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) + err = gfile.Mkdir(dirPath) + t.Assert(err, nil) + defer gfile.Remove(dirPath) + + name := "config/test.toml" + err = gfile.PutContents(gfile.Join(dirPath, name), configContent) + t.Assert(err, nil) + + err = gins.Config("test").AddPath(dirPath) + t.Assert(err, nil) + + defer gins.Config("test").Clear() + gins.Config("test").SetFileName("test.toml") + + t.Assert(gins.Config("test").Get("test"), "v=1") + t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") + }) + // for gfsnotify callbacks to refresh cache of config file for next unit testing case. + time.Sleep(500 * time.Millisecond) } func Test_Config4(t *testing.T) { + // absolute path gtest.C(t, func(t *gtest.T) { - // absolute path - gtest.C(t, func(t *gtest.T) { - path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.TimestampNano()) - file := fmt.Sprintf(`%s/%s`, path, "config.toml") - err := gfile.PutContents(file, configContent) - t.Assert(err, nil) - defer gfile.Remove(file) - defer gins.Config().Clear() + path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.TimestampNano()) + file := fmt.Sprintf(`%s/%s`, path, "config.toml") + err := gfile.PutContents(file, configContent) + t.Assert(err, nil) + defer gfile.Remove(file) + defer gins.Config().Clear() - t.Assert(gins.Config().AddPath(path), nil) - t.Assert(gins.Config().Get("test"), "v=1") - t.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") - t.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") - }) - time.Sleep(500 * time.Millisecond) + t.Assert(gins.Config().AddPath(path), nil) + t.Assert(gins.Config().Get("test"), "v=1") + t.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") + }) + time.Sleep(500 * time.Millisecond) - gtest.C(t, func(t *gtest.T) { - path := fmt.Sprintf(`%s/%d/config`, gfile.TempDir(), gtime.TimestampNano()) - file := fmt.Sprintf(`%s/%s`, path, "config.toml") - err := gfile.PutContents(file, configContent) - t.Assert(err, nil) - defer gfile.Remove(file) - defer gins.Config().Clear() - t.Assert(gins.Config().AddPath(path), nil) - t.Assert(gins.Config().Get("test"), "v=1") - t.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") - t.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") - }) - time.Sleep(500 * time.Millisecond) + gtest.C(t, func(t *gtest.T) { + path := fmt.Sprintf(`%s/%d/config`, gfile.TempDir(), gtime.TimestampNano()) + file := fmt.Sprintf(`%s/%s`, path, "config.toml") + err := gfile.PutContents(file, configContent) + t.Assert(err, nil) + defer gfile.Remove(file) + defer gins.Config().Clear() + t.Assert(gins.Config().AddPath(path), nil) + t.Assert(gins.Config().Get("test"), "v=1") + t.Assert(gins.Config().Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config().Get("redis.disk"), "127.0.0.1:6379,0") + }) + time.Sleep(500 * time.Millisecond) - gtest.C(t, func(t *gtest.T) { - path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.TimestampNano()) - file := fmt.Sprintf(`%s/%s`, path, "test.toml") - err := gfile.PutContents(file, configContent) - t.Assert(err, nil) - defer gfile.Remove(file) - defer gins.Config("test").Clear() - gins.Config("test").SetFileName("test.toml") - t.Assert(gins.Config("test").AddPath(path), nil) - t.Assert(gins.Config("test").Get("test"), "v=1") - t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") - t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") - }) - time.Sleep(500 * time.Millisecond) + gtest.C(t, func(t *gtest.T) { + path := fmt.Sprintf(`%s/%d`, gfile.TempDir(), gtime.TimestampNano()) + file := fmt.Sprintf(`%s/%s`, path, "test.toml") + err := gfile.PutContents(file, configContent) + t.Assert(err, nil) + defer gfile.Remove(file) + defer gins.Config("test").Clear() + gins.Config("test").SetFileName("test.toml") + t.Assert(gins.Config("test").AddPath(path), nil) + t.Assert(gins.Config("test").Get("test"), "v=1") + t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") + }) + time.Sleep(500 * time.Millisecond) - gtest.C(t, func(t *gtest.T) { - path := fmt.Sprintf(`%s/%d/config`, gfile.TempDir(), gtime.TimestampNano()) - file := fmt.Sprintf(`%s/%s`, path, "test.toml") - err := gfile.PutContents(file, configContent) - t.Assert(err, nil) - defer gfile.Remove(file) - defer gins.Config().Clear() - gins.Config("test").SetFileName("test.toml") - t.Assert(gins.Config("test").AddPath(path), nil) - t.Assert(gins.Config("test").Get("test"), "v=1") - t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") - t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") - }) + gtest.C(t, func(t *gtest.T) { + path := fmt.Sprintf(`%s/%d/config`, gfile.TempDir(), gtime.TimestampNano()) + file := fmt.Sprintf(`%s/%s`, path, "test.toml") + err := gfile.PutContents(file, configContent) + t.Assert(err, nil) + defer gfile.Remove(file) + defer gins.Config().Clear() + gins.Config("test").SetFileName("test.toml") + t.Assert(gins.Config("test").AddPath(path), nil) + t.Assert(gins.Config("test").Get("test"), "v=1") + t.Assert(gins.Config("test").Get("database.default.1.host"), "127.0.0.1") + t.Assert(gins.Config("test").Get("redis.disk"), "127.0.0.1:6379,0") }) } func Test_Basic2(t *testing.T) { diff --git a/frame/gins/gins_z_unit_database_test.go b/frame/gins/gins_z_unit_database_test.go index c0be272d4..3e1294f9e 100644 --- a/frame/gins/gins_z_unit_database_test.go +++ b/frame/gins/gins_z_unit_database_test.go @@ -20,18 +20,20 @@ import ( func Test_Database(t *testing.T) { databaseContent := gfile.GetContents(gfile.Join(gdebug.TestDataPath(), "database", "config.toml")) - var err error - dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) - err = gfile.Mkdir(dirPath) - t.Assert(err, nil) - defer gfile.Remove(dirPath) + gtest.C(t, func(t *gtest.T) { + var err error + dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) + err = gfile.Mkdir(dirPath) + t.Assert(err, nil) + defer gfile.Remove(dirPath) - name := "config.toml" - err = gfile.PutContents(gfile.Join(dirPath, name), databaseContent) - t.Assert(err, nil) + name := "config.toml" + err = gfile.PutContents(gfile.Join(dirPath, name), databaseContent) + t.Assert(err, nil) - err = gins.Config().AddPath(dirPath) - t.Assert(err, nil) + err = gins.Config().AddPath(dirPath) + t.Assert(err, nil) + }) defer gins.Config().Clear() diff --git a/frame/gins/gins_z_unit_redis_test.go b/frame/gins/gins_z_unit_redis_test.go index 7ec312fa6..d4184f97a 100644 --- a/frame/gins/gins_z_unit_redis_test.go +++ b/frame/gins/gins_z_unit_redis_test.go @@ -20,18 +20,20 @@ import ( func Test_Redis(t *testing.T) { redisContent := gfile.GetContents(gfile.Join(gdebug.TestDataPath(), "redis", "config.toml")) - var err error - dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) - err = gfile.Mkdir(dirPath) - t.Assert(err, nil) - defer gfile.Remove(dirPath) + gtest.C(t, func(t *gtest.T) { + var err error + dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) + err = gfile.Mkdir(dirPath) + t.Assert(err, nil) + defer gfile.Remove(dirPath) - name := "config.toml" - err = gfile.PutContents(gfile.Join(dirPath, name), redisContent) - t.Assert(err, nil) + name := "config.toml" + err = gfile.PutContents(gfile.Join(dirPath, name), redisContent) + t.Assert(err, nil) - err = gins.Config().AddPath(dirPath) - t.Assert(err, nil) + err = gins.Config().AddPath(dirPath) + t.Assert(err, nil) + }) defer gins.Config().Clear() diff --git a/i18n/gi18n/gi18n_unit_test.go b/i18n/gi18n/gi18n_unit_test.go index 189864360..34dc71fbc 100644 --- a/i18n/gi18n/gi18n_unit_test.go +++ b/i18n/gi18n/gi18n_unit_test.go @@ -28,48 +28,48 @@ import ( func Test_Basic(t *testing.T) { gtest.C(t, func(t *gtest.T) { - t := gi18n.New(gi18n.Options{ + i18n := gi18n.New(gi18n.Options{ Path: gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n", }) - t.SetLanguage("none") - t.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") + i18n.SetLanguage("none") + t.Assert(i18n.T("{#hello}{#world}"), "{#hello}{#world}") - t.SetLanguage("ja") - t.Assert(t.T("{#hello}{#world}"), "こんにちは世界") + i18n.SetLanguage("ja") + t.Assert(i18n.T("{#hello}{#world}"), "こんにちは世界") - t.SetLanguage("zh-CN") - t.Assert(t.T("{#hello}{#world}"), "你好世界") - t.SetDelimiters("{$", "}") - t.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") - t.Assert(t.T("{$hello}{$world}"), "你好世界") + i18n.SetLanguage("zh-CN") + t.Assert(i18n.T("{#hello}{#world}"), "你好世界") + i18n.SetDelimiters("{$", "}") + t.Assert(i18n.T("{#hello}{#world}"), "{#hello}{#world}") + t.Assert(i18n.T("{$hello}{$world}"), "你好世界") }) gtest.C(t, func(t *gtest.T) { - t := gi18n.New(gi18n.Options{ + i18n := gi18n.New(gi18n.Options{ Path: gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-file", }) - t.SetLanguage("none") - t.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") + i18n.SetLanguage("none") + t.Assert(i18n.T("{#hello}{#world}"), "{#hello}{#world}") - t.SetLanguage("ja") - t.Assert(t.T("{#hello}{#world}"), "こんにちは世界") + i18n.SetLanguage("ja") + t.Assert(i18n.T("{#hello}{#world}"), "こんにちは世界") - t.SetLanguage("zh-CN") - t.Assert(t.T("{#hello}{#world}"), "你好世界") + i18n.SetLanguage("zh-CN") + t.Assert(i18n.T("{#hello}{#world}"), "你好世界") }) gtest.C(t, func(t *gtest.T) { - t := gi18n.New(gi18n.Options{ + i18n := gi18n.New(gi18n.Options{ Path: gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-dir", }) - t.SetLanguage("none") - t.Assert(t.T("{#hello}{#world}"), "{#hello}{#world}") + i18n.SetLanguage("none") + t.Assert(i18n.T("{#hello}{#world}"), "{#hello}{#world}") - t.SetLanguage("ja") - t.Assert(t.T("{#hello}{#world}"), "こんにちは世界") + i18n.SetLanguage("ja") + t.Assert(i18n.T("{#hello}{#world}"), "こんにちは世界") - t.SetLanguage("zh-CN") - t.Assert(t.T("{#hello}{#world}"), "你好世界") + i18n.SetLanguage("zh-CN") + t.Assert(i18n.T("{#hello}{#world}"), "你好世界") }) } diff --git a/net/ghttp/ghttp_unit_websocket_test.go b/net/ghttp/ghttp_unit_websocket_test.go index a21a1a704..31c0059a5 100644 --- a/net/ghttp/ghttp_unit_websocket_test.go +++ b/net/ghttp/ghttp_unit_websocket_test.go @@ -51,9 +51,9 @@ func Test_WebSocket(t *testing.T) { err = conn.WriteMessage(websocket.TextMessage, msg) t.Assert(err, nil) - t, data, err := conn.ReadMessage() + mt, data, err := conn.ReadMessage() t.Assert(err, nil) - t.Assert(t, websocket.TextMessage) + t.Assert(mt, websocket.TextMessage) t.Assert(data, msg) }) } diff --git a/os/gcron/gcron_unit_2_test.go b/os/gcron/gcron_unit_2_test.go index 1432970c5..8635bff94 100644 --- a/os/gcron/gcron_unit_2_test.go +++ b/os/gcron/gcron_unit_2_test.go @@ -18,23 +18,22 @@ import ( func TestCron_Entry_Operations(t *testing.T) { gtest.C(t, func(t *gtest.T) { - - gtest.C(t, func(t *gtest.T) { - cron := gcron.New() - array := garray.New(true) - cron.DelayAddTimes(500*time.Millisecond, "* * * * * *", 2, func() { - glog.Println("add times") - array.Append(1) - }) - t.Assert(cron.Size(), 0) - time.Sleep(800 * time.Millisecond) - t.Assert(array.Len(), 0) - t.Assert(cron.Size(), 1) - time.Sleep(3000 * time.Millisecond) - t.Assert(array.Len(), 2) - t.Assert(cron.Size(), 0) + cron := gcron.New() + array := garray.New(true) + cron.DelayAddTimes(500*time.Millisecond, "* * * * * *", 2, func() { + glog.Println("add times") + array.Append(1) }) + t.Assert(cron.Size(), 0) + time.Sleep(800 * time.Millisecond) + t.Assert(array.Len(), 0) + t.Assert(cron.Size(), 1) + time.Sleep(3000 * time.Millisecond) + t.Assert(array.Len(), 2) + t.Assert(cron.Size(), 0) + }) + gtest.C(t, func(t *gtest.T) { cron := gcron.New() array := garray.New(true) entry, err1 := cron.Add("* * * * * *", func() { diff --git a/os/gres/testdata/data/data.go b/os/gres/testdata/data/data.go index a59864d77..46e1650d6 100644 --- a/os/gres/testdata/data/data.go +++ b/os/gres/testdata/data/data.go @@ -3,7 +3,7 @@ package data import "github.com/gogf/gf/os/gres" func init() { - if err := gres.Add("1f8b08000000000002ffb49a095413d7f7c79f0a2211140405ace2101194252111504388226153d9242ea042433221c16c240159440111d1828a0b2ea080c50d11452ba2e00622225471a9b81517046b81aad82aaefd9f2480334988d1dfbf9e134366defddcfbeebb6f66de9b6fc0ec415ac6600800c0216cb43f40fc1b01740143c0677122f0f22f9c44c0e3cea3698301f6758c25311c7899902e6143ae1016cf16f060fcb265cbf0129827e4d225b0188b592482991cf1120c04411093235e0a495b128853700e38071c81e43c79ca343b07acec3483ce60c32a4e13b001b37586e4566d64b20000d24fffe1ea7f09971787e3f039ffbf9112d5473a59166977b2bb8b72a45a3ed40064a483fb22958518eb382d546a8c6cd27f37cdfa8ced19d1628980f7df0d8ea3fa2e3bc9ba4ca33adffffae0182b45fd5f8c91b3fa80a7c80276d0694dfdfa18e92b06acc1508d5a321ed5e9214017303922025e1c1d2e332707f297686e3e0a612efdd84b60b1848093c44afa607d472186802f81f91229fdecf1cd24430080a15a3aa6972eb3ef232ad1d2074dffac2f4b88ba7469f5d0be3f4bc4ff2d4b445496882ab34444f62b6183f9208db34494658988ca128ae63bfd58adc659226a90a5ba55e35081e8015dc0214ce5e361fe97999e931fb904c386b95c81b4dabda57f6031cb04222e53fa7b81f40f59c93396d9cf80000090662e22e9fdb96849dedc92b2b925f9504b72414bf21184b3a7e5d9cfb666c8bc05464031b600005bcdbc89a2fbf3d698773da9b1bcf158e389eb2908578d958de5d793e41d9b7a7ae94400c044b5ae86f7ba8a67dbbbfba1bdf5397b7a26bf75ef19d53d7ade7c25d3020060a1b11bda82ff3737aa8a48eae63b8a68688fa93d9323c2c3fcbee834278c4213f0b27ea92f48295cd41ec9300000187c135c962305b88aeade65186dfd7538aaef91f4ffb5ef91f49ebec7d195fa4e529e28522f952c9b6033d91dfc5bbcc89380f2223b444295ce6eb730ee70590d22d941b055ff391045cb80d36922353950248c44137a72d07b2397b254cf5ea907ee728b89a3643dfc160ff2fe233da8ba10c0ed9d155faf816148b6ec62f01d6560a604e9c942a458f0654a25c89e44b0b23358d297799f28bb435b0c3dfdf54a50e1489e0c558e6467b05f8a42ee08d339fbf3d71d29a685b6e03bd262aa04e9494b2ca272c9d363795c280616893902be2b968073c042309f216072f811aed86809cb7e2a763a0543968228b28e9165108a3c7d6439928221e3652da4d119c48fda200dc4ff5ba393e7f27f8c4e06a1c8734e962351d1bdb79ab355393ac54bfa104474df715937ec356771b8f07ff88080f61349d7f0da875171bd32be54bf7012006092da6b8101caa1285a830b8dcac784aab9f84fd600006bb5dd334679933f2b284d35a5196d87e977f65102f0657600003bb56e8d14ddd216fc277346a37aad9b71e5260700c0515bafbac890bf630d2bad77914020c133c4e2be15a0e6e62310e678b1248e0be390201b487e4d6409f8127b31271e26419389c25817d941091c2bb1a77339117c12c480f91258e4221f2c9be6f03f890000a25ad7985ed71c1e3d02fe8ed88d50003c571021c009f9117da4b5017e5efa98d118e95ac2c79b3ab72722e290c10000f3e9e9a5008001e2b95e3341c9d531cfa56321f40e160330d448fa190076e69a0230b084435b2859e83b87c410f07074a6201cc6c5f284b200c8b1a4589e90074be8502c8fcb1793625db1b21624be98243d8cc742b22692a5aed885be0190bb4004434e38479c03565644641193459a4bf5ec31173159ae58b6442224e1a54b76dcb2c9388128024f98366d1ade81882712ed454c96bd388e2fa1c7daf3c5e3e5905e0e151633441ca18423e043d2dff47041b4c4158bed6923ffd713274fd8e7882feee91543c0c3c7d2857802ce01afca88c9e8b311468bb8b2d0980c3ccc8579305f22c61370049576120e8ba5da9bf48cdc1de58b1d39962724b98b60ba04a6d2253085e8409866efe064efe04c23104993892482530819afd04895b940441308b81437a93bc89323829709444bc5907b9023c2bca79182bdaf80c961c529b97722393993264fed718f6884306732482c8188479750e45529e44790f15f0e225a4a7b4ff2177160be842e1d340a818c573ad63bc078851196970fbea77ea4d79dbe5aa4605e2eba350800cc4a1faa1b8dadddb9709180d664b624821fc12fab1ddc50636a6dda6230427b6690964dcac603f3826e78ce9a879d396fd2bc5bbff827fec1384431a61d1c1ef841e7de592fdeba14ecea11d0e3c83d5616ebf5627ce740274e693112b8d75a1b763c0ff9d030cd5ccfca8f317b5257f69b861d89c10f4f9ebddf1c513c3dd7b4f811855df0216955c1d1194fdbdbeab437d8c53277db1d350879cdbcf3afd99bb3afbc99655647cb03ce943d9fe560d234705cd3bf6fe0e5661ff1964f8c84e9457f4de267d1b42dfc3cef566f59fc66efcab5827115b41a9cce3eac735478152b4fff8deb5aef8db32db4dfa409b579d789370cfd1797721fcf9f949ae337c4287743d0b1d4d751f37d97c2a6f4a6d5360bcd6dc7bb774cb476a4cc7a70c8cfd48899f568bbe494c99b0caae544c10c9b3bb467f94e813353521c4bac1a47d4656c6e38cfd43211051a4f635fab4a996be3d591e6aded5f38a6387ddb46bd6d99ffac3e6c3588359bfeb73f356a77f73da383e1ed71f115b65906bfe5166eb265effd750779f473dd01db6cb3df3943d4e37726134c361cffe98f8359533d6765bfba3ae73134811a1efda066ca68cca5eac1394524a79cd4df0d5a7766fcd41aa3b5df9337fa36b1c06ebc9fe06cf2aa28fda7e5f4093e1d0bb7b8a759623e766e4adda9b5fd6ac4802bb6c3128e77865b374db971a52be36488cbbe9d6bf48b7dcbbbe7070df389bf533b6a7ed292df3b1847e664bfa405ed1e5c34e39da3510ce433b430b58b3e9b614ee0d370130f4e285c8c7b78fb44b3096ef59f07efb042827dd7fde63c6e11759ce0724e22316943e6ac56e70ecc4a9d3b25ab3d1c6fcd0f1fba8c54f6f4c1634342332d8c3a766b97b62ecd75d44f1659ded08e3958f393bf6ebfa46fe034f239eb52824b45d75252f9a66e7a1b751393c9cb0a78bda56c600795bcdedb3205a3bf7f5fb4c7260ebdbbc49f64e538f2f309fbcb86f451e5fe1627527e1893b6c9eec950c3978d8d068307e32cf2ae317edd19f3cb891317a2727fcccc5f7db3aafb457d60d6689f2bab8c5d2b6fe176906f929c1eafa9a6b7640ebfb6abfad12368f46433494c0cb6fa4578a9b76be56f7b4ea4a5754f299d7dcb7fefdd6d5139d77f79e9b6293d443279c11fc58d6b0d31ab854f2f072e17d7cfef683eaec3b84bc89d1a37a2b6396e4df6cd494f9cd61a1dade418dd3dbedfcb6ff7d54623ddb4c3ebd20496f4d977578e999a54bf0dfff39123c3affdcb9eb2e27d57fd1fe762af53936786b42f892f5d3fad625ddacedd6b06184e2a893f933ed21bc366ec584570496b6e0efdf874efb68cb2730fcf0d9fde5c619210b6dc5067b8f9c5d5cd94b4e0070b697f05147a70de9966066692f47f68d0aaad1ef336a7927edfb99922d26ab91bd5b1376bc5e72bb6dd9f4b5e14b47724dc392998eee9e96990e999f9ec177f0c7eeffac820efdf1cb221dfbdc1f5461dd8bdf344078ba3de37980ddbc8dc3720e2aae4f1c777afbbb7dcfe707fe991828a8afb0dbad55eb78fc71f867ceba7ae78ed6eb3adfef1e193c3e88f6ece2e9fea90641e9ed7f96795fb5217e176ad84f8f8cae559f3cac3b67795f38d4f74bbadf78efb77567ed20d629eb7738e5397093e386590a0327973ed438f7da575b9e7af1866fd7362cbb1756113ca5ef0758df7ac4b5ec37ba477b66a96e9cacff561afae96322cc575733061f6b3fdb53367a43aef3f973ef1c5f296ee63914df1d7e60926d6b990480d0b49bb3cbd125cc2f5f6326de04b218b16f90eabab8a9c3bb5161374a02dd9ece91abfd6e24bf30e17956d1940d36ebaf13ef2206df4a190908c29cbb5efdf9baf4d87cf9ff2db43e6b072de0d21ef19b17f55c0ed5f0e1f2bcd253f395dfc7051d98f4d93af3d7a942318eca27324b47ab7490ca3254dffd29e15f0f5949c9aa3d3ca3fb6af4b2daacac8ba6cfa22e060391f137ac7e673de870be2d87f36acacf21ab772cca3f6c727cfbd73bac729cf17197a6bc17a132a2a9f4c71a7a63009ba377e9fc4697f74d36a84edd639660fcebd5876e774f450bf3c0aef32ef7e99feb5bfeead76746d11665a5e3e83c9ab7f77f48251c943c7fd01e555374e653ccbd819563affc80a83da0d636b1e86ad1cfbe9d32736fbf28fb5eb3bef942656048f67ccda16b9f3017d223df8f3f44cd15badadb176f3aaac9a8f484cd79dd959e5696175f4d5aba896dba4b41d973c682d570839f3383f12d7fd7c921b34c0e9c5665d638bb66526cf1a5c8bde9cff8d6e6b37e11c73c266ddf8d3ccae6b1d7bcde77a899a3f93937f702c17ddab1d2ea26e7b3dd53a3eeee61816fb406ae4e69d4996549f8341ae3525cf42469cbe9a61f8f153e9f6058145da903146679a71b8e1ed8284f54b530fcf2d163c36c154aed858fe72247ff572026431762a2c395db5e88d41f5f1ecd4b641d8369db507ee55d6e6ec7bd2685d6d317ecec05656f435caee0a8f99ba2bd2769b3edb1277f7588ba5415a7b2cc683e15cec9d71c9869154f0f6023b77bbdef3a20b76e619582c570c889c4ceb898b993cf3c22943e91f6d7f703a82b971b24cbbaec46d52f10f6d0184d4966a5d6e6b0da146eca17dfeed7aaf1917d9da21b4ecf2c0f4471dde0de52ea3335f6ae15aeead16ff312d6ac8f826caaa5d737e6e2da86d7c7731e6a289bd47f1d3fc0472c38785037f68df5fd2553263af560e397fe1a626dac492cd1f5f2d8aba763ea8be2124f18127751086b0eb65dec899ddd68c28f72586f53b728f9d1e4dc8b033acbf517365edeeb543c6d83638c17663cfa474acc655beaf0fdbfecf8984b39f9efa55be3c1e462f6c0da4ed21fced9f2dfc79fbf9f19cb38b5f45166eb38dcad273fadd4184835fb6fe393e6689f8292ff3c3d25ffc3a876147df9a991538d2a54ac86135e05ae0b9474e7525850ad37cc2d34f39d6051ce31c639e4acf4e5e769d7c3bf3b8eb33ed55d1ede669d583fcef9d9aafb566bdf985e1531ce9bfffec72bde9bd6531cdc86a7b42add9951d5175c25f3f6c781266419969b66a0b6116312aded39279f5b9a5657b09d5d18278efc08acd3ecb33f323075e7f5e6cb3ff9431a349d7a391dc3d80d8e457b03134b9f510e9d5df6dfa531ffc5370b76565c7e7ab31b7f02fa84c09186efcfa8fb0b7e4c56dbe45739d0585674e139e2d376b3e995540268a120b5dceadea4a7876eb56fa96050b0e9d485f77c8fbe0b2bfc752c33b8cca1f6be9ce0ff8f1f998d371438d36c785de74677b4f282d2c35370cbdbb0b73283ccad4fd505ecda3635e06f671a115157afefbac13dbae99b9ceadf0b872e803efcf1d7b766c856d1678dbb9bd7ffd36d0efe2bb1b5401e181f9c27b5ab3830f9d5fa0ddf27373bdfba3bb2d6d95a76c0e38ec170a56be696d6e4f984ffd4b3bff94813b4358e349cdd52d5c53f18ee5e5efb1f9e8930e7ae88525bbdd4ed9d9d4f804ddf85d38a6da36efd23f356387884bb2cf9bd4ede47c3e645470c23e7b917538233fd1fac94f4d8c33bb6a8ada8c8b0f5c1d61be2a173fd93aedb37864ded10e3f5648966f7cf331b6564be90ec7dcd6ee05d658374b239b0af202bbc5479e753ab54059570bf26d4d3bc73e79cc7a9dd4501c9ce1962d59bda8b023f6d5cf477356394fa116a607a69f7a3c2aabde65c82bff9403936e876aebddece267adac7af5d07dac70e4e1bc1f865dd2137ba50a8b420de73f3fe4a7b5cd9a4186821f065f2814afdd5a9440bef4fae2879be7bdf3aa374cb37ab2cbe5bd7ff74be18385a147748895cde36e49700d1ea20476509e78d6c535bfcdde195a54787418d1b53bb56d552ab5616856d15fefbb6eccc0d173f023aadefc3536fefd74c150ea59feb0c52f2fa778b5d50d7cebcbfe64f26e7cc9f4e454dd5ae952c9c7c38f5a32f3c714d9e6e58bfca42dfa00483ffdafee86f7adeef84c3816c796205ec992a5bf28185d321ba63329185d5d3297c35f0a8960ae2b56b68815b361588285d82298e58a452d6db190244e08bb62a58b57bcec375e0ac2f790c8e102669cf49bc989a19039bc08482c62b862d12b4c2c858c979ec7e8d2d81c31c4114312360cc9e2845822010f8a10c1629c942aa791f1b278a57da77776d3ca0000655f7d2f21edfb776c604917c5bdaf7a155397931fb9c447628d0cb7b729c4e270619cd4cd99ec89602c00b24fffa3638074c3a5c709a27b5e7c7edb127e9c0a0c9e21e04be81c3e2c420f7a4202136671f83084ed6b804d4cc490d9048abbbf1fcdcdc7cf632e19cf2650300909309f9928db8a98a073ff05010040501bc6185561b0040249ff31c8cff606e0e9ef4f53e19d76c9c55bf9f59d46dea5f5d8bf77f959a977f9261581e2ede1465511c1fb848d37f10000fcb74720ff56987816547f775a708007249f81e4de2fd9ece959d64ab830c54be029a2f360688e0c225dd84a8fca5a2424f4151da21fbd33b06702cad7d29c1888c1a58bc5ae88215786a0ca41be5a96cd4e4546cf902903be8c25c25ac5e4bd7235cbe23d00e0fdb74e0de2774c0d1563425459930af527f510c2fdfb57e557581a795055770af525f560e77a97fc9d1e54d555420287cfe04633fb4a42761a0be11213315fcee178740e9f26e42a1cc622b222339106a8f5ee998e1f00c04f6d8023550528f5f21d0306f5c792fd47504ea9af9b8f1fa12fa30dbe9d8c61b23748dfef84a8da09b1cf49f8f4b8566527aadea1f43a51730b1a30d078d0972891cab21140b7af5d61b2f47f35e237451052f8a58f021df90252903c2119aa2462bd2f5dc08ce001405930860e0029c332430590dd67ac4e30a6c843aaa48c51bc3903817a2997ba7ee9a3faf54911a5b27baa0443bd57ad4e37b7414095c80a6d8e94448d42f5260961de8fc84a118654446150b0e65e185a53a52e215aa884d86901451995a67988909b12d5e601297a42e7611fc2bc1f1995220ca97942e7414b1ba8524d699e87b93d009579903e3d225f58eaa17c676a03d54229450452a68446bcec45280aa194a240c88fd088d0c140b5ba491181d4fc0c4721ea7a112a544b9a531c7440bfa224cdc7635b0fa5dff15054997ca9cb1b3da6ca9a23340129114297a6f110f035cd91220c290942c3a214602a34469af7ed2a1286d214a10948e50f3a1c035df0354d91220c29f541c36214602aa44348982a751062dc90309456084d40aa7a46a2c70d03bea215526421553c68568c024b5915a46ed486a17b866429aa80d010a450077d5735190a34500129f2907a1c342f4999a742eca379279f2bf0509a1e3404a9a031450585d3035fd7f428e290921734ae4119a72cc25177511a82ba2845ea0355aa99fe6f1486a8680ef69aab54cd287290821534c7701850a38a512c71a414c500c549417114c42e8ae120a525e8c7b397288c0a158b220a29f93042a1228603b5ca147543a58b1aaad10640a56004fdccd9ffc34d8801502518419b23151ce887f91d08731582117571605071181b02d5f20f3400b959884ee93c144059fea148426ebda16fec93c7817eb71a35bfb1e321a0b86987ae0ee4ce1aba2b911050bb69a72eab06a8ac5e479294f7e5d018e4e6d8385440a61640e37d39a5e51362d36b0c8a9aa78aaa6a4b431189dcc54223c76281667b678a48e45e8e4294aa90aa362d341f958ef140dd96101a83dcbc414736d91268b625a48844eed6a0915b552135c91f727f058d7cab0af9adf91b89cadff609e0abdb3468167237054285f7b43f96aa6d1a452c72ff048df5b1029a6fcc687e632e4160111716edc1d206144001098600745a497ffd5f000000ffffdf00a5b17e380000"); err != nil { + if err := gres.Add("1f8b08000000000002ffb45a0b5c4ce9fb7f51d2284a5159721a29bacc34a3c2340d69baa10bc6a5d8ec3473a699ccad99e93aa292c41672c9a548e49644ac44b995845a7259b96d2e296bab4576c975ff9f99a99c33334da3df7f7d3e639a73cef3fd3ecff33eef7bcefb9c6fd0cc013aa6601000e00dcc0902887fc3803e6008f82c4e385ef185930878dc79345dd0af99c40a8de6c03142ba840db943583c5bc083f13131317809cc1372e912588cc52c12c14c8ef8470c04411093235e0ac9ae241027e19c704e3802c975e2a4290e4e58f969069dc186d59c26608366ea0dcaa9d8c0640100649f9edd35fce62e2f0ec7e173fe7f3d256af674a2dcd38e244f37554fc7c688519e0eecf654eea2679a3854668cbca4e7302dba8d1d1951628980f7df0d8eb3e6905de421d3a8ae0f7b1f1c5315afff8b3172d5ecf024b9c34e7a4d29bd8f91a1b2c37d18aa41401f303922025e1c15d61da8f6e62310e6b28fa304164b083849aca41bacfb28c410f025305f22433f776213c9180060ac111dd3852eb7ef4654414b1b30f5aba13c219ad2a5d389d6f72c11ffb72c11515922aacd1211199774bde500adb34494678988ca120acd7feaf16aadb344ec43960c803ee01026f3f1301f3dd3316c98cb15c8aadd57f607161323107199b2df0b647fc84b9e11e3380d020040da5144d07ba2684cdad498bca931e97063525e63d25104d9f3d2ac175bd2e56cb3c3a1687b0080bd766ca2a89ed8ea726f26d695d61daf3b7933194155575e577a335111d8e4334bc70300c66ba41ada4515cf76f40c40b375933d3fbbbb69df59f511bd6cb896610500b0d29a86b6e0ff8d465d11c968fa5044833b4d1d991c111ee6f771b62110f0f2b83417a40c5cd412c1300200187d17b83c474ae06aaa7ba771946defe0a8d823e8ff6bec11f4ced8e3e82ab19354278a8ca59c65176c21bf837f0f8b22092816f92112aa7476792ce10e95d7a0d6391045f52107c3d1089d3940dec8d5cf5e19037799d5f811f208bf8741113f9241dd4200b7b495f55e034390d8f2c5a00f29b05001e9cc428458f06d4a49e54f2258f9192ce9dbbc4f90dfa1ad069fe9bd12d4102992a18e487e06fbad28144498b6995f7b27524e0b6d411fd262ae02d299965844e592a7c6f2b850342c1273047c772c01e78485603e43c0e4f0c3ddb1511296e364ec540a862c03a2c80323cb41288af4911590140c192fbf42e69d51fc88f5810080c0eff54e91cbffd13b3908459173b20212e5dd479b595b54bd535ed20721bcebc3b26edc65cee270e1fff00101cd1341d772edc3a859af4c2fd72c9c000098a091d00845288ad262a151fb98503107ffc5160060dbeb1ee51b9be2594165aaa9cc68074c8fb38f12842f7100003868a43551a6a52df84fe68c56f57a75dab5db1c00004763bdea235deee323bf482090e01962711f969a610873bc5812c7857148203b48b126b2047c89a398130f93a0894461ac9bfca0048e9538d2b99c703e0962c07c092c72530c965d43d89f440000b1d7fd809c9ac3a387c37df0dd040580e70ac20538213fbc1b694d50808f21662446b697f0f3a5cee9f48838682000c0726a5a3100a09f788ecf7450747dd44bd958087d83c5000c36917dfa811d39e600f42fe2d0164a16facf2231043c1c9d29088371b13ca1dc01722c299627e4c1123a14cbe3f2c5a45877acfc0a125f4c921dc66321f92592a5eed885fe4190a74004432e38679c13565e44641193459a43f5ee34173159ee58b6442224e1655b765ccc449c40148e274c993205ef44c413898e2226cb511cc797d0631df9e2b10a902e1c2a2c668838420947c08764bfe9618228893b16db798de25fa79f3c6137115fdc191543c0c3c7d2857802ce09afce88c9e8b6114689b872d7980c3ccc8579305f22c6137004b576120e8ba59e4d76464147f966478ee509499e22982e81a974094c213a11a6383ab9383ab9d20844d2442289e01242c62b5da4ce5c20a209045c8a878c0ef2e688e0188168a918f29ceb8c30efbc48c9de5fc0e4b0e254e85d482eaea489933be9111721cc990c124b20e2d1251445550af9e164fcb783882b65d19302451c982fa1cb068d4220e3558e750d305e698415e583efac1fd9bad35d8b14cceb457706008059e147f5a0b175db162e12d0ea2d7e0ce787f34baa07d65699db9a371a0dd39d3e57c72e79c3c179736f79cf98879d3e6fc2bc3bbf0426fcc1384c31a51d1a3afb93de83733ebcb5c9d855c3a0a7117b6cacd61944fbcf824e9ed66148b9379a6ab7bf0cf9543bc5d2c026803173427bd6bbdaed09c18f4f9d7bd8105e3835c7bcf009859df7297165deb169cf5b9aafeaae778865ee72386614f29679ef5f8b77e7def8324b6c8e95069d2d7939c3c9acbeff98fa7fdfc1cb2c3ee3ad9f9908d30afe9ac0cfa4e95a0578dfafdcbcf8ddbe156b0463ca685538bdfd58d7c8b00a56aee13bf735be1b665ae9be4b15eaf26e126f19072e2ee63e9d3f21253b609049cefab9c753de46cef75f0a9bd3eb57d92db4b41febd93aded69932e3d1e100731366e6936d92d366efd2a9d6e305d3eceed15eec76993d3d39d9b9c8a66ed8d5f44db517983a66a2d9a653d8372a92e7d8f9b4a6faea06e68f2a4cdbbac1606bc63fab8ed80c60cda4ff1d488ddcd5f1c0e450584b5c7c997da6d16f39f91bedd9fb7edd4e1ef952bfdf56fbac0fae10f5c4bd8904b3f5277efee350e664ef19596faecf7a0a8da386453daa9a341273b972607601c9253be577a3a61de93f3745eb1cf0e68dbc4bcc73181b203897b432d2f079297d9c5febc2cd9ea9d698cf6d1b5376e86cbb1edeef9afd10e989b630dbfa49b7aeb5a79f0a71dbbf63b561a17f69c7fcb943fce2ef558f989ff8e3efad8ca3b3b25ed3e6ee1a5830ed83b34934e437383fa59d3e936149e0d370e30f8dcb5f8c7b7cf76483196ed59f87eeb14282fdd7fee63a6611758ce04a760231717dc68c26d756cc0abd7b45abbc9cefcc0f1b1c432a79fee8a931a181b6843a7a4bbbae3ecd7dc4cf5699bed0f65958cb53bf6ebb6c68e432fc25ebb2d4adac7d29a9746307bd99ba91c9e46506bddd5cd2bf954a5ee76b9d8c313cb03fca6b2387de511448b2711efef5a4e31563fa88d240ab93c93f8c4adde8f06cb0f1ebba3aa381037156b93718bfee88fee5e4c98b91393f65ec5e75bba2e355cdeccc917ed7569aba97dfc16d27df26b93c5d5d496fcc187a6367e59327d0c8891692e8686ce5abb0625ff7f2dff69c4c4ded98543cf34ee0befb5b23b36ffef2da63635a8864e2823f0aebd6186356099f5f99bd4c5c33bfb5e1841ee33e216772dcb0ea86b8d559b7273c73596372ac9c6372ffc4019f805dd7eb4cf4538fac4d1558d367de5f316a7262cd56fcdea34787def8973d69f9c7f69a3fcec7dea4264d0f69f931be78dd94b2b5a93b76adee673ca128fe6cda705f0c9bb17d25c12db5a121f4f3f37d5bd34bce3f3e3f746a43999974c93263bda1969756355052831f2da4fd1594efc5f9609e313b8364f843ad4e75e5a8f7d9e5f487ae0d14914ee3fdc8d67d99cbbf5eb3eff85af42aafa5557aef9460aab7b7b7518677c68b5f0231f87deb22e6fafee69405f9ef0bae3169c5ee9b273a5418f9b1d662c806e6fe7ee1d7254f3f7f78dbb1f9eea7874b8fe695953dacd5aff4b97b22fe08e45f3379f95b4fbbad354f8f9c1a427f727b66e964a744cbb0dcb63f2b3c97ba09b7e948e3e3cb9765ce2b5db2adbd946f7ab2c3639d6fdcbf337627de22e6faba66bbb49be183930708ca9336553ff6da5f7c35e7c235e3cc7f4e6e3ebe76c9b892577c7dd33d6b9356f39e189cab9861bee26bcd9237d78b19d6e2abb3304b1c6706ea664c4b713d703e6dfcab658d1dc723eae36fcc138cbfea4622d52e24edf4f691ba8519ec63dac19743162df21f72b52262cee46accdc83cd4916cf570734155e9e77a4a064733f9a6efdad8f118768230f8784a44f5aa6fbf0c17c5d3a7ce174c01e328795fd611079cfb0032b83eefe72e478710ef9d999c2c78b4a7eaa9f78e3c9936cc14037bda3a195bbcca2198da98697f72c876f2667571d9b52fab9656d4a41457ae615f35741874af998d07b765f733f5d14c7feb37e4585cf9815a39eb43c3d75fe83cb034ee96e91b1af0e6c30aeacfcd9244f6a3293a07febf7099c9627b76d86d96f9965f1e8fcab987b67a20607e4527857780f4b0c6ffcf56095b37ba330c3faca594c6ecd8763174d8a1e3b1f082aadb8753afd45fa8e25c5f38f2e37aa5e3fbaeaf19215a3bf7cf9c2665ff9a97a5ddbbde284b2e0b18c195b23763ca28fa7077f9d9a217aafb325d6615e854dc35189f9dab33b2abcad6c8ebd7913d9789794bafdb217adf11a217b1ee727e2dabda7b873fbb9bcdaa46f6ad51c63f6a2d6bde0dd85dfe8f60ee3ce33c76dd28f3fc36cbfd1bacf728e8fa8e12b39e907e752d183eaa122ead6b7936de3e36e8f62b10fa6446cda91684df53b34d7bdaae845c8b033d7d38d3f7f29deb66076812e648ad19b621a667c374fba6e69ca91398582a76698f2e51b4a5f0fe7af5a4680ac464f8625672a16bd33aa3c9195d23c00dbacb7e6e083f2eaecfdcfea6c2badc6ceeadfc48aba41d955e6355d7f79ea2ef3179be3ee1f6fb4364a6d89c578315c0b7dd32fdb3112f3de5f64e76c33785970d1c1321d8be58a019193613b7e319367993f6930fdb3fd0f2e4731b74e95e85e2df29850f843731021a5b1529fdb5445a8127be95e78bfce67da25b66e082dab7476da9356dfda52b79119af75708d0f5689ff981239686c3d65e5ce597b9bf2aaeb3e5c8abe64e6e855f87cb7945cfb6961ff1f5a0e14b5174ddba7934ddebd70633d6d7cd1a6cf6f1645deb830b7a63624e19137750086b0f375eef0e91db68c48cf1f8d6bb6e71c3f339290ee605c73abeada9a5d6b068db2af75811d469f4d6e5d852bff58b364db3f27a5e7be3c0f287f7d62093dbf69366d0fe1efc02ce1de6d17c672ce2d7e1391bfd53e32d3c0e57727110e7eddf4e7d8e81fc5cf79199f96fe12d036043bf2cef4ccd9c3dd2a841c562dae119e73f4747b62a830d52f2cedb4f3d5a0e39ce3ccd36959493137c977334eb8bfd05d19d562995a3920f0c1e9f93aabd7595e1c3ac999fefb5eb79bf51fad0b692636dba4d516d7b6475e15fefa69fdb3255694e9162b3713661023e3bdad99d75f5a5bb714519dad880f0e2edfe4b72c637744ff9b2f0bed0e9c3665d4eb7bd5913bfa11eb03f2368426351d26bdf9bbd970f2a37ff2ee37ae68fd7a3dfa0efe15952901434ddffeb1e43d7971b37fc11c5741fed9338417cb2c1a4e65e69189a2847cb7f32bdba52feedc49dbbc60c1e193696b0ffb1e8af97b3435acd5a4f4a98efefca09f5e8e3a1337d864535ce86d4fb6efb8e2fc624be3d0fb3b3187c322cd3d0fe7563d39ee63e418175a566610b8df36a1f98685fb9c32af6b873ff1fedcbe67fb16d86e81af83c7c7b7ef67075cfa708b2a203cb25cf8406766f0e10b0b741bf736d4783eb9dfd85c7edaeea0d301a160c5bba68616e97cea5fbabb4f1b79328455ded41cfdfcd5651f583e815e9b8e3d6ba5875efc7197c76907bb2abfb9b77e178eaab4cfbdfc4fd5e841e2a2ac0b66577770be1e36c93be998b5c8368cb13bc1f6d9cff58cb33bab0a9a4d0b0f5e1f66b932073fd136f5ab7878eeb1d6005648a67f7cc371b64e63f176e79ca68e05b6580f6b13bb32f20287c5475fb4b9344299d7f376db9bb78d7ef694f536b1b63038dd234bb26a517e6bec9bbdc7b257ba4ea2e6a7cd4e3bfd7444668ddba03781c90727dc0dd535b8ddcecf5c51f1e6b1e768e1f023b93f0cb96c20f6491116841acf7f79384067ab2d830c053f0ebe982f5eb3a5404abefcf6d2a7db177c732bd74fb179b6d3ed6360c76be1a385a147f588e50d63ee4870b55e22297b6eae78c6a5d5bfcddc115a907f6c08d1bd23a579650ab5767066c15f1fdb6f4dc3d1b3f1c32adefd353afee354c160ea39fe90c5afaf24fb345fedffde9ffdc5ecc3d8a2a94929fad5b2ad929f5700b568fa4fc9f2e6e5abdd899b0d01907d34bf0250eceef84c3816c79620f7f1b25f148c3e990dd399148cbe3e99cbe12f854430d71d2bdfc48ad9302cc1426c11cc72c7a2b6b65848122784ddb1b2cd2b5efe1b2f03c2772291c304cc38d93793134d217378e19058c470c7a27798580a192f3b8fd1a7b13962882386246c1892fb09b144021e142e82c53819aa028d8c97fb2b8b9dded6412b010094f4fa5e42167b1ffa01b24d71d7ab5e75a9f393d822ddedba146271b8304e4673366b3c180d80fca3b99dd44dc3a5c709a2102f3eb5f7768c1a183c43c097d0397c5884f65c2a65c22c0e1f86b0dd1760131230643681e2191840f3f00bf09a43c6b309148c540af39909f256c438bd87af08000082463746a973832510487af64171b6cb01efc0409a1a76da6537dfde5fdfa96597d563cfec8ab3327645938a40f1f5f2a0aaf1e0a374c36d3c0000fffd1e28be95269e1535d093161ce405296620b9eb4b3e7b3ab7b5122e4cf111788be83c189a2507916d6c6547e55748a5dd458788a36b06764e40c55e9a130d31b874b1d81d31e4aa20a87250ec96e5b35319a373c85401be8d25c25acde4bd763dd3ea2300e0e3f74e0d621fa6869a3121aaad49a5fa93318470fffeb5f757586a19d4d59d527dc9181cdcef93fbc8a0aeaea4520e9fc18d62769784fc3416c2252460be9dc3f1e81c3e4dc8553a8c4564456e227350e7c30bbd00004040af6fc8541c94b1f461c0a09eb0e4ff115453eaefe11740e8ce68ad7f1b6388fc0d52df4988ea4988dd246153e39a5449d4bd43e922d1700bead7df74c0372f91cab26140bffbbafc24d9ff1ac46fca4048e197210ae8e8372025c91312439d44aceba50b9816dc0fa80ac6d00e206558162807b2ba8d3509c694f1902a295314deacfe40b3944b535c86a8b8be2843f5189ef24877ad5a6d1e1e03803a9115da1c29891a818a261161de83c84a190ca988c2a0c01abac0d09a2a4d09d14125c4410728cba8b4cd43b8c294a8310f48d1133a0ffb11e63dc8a894c1909a27741e7474813ad594f67998d309d0631e902f2c0d50dc19ba40bd504a190229534243bcee82501642a97881901fa121420702f5ea266508a4e667280ae26a17841ad592f6284e7aa0475192f6e3b1b51345abba1c8caacb5b9da6aa9a2334025222842e4dd341a037cd913218521284068b540253a331d23eb6eb483094a6088d8054fea0dd31d207bd698a94c190521f3458b412981ae9d0778c1b120ca515422320553dc3d1e38601bd688594b1902a1e3456b41296aa2a48536443d09121b19455404af70d8450077d57351b0cb4500129e321f53868bc44553c35621fed837ca98487d2f4a041900a1a7394533803d0bba647190e297941c3d5aac2a98a70342d4a83508b52842150a79ae9f946618cf2e65097b95ad58c320e52b082c6311e0234a862947190521423144e320a4749eca20c839496a01fcf5ea360d4a85894a190920f131454f850a05199a269a8f4514335d208a8158c68fb70136204d40946d0e6480507fa617e3bc25c8d6044931f18941fa6c640bdfc43694d44340bd1299d870250957f2823215b6fe81bfbc431a0c756a3f637763c04949b766807909d3574281110d0d8b4d394552354566f229154fb72681864736c0cca21732ba0755f4e65fb84687a8d42a1e6aa4355d7d2505907115d2c34e4682cd0ae77a60c89ece52879a90e525dd342fb51691d0b34b584d030c8e60ddab389d640bb96903224b25b8386dca20e529bfc21fb2b68c8f7ea20bf377fc351f9db360ef4daa6416321bb2910cabde73d61a96bd328c322fb2768583f1ba07d6346fb1b73110216b1b0e80e945d400114203506a0cd46f6ebff020000ffff3373f97b7e380000"); err != nil { panic(err) } } diff --git a/os/gres/testdata/testdata.go b/os/gres/testdata/testdata.go index 4e0b16a3b..fc73a247b 100644 --- a/os/gres/testdata/testdata.go +++ b/os/gres/testdata/testdata.go @@ -3,7 +3,7 @@ package testdata import "github.com/gogf/gf/os/gres" func init() { - if err := gres.Add("1f8b08000000000002ffb45a075c13e71bfe5410890b04b7620808ca484864680851242c952571800a0dc98504b3480232440501d13fa8a8c5018a58ac8a8882155170411111aa382aaee240b016ac8aad451cfdff7220dc85248468f9fd507277eff3bcebbecb77efe33b7f909621180200b0099ee003103f93802e204432c48455ab561142d9d612ae142248218994c0140ad8dcd045746d30c0ba9ab9c277bece10a4a17248933e20ad991112a990af01b28d52643474d727bc54c8e775d34472a1552286948375c2e2081c211f8251a4105fc4634821090eb34c0cb1b89215182c168b6571252bb1b22b892407bc0dde064f24dbcf709865658b834f33194c0ea4e0b41d4e160c9d66ff800d0060ab0cc652dd60f8d178ae80fb6de3b0571d87031c878d4e5362df714cef2b8effae1a36aaa320c25164956f65f51d85699f51fc176520a90e60061c407bbc8b63ef00c6ac304105304169002cae9808bb4df113a8b8d9e401a728cf880c91208908d100d5ba6f54d9afb5ec10112f8d927673741fc5328502292490ca48cf9fdc4ed60700e8ab2435ee831486ed26ea45923268f6e7e10080e19a1780f4cd0b40fa4f0a40421580a4b00024646e62b7180dfada0290e03f49a802a048bc661755f52e40f5fa296a16804b9c2980d133f787a948953ca0914a406b1657ac01284e792abea012204dbcb5560b98c081783c61cf5a2ce3c0c0c764eb8f87ec0f78d111b78431f500007adf82739550cc63c971c2c7649c4b647fc09c7bf523ccfbe6542781618cff2881618cae0446337a25908cc535c66f6f4cd8de187fb4313ea731fe381c5519db22603c0060fcb720efcc248a1c3e44c6e29e95643cff3e15a6dce71ccc1b09001889a2f487ccfa9d487104cc339b2e56914879602bb580bb12f9e5992aa3e8eec3baec1bebea4aea8aea4edd488023e2ad369e3646b6b07c0be2ce242289bb9bb1aeacaee4c63a98126a7959da77374e5583328663ede2ad4143daa88bdd95ca3089b067e18885bf59e0e03338597b9cdbdf74f01c0e13073f368d879eedbb27d5e7efcca8227ef80caea73d3bf9312fe77fee9b5fcddcd29768905b82bad85db98d42dc7194d9517c1e3612124bb84281138e88b7c161210153c8e20a429d701152b6f54cdc6c2a862203a2c269a0c020d4ce1a503a21a9180a4c459539ad1733668bcc3f9f6fe4746741bed2691884da59384a2724cae90eb305dff7765afea69ca2fa29cae6f22035d618f9544ceb23153258022450fda053f41062aeb29e83050060bf9e3e8ca1e66302a3600d37bc5cb3743abcbd52955c7375fc1047a8b1ca6214ad81e50b099fcc611a55c9b054c70978a1e8bd44f45aa0ac304a570daa2fa1d80a5ee6557963a1a637f425ffc94dadd69d533de7ea2d2e0080ab321213d591fc87eddd1773184319b3e2d6969d41f4b65f2836d2126e9caf71421ca1cc89be1b9b39f3ecca69f07dacca03b33e3ce8ec699413dd3e7c79de2a8aff45c3d53463785bf495ecf425df8c5dfe8588f2dd945828946af0f24ec576568648604a241aa04eef1b95209146f3203c12df02dbf9f5842d1448ad25dc18888c9d41124539c207a55094d49ac1e3860ac8582624904262c7cef5c7a221e40f120080a4d223e33e3ce2f219a19006915aa8834be00943857891a0e7bded465f6ff7e1980918d9f6d9d383b6b0cb7fd290c1b21deeec944200c000c942f7b9a0e0daa41700005d9147800480a106b2df01604fd63800061670e94ba54bbd169099423e9ec1128640f828be08f68b12458ee28bf89094818de2f304127294130ebe822c9090658709382c7c8974a5136ea9972fd6452886b076785bbc0d0e5e2e2962169bbc90e6d6652e66b19d701ca9544426c842c5af9a81178a4309c459b366116c480412c95acc625b4ba205524694b54062d209f2058706499862ae48ca150ab0b2cf8c106184d40987ebbaa6f3a7cb4fbea89b4820e98a8a29e413a2182202116f435064c46276db8822c43cd835169300f1203e24904a08443c51a19d94cb662b66939de9a4a3f6d851a2f822b28b186248211a430a514936c459d63676d636f67422893c834426da05520872172932178ae942218fea2ca3c3ba71c5d02aa178a504ebe26f8b30efba48cede4bc8e2b2a37bd1db91edecc9336676d1232e4298b39864b650cc6748a99d5d29128452083d071157caa227fb88b99040ca90158d4aa4107a1dfb5260825c853bdb87d0d53fb2276c772f5231af97dd1e040066ad27cd99ced17eb97499905e3f7e45a82054505c35b8b6729cf9b846bd51da73fdb52c12b61e5ee47fd36dde22dcdc45d317ddfec927ee77e651aa21fdc848bf0f3af7cfbbf33725e09246619f841d3033de3c2cd26b01f6d4192d662cef7a53edee17811f6a67190d33f366ce9fde96f1ae76775cc0a3d3e71f3484e6cfce1a97ff98cac9f9b06e7dce8939cf5a9aabb5b75845b1f6599dd00b7ccbbafbeff877e7df78b08acd4e94f89e2b7e31cf666cfdc029f5ffbe83568fff48307d6a204ac9fb73ba209dae6deced76af62c7f27707d76e144e29a557e2757ec4d9878794b3b387bf73dae8b175beb1f6bb649136ff06e9a6becff242de93c5d31333bd8718646df12f4a7c1bbed86b25348e519f64b1d4c8d2c4a5759ab92d75dec3a3dee30c58e98f7749cf8c7d974a339d269c637197fe7cbf9ddfdc8404db02b3ba51d5a9db6b2fb2b4c68afd0c6771ae97272cb4706f4df6d0f6c99d949fb273ebb09d697f271d331bc49ecff8cb8716beaffdbec1919096e89852cb74bd5fb372b759720efeb29b32e185ee809d9619efedb1b493776710c76e39f9bfdf8fa4cf749b97f1e6da8227d8a9b4908887950e1330972b0667e691ed32137fd36bda93fabfa648ad436efc097748395626dec2f3f1ebc3873f2b614cf56c5dbac325d914f3f1e5b6c43d5abbae850eb86a3922f6e4cb10f37a879b57db524f073afeb867c3f07caf92f6c5fe233c63ee568d59bc6ec56fadcce30b325ed3fdf70dce9bf3ded62012eb393437b18d319f694414d0f1d38e4ccd5d8e7f74e754c3587cd21f47eeb20303bc36fd6a3f65196d8af04a661c69dd96b4794df6ad98b53a770b925c6d6f2f0e19ba8a5cfcece1137d62033d9836f9fb366d5dbad398ff19a77b60772fc0199dfe65d7e5e17a76a35fb02fc73a96b6ad24976c6b6734d3b6b158fc74dfb73b8a07b6d2289b3d4c1330c30ffd18e1ba8dcb682ff0219bd98efe7ccafa8a3e634c898ff1a984899392b7593d1daaffbaae4e6ff060bc71f675e62f7b227f3a75ea5278d67769fb936e95b7bfaaf14b9fe07975bda153d96dfc6eca2db2dd930d158cc6b491d7f7563c7e8c9d3063bc34321257f12aa4d0c3a9ecd703a79293db1d0ae7dff639786f6778e68d9f5e3b6f4b0994ce58f27b7edd467d4c92e8d915bfd5929ac5ad0d277598f7885933a3475535446fc8b835fda9dd468313655c837b270fb97befbb5667a09b7c6c53b2d09431ffdeda4933d7d5ec24fc70fcf8c8ebff721cd674b4d5fc7e21ea062d7e6e60cb8a98c2cdb34a3725efd9b76180fef482987329a33d301ce6eef544c7e48686a08fcf0eee4c2dbef0e8c2c8d90da563638357ebeb8c34fa39a9819a1cf07029fd4fdf5c57eefb71697e69e4e1136bb5aa2a26fd9359c67860df40156b35de0b6f3d98bee6f355cbf6cf05af725a5a63ef9e16ce767373d34b734b7bfe930f8670707398bfc7af361958af83013506adb8838bc447f2c33b6ac78fd8cafa7140e835e9938fefdfb6efb8f3e1c1cae339a5a50f6a752bdcef9c8c3986f5aa99b9e6ad8bc5ce9a27c74e8f603cbe35bf64a6cd3aa390ec977f94bbac7414edd28a8d89295b9dbea82478575b89c0f054bbf3668fe87fe7ed5f779394ed619f69d73696109030485816bfbdea91eb8f85d55917afeaa7ff7d6a47d1a6e0a9c5af04ba860736c56fe03f1e76be7cdeb8b59f6b82df5c2b649a4aaa176082ade7fb68a7cd49b43f742165daabd58ded4561f531d71709a7553b92c9b54bc97bdddc631d43861d6459409703972df31a515d1eb6706615c6ff7073fcf8671bbc9bf22f2f3a9657bc63005dbbfe6647d811fa84a38181a90eabb51fdc5faccd802e9ef13e40e1b233df0fa11c187568bdef9d9f8e151566519e9ecd7fb4acf8bbfa19d71f3fce140e76d4391e54b16f6c24b33179f8e5036ba01b0999952766957c6cd99498579e9a7e65dc2bdf2325024cd05d8bcfd91f2e49a2fedeb2b6dc7dcada498f5b9e9cbef0deee3eb764bf58df430b1a36b5b4eca9830b2d8145d4bdf9db746ecbe35b66a32cbf5f30fee18557abee9e8d18ea9d4de55fe13f281e7efdcffb49b64e8da234d32be730d935ef4f5c322878647bc8b7a4fce699d4e7a97b820b171f5fa357b56572e5a3e0b5933f7dfac4e15cf9ae6af3cbbb8571a50126cc793bc3f63c644c63047c9e9d26fe47ebfb28ab45e5660dc7a5e3369ddb53ee666c76e2cd9bf0c63be4e4dd975de98d5789998bb8df9136fd709ae73fc0eed5765d43e3e655639fd73ae5bdbbf82bc3d26aea05d6d4edba3167596dd75b0f1a2d7417377ca6c44fb42d11dfaf1a29a6ed7c3bd33c26fad62436e77062d8f63deb4c699e47fc9d2a0b9e078e3a7b2d55ffe3a7c25d4bfcf2b4b186189d598621fa77726237af4c3cb6305ff8642ca66ccdd692d7a30549ab8958e3c93321e9d9f265eff42a4e6624360fc235eb6c3c7cbfac2af3c7a775e615c6260b0636b123ae53f795baced55d93bc6fdcf31dd1f78a1a4df5925ba230ae4cfb7c8fd4cb16cc7539ff5ce264ed1af622ef9295512a0ec793001237cd7cda7216df28d76128e3a3e544bbe3989ba78bb5ab0b9ca7e74f6cf625263656e8f29a2a89951257ed8bff6c769ff333473b909e51e297f2b8d5a3b6c47142da6b2d7ce3fd24c9efb3c28798d453d7ef5df043534e55ddfb9f237f1e6bed9aff6c7f2ca5f6c3d281135b0e15b415cc39a89549d9bf745b3d7d5ac1f68f6f96855fbfe85f531b18f7d08d360843dcfb3a7bf4dc767366b8cb0afd9add594567271053adf46b6e565eddb86fe3904996b57690d5e47309ad49f8b28e9ae05d7f9f8a3dffe99977d9eb93c18cdc263ffa01e25f3e19a21f765d34e19e5ffe262c77a76578fa30bbdf6cc478e875d31f26912b24cff8691f56fee4fd72046ec2edb9e97ea31dcb455c762dbe115a78fc4cdbba2051b26748ca19db6adf226e11eb4c4a46fcaa1b943b69279d9e6baf8f68314aae18e473ffcc62ad0d9b8d2e8d74b065fcf683e38dfa0ed37cba81d9aed8aaf1577787578b7ef9b0e569b03175eef8f53b88f348e1316ea6ac6b2f4c4d5b0a68b6c6a4fb87d76cf75c9db63f6ce08d17f91687ce1832eb755deb28ed0348f5de395b83e29b8e92dffcd53c7ce6c3bf73ee35ae6dfd7c2df236e1158d2505230ddffe1efc0f6579b357de427b61eeb9b3c4e7abc7379c4ecfa190c471b98e17d6b7c53ebf7d3b65c79225474fa56c3aea7164d55f936921ad06254fb47417fb7ef762d2d9e8a106dba3836eb9703ca616e6161ae907dddb8b391a123ecee56876e5e322773debe8a0d2d2613e3f9ac7355f1fefb4b0d4f5ead10ffc3f761fd8fd3d64b1c4c3cab9e3ed3f7ede3fbfbf4913121f1a2dbdaf353fe0e8c525da8d3f34d4b83cbed7d85c76c6e2b0cd219170edbba68696d8c5b43fb5f79fd173618a2add6859bab91b4adfb3dd7d5cb79f78daca08bab4629ff3192b8b4a4fff9bbf89265558665ffebb72f2104941c6c5b1d57bb89f8f1ae49cb2ce58661ec2dc1f67fef47ff5cc737b2bf39a0df30f5f1b65b43e8b30c33cf9b36474f689566f7660ba574c431147abb170b76d5653fb12739cb3a98145296589d5f2e3cf5fda3562d3afe5ecb71cf772f2d327ecb7eb6af303529d33a449cb725ba3defc702273bdbd032d37c52fe5cc9331e9358e43def8241c9e7e27487bd8ad3641fadaf2378f5c268b461fcb9e38e2f230897ba2282f487ff18ba3de5a3bcd99146cc0a3804bb9928ddfe7c5522ebffdf9c3ad8b1ed9155b66993dddebd8e1d3fe5af47069d0711d5259c394db527cadab3896e39f2d99f7f3865fe7ef09cacb3d3182e4d49ed8bc3e91563b343defcf8eb69b73f08c4cc2a8f2777f4e8ee9982d1c4a3b2f18b1fcf59504f7e6ea81ff78713e8d7d6f52303b3e51b74ab655f274f5a615ccfd2e019e68bcdabf6ec7700064bfca377d667d6dfa042c280acf9122941514d9272a4697c281182c2a465797c2e30a5662c510cf0907ef84251c0892e2b01c31c476c2a1f6c738ac345a0439e1643b6002fc992003227421514284ac68d9ff2c6e2495c2e587622562a6130ebdf1c4512904d9798c2e9dc39560b912ac940361613fb16cb1908f0d154312bc0cb5138d4280fd95a584f1b29d5e0c0028d6702afb457ca1c13840c5e6fa0baa7cae65049e5273647c5f2ec5b2b93c082f633f97310d4c0600fe555e657335d8798c686144974aa17f2f0eecd5472730850229832b80c4e89e8a8d65416cae00c2e2ba2fc0c5c561281c22d5c5c79beeece9edba9042e010a998d85848c08a835f974cd579f08a080020aaf46e463fbc630b8552e5ae759efde2979b8f0f5d8153f4cb8e1ebd5f3d7e8d53b29b43b9539d67654e75be3226523d5c9d690a1ceb88dd7a8b00cf78be95639dffcb2d0ec6341f177a80af2bb67395a07cf90fbec3bb76e4521e447517ba89197c08bb000691edc96547e12b6263bbfb1c11de9755a26b91e87c0dc08dc432790c89c409d137bd41503dd5b9d1875710798cae02f706e8a93cc25ac10273f55aba710700a0e31bdd8d240dee46f52b4852d8ef72bd2d230ee4fdf54bef71ffd7102bea69b9de95115b39dda37c5b62453d1b1bcb15307911acee76834fe3b0f8b8384ccf393c9fc115d0453cb9c338440e611399df5aef9feb780300bc55fa6dd50fbf65e41a3483433f29e07f88bdebe2e5ece94dec2e4badd74be60800c0886fcf4d52cc4deae60e991ddd84e696fd6879d27c91dc639472c3d051b6b3827a1c97371eadcc1861abac00f2587a0ab03480198280d1c05cabcbbc0f5345991c203345d80d18683848b9d2fb4bd02f9d6139817aba6fe590262848ff3e207bebbed1c848d9b44d373200b9f1c79422aba1fb96a741aa9a2d5134310380468a6c7906a4e2783a8a61ee40a081565a1e1f29083645e10f1904faa76246422b12b4f654b75a29b49cbe5839e01414e0042dd00f7d311a1529fbb5466540d437aa127db13c0752f56b8ce268ea83032d27563fc5f3b4817a0a6275539ca90dfaa12046a32285bde814bfe91b558982589e03a9eb45a7983d18f443308cc455a40aeec9488d525c398db072402314e0241da0be465839280e051aae14548946180d8cd4eea24b77552d60451a61790ea45617cd411d0234d404ab9fa0223538501a60343052928b767ea82ed050032ccf81d4e0a23952d4e35020f545722852f3f624e8831a1c286d2f1a1829b7b542394fc700cdb4bdf21448792d9ae217f5287aab7855f5cf54547ae60c05fd56eda2b1910a5af497952c75b115a976e56990425934cda461407371aefa99ca528f06a5c1456323a5ad045408edea622bd0e0cab320b5a8689663c381c6a25955371cfa511b3202f443e58af61da9c99b86f2bd6404e8bfca551e1ea92445c33b8c04fd57b1cae704a9113547c15f50075e4e9c2aef3c52f389feb64ed3031aa94ee519905a4c0b14c34d3519e494a4aaca6b825e2af441bf049ef2c8481d251a79cc28d02f01672f9f11fa483472661fc8f2aa4c7964a4fad00c853cd900f4576da93e7866dfe0f2624a553b5ff4b7caf186403dada47240f46a12a614509156128d8a5429a2779f17fb4655a09554e5b531caeb85a341bf948f685ce4400c7d1fe6a983db5bf9284f801c2fa19b23db04f477caa6fe0ea1c814a83faf428322a747e894e84c059accab54d5d21ce575921a04bd47526874e400c81ee57ea3fae8ca4652bdde1e21063b335064f166e0ab264cf24cc8490d9a698c39f8aab1913c13725e81663ade0f2645efd4d56f0483e9408369081a1d39a040c711ae3eba5ab5414e24d04c7ff483499dda2067086826a605f8aa7987aada58a16a33d112683aa140532027060ea860d6f49342d184429e0d392340b37568c24652cca66ceed0f9a30fc09c482bd0f714a2c7754573881eb093cac0d4c2d24361fdab004b2d98212818376ba0682aa1dc5c0b659ed465decb54d91ca2c7f4a2cc1461a73d587686066820631c00bf5bcb3efd3f0000ffff797de2e694460000"); err != nil { + if err := gres.Add("1f8b08000000000002ffb45a0b584ce91ffe50d210a5502e99464ab7996674619a8634ddd085c6a5d8ec3473a699ccad99e92e944afc0b61732992cd2289b212e5569b504b2e2bb7cd25656d5964d726d6fe9f3925e74c33cd34da9e67aa39dff9def7773bdf39dff9bd01f38668198161008037103700207e26025d4088628809d1d1d18430b69d842b85085248222530850236376c115d1b0c6a21b34302e6e90c434e540e394505a41d33522215f23540b6578a8c86eefe86970af9bc1e9a282e142d62483958572c8ec011f22118450af1453c861492e030cbc4108b2bf90683c562b12cae642556762691e48cb7c7dbe38964a7e9ce336d1d70f03093c1e4400a861d713267e834a7076c0000bb4f676cd475861f8be70ab803eb8753df7e38c37ed8eb3427abf6c34a951fff5d36ecfbf682087b9153b985a5da0b73955efc176920f5edc074d8818e447717d50e8c57ea008b2b266a70b14d561e111922411219aa01aa9d6a54d9c74e76888897c6487b387a8e6299428114124865a4e74e6c231b00000cfa243553410ac3f610f522491b32eb931e00404ff30490063c01a4ff2401245402480a134042c6267eb3e990af4d0009fe97844a008ac4775649cdd724804b9c21d02054a67d02dab1b8620d4071ca43f1199500090636b108600207e2f184e8b518031f93ad3fdeb27fe04547dc1aced40700e80f0467b450cc63c971c2c7649c4b64ffc09c7b0c222d5573aa13c070c67f14c0704677006319bd0248c6e29a12b735256d6b4a3cd29498d794780cf6aa826d1d640200301908f2ae48a2c8e143642cee5959d6f3efd261cabd6e2b78a30000a3be3a90e2480d0269ab1670772091f7d49e3aaccfbdb1b6beacbea4fee48d24d823de2ab369630100630782b82b8848e29e62acafa82fbbb116a6845a5f96abaec6a96a50c671ecdcfd06f671178ddd1dca7089f0cbc2110f3f59e0e0119cac3cceee6b3e70168749806f9b66c3cfa8ae49f5f9bb22aa881f1ec17d29cf2e7ecccb799f54f3ab195bfa120d624b5017bb3bb631882b8e322b86cfc346416209572870c511f1f6382c24600a595c41982b2e52cab69b819b45c550644054380c141884da95034a1724154381a9a832a3f5e3c66ef60700f80f90d15d09f94aa361106a57e2285d9028a33b2de67fa7dae8c97ddf45d95c1ea441fea6a908850c960009fabed129ba0931a3ed66630100d8afa70f67a8799bc02858c38d2ed52eb582b7577dd961a98e1de2483556598ca235b07221e11f4b9846c39dec1723e085a2f712d16b81b2c5285d35a80184525b7899efcb1a6b35ada12ff94f2e6ab5ae9c2bb3afdee20200b81abe488191fec3f256c51cce50c6acb8b4652388da5e10868db2810be76b8c10472a3342756133679c59390dbe8efbb2c04285055d358d32a2c786cff75b45febf68bc9a61066f8bbe929dbee43f6357be9b120b85d281ddceca10094c894403542bd5a80489349607e191f8d6d8aec713b65020b59370e32032763a4914e3021f944231523b068f1b2620639990400a895dbad61febc6d0df49000092a67b5dd8222e9f11a6c91dcf5a1d5c024f1826c48b045fdedb6e08f0f3d2c38cc7c8b6cf3edeb485ddf693860d95ed7067a51503000649167acd0145d726be0000e88abc8324000c37947d0681dd39c6000c2ee2d2974a97face2733857c3c83250c85f0317c116c1725861cc317f12129031bc3e70924e418571c7c06592021cb0e137058f814e94a57dc52df00acbb500c611df10e787b1cbc5c52c42c367921cdb37bba98c576c571a45211992073151f3d1d2f148711883367ce24d8930824929d98c5b693c40aa48c183b81644a17c8671c1a24618ab922295728c0cabe3342859152571caefb9cae9f6e3bf9a21e2281a4db2ba6904f8861880844bc3d41d12416b3678e2852cc834d633109100fe24302a98440c41315ce9372d96cc56cb2912e3aea97799418be88ec2e86185288c6904254923d71a69dbda39dbd139d48224f2791898ec11482dc498aa60bc574a190477593d1613db962285a285e29c1ba073a20a6779f2437df57c8e2b2637bd13b921d9dc8d36774d3234e424c6731c96ca198cf9052bbaa522408a310be1c449c29f39eec2fe64202294396342a9142e875ec7382097219ee2a1f4277fdc8eeb03db548c5bc5e767b080098353e34373a47fbe5d265427a83c9376182304169cdd0ba6a634be326fdd1da7302b5ac93b61c5a1478d373ee22dc9c45568b6effe89ff01bf308d5887e78d4820f3af7cf79f13726e15246639f84efb730db3422ca773ef6e4692d663cef7a73ddae17c11fea669a8eb0f063ceb36acf7a57b72b21e8d1a9730f1ac30a67e518173ea672f23eac5d97777cf6b3d6962bda9b6d63587b6d8feb07bf65ddfdd7e4ddb937deac528be36501674b5fccb51fd7307872c3bfefa055261f09e64f0d4569057f580932e9da667e9ef7aab62f7f7760cd06e1e4727a355ee7079c534468253b57ef9deb06ef2df3ccb4dfa58ab4f93748370dfc9717f39e2cb64acef61b6698b339b024f96dc462df959031a321c57aa9a9cd14f7b669960ed4b90f8ff8191bb2321fef949e1ef72e9d663e4d38dbfa2efdf93ec7057392921c8a2cea475f49df567781a5354ebcc06826e77a65d2426bafb6546f6dfffc8985693bb68cd891f157ca518b21ec798c3ffd69117b3bee1b1e0e6d8d8d2bb7c9d4ff25277fab0de7c0cfbb28e35fe80eda6193f5de094b3b71773a71dce613fffbed70e60ccfb9596faecd7f829d4a0b8d7c58ed3c1e73a96a687601d9313bf957fde6dde9ff6b8ed23ae8c91f7f8794673bc54f782e715d84deb332c6549fb6a5dbdd53cd311f5f6e4ddeadb5f35ad8a0ab3623e34fbc0cb56c70be79b53dfd54b0cb0fbbd7eb15fa96752c0e1ce91377b766ece2b5dffcdac63c363feb353d70efd082d9ef1d0ca3b03ec3f393db19f398a644011d3fedf0d4fce5f847774e368ec3a7fc7ef82e3b38c877e32f4e9397d1260b2f672790d66ece98dbecd48659a373b728c5c3e1f6e2d0e1d1e4d2670f9f18101be92b6893be6bd7d6a5bb8efd9f59a63776d77c9ce9a99f775ed2d3771cf3827d29dea5bc7d25b96c6b07a385b695c5e26706bcdd5e3ab88d46d9e46d9e84d13bf843a4c7562ea3a3c89f6ce130e6d349bbcb068cb165fe662793264c4cdd6afb74b8c1ebfa7afda143f166b9d7993fef8efaf1e4c98b1139df66ec4bb955d9f1aa7641e6789fabeb8c5c2b6ee377516e911d9facaf6234658cbabea7eaf163ecf8e926d2a8285cd5abd0626fd78a5ff69f4c4ded702e9e77dbffc0bd1d11d9377e7cedb6352d583a7dc96f85f51b0c3029a2679717ac92d42e6e6b3ca1c3bc47cc99113bbaa631767dd62daba78e1b0c8f57700def9d38e8e5b7f75abda16eead18da94273c6bc7b6b26ce585bbb83f0fdb163a3aeffcb715eddd95efbdbf9981bb4c439c1addfc4156f9a59be3175f7def5830cac8ae2cea68df1c67098bbd6115d521b1b433e3e3bb023bdf4fca3f3a36635968f8b5fb1ca406794e94f298dd4d4a0874be97f04e47b70df1b672cc820eb4da8d3aaa99af8777605e381532355acd5742fa2ed40e6ea4f576d3a3e15bdca6b6d8bbf7b4a38cbd3d3533fc333e3f98ffe18c2814de181debfd867617d0f04d51ab6e10e2c121f2e8ce8ac3319b985f5c3a0b06bd2271fdfbfedd87ee7c38395c7f2cacb1fd4e95679dd39117714eb5b3b63f55b77eb1db54f8e9e1ac9787c6b5ed90cfbb5a6a1b92f7faf745fe922daa9151f1757b12a7351d98a9ded6502a3931d6e9bbc63ff9dbb6fed4d52aeb753b663fb384250d2106145e2b69a471e3f145fc9b970d520f3af93db4b36ae985afa4aa06bb47f63e27afee311e72ae71aaff954bbe2cdb562a6b9e4ca7ccc0abb79feda19b3939d0e9e4f9bf66a555347497843dcf545c269575cc8e4baa5e43d9e5ef12ea1230eb0aca14bc1cb96f98ebc5219be70460d26f0504ba2c9b3f57ecd8597161d2d28dd3e88aedd70b333fc307dfc91e0e074e755da0fee2fd66640174efbeda770d9d9ef8751f68f3eb82ee0ce8f474b8a73284fcf143e5a56fa6dc3f4eb8f1f670b87bae81c0ba9da3b2e8ad994aa7769ff6ae8465276f5f199651f5b37261754a6675e367e1570b84c8009b96bfd29f7c34549cc5f9bd7547a4d5e33f171eb9353e7df3bdee796ed131b786b4123a696573c7576a725b188ba377fb5e2b63ebe6531dae6bbf9260fcfbf8abe7b2672b85f2e957f99ffa054effa1ff7531c5c9b4419e697cf62726bdf1fbf6858f4c8e1604059e5cdd3e9cfd377af285e7c6cb57ecde649d58f56ac99f4cf3fff703897bfadd9f4f26e714279d014e6dc1de1bb1f32a631823ecdca10ffadf55d8ceda24a8bc66352e38d6777577a9a591c7ff326a2e90e3975d7250f7ad35562f622eeb7a48ddf9fe2050e727cb54dd7c8ac257adcf33ad78277177e61d8d84e3dcf9aba4d37ee0cabfd7adb01d3855ee2c64f94c4090e65e2fb35a3c4b41d6f6758c6c5de9ac8e61c4a0edfb67bad39cde770a06b75d1f3e0d167aea51b7cfca778e7920505da58238cce4ca350833b79f19b56261f5d58287c320e53b17a4bd9eb3182945544acd9a41990f44ce5b277fa5527b2925b86e05a74361cba5f5193fdc3d37acb2ab329f30737b323af53f7967bccd15d9dbad7f8f9f6d87b254de6faa9ad31180fa653a177fa256be6dabcbf2f7272768e785170d1d6341d87e34900899b61396d398b6f9aef3c9cf1d16682e331cccd53a5da578adcac0a27b40410939baa7479cdd5c46a8987f685bf3779cdfe89a31d4ccf2a5b90f6b8cdbbaecc657cc66b2d7cd3fd14c96f3323864d69a0aedb33fffbe6bc9afaf73f45fd34cecea3f0d9be784add87a58327b41e2c6a2f9a7d402b9bb26fe9d606fab4a26d1fdf2c8bb87e21b0b62e38e1a1276d0886b8e775ee98391d96cc08f76f0c6a77e5949c194f4cb735a8bd597d75c3de0dc326dad43942b693ce26b5a5e02b3a6b57ecfceb64fcb97f9ef955bc3eb18291dfbc80be9ff8a77f96e8fb9d17a670cf2d7f139ebfc326227384e3aff6623cf4baf9f72951df489ef1333eacfcd1efe548dcf8db7332178c71a91471d975f82668e1b1d3ed6b4344a93ea169a71dae0494704b58a7d3b212a36f50ee649c707daebd2eb2d534b56a88fffdd38bb5d66f32bd38cad981f1ebf72e371a3acd0be986163be36b4caeee8ab822faf9c3e6a72bcca8734cd66d27ce2545c4799ab3aebd30376f2da2399891ee1f5abdcd6755c6bef0c1375e145a1f3c6dc46cd0f5a8a7740c2235f8e56d09496c3e427ef3678bde8c877fe5dd6b5ad3f6e95ad46dc22b1a4b0a4619bdfd6dc5df94e52dbe050b9d84f967cf109faf32693c959947218913f25dceaf6b8f7f7efb76daf6254b8e9c4cdb78c4fb70f49f9368a16d86654fb47417077cfb62e299d8e186db62436eb973bca716e7179b1a84dcdb8339121a61ec7e24b7fa718997be5d6c4879f908ff1f2c135aae9bb82e2cf7b87ae403fff75dfb777d07592ff1b675eb7cfbf702bf9fdedfa409890f4d97ded79a1774e4c212eda6ef1b6bdd1fdf6b6aa9386d7dc8fea048b8e65d73636bfc62da1fdafb4eebbb3345d59eb41cddfcf5e5efd95efe1edb8e3f6d63845cfc66afdb695beb6a9fc09bbf8a2656d9e45efaab7ad2304951d685715776733f1d31cc3b6997b5cc3294b92fc1f2e9ff1a9867f75417b418151eba36da745d0e61ba65ea27c998dce36d7eece04cdfb8c6128e5653f12e879ce68e259638377343eb72ca12dbe5c79ebf746cc2665ecbdb6763fc72d2d327ecb76beb0a83d2ddb2a429cbf2db62de7c7f3c7b9d93332d3f6d41dae92763336b5d86bdf14f3a647527447bc4ad7641e69aca378fdc2789c61ccd9d30f2d2088957b2a820c460f18b237e5a3b2c99146cd0a3a08bf9920ddf15c4532ebdfde9c3ad0bdeb9559b675a3cdde3d2e9dff15af47069c8311d5245e3e4db527c9d87389e13982b99fbd3fa5fe6ed0e29c83f3e92e4da91dcb22e9956373cb3e08fcef69bb3f18c6cc2e8ca777f4c8aeb9c251c4e3b2718b9fcf5e524af962b83fff6e5fc33eefd94a25989c9ba35b2ad928f871fad68ceb7497047e3d5beb5dbf500907d347a07d0b5e913b0a0183c478a7c9125fb46c5e85238108345c5e8ea52785cc14aac18e2b9e2e09db0840341521c962386d8ae38d4fe188795c68a20579c6c074c80bf136440846e244aa890152bfbcbe24651295c7e18562266bae2d01b4f1c9542908d6374e91cae04cb9560a51c080bdb89658b857c6c981892e065a85d6814026caf2c248c971df4520040a9865dd9cfe28b81dd5c7f4655146b1fa925d2bfcfa762d95c1e8497b19fcd9a062601007f347a8bdbc3ce63c40a23a59a08399cd4472730850229832b80c4683fe3e359109b2b80b0b89e13700909180a874875f7f7a3bbf9f8792ca41038442a263e1e12b012e0d72553751ebc220200887d5a37bd1fd6b18542a972d3ba463fdbe5e9ef4f576014fd928bb7ea578ffd314a76712837aa6b546654d72b6322d5dbc38da6c0b0cef82db708708f67a00cebfa2bb73898d1fcdde941011ed8ae5582f2f90f7c8577efc8a53c88ea25f41433f810763e0c22db93cb8ec267c4c7f7d439c2bdcfab44f722d1f51a801b8565f21812892ba26e7a83a06aaa6ba30faf20f218dd09ee0df025f388d90a1698abd732cd3a01009d0374356aa2ea513f832485f52e57db32e260de9f3fab6ef7f78758514dcbd5ae8cd8d6f51e65608915d56c7c3c57c0e445b27aca0d1ec661f10909982f63783e832ba08b787287718818c25364766bbd7faee30700f0d3544dd0cb6e19b906c5e0dc4f0af817b1775e7cdd7cfc883d69a9f37dc91c09001839f0dc24c5dca41eeed059b1cd686eb895132d41718f55ca0d43bba74942be182e3f798cb2c988b9ca12208fa5af004b03986108180da66b754f573155512407c9a622e60d1a6c3444b9d2fbb3d32fdd6039817aba6fe590535090812a207bebbed1c848d9b47d0f3200f989479522aba1fb96a741aa9a6d5034718380468a6c7906a4e2d80ac5306730d0402b2d8f8f14049ba3f0870d01fd5331f795ddf1a8ec5e510a2da72f560e381905385e0bf4435f8c4645ca7eed501110a94655a22f96e740aa7ecd501ccd2a38d07262f5433c571ba8a7205637c4d9daa01f0a62342a52d88b0ef11bd5a84a14c4f21c485d2f3ac4eca1a01f8261f5435cab14574e23ac1cd01405385107a8af11560e8a438146280555a211460323b5bbe8d45d550b589146589e03a9d545735087010d35c1ea07a8440d0e9406180d8c94e4a28d1fae0b34d400cb732035b8688e34f53814487dd50fd007353850da5e3430526e6b8b329e8e019a697be52990f25a34c5cfea51f456f1f6159ea9a8f0cc1e0efaadda95bb032114b4e887951c75b115a976e56990425934cdc411407371aefa91ca518f06a5c1456323a5ad04940b1dea622bd0e0cab320b5a86896a37a4063d1acfab7dad091a01f2a57342a5293370d657bd948d07f95ab3c3c52498a86771e05faaf629587476a442d51f0e7d5819713a7caa323359fe8a7759a3ed048752acf80d4625aa3186eaac920a724ed2bbd53d04b8501e897c0531e19a9a344238f1d0dfa25e0ec6533421f8946ce56812cafca944746aa0f2d50c8930c417fd596ea8367ab06971753aaff54696204d4d34aaabb9a842b0554a49544a322558ae8dde705d5a80ab4927d596d86b27ae118d02fe5a3dc3307a22186be0e0bd4c1edad7c942740b697d0c5913b05f4b7cba6fe0ea1c41ca8dfaf428322bb47e890e84c059af4abfab2da1265758a1a04bd5b5268746403c809657e93fae8ca5a52bdde1e211a3bd351648916e0ab3a4cbd1e35109d1a34d3584bf0556d23792664bf02cd74ac1f4c8adea9ab5f08865640836e081a1dd9a040fb11a13eba5ab9417624d04cbff783499ddc207b086826a635f8aa7e475fb9b145e566820dd0b44381a640760c9c51ceacee2785a20e853c1bb2478066ebd4848da4984d59dfa1ebc70080d951b6407517e28be98afa105fc04e2803530b4b1f85f5af022cb56086a1603ced80a2ae84f2e95aa8e929ddd37b4d55d687f832f5826c2a629ef650d9080dd040963100bfd9c9befd3f0000ffff5311883694460000"); err != nil { panic(err) } } diff --git a/os/gsession/gsession_unit_storage_redis_hashtable_test.go b/os/gsession/gsession_unit_storage_redis_hashtable_test.go index 81c6f140a..f9f6cd3eb 100644 --- a/os/gsession/gsession_unit_storage_redis_hashtable_test.go +++ b/os/gsession/gsession_unit_storage_redis_hashtable_test.go @@ -18,7 +18,9 @@ import ( func Test_StorageRedisHashTable(t *testing.T) { redis, err := gredis.NewFromStr("127.0.0.1:6379,0") - t.Assert(err, nil) + gtest.C(t, func(t *gtest.T) { + t.Assert(err, nil) + }) storage := gsession.NewStorageRedisHashTable(redis) manager := gsession.New(time.Second, storage) @@ -78,7 +80,9 @@ func Test_StorageRedisHashTable(t *testing.T) { func Test_StorageRedisHashTablePrefix(t *testing.T) { redis, err := gredis.NewFromStr("127.0.0.1:6379,0") - t.Assert(err, nil) + gtest.C(t, func(t *gtest.T) { + t.Assert(err, nil) + }) prefix := "s_" storage := gsession.NewStorageRedisHashTable(redis, prefix) diff --git a/os/gsession/gsession_unit_storage_redis_test.go b/os/gsession/gsession_unit_storage_redis_test.go index 79f1aa61e..278c404ea 100644 --- a/os/gsession/gsession_unit_storage_redis_test.go +++ b/os/gsession/gsession_unit_storage_redis_test.go @@ -18,7 +18,7 @@ import ( func Test_StorageRedis(t *testing.T) { redis, err := gredis.NewFromStr("127.0.0.1:6379,0") - t.Assert(err, nil) + gtest.Assert(err, nil) storage := gsession.NewStorageRedis(redis) manager := gsession.New(time.Second, storage) @@ -79,7 +79,7 @@ func Test_StorageRedis(t *testing.T) { func Test_StorageRedisPrefix(t *testing.T) { redis, err := gredis.NewFromStr("127.0.0.1:6379,0") - t.Assert(err, nil) + gtest.Assert(err, nil) prefix := "s_" storage := gsession.NewStorageRedis(redis, prefix) diff --git a/os/gtime/gtime_z_unit_json_test.go b/os/gtime/gtime_z_unit_json_test.go index 39c0bde61..0c5c07592 100644 --- a/os/gtime/gtime_z_unit_json_test.go +++ b/os/gtime/gtime_z_unit_json_test.go @@ -19,10 +19,10 @@ func Test_Json_Pointer(t *testing.T) { type T struct { Time *gtime.Time } - t := new(T) + t1 := new(T) s := "2006-01-02 15:04:05" - t.Time = gtime.NewFromStr(s) - j, err := json.Marshal(t) + t1.Time = gtime.NewFromStr(s) + j, err := json.Marshal(t1) t.Assert(err, nil) t.Assert(j, `{"Time":"2006-01-02 15:04:05"}`) }) @@ -31,8 +31,8 @@ func Test_Json_Pointer(t *testing.T) { type T struct { Time *gtime.Time } - t := new(T) - j, err := json.Marshal(t) + t1 := new(T) + j, err := json.Marshal(t1) t.Assert(err, nil) t.Assert(j, `{"Time":null}`) }) @@ -41,18 +41,18 @@ func Test_Json_Pointer(t *testing.T) { type T struct { Time *gtime.Time `json:"time,omitempty"` } - t := new(T) - j, err := json.Marshal(t) + t1 := new(T) + j, err := json.Marshal(t1) t.Assert(err, nil) t.Assert(j, `{}`) }) // Unmarshal gtest.C(t, func(t *gtest.T) { - var t gtime.Time + var t1 gtime.Time s := []byte(`"2006-01-02 15:04:05"`) - err := json.Unmarshal(s, &t) + err := json.Unmarshal(s, &t1) t.Assert(err, nil) - t.Assert(t.String(), "2006-01-02 15:04:05") + t.Assert(t1.String(), "2006-01-02 15:04:05") }) } @@ -62,10 +62,10 @@ func Test_Json_Struct(t *testing.T) { type T struct { Time gtime.Time } - t := new(T) + t1 := new(T) s := "2006-01-02 15:04:05" - t.Time = *gtime.NewFromStr(s) - j, err := json.Marshal(t) + t1.Time = *gtime.NewFromStr(s) + j, err := json.Marshal(t1) t.Assert(err, nil) t.Assert(j, `{"Time":"2006-01-02 15:04:05"}`) }) @@ -74,8 +74,8 @@ func Test_Json_Struct(t *testing.T) { type T struct { Time gtime.Time } - t := new(T) - j, err := json.Marshal(t) + t1 := new(T) + j, err := json.Marshal(t1) t.Assert(err, nil) t.Assert(j, `{"Time":""}`) }) @@ -84,8 +84,8 @@ func Test_Json_Struct(t *testing.T) { type T struct { Time gtime.Time `json:"time,omitempty"` } - t := new(T) - j, err := json.Marshal(t) + t1 := new(T) + j, err := json.Marshal(t1) t.Assert(err, nil) t.Assert(j, `{"time":""}`) }) diff --git a/os/gtime/gtime_z_unit_time_test.go b/os/gtime/gtime_z_unit_time_test.go index 405e84d18..35fb0a4f8 100644 --- a/os/gtime/gtime_z_unit_time_test.go +++ b/os/gtime/gtime_z_unit_time_test.go @@ -28,12 +28,12 @@ func Test_New(t *testing.T) { func Test_Nil(t *testing.T) { gtest.C(t, func(t *gtest.T) { - var t *gtime.Time - t.Assert(t.String(), "") + var t1 *gtime.Time + t.Assert(t1.String(), "") }) gtest.C(t, func(t *gtest.T) { - var t gtime.Time - t.Assert(t.String(), "") + var t1 gtime.Time + t.Assert(t1.String(), "") }) } diff --git a/os/gtimer/gtimer_z_unit_2_test.go b/os/gtimer/gtimer_z_unit_2_test.go index 7c34f357e..dce9aed39 100644 --- a/os/gtimer/gtimer_z_unit_2_test.go +++ b/os/gtimer/gtimer_z_unit_2_test.go @@ -18,60 +18,68 @@ import ( ) func TestEntry_Start_Stop_Close(t *testing.T) { - timer := New() - array := garray.New(true) - entry := timer.Add(200*time.Millisecond, func() { - array.Append(1) - }) - time.Sleep(250 * time.Millisecond) - t.Assert(array.Len(), 1) - entry.Stop() - time.Sleep(250 * time.Millisecond) - t.Assert(array.Len(), 1) - entry.Start() - time.Sleep(250 * time.Millisecond) - t.Assert(array.Len(), 2) - entry.Close() - time.Sleep(250 * time.Millisecond) - t.Assert(array.Len(), 2) + gtest.C(t, func(t *gtest.T) { + timer := New() + array := garray.New(true) + entry := timer.Add(200*time.Millisecond, func() { + array.Append(1) + }) + time.Sleep(250 * time.Millisecond) + t.Assert(array.Len(), 1) + entry.Stop() + time.Sleep(250 * time.Millisecond) + t.Assert(array.Len(), 1) + entry.Start() + time.Sleep(250 * time.Millisecond) + t.Assert(array.Len(), 2) + entry.Close() + time.Sleep(250 * time.Millisecond) + t.Assert(array.Len(), 2) - t.Assert(entry.Status(), gtimer.STATUS_CLOSED) + t.Assert(entry.Status(), gtimer.STATUS_CLOSED) + }) } func TestEntry_Singleton(t *testing.T) { - timer := New() - array := garray.New(true) - entry := timer.Add(200*time.Millisecond, func() { - array.Append(1) - time.Sleep(10 * time.Second) - }) - t.Assert(entry.IsSingleton(), false) - entry.SetSingleton(true) - t.Assert(entry.IsSingleton(), true) - time.Sleep(250 * time.Millisecond) - t.Assert(array.Len(), 1) + gtest.C(t, func(t *gtest.T) { + timer := New() + array := garray.New(true) + entry := timer.Add(200*time.Millisecond, func() { + array.Append(1) + time.Sleep(10 * time.Second) + }) + t.Assert(entry.IsSingleton(), false) + entry.SetSingleton(true) + t.Assert(entry.IsSingleton(), true) + time.Sleep(250 * time.Millisecond) + t.Assert(array.Len(), 1) - time.Sleep(250 * time.Millisecond) - t.Assert(array.Len(), 1) + time.Sleep(250 * time.Millisecond) + t.Assert(array.Len(), 1) + }) } func TestEntry_SetTimes(t *testing.T) { - timer := New() - array := garray.New(true) - entry := timer.Add(200*time.Millisecond, func() { - array.Append(1) + gtest.C(t, func(t *gtest.T) { + timer := New() + array := garray.New(true) + entry := timer.Add(200*time.Millisecond, func() { + array.Append(1) + }) + entry.SetTimes(2) + time.Sleep(1200 * time.Millisecond) + t.Assert(array.Len(), 2) }) - entry.SetTimes(2) - time.Sleep(1200 * time.Millisecond) - t.Assert(array.Len(), 2) } func TestEntry_Run(t *testing.T) { - timer := New() - array := garray.New(true) - entry := timer.Add(1000*time.Millisecond, func() { - array.Append(1) + gtest.C(t, func(t *gtest.T) { + timer := New() + array := garray.New(true) + entry := timer.Add(1000*time.Millisecond, func() { + array.Append(1) + }) + entry.Run() + t.Assert(array.Len(), 1) }) - entry.Run() - t.Assert(array.Len(), 1) } diff --git a/test/gtest/gtest_t.go b/test/gtest/gtest_t.go index b4b522cdd..acdd8989c 100644 --- a/test/gtest/gtest_t.go +++ b/test/gtest/gtest_t.go @@ -12,7 +12,7 @@ import ( // T is the testing unit case management object. type T struct { - T *testing.T + *testing.T } // Assert checks and EQUAL. diff --git a/text/gstr/gstr_z_unit_parse_test.go b/text/gstr/gstr_z_unit_parse_test.go index fed8ae01d..d2e414ca7 100644 --- a/text/gstr/gstr_z_unit_parse_test.go +++ b/text/gstr/gstr_z_unit_parse_test.go @@ -18,20 +18,18 @@ import ( ) func Test_Parse(t *testing.T) { + // url gtest.C(t, func(t *gtest.T) { - // url - gtest.C(t, func(t *gtest.T) { - s := "goframe.org/index?name=john&score=100" - u, err := url.Parse(s) - t.Assert(err, nil) - m, err := gstr.Parse(u.RawQuery) - t.Assert(err, nil) - t.Assert(m["name"], "john") - t.Assert(m["score"], "100") - }) + s := "goframe.org/index?name=john&score=100" + u, err := url.Parse(s) + t.Assert(err, nil) + m, err := gstr.Parse(u.RawQuery) + t.Assert(err, nil) + t.Assert(m["name"], "john") + t.Assert(m["score"], "100") // name overwrite - m, err := gstr.Parse("a=1&a=2") + m, err = gstr.Parse("a=1&a=2") t.Assert(err, nil) t.Assert(m, g.Map{ "a": 2, diff --git a/util/gvalid/gvalid_unit_customerror_test.go b/util/gvalid/gvalid_unit_customerror_test.go index 894d59d4f..7e7ef3908 100755 --- a/util/gvalid/gvalid_unit_customerror_test.go +++ b/util/gvalid/gvalid_unit_customerror_test.go @@ -15,23 +15,27 @@ import ( ) func Test_Map(t *testing.T) { - rule := "ipv4" - val := "0.0.0" - msg := map[string]string{ - "ipv4": "IPv4地址格式不正确", - } + gtest.C(t, func(t *gtest.T) { + rule := "ipv4" + val := "0.0.0" + msg := map[string]string{ + "ipv4": "IPv4地址格式不正确", + } - err := gvalid.Check(val, rule, nil) - t.Assert(err.Map(), msg) + err := gvalid.Check(val, rule, nil) + t.Assert(err.Map(), msg) + }) } func Test_FirstString(t *testing.T) { - rule := "ipv4" - val := "0.0.0" + gtest.C(t, func(t *gtest.T) { + rule := "ipv4" + val := "0.0.0" - err := gvalid.Check(val, rule, nil) - n := err.FirstString() - t.Assert(n, "IPv4地址格式不正确") + err := gvalid.Check(val, rule, nil) + n := err.FirstString() + t.Assert(n, "IPv4地址格式不正确") + }) } func Test_SetDefaultErrorMsgs(t *testing.T) { From f18e6f078c67832419a7ea5b7eb62322bcce1326 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 20 Mar 2020 08:49:40 +0800 Subject: [PATCH 8/9] improve unit testing cases --- .../garray/garray_z_unit_all_basic_test.go | 124 +++++++++-------- .../garray_z_unit_sorted_any_array_test.go | 18 +-- .../garray_z_unit_sorted_int_array_test.go | 18 +-- .../garray_z_unit_sorted_str_array_test.go | 18 +-- container/gmap/gmap_z_basic_test.go | 119 +++++++++-------- container/gpool/gpool_z_unit_test.go | 2 +- container/gtree/gtree_z_redblack_tree_test.go | 60 +++++---- container/gvar/gvar_z_unit_test.go | 10 +- database/gdb/gdb_unit_init_test.go | 2 +- database/gdb/gdb_unit_z_mysql_model_test.go | 26 ++-- .../gdb/gdb_unit_z_mysql_transaction_test.go | 2 +- encoding/gbinary/gbinary_z_le_test.go | 126 +++++++++--------- encoding/gurl/url_test.go | 17 +-- net/gtcp/gtcp_unit_pkg_test.go | 4 +- net/gtcp/gtcp_unit_pool_pkg_test.go | 4 +- 15 files changed, 294 insertions(+), 256 deletions(-) diff --git a/container/garray/garray_z_unit_all_basic_test.go b/container/garray/garray_z_unit_all_basic_test.go index af6e56837..faeaa960d 100644 --- a/container/garray/garray_z_unit_all_basic_test.go +++ b/container/garray/garray_z_unit_all_basic_test.go @@ -18,81 +18,95 @@ import ( ) func Test_IntArray_Unique(t *testing.T) { - expect := []int{1, 2, 3, 4, 5, 6} - array := garray.NewIntArray() - array.Append(1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6) - array.Unique() - t.Assert(array.Slice(), expect) + gtest.C(t, func(t *gtest.T) { + expect := []int{1, 2, 3, 4, 5, 6} + array := garray.NewIntArray() + array.Append(1, 1, 2, 3, 3, 4, 4, 5, 5, 6, 6) + array.Unique() + t.Assert(array.Slice(), expect) + }) } func Test_SortedIntArray1(t *testing.T) { - expect := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - array := garray.NewSortedIntArray() - for i := 10; i > -1; i-- { - array.Add(i) - } - t.Assert(array.Slice(), expect) - t.Assert(array.Add().Slice(), expect) + gtest.C(t, func(t *gtest.T) { + expect := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + array := garray.NewSortedIntArray() + for i := 10; i > -1; i-- { + array.Add(i) + } + t.Assert(array.Slice(), expect) + t.Assert(array.Add().Slice(), expect) + }) } func Test_SortedIntArray2(t *testing.T) { - expect := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - array := garray.NewSortedIntArray() - for i := 0; i <= 10; i++ { - array.Add(i) - } - t.Assert(array.Slice(), expect) + gtest.C(t, func(t *gtest.T) { + expect := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + array := garray.NewSortedIntArray() + for i := 0; i <= 10; i++ { + array.Add(i) + } + t.Assert(array.Slice(), expect) + }) } func Test_SortedStrArray1(t *testing.T) { - expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"} - array1 := garray.NewSortedStrArray() - array2 := garray.NewSortedStrArray(true) - for i := 10; i > -1; i-- { - array1.Add(gconv.String(i)) - array2.Add(gconv.String(i)) - } - t.Assert(array1.Slice(), expect) - t.Assert(array2.Slice(), expect) + gtest.C(t, func(t *gtest.T) { + expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"} + array1 := garray.NewSortedStrArray() + array2 := garray.NewSortedStrArray(true) + for i := 10; i > -1; i-- { + array1.Add(gconv.String(i)) + array2.Add(gconv.String(i)) + } + t.Assert(array1.Slice(), expect) + t.Assert(array2.Slice(), expect) + }) } func Test_SortedStrArray2(t *testing.T) { - expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"} - array := garray.NewSortedStrArray() - for i := 0; i <= 10; i++ { - array.Add(gconv.String(i)) - } - t.Assert(array.Slice(), expect) - array.Add() - t.Assert(array.Slice(), expect) + gtest.C(t, func(t *gtest.T) { + expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"} + array := garray.NewSortedStrArray() + for i := 0; i <= 10; i++ { + array.Add(gconv.String(i)) + } + t.Assert(array.Slice(), expect) + array.Add() + t.Assert(array.Slice(), expect) + }) } func Test_SortedArray1(t *testing.T) { - expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"} - array := garray.NewSortedArray(func(v1, v2 interface{}) int { - return strings.Compare(gconv.String(v1), gconv.String(v2)) + gtest.C(t, func(t *gtest.T) { + expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"} + array := garray.NewSortedArray(func(v1, v2 interface{}) int { + return strings.Compare(gconv.String(v1), gconv.String(v2)) + }) + for i := 10; i > -1; i-- { + array.Add(gconv.String(i)) + } + t.Assert(array.Slice(), expect) }) - for i := 10; i > -1; i-- { - array.Add(gconv.String(i)) - } - t.Assert(array.Slice(), expect) } func Test_SortedArray2(t *testing.T) { - expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"} - func1 := func(v1, v2 interface{}) int { - return strings.Compare(gconv.String(v1), gconv.String(v2)) - } - array := garray.NewSortedArray(func1) - array2 := garray.NewSortedArray(func1, true) - for i := 0; i <= 10; i++ { - array.Add(gconv.String(i)) - array2.Add(gconv.String(i)) - } - t.Assert(array.Slice(), expect) - t.Assert(array.Add().Slice(), expect) - t.Assert(array2.Slice(), expect) + gtest.C(t, func(t *gtest.T) { + expect := []string{"0", "1", "10", "2", "3", "4", "5", "6", "7", "8", "9"} + func1 := func(v1, v2 interface{}) int { + return strings.Compare(gconv.String(v1), gconv.String(v2)) + } + array := garray.NewSortedArray(func1) + array2 := garray.NewSortedArray(func1, true) + for i := 0; i <= 10; i++ { + array.Add(gconv.String(i)) + array2.Add(gconv.String(i)) + } + t.Assert(array.Slice(), expect) + t.Assert(array.Add().Slice(), expect) + t.Assert(array2.Slice(), expect) + }) } func TestNewFromCopy(t *testing.T) { diff --git a/container/garray/garray_z_unit_sorted_any_array_test.go b/container/garray/garray_z_unit_sorted_any_array_test.go index 2946ca5ad..ac863decd 100644 --- a/container/garray/garray_z_unit_sorted_any_array_test.go +++ b/container/garray/garray_z_unit_sorted_any_array_test.go @@ -679,31 +679,31 @@ func TestSortedArray_RemoveValue(t *testing.T) { } func TestSortedArray_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Array *garray.SortedArray } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`[2,3,1]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "array": g.Slice{2, 3, 1}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) }) } diff --git a/container/garray/garray_z_unit_sorted_int_array_test.go b/container/garray/garray_z_unit_sorted_int_array_test.go index 26542fff4..cd4e29ae9 100644 --- a/container/garray/garray_z_unit_sorted_int_array_test.go +++ b/container/garray/garray_z_unit_sorted_int_array_test.go @@ -560,31 +560,31 @@ func TestSortedIntArray_RemoveValue(t *testing.T) { } func TestSortedIntArray_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Array *garray.SortedIntArray } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`[2,3,1]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "array": g.Slice{2, 3, 1}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.Slice{1, 2, 3}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) }) } diff --git a/container/garray/garray_z_unit_sorted_str_array_test.go b/container/garray/garray_z_unit_sorted_str_array_test.go index fd1e75cbe..94b5f255e 100644 --- a/container/garray/garray_z_unit_sorted_str_array_test.go +++ b/container/garray/garray_z_unit_sorted_str_array_test.go @@ -569,31 +569,31 @@ func TestSortedStrArray_RemoveValue(t *testing.T) { } func TestSortedStrArray_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Array *garray.SortedStrArray } // JSON gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "array": []byte(`["1","3","2"]`), - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"}) }) // Map gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(g.Map{ "name": "john", "array": g.SliceStr{"1", "3", "2"}, - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Array.Slice(), g.SliceStr{"1", "2", "3"}) + t.Assert(v.Name, "john") + t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"}) }) } diff --git a/container/gmap/gmap_z_basic_test.go b/container/gmap/gmap_z_basic_test.go index b847e2809..383a3f4f5 100644 --- a/container/gmap/gmap_z_basic_test.go +++ b/container/gmap/gmap_z_basic_test.go @@ -52,75 +52,86 @@ func Test_Map_Basic(t *testing.T) { }) } func Test_Map_Set_Fun(t *testing.T) { - m := gmap.New() - m.GetOrSetFunc("fun", getValue) - m.GetOrSetFuncLock("funlock", getValue) - t.Assert(m.Get("funlock"), 3) - t.Assert(m.Get("fun"), 3) - m.GetOrSetFunc("fun", getValue) - t.Assert(m.SetIfNotExistFunc("fun", getValue), false) - t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + gtest.C(t, func(t *gtest.T) { + m := gmap.New() + m.GetOrSetFunc("fun", getValue) + m.GetOrSetFuncLock("funlock", getValue) + t.Assert(m.Get("funlock"), 3) + t.Assert(m.Get("fun"), 3) + m.GetOrSetFunc("fun", getValue) + t.Assert(m.SetIfNotExistFunc("fun", getValue), false) + t.Assert(m.SetIfNotExistFuncLock("funlock", getValue), false) + }) } func Test_Map_Batch(t *testing.T) { - m := gmap.New() - m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - m.Removes([]interface{}{"key1", 1}) - t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + gtest.C(t, func(t *gtest.T) { + m := gmap.New() + m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + m.Removes([]interface{}{"key1", 1}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + }) } func Test_Map_Iterator(t *testing.T) { - expect := map[interface{}]interface{}{1: 1, "key1": "val1"} + gtest.C(t, func(t *gtest.T) { + expect := map[interface{}]interface{}{1: 1, "key1": "val1"} - m := gmap.NewFrom(expect) - m.Iterator(func(k interface{}, v interface{}) bool { - t.Assert(expect[k], v) - return true + m := gmap.NewFrom(expect) + m.Iterator(func(k interface{}, v interface{}) bool { + t.Assert(expect[k], v) + return true + }) + // 断言返回值对遍历控制 + i := 0 + j := 0 + m.Iterator(func(k interface{}, v interface{}) bool { + i++ + return true + }) + m.Iterator(func(k interface{}, v interface{}) bool { + j++ + return false + }) + t.Assert(i, 2) + t.Assert(j, 1) }) - // 断言返回值对遍历控制 - i := 0 - j := 0 - m.Iterator(func(k interface{}, v interface{}) bool { - i++ - return true - }) - m.Iterator(func(k interface{}, v interface{}) bool { - j++ - return false - }) - t.Assert(i, 2) - t.Assert(j, 1) } func Test_Map_Lock(t *testing.T) { - expect := map[interface{}]interface{}{1: 1, "key1": "val1"} - - m := gmap.NewFrom(expect) - m.LockFunc(func(m map[interface{}]interface{}) { - t.Assert(m, expect) - }) - m.RLockFunc(func(m map[interface{}]interface{}) { - t.Assert(m, expect) + gtest.C(t, func(t *gtest.T) { + expect := map[interface{}]interface{}{1: 1, "key1": "val1"} + m := gmap.NewFrom(expect) + m.LockFunc(func(m map[interface{}]interface{}) { + t.Assert(m, expect) + }) + m.RLockFunc(func(m map[interface{}]interface{}) { + t.Assert(m, expect) + }) }) } func Test_Map_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gmap.NewFrom(map[interface{}]interface{}{1: 1, "key1": "val1"}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gmap.NewFrom(map[interface{}]interface{}{1: 1, "key1": "val1"}) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove("key1") - //修改clone map,原 map 不影响 - t.AssertIN("key1", m.Keys()) + m_clone.Remove("key1") + //修改clone map,原 map 不影响 + t.AssertIN("key1", m.Keys()) + }) } func Test_Map_Basic_Merge(t *testing.T) { - m1 := gmap.New() - m2 := gmap.New() - m1.Set("key1", "val1") - m2.Set("key2", "val2") - m1.Merge(m2) - t.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"}) + gtest.C(t, func(t *gtest.T) { + m1 := gmap.New() + m2 := gmap.New() + m1.Set("key1", "val1") + m2.Set("key2", "val2") + m1.Merge(m2) + t.Assert(m1.Map(), map[interface{}]interface{}{"key1": "val1", "key2": "val2"}) + }) } diff --git a/container/gpool/gpool_z_unit_test.go b/container/gpool/gpool_z_unit_test.go index c3bdbdf03..cca547339 100644 --- a/container/gpool/gpool_z_unit_test.go +++ b/container/gpool/gpool_z_unit_test.go @@ -24,7 +24,7 @@ var nf gpool.NewFunc = func() (i interface{}, e error) { var assertIndex int = 0 var ef gpool.ExpireFunc = func(i interface{}) { assertIndex++ - t.Assert(i, assertIndex) + gtest.Assert(i, assertIndex) } func Test_Gpool(t *testing.T) { diff --git a/container/gtree/gtree_z_redblack_tree_test.go b/container/gtree/gtree_z_redblack_tree_test.go index dbb7bc50d..37dee0c9c 100644 --- a/container/gtree/gtree_z_redblack_tree_test.go +++ b/container/gtree/gtree_z_redblack_tree_test.go @@ -104,11 +104,13 @@ func Test_RedBlackTree_Get_Set_Var(t *testing.T) { } func Test_RedBlackTree_Batch(t *testing.T) { - m := gtree.NewRedBlackTree(gutil.ComparatorString) - m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) - m.Removes([]interface{}{"key1", 1}) - t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + gtest.C(t, func(t *gtest.T) { + m := gtree.NewRedBlackTree(gutil.ComparatorString) + m.Sets(map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + t.Assert(m.Map(), map[interface{}]interface{}{1: 1, "key1": "val1", "key2": "val2", "key3": "val3"}) + m.Removes([]interface{}{"key1", 1}) + t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) + }) } func Test_RedBlackTree_Iterator(t *testing.T) { @@ -117,22 +119,24 @@ func Test_RedBlackTree_Iterator(t *testing.T) { index := 0 expect := map[interface{}]interface{}{"key4": "val4", 1: 1, "key1": "val1", "key2": "val2", "key3": "val3"} - m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, expect) - m.Iterator(func(k interface{}, v interface{}) bool { - t.Assert(k, keys[index]) - index++ - t.Assert(expect[k], v) - return true - }) - m.IteratorDesc(func(k interface{}, v interface{}) bool { - index-- - t.Assert(k, keys[index]) - t.Assert(expect[k], v) - return true - }) + gtest.C(t, func(t *gtest.T) { + m.Iterator(func(k interface{}, v interface{}) bool { + t.Assert(k, keys[index]) + index++ + t.Assert(expect[k], v) + return true + }) + + m.IteratorDesc(func(k interface{}, v interface{}) bool { + index-- + t.Assert(k, keys[index]) + t.Assert(expect[k], v) + return true + }) + }) m.Print() // 断言返回值对遍历控制 gtest.C(t, func(t *gtest.T) { @@ -201,16 +205,18 @@ func Test_RedBlackTree_IteratorFrom(t *testing.T) { } func Test_RedBlackTree_Clone(t *testing.T) { - //clone 方法是深克隆 - m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) - m_clone := m.Clone() - m.Remove(1) - //修改原 map,clone 后的 map 不影响 - t.AssertIN(1, m_clone.Keys()) + gtest.C(t, func(t *gtest.T) { + //clone 方法是深克隆 + m := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, map[interface{}]interface{}{1: 1, "key1": "val1"}) + m_clone := m.Clone() + m.Remove(1) + //修改原 map,clone 后的 map 不影响 + t.AssertIN(1, m_clone.Keys()) - m_clone.Remove("key1") - //修改clone map,原 map 不影响 - t.AssertIN("key1", m.Keys()) + m_clone.Remove("key1") + //修改clone map,原 map 不影响 + t.AssertIN("key1", m.Keys()) + }) } func Test_RedBlackTree_LRNode(t *testing.T) { diff --git a/container/gvar/gvar_z_unit_test.go b/container/gvar/gvar_z_unit_test.go index f12f615eb..b0c9b370b 100644 --- a/container/gvar/gvar_z_unit_test.go +++ b/container/gvar/gvar_z_unit_test.go @@ -390,18 +390,18 @@ func Test_Json(t *testing.T) { } func Test_UnmarshalValue(t *testing.T) { - type T struct { + type V struct { Name string Var *gvar.Var } gtest.C(t, func(t *gtest.T) { - var t *T + var v *V err := gconv.Struct(map[string]interface{}{ "name": "john", "var": "v", - }, &t) + }, &v) t.Assert(err, nil) - t.Assert(t.Name, "john") - t.Assert(t.Var.String(), "v") + t.Assert(v.Name, "john") + t.Assert(v.Var.String(), "v") }) } diff --git a/database/gdb/gdb_unit_init_test.go b/database/gdb/gdb_unit_init_test.go index 24f1bd3df..2879fe6ab 100644 --- a/database/gdb/gdb_unit_init_test.go +++ b/database/gdb/gdb_unit_init_test.go @@ -36,7 +36,7 @@ func init() { "name": true, "type": true, }, false) - t.Assert(err, nil) + gtest.Assert(err, nil) configNode = gdb.ConfigNode{ Host: "127.0.0.1", Port: "3306", diff --git a/database/gdb/gdb_unit_z_mysql_model_test.go b/database/gdb/gdb_unit_z_mysql_model_test.go index 37adfbb05..73c94362f 100644 --- a/database/gdb/gdb_unit_z_mysql_model_test.go +++ b/database/gdb/gdb_unit_z_mysql_model_test.go @@ -1510,23 +1510,25 @@ func Test_Model_Delete(t *testing.T) { func Test_Model_Offset(t *testing.T) { table := createInitTable() defer dropTable(table) - - result, err := db.Table(table).Limit(2).Offset(5).Order("id").Select() - t.Assert(err, nil) - t.Assert(len(result), 2) - t.Assert(result[0]["id"], 6) - tgit.Assert(result[1]["id"], 7) + gtest.C(t, func(t *gtest.T) { + result, err := db.Table(table).Limit(2).Offset(5).Order("id").Select() + t.Assert(err, nil) + t.Assert(len(result), 2) + t.Assert(result[0]["id"], 6) + t.Assert(result[1]["id"], 7) + }) } func Test_Model_ForPage(t *testing.T) { table := createInitTable() defer dropTable(table) - - result, err := db.Table(table).ForPage(3, 3).Order("id").Select() - t.Assert(err, nil) - t.Assert(len(result), 3) - t.Assert(result[0]["id"], 7) - t.Assert(result[1]["id"], 8) + gtest.C(t, func(t *gtest.T) { + result, err := db.Table(table).Page(3, 3).Order("id").All() + t.Assert(err, nil) + t.Assert(len(result), 3) + t.Assert(result[0]["id"], 7) + t.Assert(result[1]["id"], 8) + }) } func Test_Model_Option_Map(t *testing.T) { diff --git a/database/gdb/gdb_unit_z_mysql_transaction_test.go b/database/gdb/gdb_unit_z_mysql_transaction_test.go index a90849abe..3dd776fbf 100644 --- a/database/gdb/gdb_unit_z_mysql_transaction_test.go +++ b/database/gdb/gdb_unit_z_mysql_transaction_test.go @@ -102,7 +102,7 @@ func Test_TX_Prepare(t *testing.T) { if err != nil { gtest.Error(err) } - t.Assert(array[0], "100") + gtest.Assert(array[0], "100") if err := rows.Close(); err != nil { gtest.Error(err) } diff --git a/encoding/gbinary/gbinary_z_le_test.go b/encoding/gbinary/gbinary_z_le_test.go index f534248e6..a25528b69 100644 --- a/encoding/gbinary/gbinary_z_le_test.go +++ b/encoding/gbinary/gbinary_z_le_test.go @@ -14,71 +14,75 @@ import ( ) func Test_LeEncodeAndLeDecode(t *testing.T) { - for k, v := range testData { - ve := gbinary.LeEncode(v) - ve1 := gbinary.LeEncodeByLength(len(ve), v) + gtest.C(t, func(t *gtest.T) { + for k, v := range testData { + ve := gbinary.LeEncode(v) + ve1 := gbinary.LeEncodeByLength(len(ve), v) - //t.Logf("%s:%v, encoded:%v\n", k, v, ve) - switch v.(type) { - case int: - t.Assert(gbinary.LeDecodeToInt(ve), v) - t.Assert(gbinary.LeDecodeToInt(ve1), v) - case int8: - t.Assert(gbinary.LeDecodeToInt8(ve), v) - t.Assert(gbinary.LeDecodeToInt8(ve1), v) - case int16: - t.Assert(gbinary.LeDecodeToInt16(ve), v) - t.Assert(gbinary.LeDecodeToInt16(ve1), v) - case int32: - t.Assert(gbinary.LeDecodeToInt32(ve), v) - t.Assert(gbinary.LeDecodeToInt32(ve1), v) - case int64: - t.Assert(gbinary.LeDecodeToInt64(ve), v) - t.Assert(gbinary.LeDecodeToInt64(ve1), v) - case uint: - t.Assert(gbinary.LeDecodeToUint(ve), v) - t.Assert(gbinary.LeDecodeToUint(ve1), v) - case uint8: - t.Assert(gbinary.LeDecodeToUint8(ve), v) - t.Assert(gbinary.LeDecodeToUint8(ve1), v) - case uint16: - t.Assert(gbinary.LeDecodeToUint16(ve1), v) - t.Assert(gbinary.LeDecodeToUint16(ve), v) - case uint32: - t.Assert(gbinary.LeDecodeToUint32(ve1), v) - t.Assert(gbinary.LeDecodeToUint32(ve), v) - case uint64: - t.Assert(gbinary.LeDecodeToUint64(ve), v) - t.Assert(gbinary.LeDecodeToUint64(ve1), v) - case bool: - t.Assert(gbinary.LeDecodeToBool(ve), v) - t.Assert(gbinary.LeDecodeToBool(ve1), v) - case string: - t.Assert(gbinary.LeDecodeToString(ve), v) - t.Assert(gbinary.LeDecodeToString(ve1), v) - case float32: - t.Assert(gbinary.LeDecodeToFloat32(ve), v) - t.Assert(gbinary.LeDecodeToFloat32(ve1), v) - case float64: - t.Assert(gbinary.LeDecodeToFloat64(ve), v) - t.Assert(gbinary.LeDecodeToFloat64(ve1), v) - default: - if v == nil { - continue + //t.Logf("%s:%v, encoded:%v\n", k, v, ve) + switch v.(type) { + case int: + t.Assert(gbinary.LeDecodeToInt(ve), v) + t.Assert(gbinary.LeDecodeToInt(ve1), v) + case int8: + t.Assert(gbinary.LeDecodeToInt8(ve), v) + t.Assert(gbinary.LeDecodeToInt8(ve1), v) + case int16: + t.Assert(gbinary.LeDecodeToInt16(ve), v) + t.Assert(gbinary.LeDecodeToInt16(ve1), v) + case int32: + t.Assert(gbinary.LeDecodeToInt32(ve), v) + t.Assert(gbinary.LeDecodeToInt32(ve1), v) + case int64: + t.Assert(gbinary.LeDecodeToInt64(ve), v) + t.Assert(gbinary.LeDecodeToInt64(ve1), v) + case uint: + t.Assert(gbinary.LeDecodeToUint(ve), v) + t.Assert(gbinary.LeDecodeToUint(ve1), v) + case uint8: + t.Assert(gbinary.LeDecodeToUint8(ve), v) + t.Assert(gbinary.LeDecodeToUint8(ve1), v) + case uint16: + t.Assert(gbinary.LeDecodeToUint16(ve1), v) + t.Assert(gbinary.LeDecodeToUint16(ve), v) + case uint32: + t.Assert(gbinary.LeDecodeToUint32(ve1), v) + t.Assert(gbinary.LeDecodeToUint32(ve), v) + case uint64: + t.Assert(gbinary.LeDecodeToUint64(ve), v) + t.Assert(gbinary.LeDecodeToUint64(ve1), v) + case bool: + t.Assert(gbinary.LeDecodeToBool(ve), v) + t.Assert(gbinary.LeDecodeToBool(ve1), v) + case string: + t.Assert(gbinary.LeDecodeToString(ve), v) + t.Assert(gbinary.LeDecodeToString(ve1), v) + case float32: + t.Assert(gbinary.LeDecodeToFloat32(ve), v) + t.Assert(gbinary.LeDecodeToFloat32(ve1), v) + case float64: + t.Assert(gbinary.LeDecodeToFloat64(ve), v) + t.Assert(gbinary.LeDecodeToFloat64(ve1), v) + default: + if v == nil { + continue + } + res := make([]byte, len(ve)) + err := gbinary.LeDecode(ve, res) + if err != nil { + t.Errorf("test data: %s, %v, error:%v", k, v, err) + } + t.Assert(res, v) } - res := make([]byte, len(ve)) - err := gbinary.LeDecode(ve, res) - if err != nil { - t.Errorf("test data: %s, %v, error:%v", k, v, err) - } - t.Assert(res, v) } - } + }) } func Test_LeEncodeStruct(t *testing.T) { - user := User{"wenzi1", 999, "www.baidu.com"} - ve := gbinary.LeEncode(user) - s := gbinary.LeDecodeToString(ve) - t.Assert(string(s), s) + gtest.C(t, func(t *gtest.T) { + user := User{"wenzi1", 999, "www.baidu.com"} + ve := gbinary.LeEncode(user) + s := gbinary.LeDecodeToString(ve) + t.Assert(s, s) + }) } diff --git a/encoding/gurl/url_test.go b/encoding/gurl/url_test.go index 63126cee8..59cba45b3 100644 --- a/encoding/gurl/url_test.go +++ b/encoding/gurl/url_test.go @@ -44,14 +44,15 @@ func TestRowEncodeAndDecode(t *testing.T) { } func TestBuildQuery(t *testing.T) { - src := url.Values{ - "a": {"a2", "a1"}, - "b": {"b2", "b1"}, - "c": {"c1", "c2"}, - } - expect := "a=a2&a=a1&b=b2&b=b1&c=c1&c=c2" - - t.Assert(gurl.BuildQuery(src), expect) + gtest.C(t, func(t *gtest.T) { + src := url.Values{ + "a": {"a2", "a1"}, + "b": {"b2", "b1"}, + "c": {"c1", "c2"}, + } + expect := "a=a2&a=a1&b=b2&b=b1&c=c1&c=c2" + t.Assert(gurl.BuildQuery(src), expect) + }) } func TestParseURL(t *testing.T) { diff --git a/net/gtcp/gtcp_unit_pkg_test.go b/net/gtcp/gtcp_unit_pkg_test.go index c86102ffc..2498ad08f 100644 --- a/net/gtcp/gtcp_unit_pkg_test.go +++ b/net/gtcp/gtcp_unit_pkg_test.go @@ -105,7 +105,7 @@ func Test_Package_Timeout(t *testing.T) { break } time.Sleep(time.Second) - t.Assert(conn.SendPkg(data), nil) + gtest.Assert(conn.SendPkg(data), nil) } }) go s.Run() @@ -141,7 +141,7 @@ func Test_Package_Option(t *testing.T) { if err != nil { break } - t.Assert(conn.SendPkg(data, option), nil) + gtest.Assert(conn.SendPkg(data, option), nil) } }) go s.Run() diff --git a/net/gtcp/gtcp_unit_pool_pkg_test.go b/net/gtcp/gtcp_unit_pool_pkg_test.go index 28bea03e1..d8e517d46 100644 --- a/net/gtcp/gtcp_unit_pool_pkg_test.go +++ b/net/gtcp/gtcp_unit_pool_pkg_test.go @@ -105,7 +105,7 @@ func Test_Pool_Package_Timeout(t *testing.T) { break } time.Sleep(time.Second) - t.Assert(conn.SendPkg(data), nil) + gtest.Assert(conn.SendPkg(data), nil) } }) go s.Run() @@ -141,7 +141,7 @@ func Test_Pool_Package_Option(t *testing.T) { if err != nil { break } - t.Assert(conn.SendPkg(data, option), nil) + gtest.Assert(conn.SendPkg(data, option), nil) } }) go s.Run() From e57942b374fd1517382dacac110c926b24ec476a Mon Sep 17 00:00:00 2001 From: John Date: Fri, 20 Mar 2020 08:56:17 +0800 Subject: [PATCH 9/9] improve unit testing cases --- encoding/gbinary/gbinary_z_test.go | 143 +++++++++++---------- encoding/gjson/gjson_z_unit_struct_test.go | 2 - frame/gins/gins_z_unit_database_test.go | 13 +- frame/gins/gins_z_unit_redis_test.go | 12 +- os/gres/testdata/data/data.go | 2 +- os/gres/testdata/testdata.go | 2 +- 6 files changed, 88 insertions(+), 86 deletions(-) diff --git a/encoding/gbinary/gbinary_z_test.go b/encoding/gbinary/gbinary_z_test.go index 55714f053..6472375ba 100644 --- a/encoding/gbinary/gbinary_z_test.go +++ b/encoding/gbinary/gbinary_z_test.go @@ -49,84 +49,89 @@ var testData = map[string]interface{}{ var testBitData = []int{0, 99, 122, 129, 222, 999, 22322} func Test_EncodeAndDecode(t *testing.T) { - for k, v := range testData { - ve := gbinary.Encode(v) - ve1 := gbinary.EncodeByLength(len(ve), v) + gtest.C(t, func(t *gtest.T) { + for k, v := range testData { + ve := gbinary.Encode(v) + ve1 := gbinary.EncodeByLength(len(ve), v) - //t.Logf("%s:%v, encoded:%v\n", k, v, ve) - switch v.(type) { - case int: - t.Assert(gbinary.DecodeToInt(ve), v) - t.Assert(gbinary.DecodeToInt(ve1), v) - case int8: - t.Assert(gbinary.DecodeToInt8(ve), v) - t.Assert(gbinary.DecodeToInt8(ve1), v) - case int16: - t.Assert(gbinary.DecodeToInt16(ve), v) - t.Assert(gbinary.DecodeToInt16(ve1), v) - case int32: - t.Assert(gbinary.DecodeToInt32(ve), v) - t.Assert(gbinary.DecodeToInt32(ve1), v) - case int64: - t.Assert(gbinary.DecodeToInt64(ve), v) - t.Assert(gbinary.DecodeToInt64(ve1), v) - case uint: - t.Assert(gbinary.DecodeToUint(ve), v) - t.Assert(gbinary.DecodeToUint(ve1), v) - case uint8: - t.Assert(gbinary.DecodeToUint8(ve), v) - t.Assert(gbinary.DecodeToUint8(ve1), v) - case uint16: - t.Assert(gbinary.DecodeToUint16(ve1), v) - t.Assert(gbinary.DecodeToUint16(ve), v) - case uint32: - t.Assert(gbinary.DecodeToUint32(ve1), v) - t.Assert(gbinary.DecodeToUint32(ve), v) - case uint64: - t.Assert(gbinary.DecodeToUint64(ve), v) - t.Assert(gbinary.DecodeToUint64(ve1), v) - case bool: - t.Assert(gbinary.DecodeToBool(ve), v) - t.Assert(gbinary.DecodeToBool(ve1), v) - case string: - t.Assert(gbinary.DecodeToString(ve), v) - t.Assert(gbinary.DecodeToString(ve1), v) - case float32: - t.Assert(gbinary.DecodeToFloat32(ve), v) - t.Assert(gbinary.DecodeToFloat32(ve1), v) - case float64: - t.Assert(gbinary.DecodeToFloat64(ve), v) - t.Assert(gbinary.DecodeToFloat64(ve1), v) - default: - if v == nil { - continue + //t.Logf("%s:%v, encoded:%v\n", k, v, ve) + switch v.(type) { + case int: + t.Assert(gbinary.DecodeToInt(ve), v) + t.Assert(gbinary.DecodeToInt(ve1), v) + case int8: + t.Assert(gbinary.DecodeToInt8(ve), v) + t.Assert(gbinary.DecodeToInt8(ve1), v) + case int16: + t.Assert(gbinary.DecodeToInt16(ve), v) + t.Assert(gbinary.DecodeToInt16(ve1), v) + case int32: + t.Assert(gbinary.DecodeToInt32(ve), v) + t.Assert(gbinary.DecodeToInt32(ve1), v) + case int64: + t.Assert(gbinary.DecodeToInt64(ve), v) + t.Assert(gbinary.DecodeToInt64(ve1), v) + case uint: + t.Assert(gbinary.DecodeToUint(ve), v) + t.Assert(gbinary.DecodeToUint(ve1), v) + case uint8: + t.Assert(gbinary.DecodeToUint8(ve), v) + t.Assert(gbinary.DecodeToUint8(ve1), v) + case uint16: + t.Assert(gbinary.DecodeToUint16(ve1), v) + t.Assert(gbinary.DecodeToUint16(ve), v) + case uint32: + t.Assert(gbinary.DecodeToUint32(ve1), v) + t.Assert(gbinary.DecodeToUint32(ve), v) + case uint64: + t.Assert(gbinary.DecodeToUint64(ve), v) + t.Assert(gbinary.DecodeToUint64(ve1), v) + case bool: + t.Assert(gbinary.DecodeToBool(ve), v) + t.Assert(gbinary.DecodeToBool(ve1), v) + case string: + t.Assert(gbinary.DecodeToString(ve), v) + t.Assert(gbinary.DecodeToString(ve1), v) + case float32: + t.Assert(gbinary.DecodeToFloat32(ve), v) + t.Assert(gbinary.DecodeToFloat32(ve1), v) + case float64: + t.Assert(gbinary.DecodeToFloat64(ve), v) + t.Assert(gbinary.DecodeToFloat64(ve1), v) + default: + if v == nil { + continue + } + res := make([]byte, len(ve)) + err := gbinary.Decode(ve, res) + if err != nil { + t.Errorf("test data: %s, %v, error:%v", k, v, err) + } + t.Assert(res, v) } - res := make([]byte, len(ve)) - err := gbinary.Decode(ve, res) - if err != nil { - t.Errorf("test data: %s, %v, error:%v", k, v, err) - } - t.Assert(res, v) } - } + }) } func Test_EncodeStruct(t *testing.T) { - user := User{"wenzi1", 999, "www.baidu.com"} - ve := gbinary.Encode(user) - s := gbinary.DecodeToString(ve) - t.Assert(string(s), s) + gtest.C(t, func(t *gtest.T) { + user := User{"wenzi1", 999, "www.baidu.com"} + ve := gbinary.Encode(user) + s := gbinary.DecodeToString(ve) + t.Assert(s, s) + }) } func Test_Bits(t *testing.T) { - for i := range testBitData { - bits := make([]gbinary.Bit, 0) - res := gbinary.EncodeBits(bits, testBitData[i], 64) + gtest.C(t, func(t *gtest.T) { + for i := range testBitData { + bits := make([]gbinary.Bit, 0) + res := gbinary.EncodeBits(bits, testBitData[i], 64) - t.Assert(gbinary.DecodeBits(res), testBitData[i]) - t.Assert(gbinary.DecodeBitsToUint(res), uint(testBitData[i])) - - t.Assert(gbinary.DecodeBytesToBits(gbinary.EncodeBitsToBytes(res)), res) - } + t.Assert(gbinary.DecodeBits(res), testBitData[i]) + t.Assert(gbinary.DecodeBitsToUint(res), uint(testBitData[i])) + t.Assert(gbinary.DecodeBytesToBits(gbinary.EncodeBitsToBytes(res)), res) + } + }) } diff --git a/encoding/gjson/gjson_z_unit_struct_test.go b/encoding/gjson/gjson_z_unit_struct_test.go index b855fb0d4..6f8a95cae 100644 --- a/encoding/gjson/gjson_z_unit_struct_test.go +++ b/encoding/gjson/gjson_z_unit_struct_test.go @@ -8,7 +8,6 @@ package gjson_test import ( "github.com/gogf/gf/encoding/gjson" - "github.com/gogf/gf/frame/g" "github.com/gogf/gf/test/gtest" "testing" ) @@ -91,7 +90,6 @@ func Test_ToStruct1(t *testing.T) { t.Assert(err, nil) err = j.ToStruct(data) t.Assert(err, nil) - g.Dump(data) }) } diff --git a/frame/gins/gins_z_unit_database_test.go b/frame/gins/gins_z_unit_database_test.go index 3e1294f9e..b3a82a955 100644 --- a/frame/gins/gins_z_unit_database_test.go +++ b/frame/gins/gins_z_unit_database_test.go @@ -18,8 +18,9 @@ import ( ) func Test_Database(t *testing.T) { - databaseContent := gfile.GetContents(gfile.Join(gdebug.TestDataPath(), "database", "config.toml")) - + databaseContent := gfile.GetContents( + gfile.Join(gdebug.TestDataPath(), "database", "config.toml"), + ) gtest.C(t, func(t *gtest.T) { var err error dirPath := gfile.Join(gfile.TempDir(), gtime.TimestampNanoStr()) @@ -33,14 +34,12 @@ func Test_Database(t *testing.T) { err = gins.Config().AddPath(dirPath) t.Assert(err, nil) - }) - defer gins.Config().Clear() + defer gins.Config().Clear() - // for gfsnotify callbacks to refresh cache of config file - time.Sleep(500 * time.Millisecond) + // for gfsnotify callbacks to refresh cache of config file + time.Sleep(500 * time.Millisecond) - gtest.C(t, func(t *gtest.T) { //fmt.Println("gins Test_Database", Config().Get("test")) dbDefault := gins.Database() diff --git a/frame/gins/gins_z_unit_redis_test.go b/frame/gins/gins_z_unit_redis_test.go index d4184f97a..a9fdc679e 100644 --- a/frame/gins/gins_z_unit_redis_test.go +++ b/frame/gins/gins_z_unit_redis_test.go @@ -18,7 +18,9 @@ import ( ) func Test_Redis(t *testing.T) { - redisContent := gfile.GetContents(gfile.Join(gdebug.TestDataPath(), "redis", "config.toml")) + redisContent := gfile.GetContents( + gfile.Join(gdebug.TestDataPath(), "redis", "config.toml"), + ) gtest.C(t, func(t *gtest.T) { var err error @@ -33,14 +35,12 @@ func Test_Redis(t *testing.T) { err = gins.Config().AddPath(dirPath) t.Assert(err, nil) - }) - defer gins.Config().Clear() + defer gins.Config().Clear() - // for gfsnotify callbacks to refresh cache of config file - time.Sleep(500 * time.Millisecond) + // for gfsnotify callbacks to refresh cache of config file + time.Sleep(500 * time.Millisecond) - gtest.C(t, func(t *gtest.T) { //fmt.Println("gins Test_Redis", Config().Get("test")) redisDefault := gins.Redis() diff --git a/os/gres/testdata/data/data.go b/os/gres/testdata/data/data.go index 46e1650d6..4d554c9c0 100644 --- a/os/gres/testdata/data/data.go +++ b/os/gres/testdata/data/data.go @@ -3,7 +3,7 @@ package data import "github.com/gogf/gf/os/gres" func init() { - if err := gres.Add("1f8b08000000000002ffb45a0b5c4ce9fb7f51d2284a5159721a29bacc34a3c2340d69baa10bc6a5d8ec3473a699ccad99e93aa292c41672c9a548e49644ac44b995845a7259b96d2e296bab4576c975ff9f99a99c33334da3df7f7d3e639a73cef3fd3ecff33eef7bcefb9c6fd0cc013aa6601000e00dcc0902887fc3803e6008f82c4e385ef185930878dc79345dd0af99c40a8de6c03142ba840db943583c5bc083f13131317809cc1372e912588cc52c12c14c8ef8470c04411093235e0ac9ae241027e19c704e3802c975e2a4290e4e58f969069dc186d59c26608366ea0dcaa9d8c0640100649f9edd35fce62e2f0ec7e173fe7f3d256af674a2dcd38e244f37554fc7c688519e0eecf654eea2679a3854668cbca4e7302dba8d1d1951628980f7df0d8eb3e6905de421d3a8ae0f7b1f1c5315afff8b3172d5ecf024b9c34e7a4d29bd8f91a1b2c37d18aa41401f303922025e1c15d61da8f6e62310e6b28fa304164b083849aca41bacfb28c410f025305f22433f776213c9180060ac111dd3852eb7ef4654414b1b30f5aba13c219ad2a5d389d6f72c11ffb72c11515922aacd1211199774bde500adb34494678988ca120acd7feaf16aadb344ec43960c803ee01026f3f1301f3dd3316c98cb15c8aadd57f607161323107199b2df0b647fc84b9e11e3380d020040da5144d07ba2684cdad498bca931e97063525e63d25104d9f3d2ac175bd2e56cb3c3a1687b0080bd766ca2a89ed8ea726f26d695d61daf3b7933194155575e577a335111d8e4334bc70300c66ba41ada4515cf76f40c40b375933d3fbbbb69df59f511bd6cb896610500b0d29a86b6e0ff8d465d11c968fa5044833b4d1d991c111ee6f771b62110f0f2b83417a40c5cd412c1300200187d17b83c474ae06aaa7ba771946defe0a8d823e8ff6bec11f4ced8e3e82ab19354278a8ca59c65176c21bf837f0f8b22092816f92112aa7476792ce10e95d7a0d6391045f52107c3d1089d3940dec8d5cf5e19037799d5f811f208bf8741113f9241dd4200b7b495f55e034390d8f2c5a00f29b05001e9cc428458f06d4a49e54f2258f9192ce9dbbc4f90dfa1ad069fe9bd12d4102992a18e487e06fbad28144498b6995f7b27524e0b6d411fd262ae02d299965844e592a7c6f2b850342c1273047c772c01e78485603e43c0e4f0c3ddb1511296e364ec540a862c03a2c80323cb41288af4911590140c192fbf42e69d51fc88f5810080c0eff54e91cbffd13b3908459173b20212e5dd479b595b54bd535ed20721bcebc3b26edc65cee270e1fff00101cd1341d772edc3a859af4c2fd72c9c000098a091d00845288ad262a151fb98503107ffc5160060dbeb1ee51b9be2594165aaa9cc68074c8fb38f12842f7100003868a43551a6a52df84fe68c56f57a75dab5db1c00004763bdea235deee323bf482090e01962711f969a610873bc5812c7857148203b48b126b2047c89a398130f93a0894461ac9bfca0048e9538d2b99c703e0962c07c092c72530c965d43d89f440000b1d7fd809c9ac3a387c37df0dd040580e70ac20538213fbc1b694d50808f21662446b697f0f3a5cee9f48838682000c0726a5a3100a09f788ecf7450747dd44bd958087d83c5000c36917dfa811d39e600f42fe2d0164a16facf2231043c1c9d29088371b13ca1dc01722c299627e4c1123a14cbe3f2c5a45877acfc0a125f4c921dc66321f92592a5eed885fe4190a74004432e38679c13565e44641193459a43f5ee34173159ee58b6442224e1655b765ccc449c40148e274c993205ef44c413898e2226cb511cc797d0631df9e2b10a902e1c2a2c668838420947c08764bfe9618228893b16db798de25fa79f3c6137115fdc191543c0c3c7d2857802ce09afce88c9e8b6114689b872d7980c3ccc8579305f22c6137004b576120e8ba59e4d76464147f966478ee509499e22982e81a974094c213a11a6383ab9383ab9d20844d2442289e01242c62b5da4ce5c20a209045c8a878c0ef2e688e0188168a918f29ceb8c30efbc48c9de5fc0e4b0e254e85d482eaea489933be9111721cc990c124b20e2d1251445550af9e164fcb783882b65d19302451c982fa1cb068d4220e3558e750d305e698415e583efac1fd9bad35d8b14cceb457706008059e147f5a0b175db162e12d0ea2d7e0ce787f34baa07d65699db9a371a0dd39d3e57c72e79c3c179736f79cf98879d3e6fc2bc3bbf0426fcc1384c31a51d1a3afb93de83733ebcb5c9d855c3a0a7117b6cacd61944fbcf824e9ed66148b9379a6ab7bf0cf9543bc5d2c026803173427bd6bbdaed09c18f4f9d7bd8105e3835c7bcf009859df7297165deb169cf5b9aafeaae778865ee72386614f29679ef5f8b77e7def8324b6c8e95069d2d7939c3c9acbeff98fa7fdfc1cb2c3ee3ad9f9908d30afe9ac0cfa4e95a0578dfafdcbcf8ddbe156b0463ca685538bdfd58d7c8b00a56aee13bf735be1b665ae9be4b15eaf26e126f19072e2ee63e9d3f21253b609049cefab9c753de46cef75f0a9bd3eb57d92db4b41febd93aded69932e3d1e100731366e6936d92d366efd2a9d6e305d3eceed15eec76993d3d39d9b9c8a66ed8d5f44db517983a66a2d9a653d8372a92e7d8f9b4a6faea06e68f2a4cdbbac1606bc63fab8ed80c60cda4ff1d488ddcd5f1c0e450584b5c7c997da6d16f39f91bedd9fb7edd4e1ef952bfdf56fbac0fae10f5c4bd8904b3f5277efee350e664ef19596faecf7a0a8da386453daa9a341273b972607601c9253be577a3a61de93f3745eb1cf0e68dbc4bcc73181b203897b432d2f079297d9c5febc2cd9ea9d698cf6d1b5376e86cbb1edeef9afd10e989b630dbfa49b7aeb5a79f0a71dbbf63b561a17f69c7fcb943fce2ef558f989ff8e3efad8ca3b3b25ed3e6ee1a5830ed83b34934e437383fa59d3e936149e0d370e30f8dcb5f8c7b7cf76483196ed59f87eeb14282fdd7fee63a6611758ce04a760231717dc68c26d756cc0abd7b45abbc9cefcc0f1b1c432a79fee8a931a181b6843a7a4bbbae3ecd7dc4cf5699bed0f65958cb53bf6ebb6c68e432fc25ebb2d4adac7d29a9746307bd99ba91c9e46506bddd5cd2bf954a5ee76b9d8c313cb03fca6b2387de511448b2711efef5a4e31563fa88d240ab93c93f8c4adde8f06cb0f1ebba3aa381037156b93718bfee88fee5e4c98b91393f65ec5e75bba2e355cdeccc917ed7569aba97dfc16d27df26b93c5d5d496fcc187a6367e59327d0c8891692e8686ce5abb0625ff7f2dff69c4c4ded98543cf34ee0befb5b23b36ffef2da63635a8864e2823f0aebd6186356099f5f99bd4c5c33bfb5e1841ee33e216772dcb0ea86b8d559b7273c73596372ac9c6372ffc4019f805dd7eb4cf4538fac4d1558d367de5f316a7262cd56fcdea34787def8973d69f9c7f69a3fcec7dea4264d0f69f931be78dd94b2b5a93b76adee673ca128fe6cda705f0c9bb17d25c12db5a121f4f3f37d5bd34bce3f3e3f746a43999974c93263bda1969756355052831f2da4fd1594efc5f9609e313b8364f843ad4e75e5a8f7d9e5f487ae0d14914ee3fdc8d67d99cbbf5eb3eff85af42aafa5557aef9460aab7b7b7518677c68b5f0231f87deb22e6fafee69405f9ef0bae3169c5ee9b273a5418f9b1d662c806e6fe7ee1d7254f3f7f78dbb1f9eea7874b8fe695953dacd5aff4b97b22fe08e45f3379f95b4fbbad354f8f9c1a427f727b66e964a744cbb0dcb63f2b3c97ba09b7e948e3e3cb9765ce2b5db2adbd946f7ab2c3639d6fdcbf337627de22e6faba66bbb49be183930708ca9336553ff6da5f7c35e7c235e3cc7f4e6e3ebe76c9b892577c7dd33d6b9356f39e189cab9861bee26bcd9237d78b19d6e2abb3304b1c6706ea664c4b713d703e6dfcab658d1dc723eae36fcc138cbfea4622d52e24edf4f691ba8519ec63dac19743162df21f72b52262cee46accdc83cd4916cf570734155e9e77a4a064733f9a6efdad8f118768230f8784a44f5aa6fbf0c17c5d3a7ce174c01e328795fd611079cfb0032b83eefe72e478710ef9d999c2c78b4a7eaa9f78e3c9936cc14037bda3a195bbcca2198da98697f72c876f2667571d9b52fab9656d4a41457ae615f35741874af998d07b765f733f5d14c7feb37e4585cf9815a39eb43c3d75fe83cb034ee96e91b1af0e6c30aeacfcd9244f6a3293a07febf7099c9627b76d86d96f9965f1e8fcab987b67a20607e4527857780f4b0c6ffcf56095b37ba330c3faca594c6ecd8763174d8a1e3b1f082aadb8753afd45fa8e25c5f38f2e37aa5e3fbaeaf19215a3bf7cf9c2665ff9a97a5ddbbde284b2e0b18c195b23763ca28fa7077f9d9a217aafb325d6615e854dc35189f9dab33b2abcad6c8ebd7913d9789794bafdb217adf11a217b1ee727e2dabda7b873fbb9bcdaa46f6ad51c63f6a2d6bde0dd85dfe8f60ee3ce33c76dd28f3fc36cbfd1bacf728e8fa8e12b39e907e752d183eaa122ead6b7936de3e36e8f62b10fa6446cda91684df53b34d7bdaae845c8b033d7d38d3f7f29deb66076812e648ad19b621a667c374fba6e69ca91398582a76698f2e51b4a5f0fe7af5a4680ac464f8625672a16bd33aa3c9195d23c00dbacb7e6e083f2eaecfdcfea6c2badc6ceeadfc48aba41d955e6355d7f79ea2ef3179be3ee1f6fb4364a6d89c578315c0b7dd32fdb3112f3de5f64e76c33785970d1c1321d8be58a019193613b7e319367993f6930fdb3fd0f2e4731b74e95e85e2df29850f843731021a5b1529fdb5445a8127be95e78bfce67da25b66e082dab7476da9356dfda52b79119af75708d0f5689ff981239686c3d65e5ce597b9bf2aaeb3e5c8abe64e6e855f87cb7945cfb6961ff1f5a0e14b5174ddba7934ddebd70633d6d7cd1a6cf6f1645deb830b7a63624e19137750086b0f375eef0e91db68c48cf1f8d6bb6e71c3f339290ee605c73abeada9a5d6b068db2af75811d469f4d6e5d852bff58b364db3f27a5e7be3c0f287f7d62093dbf69366d0fe1efc02ce1de6d17c672ce2d7e1391bfd53e32d3c0e57727110e7eddf4e7d8e81fc5cf79199f96fe12d036043bf2cef4ccd9c3dd2a841c562dae119e73f4747b62a830d52f2cedb4f3d5a0e39ce3ccd36959493137c977334eb8bfd05d19d562995a3920f0c1e9f93aabd7595e1c3ac999fefb5eb79bf51fad0b692636dba4d516d7b6475e15fefa69fdb3255694e9162b3713661023e3bdad99d75f5a5bb714519dad880f0e2edfe4b72c637744ff9b2f0bed0e9c3665d4eb7bd5913bfa11eb03f2368426351d26bdf9bbd970f2a37ff2ee37ae68fd7a3dfa0efe15952901434ddffeb1e43d7971b37fc11c5741fed9338417cb2c1a4e65e69189a2847cb7f32bdba52feedc49dbbc60c1e193696b0ffb1e8af97b3435acd5a4f4a98efefca09f5e8e3a1337d864535ce86d4fb6efb8e2fc624be3d0fb3b3187c322cd3d0fe7563d39ee63e418175a566610b8df36a1f98685fb9c32af6b873ff1fedcbe67fb16d86e81af83c7c7b7ef67075cfa708b2a203cb25cf8406766f0e10b0b741bf736d4783eb9dfd85c7edaeea0d301a160c5bba68616e97cea5fbabb4f1b79328455ded41cfdfcd5651f583e815e9b8e3d6ba5875efc7197c76907bb2abfb9b77e178eaab4cfbdfc4fd5e841e2a2ac0b66577770be1e36c93be998b5c8368cb13bc1f6d9cff58cb33bab0a9a4d0b0f5e1f66b932073fd136f5ab7878eeb1d6005648a67f7cc371b64e63f176e79ca68e05b6580f6b13bb32f20287c5475fb4b9344299d7f376db9bb78d7ef694f536b1b63038dd234bb26a517e6bec9bbdc7b257ba4ea2e6a7cd4e3bfd7444668ddba03781c90727dc0dd535b8ddcecf5c51f1e6b1e768e1f023b93f0cb96c20f6491116841acf7f79384067ab2d830c053f0ebe982f5eb3a5404abefcf6d2a7db177c732bd74fb179b6d3ed6360c76be1a385a147f588e50d63ee4870b55e22297b6eae78c6a5d5bfcddc115a907f6c08d1bd23a579650ab5767066c15f1fdb6f4dc3d1b3f1c32adefd353afee354c160ea39fe90c5afaf24fb345fedffde9ffdc5ecc3d8a2a94929fad5b2ad929f5700b568fa4fc9f2e6e5abdd899b0d01907d34bf0250eceef84c3816c79620f7f1b25f148c3e990dd399148cbe3e99cbe12f854430d71d2bdfc48ad9302cc1426c11cc72c7a2b6b65848122784ddb1b2cd2b5efe1b2f03c2772291c304cc38d93793134d217378e19058c470c7a27798580a192f3b8fd1a7b13962882386246c1892fb09b144021e142e82c53819aa028d8c97fb2b8b9dded6412b010094f4fa5e42167b1ffa01b24d71d7ab5e75a9f393d822ddedba146271b8304e4673366b3c180d80fca3b99dd44dc3a5c709a2102f3eb5f7768c1a183c43c097d0397c5884f65c2a65c22c0e1f86b0dd1760131230643681e2191840f3f00bf09a43c6b309148c540af39909f256c438bd87af08000082463746a973832510487af64171b6cb01efc0409a1a76da6537dfde5fdfa96597d563cfec8ab3327645938a40f1f5f2a0aaf1e0a374c36d3c0000fffd1e28be95269e1535d093161ce405296620b9eb4b3e7b3ab7b5122e4cf111788be83c189a2507916d6c6547e55748a5dd458788a36b06764e40c55e9a130d31b874b1d81d31e4aa20a87250ec96e5b35319a373c85401be8d25c25acde4bd763dd3ea2300e0e3f74e0d621fa6869a3121aaad49a5fa93318470fffeb5f757586a19d4d59d527dc9181cdcef93fbc8a0aeaea4520e9fc18d62769784fc3416c2252460be9dc3f1e81c3e4dc8553a8c4564456e227350e7c30bbd00004040af6fc8541c94b1f461c0a09eb0e4ff115453eaefe11740e8ce68ad7f1b6388fc0d52df4988ea4988dd246153e39a5449d4bd43e922d1700bead7df74c0372f91cab26140bffbbafc24d9ff1ac46fca4048e197210ae8e8372025c91312439d44aceba50b9816dc0fa80ac6d00e206558162807b2ba8d3509c694f1902a295314deacfe40b3944b535c86a8b8be2843f5189ef24877ad5a6d1e1e03803a9115da1c29891a818a261161de83c84a190ca988c2a0c01abac0d09a2a4d09d14125c4410728cba8b4cd43b8c294a8310f48d1133a0ffb11e63dc8a894c1909a27741e7474813ad594f67998d309d0631e902f2c0d50dc19ba40bd504a190229534243bcee82501642a97881901fa121420702f5ea266508a4e667280ae26a17841ad592f6284e7aa0475192f6e3b1b51345abba1c8caacb5b9da6aa9a2334025222842e4dd341a037cd913218521284068b540253a331d23eb6eb483094a6088d8054fea0dd31d207bd698a94c190521f3458b412981ae9d0778c1b120ca515422320553dc3d1e38601bd688594b1902a1e3456b41296aa2a48536443d09121b19455404af70d8450077d57351b0cb4500129e321f53868bc44553c35621fed837ca98487d2f4a041900a1a7394533803d0bba647190e297941c3d5aac2a98a70342d4a83508b52842150a79ae9f946618cf2e65097b95ad58c320e52b082c6311e0234a862947190521423144e320a4749eca20c839496a01fcf5ea360d4a85894a190920f131454f850a05199a269a8f4514335d208a8158c68fb70136204d40946d0e6480507fa617e3bc25c8d6044931f18941fa6c640bdfc43694d44340bd1299d870250957f2823215b6fe81bfbc431a0c756a3f637763c04949b766807909d3574281110d0d8b4d394552354566f229154fb72681864736c0cca21732ba0755f4e65fb84687a8d42a1e6aa4355d7d2505907115d2c34e4682cd0ae77a60c89ece52879a90e525dd342fb51691d0b34b584d030c8e60ddab389d640bb96903224b25b8386dca20e529bfc21fb2b68c8f7ea20bf377fc351f9db360ef4daa6416321bb2910cabde73d61a96bd328c322fb2768583f1ba07d6346fb1b73110216b1b0e80e945d400114203506a0cd46f6ebff020000ffff3373f97b7e380000"); err != nil { + if err := gres.Add("1f8b08000000000002ffb45a0b5c4ce9fb7f51d2284a5159721a29bacc34a3c2340d69baa10b06159b9d66ce3493b93533a51a5149620bb9e45224724b2256a2dc4a422db9acdc369794b5d522bbe4baffcfcc54ce9999a6d1efbf3e9f31cd39e7f97e9fe7799ff73de77dce3768e6001d53300800f006e60401c4bf61401f30047c162702aff8c249043cee3c9a2ee8d74c6285c570e0a542ba840db943583c5bc083f14b972ec54b609e904b97c0622c66a1086672c43f62200882981cf112487625813809e78473c21148ae13274d7170c2ca4f33e80c36ace634011b34536f504ec506260b0020fbf4ecaee137777971380e9ff3ffeb2951b3a713e59e762479baa97a1a3c5082f27460b7a77217392692309931f2929ec3b4e8367664448b2502de7f3738ce9a437691874ca3ba3eec7d704c55bcfe2fc6c855b3c393e40e3be935a5f43e4686ca0ef761a806017dc0e488087871747877a0da9b8f4098cb3e8e12582c21e024b1926eb0eea31043c097c07c890cfddc894d24630080b146744c17badcbe1b51052d6dc0d4af86f284684a974e275adfb344fcdfb244446589a8364b44645cd2f59603b4ce12519e25222a4b2834ffa9c7abb5ce12b10f593200fa804398ccc7c37cf44cc7b0612e5720ab765fd91f58cc528188cb94fd5e20fb435ef28ca58ed3200000a41d4524bd278ac6a44d8dc99b1a930e3726e535261d45903d2fcd7ab1255dce363b028ab10700d86bc7268aee89ad2ef766625d69ddf1ba933793115475e575a5371315814d3eb3643c0060bc46aaa15d54f16c47cf00345b37d9f3b3bb9bf69d551fd1cb866b195600002bad69680bfedf68d415918ca60f4534b8d3d491c911e1617e1f671b02012f8f4b7341cac0452d910c230080d17781cb73a404aea6ba771a47dbf60e8e8a3d92febfc61e49ef8c3d8eae123b4975a2c858ca59762116f23bf8f7b028928062911f22a14a6797c762ee50790d6a9d0351741f72301c8dd09903e48d5cfdec95317097598d1f218ff07b1814f12319d42d04704b5b59ef353004892d5f0cfa90020b1590ce2c448a05dfa69454fe2482959fc192becdfb04f91dda6af099de2b410d912219ea88e467b0df8a424184699bf9b57722e5b4d016f4212de62a209d698945542e796a2c8f0bc5c0223147c077c712704e5808e633044c0e3fc21d1b2d61394ec64ea560c832208a3c30b21c84a2481f590149c190f1f22b64de19c58f581f080008fc5eef14b9fc1fbd9383501439272b2051de7db499b545d53be5257d10c2bb3e2cebc65de62c0e17fe0f1f10d03c91742dd73e8c9af5caf4724df00400c0048d8446284251b4160b8ddac7848a39f82fb60000db5ef728dfd814cf0a2a534d65463b607a9c7d94207c890300c04123ad89322d6dc17f3267b4aad7abd3aedde60000381aeb551fe9721f1ff945028104cf108bfbb0d40c4398e3c592382e8c4302d9418a359125e04b1cc59c7898044d240a63dde4072570acc491cee544f0491003e64b60919b62b0ec1ac2ff24020088bdee07e4d41c1e3d02ee83ef2628003c571021c009f911dd486b82027c0c312331b2bd849f2f754ea747c4410301009653d38a0100fdc4737ca683a2eba35ecac642e81b220660b089ecd30fecc83107a07f1187162c09f69f45620878383a53100ee3627942b903e458522c4fc88325742896c7e58b49b1ee58f91524be98243b8cc742f24b244bdcb1c1fe4190a74004432e38679c13565e44641193459a43f5ee34173159ee58b6442224e1655b76dcd289388128024f9832650ade898827121d454c96a3388e2fa1c73af2c56315205d385458cc107184128e800fc97ed3c305d112772cb6f31ac5bf4e3f79c26e22beb8332a8680878fa50bf1049c135e9d1193d16d238c1671e5ae311978980bf360be448c27e0086aed241c164b3d9bec8c828ef2cd8e1ccb13923c45305d0253e912984274224c717472717472a51188a4894412c125948c57ba489db940441308b8140f191de4cd11c14b05a22562c873ae33c2bcf322257b7f0193c38a53a17721b9b892264eeea4475c84306732482c8188479750145529e44790f1df0e22ae94454f0a147160be842e1b340a818c5739d635c078a51156940fbeb37e64eb4e772d5230af17de19000066851fd583c6d66d0b5e28a0d55bfc18c18fe097540facad32b7356f341aa63b7dae8e5df28683f3e6def29e310f3b7dde8479777e094cf8837198624a3b3474f627bd07e77c786b93b1ab86414f23f7d858ad3388f19f059d3cadc390726f34d56e7f19faa9768aa5814d0063e684f6ac77b5db13421e9f3af7b021a2706a8e79e1130a3bef53e2cabc63d39eb7345fd55def10cbdce570cc28f42df3debf16efcebdf16596d81c2b0d3a5bf2728693597dff31f5ffbe8397597cc65b3f3311a615fc35819f49d3b50af0be5fb979d1bb7d2bd608c694d1aa707afbb1ae51e115ac5cc377ee6b7c37ccb4d27d972ad4e5dd24de320e5c54cc7d3a7f424a76c020939cf5738fa7bc8d9aefbf0436a7d7afb20bb6b41febd93aded69932e3d1e100731366e6936d92d366efd2a9d6e305d3eceed15eec76993d3d39d9b9c8a66ed8d5f44db517983a66a2d9a653d8372a92e7d8f9b4a6faea06e68f2a4cdbbac1606bc63fab8ed80c60cda4ff1d488ddad5f1c0e450784b5c7c997da6d16f39f91bedd9fb7edd4e1ef952bfdf56fbac0fae10f5c4bd8904b3f5277efee350e664ef19596faecf7a0a8da386473faa9a341273b972607601c9253be577a3a61de93f37c5e81cf0e68dbc4bcc73181b203897b432caf079297d9c5f6bf066cf546bcce7b68d293b74b65d8fe877cd7e88f4445bb86dfda45bd7dad34f85baeddfb1dab0d0bfb463fedc217ef1f7aa47cc4ffcf1f756c6d15959af6973770d2c98f6c1d92406f21b9c9fd24e9fc9b024f069b8f187c6e52fc23dbe7bb2c10cb7eacf43f758a121fe6b7f731db3903a4670253b8198b83e6346936b2b6685debda2555ece77e6870f5e4a2a79fee8a931a181b6983a7a4bbbae3ecd7dc4cf5699bed0f65958cb53bf6ebb6c68e432fc25ebb2d4adac7d09a9746307bd99ba91c9e46506bddd5cd2bf954a5ee76b9d8c313cb03fda6b2387de511448b2711efef5a4e31563fa88d240ab93c93f8c4adde8f06cb0f1ebba3aa381037156b93718bfee88f9e5e4c98b51393f65ec5e75bba2e355cdeccc917ed7569aba97dfc16d27df26b93c5d5d496fcc187a6367e59327d0c889169298186ce5abf0625ff7f2dff69c4c4ded98543cf34ee0befb5ba3b26ffef2da63635aa864e2823f0aebd6186356099f5f99bd4c5c33bfb5e1841ee33e216772dcb0ea86b8d559b7273c73596372ac9c6372ffc4019f805dd7eb4cf4538fac4d1558d367de5f316a7262cd56fcdea34787def8973d69f9c7f69a3fcec7dea4264d0f6df931be78dd94b2b5a93b76adee673ca128fe6cda705f0c9bb17d25c12db5a121ecf3f37d5bd34bce3f3e3f746a43999974f13263bda1969756355052431e05d3fe0acaf7e27c30cf989d4132fca156a7ba72d4fbec72fa43d7068a48a7f17e54ebbecce55fafd9777c2d7a95d7d22abd774a30d5dbdbdb28c33be3c52f8118fcbe7591737d7f73ca82fcf785d498b462f7cd131d2a8cfa586b316403737fbf88eb92a79f3fbcedd87cf7d3c32547f3caca1ed6ea57fadc3d117f04f2af99bcfcada7ddd69aa7474e0da13fb93db374b253a265786edb9f159e4bdc84db74a4f1f1e5cb32e7952eded65eca373dd9e1b1ce37eedf19bb136f11737d5db35ddacdf021c90304e5499baa1f7bed2fbe9a73e19a71e63f27371f5fbb785cc92bbebee99eb549ab794f0cce55cc305ff1b566f19bebc50c6bf1d55998c58e33037533a6a5b81e389f36fed5b2c68ee391f5f137e609c65f7523916a83493bbd7da46ee106fb9876f0e5d0850bfd875cad889c33b91a33f7607392c5f3d5014d8597e71d2928d9dc8fa65b7feb63e421dac8c3a1a1e99396e93e7c305f970e5f381db087cc61657f1844de33ecc0caa0bbbf1c395e9c437e76a6f0f1c2929fea27de78f2245b30d04def6858e52eb3184663aae1e53dcbe19bc9d955c7a6947e6e599b5250919e79c5fc55d0a1523e26ec9eddd7dc4f17c5b1ffac5f51e13366c5a8272d4f4f9dffe0f28053ba5b64ecab031b8c2b2b7f36c9939acc24e8dffa7d02a7e5c96d9b61f65b66593c3aff6ae9bd33d183037229bc2bbc87258637fe7ab0cad9bd5198617de52c26b7e6c3b18b26458f9d0f049556dc3a9dfe227dc7e2e2f947971b55af1f5df578f18ad15fbe7c61b3affc54bdaeed5e714259c858c68cad913b1ed1c7d343be4ecd10bdd7d912eb30afc2a6e1a8c47cedd91d15de5636c7debc896abc4b4add7ed98bd6788d903d8ff31371edde53dcb9fd5c5e6dd237b56a5e6af6a2d6bde0dd85dfe8f60ee3ce33c76dd28f3fc36cbfd1bacf728e8fa8e12b39e907e752d183eaa122ead6b7936de3e36e8f62b10fa6446eda91684df53b34d7bdaae845e8b033d7d38d3f7f29deb66076812e648ad19b621a6e7c374fba6e49ca91398582a76698f2e51b4a5f0fe7af5a4680ac464f8625672a16be33aa3c9195d23c00dbacb7e6e083f2eaecfdcfea6c2badc6ceeadfc48abe41d955e6355d7f79ea2ef3179be3ee1f6fb4364a6d89c578315c0b7dd32fdb3112f3de5f64e76c33785970d1c1321d8be58a019193613b7e119367993f6930fdb3fd0f2e4731b74e95e85e2df29850f843731021a5b1529fdb5445a8127be95e78bfce67da25b66e282dab7476da9356dfda52b79119af75708d0f5689ff981235686c3d65e5ce597b9bf2aaeb3e5c8ab964e6e855f87cb7945cfb29b8ff0f2d078ada8ba6edd3c926ef0ede584f1b5fb4e9f39b8551372eccada90d4d78e44d1d8021ec7c9d3b7c7a872d23caf347e39aed39c7cf8c24a43b18d7dcaabab666d79a41a3ec6b5d6087d167935b57e1ca3fd62cdef6cf49e9b92fcf03ca5f9f584ccf6f9a4ddb43f83b304bb877db85b19c738bde44e66fb58fca3470f9dd4984835f37fd3936e647f1735ec6a725bf04b40dc18ebc333d73f670b70a2187558b6b84e71c3ddd9e18264cf50b4f3bed7c35e838e738f3745a56d2d29be4bb1927dc5fe8ae8c6eb14cad1c10f8e0f47c9dd5eb2c2f0e9de44cff7dafdbcdfa8fd68534139b6dd26a8b6bdba3ae0a7ffdb4fed9622bca748b959b09338851f1ded6cceb2fadad5b8aa8ce56c40707976ff25b96b13bb2ffcd978576074e9b32eaf5bdeac81dfd88f501791bc2929a0e93defcdd6c38f9d13f79f71b57b47ebd1e7307ff8aca9480a1a66fff58fc9ebca8d9bf608eab20ffec19c28b65160da732f3c8445142bedbf995edd21777eea46d5eb0e0f0c9b4b5877d0f2dfd7b3435bcd5a4f4a98efefca09f5e8e3a1337d864535cd86d4fb6efb8e2fc624be3b0fb3b3187c3a3cc3d0fe7563d39ee63e4181756566610b8df36a1f98685fb9c32af6b873ff1fedcbe67fb16d86e81af83c7c7b7ef67075cfa708b2a203cb20c7ea03333e4f08505ba8d7b1b6a3c9fdc6f6c2e3f6d77d0e98050b0e25d53438b743ef52fdddda78d3c19c22a6f6a8e7efeeab20f2c9f40af4dc79eb5d2c32efeb8cbe3b4835d95dfdc5bbf0b4755dae75efea76af4207151d605b3ab3b385f0f9be49d74cc5a681bced89d60fbece77ac6d99d5505cda68507af0fb35c99839f689bfa553c3cf7586b002b34d33fbee1385ba7b178bb734e53c7025bac87b5895d197981c3a2a32fda5c1aa1cceb79bbedcddb463f7bca7a9b585b1892ee912559b530bf35f6cdde63d92b5d2751f3d366a79d7e3a22b3c66dd09bc0e48313ee86e91adc6ee767aea878f3d873b470f891dc1f865c3610fba4080bc28ce7bf3c1ca0b3d5964186421e875ccc17afd95220255f7e7be9d3ed0bbeb995eba7d83cdbe9f631b0e3b5f05170d8513d6279c3983b125cad9748ca9e9b2b9e7169f56f33778415e41f1b4274ef48695e9942ad1d9c59f0d7c7f65bd370f46cfcb08a777f8d8eff385530987a8e3f64d1eb2bc93ecd57fbbff7677f31fb30b6686a528a7eb56cabe4e715402d9afe53b2bc79f96a77e2664300641fcdaf0014bb3b3e138ec5b125c87dbcec1705a34f66c3742605a3af4fe672f84b2011cc75c7ca37b162360c4bb0105b04b3dcb1a8ad2d1692c4096177ac6cf38a97ffc6cb80f09d48e47001334ef6cde4c450c81c5e04241631dcb1e81d269642c6cbce63f4696c8e18e28821091b86e47e422c918007458860314e86aa4023e3e5feca62a7b775d04a000025bdbe9790c5de877e806c53dcf5aa575deafc24b64877bb2e85581c2e8c93d19ccd1a0f460320ff686e2775d370e9718268c48b4fedbd1da30606cf10f025740e1f16a13d974a99308bc387216cf705d884040c994da0780606d03cfc02bce690f16c02052395c27c6682bc15314eefe12b020080a0d18d51eadc600904929e7d509ced72c03b3090a6869d76d9cdb7f7d7776ad965f5d833bbe2ac8c5dd1a422507cbd3ca86a3cf828dd701b0f00c07fbf078a6fa58967450df4a4850479418a1948eefa92cf9ece6dad840b537c04de223a0f8666c941641b5bd951f915526977d121e2e89a819d1350b197e6c4400c2e5d2c76470cb92a08aa1c14bb65f9ec54c6e81c3255806f6389b0563379af5dcfb4fa0800f8f8bd5383d887a9a1664c886a6b52a9fe640ca1dcbf7fedfd15965a067575a7545f320607f7fbe43e32a8ab2ba994c36770a399dd25213f8d85700909986fe7703c3a874f1372950e631159919bc81cd4f9f0422f000010d0eb1b321507652c7d1830a8272cf97f04d594fa7bf80510ba335aebdfc618227f83d47712a27a12623749f8d4b826551275ef50ba4834dc82faf5371df0cd4ba4b26c18d0efbe2e3f49f6bf06f19b321052f86588023afa0d4849f284c4502711eb7ae902a685f403aa8231b40348199605ca81ac6e634d8231653ca44aca148537ab3fd02ce5d21497212aae2fca503d86a73cd25dab569b87c700a04e648536474aa246a0a2494498f720b25206432aa23028b0862e30b4a64a534274500971d001ca322a6df310a130256acc0352f484cec37e84790f322a6530a4e6099d071d5da04e35a57d1ee67402f49807e40b4b031477862e502f94528640ca94d010afbb209485502a5e20e4476888b08140bdba491902a9f9198a82b8da05a146b5a43d8a931ee85194a4fd786ced44d1aa2e07a3eaf256a7a9aae6088d809408a14bd37410e84d73a40c869404a1c1a294c0d4688cb48fed3a120ca529422320953f68778cf4416f9a226530a4d4070d16a304a6463af41de38604436985d0084855cf70f4b861402f5a21652ca48a078d15a384a5aa0ad214d9107464482c651590d27d0321d441df55cd06032d5440ca78483d0e1a2f51154f8dd847fb205f2ae1a1343d6810a482c61ce514ce00f4aee95186434a5ed070b5aa70aa221c4d8bd220d4a2146908d4a9667abe5118a3bc39d465ae5635a38c8314aca0718c87000daa18651ca414c50885938cc25112bb28c320a525e8c7b3d72818352a166528a4e4c304051531146854a6681a2a7dd4508d34026a0523da3edc841a01758211b43952c1817e98df8e30572318d1e40706e587a931502fff505a1311cd42744ae7a10054e51fca48c8d61bfac63e710ce8b1d5a8fd8d1d0f01e5a61dda0164670d1d4a24043436ed3465d50895d59b4824d5be1c1a06d91c1b8372c8dc0a68dd9753d93e219a5ea350a8b9ea50d5b53454d64144170b0d391a0bb4eb9d2943227b394a5eaa8354d7b4d07e545ac7024d2d21340cb27983f66ca235d0ae25a40c89ecd6a021b7a883d4267fc8fe0a1af2bd3ac8efcddf7054feb68d03bdb669d058c86e0a8472ef794f58eada34cab0c8fe091ad6cf0668df98d1fec65c8480452c2cba036517500005488d0168b391fdfabf000000fffffdd456717e380000"); err != nil { panic(err) } } diff --git a/os/gres/testdata/testdata.go b/os/gres/testdata/testdata.go index fc73a247b..2c8871504 100644 --- a/os/gres/testdata/testdata.go +++ b/os/gres/testdata/testdata.go @@ -3,7 +3,7 @@ package testdata import "github.com/gogf/gf/os/gres" func init() { - if err := gres.Add("1f8b08000000000002ffb45a0b584ce91ffe50d210a5502e99464ab7996674619a8634ddd085c6a5d8ec3473a699ccad99e92e944afc0b61732992cd2289b212e5569b504b2e2bb7cd25656d5964d726d6fe9f3925e74c33cd34da9e67aa39dff9def7773bdf39dff9bd01f38668198161008037103700207e26025d4088628809d1d1d18430b69d842b85085248222530850236376c115d1b0c6a21b34302e6e90c434e540e394505a41d33522215f23540b6578a8c86eefe86970af9bc1e9a282e142d62483958572c8ec011f22118450af1453c861492e030cbc4108b2bf90683c562b12cae642556762691e48cb7c7dbe38964a7e9ce336d1d70f03093c1e4400a861d713267e834a7076c0000bb4f676cd475861f8be70ab803eb8753df7e38c37ed8eb3427abf6c34a951fff5d36ecfbf682087b9153b985a5da0b73955efc176920f5edc074d8818e447717d50e8c57ea008b2b266a70b14d561e111922411219aa01aa9d6a54d9c74e76888897c6487b387a8e6299428114124865a4e74e6c231b00000cfa243553410ac3f610f522491b32eb931e00404ff30490063c01a4ff2401245402480a134042c6267eb3e990af4d0009fe97844a008ac4775649cdd724804b9c21d02054a67d02dab1b8620d4071ca43f1199500090636b108600207e2f184e8b518031f93ad3fdeb27fe04547dc1aced40700e80f0467b450cc63c971c2c7649c4b64ffc09c7b0c222d5573aa13c070c67f14c0704677006319bd0248c6e29a12b735256d6b4a3cd29498d794780cf6aa826d1d640200301908f2ae48a2c8e143642cee5959d6f3efd261cabd6e2b78a30000a3be3a90e2480d0269ab1670772091f7d49e3aaccfbdb1b6beacbea4fee48d24d823de2ab369630100630782b82b8848e29e62acafa82fbbb116a6845a5f96abaec6a96a50c671ecdcfd06f671178ddd1dca7089f0cbc2110f3f59e0e0119cac3cceee6b3e70168749806f9b66c3cfa8ae49f5f9bb22aa881f1ec17d29cf2e7ecccb799f54f3ab195bfa120d624b5017bb3bb631882b8e322b86cfc346416209572870c511f1f6382c24600a595c41982b2e52cab69b819b45c550644054380c141884da95034a1724154381a9a832a3f5e3c66ef60700f80f90d15d09f94aa361106a57e2285d9028a33b2de67fa7dae8c97ddf45d95c1ea441fea6a908850c960009fabed129ba0931a3ed66630100d8afa70f67a8799bc02858c38d2ed52eb582b7577dd961a98e1de2483556598ca235b07221e11f4b9846c39dec1723e085a2f712d16b81b2c5285d35a80184525b7899efcb1a6b35ada12ff94f2e6ab5ae9c2bb3afdee20200b81abe488191fec3f256c51cce50c6acb8b4652388da5e10868db2810be76b8c10472a3342756133679c59390dbe8efbb2c04285055d358d32a2c786cff75b45febf68bc9a61066f8bbe929dbee43f6357be9b120b85d281ddceca10094c894403542bd5a80489349607e191f8d6d8aec713b65020b59370e32032763a4914e3021f944231523b068f1b2620639990400a895dbad61febc6d0df49000092a67b5dd8222e9f11a6c91dcf5a1d5c024f1826c48b045fdedb6e08f0f3d2c38cc7c8b6cf3edeb485ddf693860d95ed7067a51503000649167acd0145d726be0000e88abc8324000c37947d0681dd39c6000c2ee2d2974a97face2733857c3c83250c85f0317c116c1725861cc317f12129031bc3e70924e418571c7c06592021cb0e137058f814e94a57dc52df00acbb500c611df10e787b1cbc5c52c42c367921cdb37bba98c576c571a45211992073151f3d1d2f148711883367ce24d8930824929d98c5b693c40aa48c183b81644a17c8671c1a24618ab922295728c0cabe3342859152571caefb9cae9f6e3bf9a21e2281a4db2ba6904f8861880844bc3d41d12416b3678e2852cc834d633109100fe24302a98440c41315ce9372d96cc56cb2912e3aea97799418be88ec2e86185288c6904254923d71a69dbda39dbd139d48224f2791898ec11482dc498aa60bc574a190477593d1613db962285a285e29c1ba073a20a6779f2437df57c8e2b2637bd13b921d9dc8d36774d3234e424c6731c96ca198cf9052bbaa522408a310be1c449c29f39eec2fe64202294396342a9142e875ec7382097219ee2a1f4277fdc8eeb03db548c5bc5e767b080098353e34373a47fbe5d265427a83c9376182304169cdd0ba6a634be326fdd1da7302b5ac93b61c5a1478d373ee22dc9c45568b6effe89ff01bf308d5887e78d4820f3af7cf79f13726e15246639f84efb730db3422ca773ef6e4692d663cef7a73ddae17c11fea669a8eb0f063ceb36acf7a57b72b21e8d1a9730f1ac30a67e518173ea672f23eac5d97777cf6b3d6962bda9b6d63587b6d8feb07bf65ddfdd7e4ddb937deac528be36501674b5fccb51fd7307872c3bfefa055261f09e64f0d4569057f580932e9da667e9ef7aab62f7f7760cd06e1e4727a355ee7079c534468253b57ef9deb06ef2df3ccb4dfa58ab4f93748370dfc9717f39e2cb64acef61b6698b339b024f96dc462df959031a321c57aa9a9cd14f7b669960ed4b90f8ff8191bb2321fef949e1ef72e9d663e4d38dbfa2efdf93ec7057392921c8a2cea475f49df567781a5354ebcc06826e77a65d2426bafb6546f6dfffc8985693bb68cd891f157ca518b21ec798c3ffd69117b3bee1b1e0e6d8d8d2bb7c9d4ff25277fab0de7c0cfbb28e35fe80eda6193f5de094b3b71773a71dce613fffbed70e60ccfb9596faecd7f829d4a0b8d7c58ed3c1e73a96a687601d9313bf957fde6dde9ff6b8ed23ae8c91f7f8794673bc54f782e715d84deb332c6549fb6a5dbdd53cd311f5f6e4ddeadb5f35ad8a0ab3623e34fbc0cb56c70be79b53dfd54b0cb0fbbd7eb15fa96752c0e1ce91377b766ece2b5dffcdac63c363feb353d70efd082d9ef1d0ca3b03ec3f393db19f398a644011d3fedf0d4fce5f847774e368ec3a7fc7ef82e3b38c877e32f4e9397d1260b2f672790d66ece98dbecd48659a373b728c5c3e1f6e2d0e1d1e4d2670f9f18101be92b6893be6bd7d6a5bb8efd9f59a63776d77c9ce9a99f775ed2d3771cf3827d29dea5bc7d25b96c6b07a385b695c5e26706bcdd5e3ab88d46d9e46d9e84d13bf843a4c7562ea3a3c89f6ce130e6d349bbcb068cb165fe662793264c4cdd6afb74b8c1ebfa7afda143f166b9d7993fef8efaf1e4c98b1139df66ec4bb955d9f1aa7641e6789fabeb8c5c2b6ee377516e911d9facaf6234658cbabea7eaf163ecf8e926d2a8285cd5abd0626fd78a5ff69f4c4ded702e9e77dbffc0bd1d11d9377e7cedb6352d583a7dc96f85f51b0c3029a2679717ac92d42e6e6b3ca1c3bc47cc99113bbaa631767dd62daba78e1b0c8f57700def9d38e8e5b7f75abda16eead18da94273c6bc7b6b26ce585bbb83f0fdb163a3aeffcb715eddd95efbdbf9981bb4c439c1addfc4156f9a59be3175f7def5830cac8ae2cea68df1c67098bbd6115d521b1b433e3e3bb023bdf4fca3f3a36635968f8b5fb1ca406794e94f298dd4d4a0874be97f04e47b70df1b672cc820eb4da8d3aaa99af8777605e381532355acd5742fa2ed40e6ea4f576d3a3e15bdca6b6d8bbf7b4a38cbd3d3533fc333e3f98ffe18c2814de181debfd867617d0f04d51ab6e10e2c121f2e8ce8ac3319b985f5c3a0b06bd2271fdfbfedd87ee7c38395c7f2cacb1fd4e95679dd39117714eb5b3b63f55b77eb1db54f8e9e1ac9787c6b5ed90cfbb5a6a1b92f7faf745fe922daa9151f1757b12a7351d98a9ded6502a3931d6e9bbc63ff9dbb6fed4d52aeb753b663fb384250d2106145e2b69a471e3f145fc9b970d520f3af93db4b36ae985afa4aa06bb47f63e27afee311e72ae71aaff954bbe2cdb562a6b9e4ca7ccc0abb79feda19b3939d0e9e4f9bf66a555347497843dcf545c269575cc8e4baa5e43d9e5ef12ea1230eb0aca14bc1cb96f98ebc5219be70460d26f0504ba2c9b3f57ecd8597161d2d28dd3e88aedd70b333fc307dfc91e0e074e755da0fee2fd66640174efbeda770d9d9ef8751f68f3eb82ee0ce8f474b8a73284fcf143e5a56fa6dc3f4eb8f1f670b87bae81c0ba9da3b2e8ad994aa7769ff6ae8465276f5f199651f5b37261754a6675e367e1570b84c8009b96bfd29f7c34549cc5f9bd7547a4d5e33f171eb9353e7df3bdee796ed131b786b4123a696573c7576a725b188ba377fb5e2b63ebe6531dae6bbf9260fcfbf8abe7b2672b85f2e957f99ffa054effa1ff7531c5c9b4419e697cf62726bdf1fbf6858f4c8e1604059e5cdd3e9cfd377af285e7c6cb57ecde649d58f56ac99f4cf3fff703897bfadd9f4f26e714279d014e6dc1de1bb1f32a631823ecdca10ffadf55d8ceda24a8bc66352e38d6777577a9a591c7ff326a2e90e3975d7250f7ad35562f622eeb7a48ddf9fe2050e727cb54dd7c8ac257adcf33ad78277177e61d8d84e3dcf9aba4d37ee0cabfd7adb01d3855ee2c64f94c4090e65e2fb35a3c4b41d6f6758c6c5de9ac8e61c4a0edfb67bad39cde770a06b75d1f3e0d167aea51b7cfca778e7920505da58238cce4ca350833b79f19b56261f5d58287c320e53b17a4bd9eb3182945544acd9a41990f44ce5b277fa5527b2925b86e05a74361cba5f5193fdc3d37acb2ab329f30737b323af53f7967bccd15d9dbad7f8f9f6d87b254de6faa9ad31180fa653a177fa256be6dabcbf2f7272768e785170d1d6341d87e34900899b61396d398b6f9aef3c9cf1d16682e331cccd53a5da578adcac0a27b40410939baa7479cdd5c46a8987f685bf3779cdfe89a31d4ccf2a5b90f6b8cdbbaecc657cc66b2d7cd3fd14c96f3323864d69a0aedb33fffbe6bc9afaf73f45fd34cecea3f0d9be784add87a58327b41e2c6a2f9a7d402b9bb26fe9d606fab4a26d1fdf2c8bb87e21b0b62e38e1a1276d0886b8e775ee98391d96cc08f76f0c6a77e5949c194f4cb735a8bd597d75c3de0dc326dad43942b693ce26b5a5e02b3a6b57ecfceb64fcb97f9ef955bc3eb18291dfbc80be9ff8a77f96e8fb9d17a670cf2d7f139ebfc326227384e3aff6623cf4baf9f72951df489ef1333eacfcd1efe548dcf8db7332178c71a91471d975f82668e1b1d3ed6b4344a93ea169a71dae0494704b58a7d3b212a36f50ee649c707daebd2eb2d534b56a88fffdd38bb5d66f32bd38cad981f1ebf72e371a3acd0be986163be36b4caeee8ab822faf9c3e6a72bcca8734cd66d27ce2545c4799ab3aebd30376f2da2399891ee1f5abdcd6755c6bef0c1375e145a1f3c6dc46cd0f5a8a7740c2235f8e56d09496c3e427ef3678bde8c877fe5dd6b5ad3f6e95ad46dc22b1a4b0a4619bdfd6dc5df94e52dbe050b9d84f967cf109faf32693c959947218913f25dceaf6b8f7f7efb76daf6254b8e9c4cdb78c4fb70f49f9368a16d86654fb47417077cfb62e299d8e186db62436eb973bca716e7179b1a84dcdb8339121a61ec7e24b7fa718997be5d6c4879f908ff1f2c135aae9bb82e2cf7b87ae403fff75dfb777d07592ff1b675eb7cfbf702bf9fdedfa409890f4d97ded79a1774e4c212eda6ef1b6bdd1fdf6b6aa9386d7dc8fea048b8e65d73636bfc62da1fdafb4eebbb3345d59eb41cddfcf5e5efd95efe1edb8e3f6d63845cfc66afdb695beb6a9fc09bbf8a2656d9e45efaab7ad2304951d685715776733f1d31cc3b6997b5cc3294b92fc1f2e9ff1a9867f75417b418151eba36da745d0e61ba65ea27c998dce36d7eece04cdfb8c6128e5653f12e879ce68e259638377343eb72ca12dbe5c79ebf746cc2665ecbdb6763fc72d2d327ecb76beb0a83d2ddb2a429cbf2db62de7c7f3c7b9d93332d3f6d41dae92763336b5d86bdf14f3a647527447bc4ad7641e69aca378fdc2789c61ccd9d30f2d2088957b2a820c460f18b237e5a3b2c99146cd0a3a08bf9920ddf15c4532ebdfde9c3ad0bdeb9559b675a3cdde3d2e9dff15af47069c8311d5245e3e4db527c9d87389e13982b99fbd3fa5fe6ed0e29c83f3e92e4da91dcb22e9956373cb3e08fcef69bb3f18c6cc2e8ca777f4c8aeb9c251c4e3b2718b9fcf5e524af962b83fff6e5fc33eefd94a25989c9ba35b2ad928f871fad68ceb7497047e3d5beb5dbf500907d347a07d0b5e913b0a0183c478a7c9125fb46c5e85238108345c5e8ea52785cc14aac18e2b9e2e09db0840341521c962386d8ae38d4fe188795c68a20579c6c074c80bf136440846e244aa890152bfbcbe24651295c7e18562266bae2d01b4f1c9542908d6374e91cae04cb9560a51c080bdb89658b857c6c981892e065a85d6814026caf2c248c971df4520040a9865dd9cfe28b81dd5c7f4655146b1fa925d2bfcfa762d95c1e8497b19fcd9a062601007f347a8bdbc3ce63c40a23a59a08399cd4472730850229832b80c4683fe3e359109b2b80b0b89e13700909180a874875f7f7a3bbf9f8792ca41038442a263e1e12b012e0d72553751ebc220200887d5a37bd1fd6b18542a972d3ba463fdbe5e9ef4f576014fd928bb7ea578ffd314a76712837aa6b546654d72b6322d5dbc38da6c0b0cef82db708708f67a00cebfa2bb73898d1fcdde941011ed8ae5582f2f90f7c8577efc8a53c88ea25f41433f810763e0c22db93cb8ec267c4c7f7d439c2bdcfab44f722d1f51a801b8565f21812892ba26e7a83a06aaa6ba30faf20f218dd09ee0df025f388d90a1698abd732cd3a01009d0374356aa2ea513f832485f52e57db32e260de9f3fab6ef7f78758514dcbd5ae8cd8d6f51e65608915d56c7c3c57c0e445b27aca0d1ec661f10909982f63783e832ba08b787287718818c25364766bbd7faee30700f0d3544dd0cb6e19b906c5e0dc4f0af817b1775e7cdd7cfc883d69a9f37dc91c09001839f0dc24c5dca41eeed059b1cd686eb895132d41718f55ca0d43bba74942be182e3f798cb2c988b9ca12208fa5af004b03986108180da66b754f573155512407c9a622e60d1a6c3444b9d2fbb3d32fdd6039817aba6fe590535090812a207bebbed1c848d9b47d0f3200f989479522aba1fb96a741aa9a6d5034718380468a6c7906a4e2d80ac5306730d0402b2d8f8f14049ba3f0870d01fd5331f795ddf1a8ec5e510a2da72f560e381905385e0bf4435f8c4645ca7eed501110a94655a22f96e740aa7ecd501ccd2a38d07262f5433c571ba8a7205637c4d9daa01f0a62342a52d88b0ef11bd5a84a14c4f21c485d2f3ac4eca1a01f8261f5435cab14574e23ac1cd01405385107a8af11560e8a438146280555a211460323b5bbe8d45d550b589146589e03a9d545735087010d35c1ea07a8440d0e9406180d8c94e4a28d1fae0b34d400cb732035b8688e34f53814487dd50fd007353850da5e3430526e6b8b329e8e019a697be52990f25a34c5cfea51f456f1f6159ea9a8f0cc1e0efaadda95bb032114b4e887951c75b115a976e56990425934cdc411407371aefa91ca518f06a5c1456323a5ad04940b1dea622bd0e0cab320b5a86896a37a4063d1acfab7dad091a01f2a57342a5293370d657bd948d07f95ab3c3c52498a86771e05faaf629587476a442d51f0e7d5819713a7caa323359fe8a7759a3ed048752acf80d4625aa3186eaac920a724ed2bbd53d04b8501e897c0531e19a9a344238f1d0dfa25e0ec6533421f8946ce56812cafca944746aa0f2d50c8930c417fd596ea8367ab06971753aaff54696204d4d34aaabb9a842b0554a49544a322558ae8dde705d5a80ab4927d596d86b27ae118d02fe5a3dc3307a22186be0e0bd4c1edad7c942740b697d0c5913b05f4b7cba6fe0ea1c41ca8dfaf428322bb47e890e84c059af4abfab2da1265758a1a04bd5b5268746403c809657e93fae8ca5a52bdde1e211a3bd351648916e0ab3a4cbd1e35109d1a34d3584bf0556d23792664bf02cd74ac1f4c8adea9ab5f08865640836e081a1dd9a040fb11a13eba5ab9417624d04cbff783499ddc207b086826a635f8aa7e475fb9b145e566820dd0b44381a640760c9c51ceacee2785a20e853c1bb2478066ebd4848da4984d59dfa1ebc70080d951b6407517e28be98afa105fc04e2803530b4b1f85f5af022cb56086a1603ced80a2ae84f2e95aa8e929ddd37b4d55d687f832f5826c2a629ef650d9080dd040963100bfd9c9befd3f0000ffff5311883694460000"); err != nil { + if err := gres.Add("1f8b08000000000002ffb45a0b584ce91ffe50d210a5502e99464ab7996674619a8634ddd08506159b9d66ce3493b93533a58b502af12f84cda548368b24ca4a945b6d422db9acdc369794b565915d9b58fb7fe6949c33cd34d368e77986e67ce77bdfdfed7ce77ce7f706cc1ba26504860100de40dc0080f84c04ba8010cd101356ae5c490867db49b85288208524520253286073c317d1b5c1a016323b34609ece30e444e590535440da31a32452215f03647ba5c868e8ee5f78a990cfeba189e6422b450c2907eb8ac51138423e04a34821be88c79042121c66a918627125df60b0582c96c595acc0cace24929cf1f6787b3c91ec34dd79a6ad030e1e6632981c48c1b0234ee60c9de6f4800d0060f7e98c8dbacef063f15c017760fd70eadb0f67d80f7b9de664d57e58a9f2e3bfcb867ddf5e10612f722ab7b0547b61aed28bff220da4be1d980e3bd091e8eea2da81f14a1d6071c5440d2eb6c9ca2322432448a2c23440b5538d2afbdac90e11f1d218690f47cf512c5328904202a98cf4dc896d64030080419fa4662a4861d81ea25e246943667dd20300e8699e00d2802780f49f2480844a0049610248c8d8c46f361df2b50920c17f9250094091f8ce2aa9f99a04708933041a84cab44f403b1657ac01284e79283ea31220c1c02616014ce0403c9e10bd1663e063b2f5c75bf607bce8885b2398fa0000fd81e05c2914f358729cf03119e712d91f30e71e83284bd59cea043082f11f053082d11dc05846af0092b1b8a6c46d4d49db9a128f3425e635251e83bdaa605b079b00004c0682bc2b922872f810198b7b5696f5fcbb749872afdb72de2800c0a8af0ea4384a8340daaa05dc1d48e43db5a70eeb736facad2fab2fa93f792309f688b7ca6cda5800c0d88120ee0a2292b8a718eb2beacb6eac8529a1d697e5aaab71aa1a94711c3b77bf817ddc45637787324222fcb270c4c34f16387804272b8fb3fb9a0f9cc56112e0dba6d9f033aa6b527dfeae882ae28747705fcab38b1ff372de27d5fc6ac696be4483d812d4c5ee8e6d0ce28aa3cc8ae1f3b0d19058c2150a5c7144bc3d0e0b099842165710ee8a8b92b2ed66e0665131141910150e030506a176e580d20549c550602aaacc68fdb8b19bfd0100fe0364745742bed2681884da95384a1724cae84e8bf9dfa9367a72df77513697076990bf692a422183254082be6f748a6e42cc9576b3b10000ecd7d34730d4bc4d6014ace146976a83ace0ed555f7658aa6387384a8d5516a3680dac5c48f8c712a6d17027fbc50878a1e8bd44f45aa06c314a570d6a00a1d4165ee6fbb2c65a4d6be84bfe938b5aad2be7caecabb7b80000ae862f5260a4ffb0bc5531473094312b2e6dd908a2b6178463a36de0c2f91a23c451ca8c505dd8cc1967564c83afe3be2cb0506141574da38ce8b1e1f3fd5691ff2f1aaf6698c1dba2af64a72ff9cfd895efa6c442a17460b7b33244025322d100d54a352a41228de5417824be35b6ebf1842d1448ed24dc38888c9d4e12c5b8c007a5508cd48ec1e3860bc858262490426297aef5c7ba31ec77120080a4e95e17b688cb67846b72c7b3560797c013860bf122c197f7b61b02fcbcf430e331b2edb38f376d61b7fda46143653bdc5969c500804192855e7340d1b5892f0000ba22ef600900c30d65df4160778e3100838bb8f4206990ef7c3253c8c73358c230081fc317c1765162c8317c111f9232b0317c9e40428e71c5c167900512b2ec300187854f91ae70c505f90660dd856208eb8877c0dbe3e0e5922266b1c90b699eddd3c52cb62b8e23958ac80499abf895d3f1427138813873e64c823d894022d989596c3b49ac40ca88b11348a674817cc6a14112a6982b92728502acec37234c182575c5e1bacfe9fa74dbc917f5100924dd5e31857c420c434420e2ed098a26b1983d734451621e6c1a8b498078101f12482504229ea8709e94cb662b66938d74d151bfcca3c4f045647731c49042348614a292ec8933edec1dedec9de84412793a894c740ca110e44e52345d28a60b853caa9b8c0eebc915432b85e21512ac7ba003627af74972f37d852c2e3bb617bd23d9d1893c7d46373de224c4741693cc168af90c29b5ab2a4582700ae1cb41c49932efc9fe622e2490326449a31229845ec73e27982097e1aef22174d78fec0edb538b54cceba5b787008059e34373a373b45f062d15d21b4cbe0917840b4a6b86d6551b5b1a37e98fd69e13a8659db4e5d0a2c09b9e7317e1e62cb25a74fb47ff84df9847a846f4c3a3167cd0b97fce8bbf310997321afb2462bf85d9a611d1bef3b1274f6b31e379d79beb76bd08f95037d37484851f739e557bd6bbba5d09c18f4e9d7bd0185e382bc7b8f0319593f761edbabce3b39fb5b65cd1de6c1bc3da6b7b5c3fe42debeebf26efcebdf166955a1c2f0b385bfa62aefdb886c1931bfe7d07ad32f948307f6a284a2bf8c34a9049d736f3f3bc57b57dd9bb036b36082797d3abf13a3fe09c22c32ad9b97aef5c37786f9967a6fd2e55a4cdbf41ba69e0bfac98f764b15572b6df30c39ccd8125c96f2317fbae808c190d29d641a63653dcdba6593a50e73e3ce2676cc8ca7cbc537a7adcbb749af934e16cebbbf4e7fb1c17cc494a7228b2a81f7d257d5bdd0596d638f102a3999ceb95490badbdda52bdb5fdf32716a6edd8326247c65f29472d86b0e731fef4a745eeedb86f7838ac3536aedc2653ff979cfcad369c033fefa28c7fa13b68874dd67b272cedc4dde9c4719b4ffcefb7c399333ce766bdb936ff09762a2d2cea61b5f378cca5aaa1d90564c7ece45ff59b77a7ffaf395aeba0277ffc1d529eed143fe1b9c475917acfca18537dda82b6bba79a633ebedc9abc5b6be7b5f041576d46c69f781966d9e07cf36a7bfaa910971f76afd72bf42deb581c38d227ee6ecdd8c56bbff9b58d796c7ed66b7ae0dea105b3df3b1846637d86e727b733e6314d89023a7edae1a9f9cbf08fee9c6c1c874ff9fdf05d7648b0efc65f9c262fa54d165ece4e20addd9c31b7d9a90db346e76e518a87c3edc561c357924b9f3d7c62406ca42fa74dfaae5d5b97ee3af67f6699ded85df371a6a77ede79494fdf71cc0bf6a57897f2f615e4b2ad1d8c16da56168b9f19f0767be9e0361a6593b7791246efe00f511e5bb98c8e227fb285c3984f27ed2e1b30c696f99b9d4c9a303175abedd3e106afebebf5870ec59be55e67febc3bfac793272f46e67c9bb12fe55665c7abda0599e37daeae3372adb88ddf45b945767cb2be8ad19431eafa9eaac78fb1e3a79b48a3a37155afc28abd5d2b7ed97f3235b5c3b978de6dff03f7764466dff8f1b5dbd6b410e9f425bf15d66f30c0a4889e5d5eb04a52bbb8adf1840ef31e316746ece89ac6d8f559b7ac9e3a6e303c5ec135bc77e2a097dfde6bf586baa94737a60acd19f3eead9938636ded0ec2f7c78e8dbafe2fc77975677bed6fe7636ed012e784b47e1357bc6966f9c6d4dd7bd70f32b02a8a3b9b36c61bc361ee5a4774496d6c0cfdf8ecc08ef4d2f38fce8f9ad5583e2e7ef92a039d51a63fa5345253831f06d1ff08c8f7e0be37ce589041d69b50a7555335f1efec0ac603a746aa58abe95e64db81ccd59faeda747c2a7a95d7da167ff7947096a7a7a77e8667c6f31ffd3184039b2202bd7fb1cfc2fa1e08ae356cc31d58243e5c18d9596732720beb8741e1d7a44f3ebe7fdbb1fdce87072b8ee595973fa8d3adf2ba7322ee28d6b776c6eab7eed63b6a9f1c3d3592f1f8d6bcb219f66b4dc3725ffe5ee9bec245b4532b3e2eae6255e6a2b2e53bdbcb0446273bdc3679c7fe3b77dfda9ba45c6fa76cc7f67184e0a421c28ac46d358f3c7e28be9273e1aa41e65f27b7976c5c3eb5f49540d768ffc6c4f5fcc723ce55ce355ef3a976f99b6bc54c73c995f998e576f3fcb53366273b1d3c9f36edd5aaa68e928886b8eb8b84d3aeb890c97541e43d9e5ef12e61230eb0aca14b214b97fa8ebc5219b170460d26f0504ba2c9b3f57ecd8597161d2d28dd3e88aedd70b333e2307dfc91909074e755da0fee2fd66640174efbeda770d9d9ef8751f68f3eb82ee0ce8f474b8a73284fcf143e5a5afa6dc3f4eb8f1f670b87bae81c0badda3b2e9ad994aa7769ff6ae8465276f5f199651f5b37261754a6675e367e1570b84c8009bd6bfd29f7c34549cc5f9bd7547a4d5e33f171eb9353e7df3bdee796ed131b786b4123a696573c7576a725b188ba377fb5e2b63ebe6531dae6bbf9260fcfbf5a79f74cd470bf5c2aff32ff41a9def53feea738b8368932cc2f9fc5e4d6be3f7ed1b0e891c3c180b2ca9ba7d39fa7ef5e5ebcf8d86afd9acd93aa1f2d5f33e99f7ffee1702e7f5bb3e9e5dde284f2e029ccb93b22763f644c63047f9a9521fe5bebbb18db4595168dc7a4c61bcfeeaef434b338fee64d64d31d72eaae4b1ef4a6abc4ec45dc6f491bbf3fc50b1ce4f86a9bae9159cbca71cfeb5c0bde5df88561633bf53c6bea36ddb833acf6eb6d074c177a891b3f511227389489efd78c12d376bc9d6119177b6b229b73283962dbeeb5e6349fc381aed545cf43469fb9966ef0f19fe29d4b161468638d303a338dc20ceee4c56f5a917c7461a1f0c9384cc5ea2d65afc708525611b166936640d233954bdfe9579dc84a6e19826bd1d970e87e454df60f4feb2dabcca6cc1fdccc8eba4edd5bee31477775ea5ee3e7db63ef953499eba7b6c6603c984e85dee997ac996bf3febec8c9d939e245c1455bd3741c8e2701246e86e5b4652cbe69bef370c6479b098ec730374f956a5f2972b32a9cd012404c6eaad2e5355713ab251eda17fedee435fb278e76083dab6c41dae336efba3297f119afb5f04df75324bfcd8c1c36a581ba6ecffcef9bf36aeadfff14fdd3383b8fc267fbe229751f82064f683d58d45e34fb805636655fd0d606fab4a26d1fdf2c8dbc7e21b0b62e24e1a1276d0886b8e775ee98391d96cc48f76f0c6a77e5949c194f4cb735a8bd597d75c3de0dc326dad43942b693ce26b5a5e02b3a6b97effceb64fcb97f9ef955bc3eb19c91dfbc80be9ff8a77f96e8fb9d17a670cf2d7b1391bfc326327384e3aff6623cf4baf9f729d1df489ef1333eacf8d1efe548dcf8db7332178c71a91471d975f82668e1b1d3ed6b4345a93e6169a71dae0494704b58a7d3b21257dea0dcc938e1fa5c7b5d54ab696ad510fffba7176baddf647a7194b303e3d7ef5d6e34749a17d20d2d76c6d7985cdd157945f4f387cd4f979b51e798acdb4e9c4b8a8cf334675d7b616ede5a44733023dd3fb47a9bcfaa8c7d11836fbc28b43e78da88d9a0eb514fe918446af0cbdb129ad87c84fce6cf16bd190fffcabbd7b4a6edd3b5e8db84573496148c327afbdbf2bf29cb5a7c0b163a09f3cf9e213e5f65d2782a338f421227e4bb9c5fd71efffcf6edb4ed4b961c3999b6f188f7e1957f4ea285b519963dd1d25d1cf0ed8b896762871b6e8b0dbde5cef19e5a9c5f6c6a107a6f0fe64858a4b1fb91dceac7255efa76b1a1e5e523fc7fb04c68b96ee2bab0dce3ea910ffcdf77eddff51d64bdc4dbd6adf3eddf0bfc7e7a7f9326243e340dbaaf352ff8c88525da4ddf37d6ba3fbed7d45271dafa90fd419170cdbbe6c6d6f8c5b43fb4f79dd677678aaa3d6939baf9ebcbdfb3bdfc3db61d7fdac608bdf8cd5eb7d3b6d6d53e81377f154dacb2c9bdf457f5a46192a2ac0be3aeece67e3a629877d22e6ba96518735f82e5d3ff3530cfeea92e68312a3c746db4e9ba1cc274cbd44f9231b9c7dbfcd82199be718d251cada6e25d0e39cd1d4b2c716ee686d6e59425b6cb8e3d7fe9d884cdbc96b7cfc6f8e5a4a74fd86fd7d61506a7bb65495396e6b7c5bcf9fe78f63a27675a7eda82b4d34fc666d6ba0c7be39f74c8ea4ea8f6885bed82cc35956f1eb94f128d399a3b61e4a51112af645141a8c1e21747fcb476583229d8e047c117f3251bbe2b88a75c7afbd3875b17bc73ab36cfb478bac7a5d3bfe3b5e86150e8311d5245e3e4db527c9d87389e13982b99fbd3fa5fe6ed0e2dc83f3e92e4da91dcb22e9956373cb3e08fcef69bb3f18c6cc2e8ca777f4c8aeb9c251c4e3b2718b9ecf5e524af962b83fff6e5fc33eefd94a25989c9ba35b2ad928f871fad68ceb7497047e3d5beb5dbf500907d357a07d0b5e913b0a0183c478a7c9125fb45c5e85238108345c5e8ea52785cc10aac18e2b9e2e09db0840341521c962386d8ae38d4fe188795c68a20579c6c074c807f136440846e244a9890152bfb9fc58da652b8fc70ac44cc74c5a1379e382a85201bc7e8d2395c09962bc14a391016b613cb160bf9d8703124c1cb50bbd02804d85e5948182f3be8a50080520dbbb29fc51703bbb9fe8caa28d63e524ba47f9f4fc5b2b93c082f633f9b350d4c0200fe6af416b7879dc78815464935117238a98f4e600a055206570089d17ec6c7b32036570061713d27e0121230140e91eaeeef4777f3f1f35848217088544c7c3c246025c0af4ba6ea3c7845040010fbb46e7a3fac630b8552e5a6758d7eb6cbd3df9faec028fa25176fd5af1efb6394ece2506e54d7a8cca8ae57c644aab7871b4d81619df15b6e11e01ecf4019d6f5bfdce26046f377a707077860bb5609cae7ffe02bbc7b472ee541542fa1a798c187b0f36110d99e5c76143e233ebea7ce11ee7d5e25ba1789aed700dc682c93c790485c1175d31b0455535d1b7d780591c7e84e706f802f9947cc56b0c05cbd9669d60900e81ca0ab5113558ffa192429ac77b9da961187f0fefc5975bbbf3fc48a6a5aae7665c4b6aef728034baca866e3e3b902262f8ad5536ef0300e8b4f48c07c19c3f3195c015dc4933b8c43c4109e22b35bebfd731d3f00809fa66a825e76cbc8352806e77e52c0ff107be7c5d7cdc78fd893963adf97cc9100809103cf4d52cc4deae10e9b15db8ce6967d82864a51dc639572c3d05c4369e817c3e5278f51361931575902e4b1f415606900330c01a3c174adeee92aa62a8ae420d954c4bc41838d8628577a7f76faa51b2c27504ff7ad1c720a0a325005646fdd371a19299bb6ef4106203ff1a852643574dff2344855b30d8a266e10d048912dcf80541c5ba118e60c061a68a5e5f19182607314feb021a07f2ae6beb23b1e95dd2b4aa1e5f4c5ca0127a300c76b817ee88bd1a848d9af1d2a0222d5a84af4c5f21c48d5af198aa35905075a4eac7e88e76a03f514c4ea86385b1bf443418c46450a7bd1217ea31a558982589e03a9eb4587983d14f44330ac7e886b95e2ca698495039aa20027ea00f535c2ca417128d048a5a04a34c26860a476179dbaab6a012bd208cb7320b5ba680eea30a0a12658fd0095a8c181d200a38191925cb4f1c37581861a60790ea40617cd91a61e8702a9affa01faa006074adb8b0646ca6d6d51c6d33140336daf3c05525e8ba6f8593d8ade2adebec23315159ed9c341bf55bb727720848216fdb092a32eb622d5ae3c0d52288ba6993802682ece553f5239ead1a034b8686ca4b4958072a1435d6c051a5c7916a41615cd72540f682c9a55ff561b3612f443e58a46456af2a6a16c2f1b09faaf729587472a49d1f0cea340ff55acf2f0488da8250afebc3af072e2547974a4e613fdb44ed3071aa94ee519905a4c6b14c34d3519e494a47da5770a7aa93000fd1278ca2323759468e4b1a341bf049cbd6c46e823d1c8d92a90e55599f2c848f5a1050a799221e8afda527df06cd5e0f2624af59f2a4d8c807a5a4975579308a5808ab4926854a44a11bdfbbca01a558156b22fabcd50562f1c03faa57c947be64034c4d0d761813ab8bd958ff204c8f612ba3872a780fe76d9d4df21949803f5fb55685064f7081d129da940937e555f565ba2ac4e5183a0774b0a8d8e6c0039a1cc6f521f5d594baad7db234463673a8a2cd1027c5587a9d7a306a25383661a6b09beaa6d24cf84ec57a0998ef58349d13b75f50bc1d00a68d00d41a3231b14683f22d547572b37c88e049ae9f77e30a9931b640f01cdc4b4065fd5efe82b37b6a8dc4cb0019a7628d014c88e8133ca99d5fda450d4a1906743f608d06c9d9ab09114b329eb3b747d0c00981d6d0b547721be98aea80ff105ec843230b5b0f45158ff2ac0520b66180ac6d30e28ea4a289fae859a9ed23dbdd754657d882f532fc8a622e6690f958dd0000d641903f09b9decd7ff030000fffff2af776694460000"); err != nil { panic(err) } }