diff --git a/dbt_meshify/storage/jinja_blocks.py b/dbt_meshify/storage/jinja_blocks.py index 2332e5c..2eb55d2 100644 --- a/dbt_meshify/storage/jinja_blocks.py +++ b/dbt_meshify/storage/jinja_blocks.py @@ -24,7 +24,11 @@ def find_block_range(file_content: str, block_type: str, name: str) -> Tuple[int end_line = None for match in re.finditer( - r"{%-?\s*" + block_type + r"\s*" + name + r"\s*([(a-zA-Z0-9=,_ \'\")]*)\s*-?%}", + r"{%-?[\s\n]*" + + block_type + + r"[\s\n]*" + + name + + r"([(a-zA-Z0-9=,_ \[\]{}\"'\s\n)]*)[\s\n]*-?%}", file_content, re.MULTILINE, ): diff --git a/tests/unit/test_jinja_blocks.py b/tests/unit/test_jinja_blocks.py index 1ad60e9..42b1fb1 100644 --- a/tests/unit/test_jinja_blocks.py +++ b/tests/unit/test_jinja_blocks.py @@ -116,6 +116,44 @@ {% endmacro %} """ +simple_macro_empty_list_defaults = """\ + + +{% macro test_macro(num=[]) %} + {{ num }} +{% endmacro %} +""" + +simple_macro_empty_bracket_defaults = """\ + + +{% macro test_macro(num={}) %} + {{ num }} +{% endmacro %} +""" + +simple_macro_empty_string_defaults = """\ + + +{% macro test_macro(num='') %} + {{ num }} +{% endmacro %} +""" + +simple_macro_new_line_args = """\ + + +{% macro test_macro( + num='', + list=[], + dict={}, + int=8, + string='dave' + ) %} + {{ num }} +{% endmacro %} +""" + class TestJinjaBlock: def test_from_file_detects_block_range(self): @@ -168,6 +206,28 @@ def test_from_file_detects_block_range_simple_macro_int_defaults(self): range = JinjaBlock.find_block_range(simple_macro_int_defaults, "macro", "test_macro") assert range == (2, 58) + def test_from_file_detects_block_range_simple_macro_empty_list_defaults(self): + range = JinjaBlock.find_block_range( + simple_macro_empty_list_defaults, "macro", "test_macro" + ) + assert range == (2, 59) + + def test_from_file_detects_block_range_simple_macro_empty_bracket_defaults(self): + range = JinjaBlock.find_block_range( + simple_macro_empty_bracket_defaults, "macro", "test_macro" + ) + assert range == (2, 59) + + def test_from_file_detects_block_range_simple_macro_empty_string_defaults(self): + range = JinjaBlock.find_block_range( + simple_macro_empty_string_defaults, "macro", "test_macro" + ) + assert range == (2, 59) + + def test_from_file_detects_block_range_simple_macro_new_line_args(self): + range = JinjaBlock.find_block_range(simple_macro_new_line_args, "macro", "test_macro") + assert range == (2, 125) + def test_from_file_extracts_content(self): content = JinjaBlock.isolate_content(string, 2, 72) assert (