Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/generate_tests
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def quote(obj) -> str:
return TypeError(f"quote for type {type(obj)} not supported")


def binary(num: int, padding: int = 0) -> str:
"""Filter `binary` that converts an int to a binary string."""
return f"{num:0{padding}b}"


def camel_to_screaming(name: str) -> str:
"""Filter `camel_to_screaming` that converts a camel case string to screaming case."""
return name[0].upper() + name[1:]
Expand All @@ -94,6 +99,7 @@ def jinja_env(exercise: pathlib.Path) -> jinja2.Environment:
"""Return a configured Jinja env with filters added."""
env = jinja2.Environment(loader=jinja2.FileSystemLoader(exercise / ".meta"))
# C quoting of arbitrary data objects.
env.filters["binary"] = binary
env.filters["quote"] = quote
env.filters["camel_to_screaming"] = camel_to_screaming
return env
Expand Down
40 changes: 40 additions & 0 deletions exercises/practice/micro-blog/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{%- macro let_inputs(case) %}
{%- for k, v in case.input.items() -%}
let g:{{ k }} = {{ v | quote }}
{%- if not loop.last %}
{% endif %}
{%- endfor -%}
{%- endmacro %}

{%- macro let_expected(case) -%}
{%- if case.expect_error -%}
let g:expected = {{ case.expect_error_msg | quote }}
{%- else -%}
let g:expected = {{ case.expected | quote }}
{%- endif -%}
{%- endmacro %}

{%- macro check(case) -%}
{%- if case.expect_error -%}
AssertThrows call
{%- else -%}
AssertEqual g:expected,
{%- endif %} {{ case.property_function }}(
{%- for k in case.input -%}
g:{{ k }}
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
)
{%- if case.expect_error %}
AssertEqual g:expected, g:vader_exception
{%- endif %}
{%- endmacro %}

{%- for case in cases %}
Execute ({{ case.descriptions | join(" - ") }}):
{%- if case.input %}
{{ let_inputs(case) }}
{%- endif %}
{{ let_expected(case) }}
{{ check(case) }}
{% endfor %}
1 change: 0 additions & 1 deletion exercises/practice/micro-blog/micro_blog.vader
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Execute (English language short):
let g:phrase = "Hi"
let g:expected = "Hi"
Expand Down
Loading