Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Oct 1, 2024
1 parent 1a643e3 commit 8aa646b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/unit/test_jinja.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from dbt_common.clients._jinja_blocks import BlockTag
from dbt_common.clients.jinja import extract_toplevel_blocks
from dbt_common.clients.jinja import extract_toplevel_blocks, get_template, render_template
from dbt_common.exceptions import CompilationError


Expand Down Expand Up @@ -503,3 +503,24 @@ def test_if_endfor_newlines(self) -> None:
hi
{% endmaterialization %}
"""


def test_if_list_filter():
jinja_string = """
{%- if my_var | is_list -%}
Found a list
{%- else -%}
Did not find a list
{%- endif -%}
"""
# Check with list variable
ctx = {"my_var": ["one", "two"]}
template = get_template(jinja_string, ctx)
rendered = render_template(template, ctx)
assert "Found a list" in rendered

# Check with non-list variable
ctx = {"my_var": "one"}
template = get_template(jinja_string, ctx)
rendered = render_template(template, ctx)
assert "Did not find a list" in rendered

0 comments on commit 8aa646b

Please sign in to comment.