From 13f59ea63065de4c7bfb1de00ec52f882a312846 Mon Sep 17 00:00:00 2001 From: David Gofman Date: Mon, 17 Jun 2019 20:27:27 -0700 Subject: [PATCH] workaround issue 209 --- parser_expression.go | 7 +++++++ template_tests/if.tpl | 2 ++ template_tests/if.tpl.out | 2 ++ 3 files changed, 11 insertions(+) diff --git a/parser_expression.go b/parser_expression.go index 1663ec4..60038b5 100644 --- a/parser_expression.go +++ b/parser_expression.go @@ -201,6 +201,13 @@ func (expr *relationalExpression) Evaluate(ctx *ExecutionContext) (*Value, *Erro case "!=", "<>": return AsValue(!v1.EqualValueTo(v2)), nil case "in": + val, ok := expr.expr1.(*simpleExpression) + if ok && val.negate { + t1, err := val.term1.Evaluate(ctx) + if err == nil { + return AsValue(!v2.Contains(t1)), nil + } + } return AsValue(v2.Contains(v1)), nil default: return nil, ctx.Error(fmt.Sprintf("unimplemented: %s", expr.opToken.Val), expr.opToken) diff --git a/template_tests/if.tpl b/template_tests/if.tpl index 29fe936..118aea2 100644 --- a/template_tests/if.tpl +++ b/template_tests/if.tpl @@ -6,6 +6,8 @@ {% if !simple.uint %}false{% else %}!simple.uint{% endif %} {% if !simple.float %}false{% else %}!simple.float{% endif %} {% if "Text" in complex.post %}text field in complex.post{% endif %} +Hello string {% if not "Hello" in complex.post.Text %}is not{% else %}is{% endif %} in complex.post.Text +World string {% if not "World" in complex.post.Text %}is not{% else %}is{% endif %} in complex.post.Text {% if 5 in simple.intmap %}5 in simple.intmap{% endif %} {% if !0.0 %}!0.0{% endif %} {% if !0 %}!0{% endif %} diff --git a/template_tests/if.tpl.out b/template_tests/if.tpl.out index d4733ec..94d9178 100644 --- a/template_tests/if.tpl.out +++ b/template_tests/if.tpl.out @@ -6,6 +6,8 @@ float != 0.0 !simple.uint !simple.float text field in complex.post +Hello string is in complex.post.Text +World string is not in complex.post.Text 5 in simple.intmap !0.0 !0