mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 17:30:43 -07:00
snippet using inner context
This commit is contained in:
@@ -73,7 +73,6 @@ class SnippetTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_render_inline_snippet_with_argument
|
||||
# This passes whether or not we have the new or old SYNTAX
|
||||
template = <<~LIQUID.strip
|
||||
{% snippet "input" |type| %}
|
||||
<input type="{{ type }}" />
|
||||
@@ -89,38 +88,78 @@ class SnippetTest < Minitest::Test
|
||||
assert_template_result(expected, template)
|
||||
end
|
||||
|
||||
# def test_render_inline_snippet_with_multiple_arguments
|
||||
# template = <<~LIQUID.strip
|
||||
# {% snippet "input" |type, value| %}
|
||||
# <input type="{{ type }}" value="{{ value }}" />
|
||||
# {% endsnippet %}
|
||||
def test_render_inline_snippet_with_multiple_arguments
|
||||
template = <<~LIQUID.strip
|
||||
{% snippet "input" |type, value| %}
|
||||
<input type="{{ type }}" value="{{ value }}" />
|
||||
{% endsnippet %}
|
||||
|
||||
# {%- render "input", type: "text", value: "Hello" -%}
|
||||
# LIQUID
|
||||
# expected = <<~OUTPUT
|
||||
{%- render "input", type: "text", value: "Hello" -%}
|
||||
LIQUID
|
||||
expected = <<~OUTPUT
|
||||
|
||||
# <input type="text" value="Hello" />
|
||||
# OUTPUT
|
||||
<input type="text" value="Hello" />
|
||||
OUTPUT
|
||||
|
||||
# assert_template_result(expected, template)
|
||||
# end
|
||||
assert_template_result(expected, template)
|
||||
end
|
||||
|
||||
# def test_render_inline_snippet_shouldnt_leak_context
|
||||
# template = <<~LIQUID.strip
|
||||
# {% snippet "input" |type, value| %}
|
||||
# <input type="{{ type }}" value="{{ value }}" />
|
||||
# {% endsnippet %}
|
||||
def test_render_inline_snippet_empty_string_when_missing_argument
|
||||
template = <<~LIQUID.strip
|
||||
{% snippet "input" |type| %}
|
||||
<input type="{{ type }}" value="{{ value }}" />
|
||||
{% endsnippet %}
|
||||
|
||||
# {%- render "input", type: "text", value: "Hello" -%}
|
||||
{%- render "input", type: "text" -%}
|
||||
LIQUID
|
||||
expected = <<~OUTPUT
|
||||
|
||||
# {{ type }}
|
||||
# {{ value }}
|
||||
# LIQUID
|
||||
# expected = <<~OUTPUT
|
||||
<input type="text" value="" />
|
||||
OUTPUT
|
||||
|
||||
# <input type="text" value="Hello" />
|
||||
# OUTPUT
|
||||
assert_template_result(expected, template)
|
||||
end
|
||||
|
||||
# assert_template_result(expected, template)
|
||||
# end
|
||||
def test_render_inline_snippet_shouldnt_leak_context
|
||||
template = <<~LIQUID.strip
|
||||
{% snippet "input" |type, value| %}
|
||||
<input type="{{ type }}" value="{{ value }}" />
|
||||
{% endsnippet %}
|
||||
|
||||
{%- render "input", type: "text", value: "Hello" -%}
|
||||
|
||||
{{ type }}
|
||||
{{ value }}
|
||||
LIQUID
|
||||
expected = <<~OUTPUT
|
||||
|
||||
<input type="text" value="Hello" />
|
||||
|
||||
OUTPUT
|
||||
|
||||
assert_template_result(expected, template)
|
||||
end
|
||||
|
||||
def test_render_multiple_inline_snippets_without_leaking_context
|
||||
template = <<~LIQUID.strip
|
||||
{% snippet "input" |type| %}
|
||||
<input type="{{ type }}" />
|
||||
{% endsnippet %}
|
||||
|
||||
{% snippet "banner"%}
|
||||
{{ type }}
|
||||
{% endsnippet %}
|
||||
|
||||
{%- render "input", type: "text" -%}
|
||||
{%- render "banner" -%}
|
||||
LIQUID
|
||||
expected = <<~OUTPUT.strip
|
||||
|
||||
<input type="text" />
|
||||
|
||||
|
||||
OUTPUT
|
||||
|
||||
assert_template_result(expected, template)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user