{# Usage: {%- import "generator_macros.j2" as macros -%} #}
{# {{ macros.linebreak(text) }} #}

{%- macro linebreak(s) %}
{%- set parts = s.split(": ") -%}
"{{ parts[0] }}: "
{% for part in parts[1].split(", ") %}
"{{ part }}{% if not loop.last %}, {% endif %}"
{%- endfor %}
{% endmacro -%}

{% macro canonical_ref() -%}
# Tests adapted from `problem-specifications//canonical-data.json`
{%- endmacro %}

{% macro header(imports=[], ignore=[]) -%}
import unittest

from {{ exercise | to_snake }} import ({% if imports -%}
{% for name in imports -%}
    {{ name }},
{% endfor %}
{%- else -%}
{% for prop in properties -%}
    {%- if prop not in ignore -%}
    {{ prop | to_snake }},
    {%- endif -%}
{% endfor %}
{%- endif %})

{{ canonical_ref() }}
{%- endmacro %}

{% macro utility() -%}# Utility functions
    def assertRaisesWithMessage(self, exception):
        return self.assertRaisesRegex(exception, r".+")
{%- endmacro %}

{% macro footer(_has_error_case) -%}
{% if has_error_case or _has_error_case %}
{{ utility() }}
{% endif %}
if __name__ == '__main__':
    unittest.main()
{%- endmacro %}

{% macro empty_set(set, list, class_name) -%}
{%- if list|length > 0 -%}
{{ set }} = {{ class_name }}({{ list }})
{%- else -%}
{{ set }} = {{ class_name }}()
{%- endif %}
{%- endmacro %}
