Skip to content

Commit 6148604

Browse files
committed
Added another failing unit test for behavior in main
1 parent e6e8221 commit 6148604

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/unit/boolean_unit_test.rb

+48
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,56 @@ def test_boolean_conditional_with_json_filter
438438
assert_equal(expected_output, actual_output.strip)
439439
end
440440

441+
# TESTING INCORRECT BEHAVIOUR OF LIQUID-RUBY
442+
# If liquid-vm fails this test, we should change it.
443+
def test_chained_conditional_with_object_contains
444+
# Define the Liquid template to test
445+
template = <<~LIQUID
446+
{{ settings.prefilter_status and template contains 'collection' }}
447+
LIQUID
448+
449+
# Test with context containing 'collection'
450+
context_with_collection = {
451+
"template" => {
452+
"name" => "collection",
453+
},
454+
"settings" => {
455+
"prefilter_status" => true,
456+
},
457+
}
458+
# NOTE: This is a bug that liquid-ruby `main` output returns the first value.
459+
assert_with_lax_parsing(template, "true", context_with_collection)
460+
461+
# Test with context not containing 'collection'
462+
context_without_collection = {
463+
"template" => {
464+
"name" => "not-collection",
465+
},
466+
"settings" => {
467+
"prefilter_status" => true,
468+
},
469+
}
470+
# NOTE: This is a bug that liquid-ruby `main` output returns the first value.
471+
assert_with_lax_parsing(template, "true", context_without_collection)
472+
end
473+
441474
private
442475

476+
def assert_with_lax_parsing(template, expected_output, context = {})
477+
prev_error_mode = Liquid::Environment.default.error_mode
478+
Liquid::Environment.default.error_mode = :lax
479+
480+
begin
481+
actual_output = Liquid::Template.parse(template).render(context)
482+
rescue StandardError => e
483+
actual_output = e.message
484+
ensure
485+
Liquid::Environment.default.error_mode = prev_error_mode
486+
end
487+
488+
assert_equal(expected_output.strip, actual_output.strip)
489+
end
490+
443491
def assert_parity(liquid_expression, expected_result, args = {})
444492
assert_condition(liquid_expression, expected_result, args)
445493
assert_expression(liquid_expression, expected_result, args)

0 commit comments

Comments
 (0)