'{{ string }}'
{%- endmacro %}
+{% macro boolean(val, negation=false) -%}
+{%- if negation -%}
+{{ 'false' if val else 'true' }}
+{%- else-%}
+{{ 'true' if val else 'false' }}
+{%- endif -%}
+{%- endmacro %}
+
{# Return string or table of strings #}
{% macro string_table(table) -%}
{%- if table is string -%}
from knot_resolver_manager.datamodel.forward_schema import ForwardServerSchema
+def test_boolean():
+ tmpl_str = """{% from 'macros/common_macros.lua.j2' import boolean %}
+{{ boolean(x) }}"""
+
+ tmpl = template_from_str(tmpl_str)
+ assert tmpl.render(x=True) == "true"
+ assert tmpl.render(x=False) == "false"
+
+
+def test_boolean_neg():
+ tmpl_str = """{% from 'macros/common_macros.lua.j2' import boolean %}
+{{ boolean(x,true) }}"""
+
+ tmpl = template_from_str(tmpl_str)
+ assert tmpl.render(x=True) == "false"
+ assert tmpl.render(x=False) == "true"
+
+
def test_string_table():
s = "any string"
t = [s, "other string"]