18659e16 by Black.Lee

add compare_not/not_nil methods for template

1 parent 07c628c7
...@@ -42,6 +42,9 @@ func init() { ...@@ -42,6 +42,9 @@ func init() {
42 beegoTplFuncMap["dateformat"] = DateFormat 42 beegoTplFuncMap["dateformat"] = DateFormat
43 beegoTplFuncMap["date"] = Date 43 beegoTplFuncMap["date"] = Date
44 beegoTplFuncMap["compare"] = Compare 44 beegoTplFuncMap["compare"] = Compare
45 beegoTplFuncMap["compare_not"] = CompareNot
46 beegoTplFuncMap["not_nil"] = NotNil
47 beegoTplFuncMap["not_null"] = NotNil
45 beegoTplFuncMap["substr"] = Substr 48 beegoTplFuncMap["substr"] = Substr
46 beegoTplFuncMap["html2str"] = Html2str 49 beegoTplFuncMap["html2str"] = Html2str
47 beegoTplFuncMap["str2html"] = Str2html 50 beegoTplFuncMap["str2html"] = Str2html
......
...@@ -139,6 +139,14 @@ func Compare(a, b interface{}) (equal bool) { ...@@ -139,6 +139,14 @@ func Compare(a, b interface{}) (equal bool) {
139 return 139 return
140 } 140 }
141 141
142 func CompareNot(a, b interface{}) (equal bool) {
143 return ! Compare(a, b)
144 }
145
146 func NotNil(a interface{}) (is_nil bool) {
147 return CompareNot(a, nil)
148 }
149
142 func Config(returnType, key string, defaultVal interface{}) (value interface{}, err error) { 150 func Config(returnType, key string, defaultVal interface{}) (value interface{}, err error) {
143 switch returnType { 151 switch returnType {
144 case "String": 152 case "String":
......
...@@ -72,7 +72,7 @@ func TestDate(t *testing.T) { ...@@ -72,7 +72,7 @@ func TestDate(t *testing.T) {
72 } 72 }
73 } 73 }
74 74
75 func TestCompare(t *testing.T) { 75 func TestCompareRelated(t *testing.T) {
76 if !Compare("abc", "abc") { 76 if !Compare("abc", "abc") {
77 t.Error("should be equal") 77 t.Error("should be equal")
78 } 78 }
...@@ -82,6 +82,15 @@ func TestCompare(t *testing.T) { ...@@ -82,6 +82,15 @@ func TestCompare(t *testing.T) {
82 if !Compare("1", 1) { 82 if !Compare("1", 1) {
83 t.Error("should be equal") 83 t.Error("should be equal")
84 } 84 }
85 if CompareNot("abc", "abc") {
86 t.Error("should be equal")
87 }
88 if !CompareNot("abc", "aBc") {
89 t.Error("should be not equal")
90 }
91 if !NotNil("a string") {
92 t.Error("should not be nil")
93 }
85 } 94 }
86 95
87 func TestHtmlquote(t *testing.T) { 96 func TestHtmlquote(t *testing.T) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!