Skip to content

Commit

Permalink
workaround issue 209
Browse files Browse the repository at this point in the history
  • Loading branch information
dgofman committed Jun 18, 2019
1 parent 8914e1c commit 13f59ea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions parser_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions template_tests/if.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
2 changes: 2 additions & 0 deletions template_tests/if.tpl.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 13f59ea

Please sign in to comment.