fix issue in eq for package gview

This commit is contained in:
John Guo
2021-01-04 00:05:02 +08:00
parent 4d962c5aa5
commit 8a91592839
2 changed files with 17 additions and 4 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
// Copyright GoFrame Author(https://goframe.org). 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,
@ -51,11 +51,11 @@ func (view *View) buildInFuncMaps(value ...interface{}) []map[string]interface{}
func (view *View) buildInFuncEq(value interface{}, others ...interface{}) bool {
s := gconv.String(value)
for _, v := range others {
if strings.Compare(s, gconv.String(v)) != 0 {
return false
if strings.Compare(s, gconv.String(v)) == 0 {
return true
}
}
return true
return false
}
// buildInFuncNe implements build-in template function: ne

View File

@ -175,6 +175,19 @@ func Test_Func(t *testing.T) {
t.Assert(err, nil)
t.Assert(result, `ILoveGoFrame`)
})
// eq: multiple values.
gtest.C(t, func(t *gtest.T) {
str := `{{eq 1 2 1 3 4 5}}`
result, err := gview.ParseContent(str, nil)
t.Assert(err != nil, false)
t.Assert(result, `true`)
})
gtest.C(t, func(t *gtest.T) {
str := `{{eq 6 2 1 3 4 5}}`
result, err := gview.ParseContent(str, nil)
t.Assert(err != nil, false)
t.Assert(result, `false`)
})
}
func Test_FuncNl2Br(t *testing.T) {