Skip to content

Commit 1ae2ff1

Browse files
committed
Added more non-parity unit tests
1 parent 6148604 commit 1ae2ff1

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

test/unit/boolean_unit_test.rb

+24-7
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,9 @@ def test_conditions_with_boolean_operators_without_whitespace_around_operator
398398
HTML
399399

400400
# This bugged output only happens in lax mode.
401-
prev_error_mode = Liquid::Environment.default.error_mode
402-
Liquid::Environment.default.error_mode = :lax
403-
actual_lax_output = Liquid::Template.parse(template).render(context)
404-
Liquid::Environment.default.error_mode = prev_error_mode
401+
assert_with_lax_parsing(template, expected_lax_output, context)
405402

406-
actual_strict_output = Liquid::Template.parse(template).render(context)
407-
408-
assert_equal(expected_lax_output.delete("\n"), actual_lax_output.delete("\n"))
403+
# Default test parsing mode (strict) works as properly expected
409404
assert_equal(expected_strict_output.delete("\n"), actual_strict_output.delete("\n"))
410405
end
411406

@@ -471,6 +466,28 @@ def test_chained_conditional_with_object_contains
471466
assert_with_lax_parsing(template, "true", context_without_collection)
472467
end
473468

469+
# TESTING INCORRECT BEHAVIOUR OF LIQUID-RUBY
470+
# If liquid-vm fails this test, we should change it.
471+
def test_assign_boolean_expression_to_variable
472+
template = <<~LIQUID
473+
{%- liquid
474+
assign is_preview_mode = content_for_header contains "foo" or content_for_header contains "bar"
475+
echo is_preview_mode
476+
-%}
477+
LIQUID
478+
479+
context = { "content_for_header" => "Some content" }
480+
481+
# Expected output
482+
# This value should be "false" but it is the value of the variable from the failed expression.
483+
assert_template_result("Some content", template, context)
484+
485+
# This following validation should only be supported with our changes. It is the short-hand for the above template.
486+
# The validation for it is the expected correct output.
487+
template = Liquid::Template.parse("{% assign is_preview_mode = content_for_header contains 'foo' or content_for_header contains 'bar' %}{{ is_preview_mode }}")
488+
assert_equal("false", template.render(context))
489+
end
490+
474491
private
475492

476493
def assert_with_lax_parsing(template, expected_output, context = {})

0 commit comments

Comments
 (0)