{{ import_string }}
const {
    {% for func in assert_funcs -%}
    {{ func }},
    {% endfor %}
} = require('./commons');
const { readFileSync } = require('fs');

{%- macro input(params, var_name) -%}
    {%- if params.type == "file" -%}
    const {{ var_name }} = readFileSync("fixtures/{{params.arg}}", "utf-8")
    {%- elif params.type == "raw" -%}
    const {{var_name}} = {{ params.arg }}
    {%- elif params.type == "str" -%}
    const {{ var_name }} = "{{ params.arg }}"
    {%- endif -%}
{%- endmacro %}

{% for t_name, t in tests.items() %}
it('{{t.info}}', () => {
    {{ input(t.input, 'data') }}
    {%- if is_dict(t.assert.arg) is true %}
    {{ input(t.input, 'expected') }}
    {%- elif t.assert.get('arg') is not none %}
    const expected = {{ t.assert.arg }}
    {%- endif %}
    {% if t.assert.func != "fail" -%}
    const serialized_data = {{func}}(data)
    expect({{ t.assert.func }}(serialized_data, expected)).toBe(true)
    {%- else -%}
    try {
        const serialized_data = {{ func }}(data)
        fail("Expected an error, but didn't get")
    } catch(e){
        {%- if t.assert.get('arg') != None %}
        expect(e.toString()).toBe(expected)
        {% endif %}
    }
    {%- endif %}
})
{% endfor %}
