From 8a91592839ec4dcca15f5a377ea14bab0b7d32a6 Mon Sep 17 00:00:00 2001 From: John Guo Date: Mon, 4 Jan 2021 00:05:02 +0800 Subject: [PATCH] fix issue in eq for package gview --- os/gview/gview_buildin.go | 8 ++++---- os/gview/gview_unit_basic_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/os/gview/gview_buildin.go b/os/gview/gview_buildin.go index fc4f8f697..064903897 100644 --- a/os/gview/gview_buildin.go +++ b/os/gview/gview_buildin.go @@ -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 diff --git a/os/gview/gview_unit_basic_test.go b/os/gview/gview_unit_basic_test.go index afca128ed..c46767919 100644 --- a/os/gview/gview_unit_basic_test.go +++ b/os/gview/gview_unit_basic_test.go @@ -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) {