update donator; update unit test case for gdb; fix issue in bool convertion for []byte for gconv

This commit is contained in:
John 2019-08-22 23:24:45 +08:00
parent 7dffd9d1ff
commit fd6321e71b
4 changed files with 33 additions and 1 deletions

View File

@ -16,6 +16,8 @@
|潘兄|wechat|¥100.00
|Fly的狐狸|wechat|¥100.00
|全|alipay|¥100.00
|东东|wechat|¥100.00
|严宇轩|alipay|¥99.99
|土豆相公|alipay|¥66.60
|Hades|alipay|¥66.66
|蔡蔡|wechat|¥666.00

View File

@ -27,9 +27,11 @@ func Test_Types(t *testing.T) {
%s decimal(5,2) NOT NULL,
%s double NOT NULL,
%s bit(2) NOT NULL,
%s tinyint(1) NOT NULL,
%s bool NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`, "`blob`", "`binary`", "`date`", "`decimal`", "`double`", "`bit`")); err != nil {
`, "`blob`", "`binary`", "`date`", "`decimal`", "`double`", "`bit`", "`tinyint`", "`bool`")); err != nil {
gtest.Error(err)
}
defer dropTable("types")
@ -41,6 +43,8 @@ func Test_Types(t *testing.T) {
"decimal": 123.456,
"double": 123.456,
"bit": 2,
"tinyint": true,
"bool": false,
}
r, err := db.Table("types").Data(data).Insert()
gtest.Assert(err, nil)
@ -56,5 +60,7 @@ func Test_Types(t *testing.T) {
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"])
})
}

View File

@ -208,3 +208,22 @@ func Test_Basic(t *testing.T) {
time.Sleep(time.Second)
})
}
func Test_Bool(t *testing.T) {
gtest.Case(t, func() {
redis := gredis.New(config)
_, err := redis.Do("SET", "key-true", true)
gtest.Assert(err, nil)
_, err = redis.Do("SET", "key-false", false)
gtest.Assert(err, nil)
r, err := redis.DoVar("GET", "key-true")
gtest.Assert(err, nil)
gtest.Assert(r.Bool(), true)
r, err = redis.DoVar("GET", "key-false")
gtest.Assert(err, nil)
gtest.Assert(r.Bool(), false)
})
}

View File

@ -213,6 +213,11 @@ func Bool(i interface{}) bool {
switch value := i.(type) {
case bool:
return value
case []byte:
if _, ok := emptyStringMap[string(value)]; ok {
return false
}
return true
case string:
if _, ok := emptyStringMap[value]; ok {
return false