mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 02:40:41 -07:00
Conditions
- added test to assert that conditions can contain conditions within its value (eg 'a-and-b') Tags - indented the if tag Tests - added ruby-debug to the test_helper - indented some tests
This commit is contained in:
@@ -48,16 +48,14 @@ class ConditionTest < Test::Unit::TestCase
|
||||
@context = Liquid::Context.new
|
||||
@context['array'] = [1,2,3,4,5]
|
||||
|
||||
assert_evalutes_false "array", 'contains', '0'
|
||||
assert_evalutes_true "array", 'contains', '1'
|
||||
assert_evalutes_true "array", 'contains', '2'
|
||||
assert_evalutes_true "array", 'contains', '3'
|
||||
assert_evalutes_true "array", 'contains', '4'
|
||||
assert_evalutes_true "array", 'contains', '5'
|
||||
assert_evalutes_false "array", 'contains', '6'
|
||||
|
||||
assert_evalutes_false "array", 'contains', '"1"'
|
||||
|
||||
assert_evalutes_false "array", 'contains', '0'
|
||||
assert_evalutes_true "array", 'contains', '1'
|
||||
assert_evalutes_true "array", 'contains', '2'
|
||||
assert_evalutes_true "array", 'contains', '3'
|
||||
assert_evalutes_true "array", 'contains', '4'
|
||||
assert_evalutes_true "array", 'contains', '5'
|
||||
assert_evalutes_false "array", 'contains', '6'
|
||||
assert_evalutes_false "array", 'contains', '"1"'
|
||||
end
|
||||
|
||||
def test_contains_returns_false_for_nil_operands
|
||||
@@ -94,17 +92,23 @@ class ConditionTest < Test::Unit::TestCase
|
||||
assert_equal false, condition.evaluate
|
||||
end
|
||||
|
||||
|
||||
def test_should_allow_custom_proc_operator
|
||||
Condition.operators['starts_with'] = Proc.new { |cond, left, right| left =~ %r{^#{right}} }
|
||||
|
||||
assert_evalutes_true "'bob'", 'starts_with', "'b'"
|
||||
assert_evalutes_false "'bob'", 'starts_with', "'o'"
|
||||
assert_evalutes_true "'bob'", 'starts_with', "'b'"
|
||||
assert_evalutes_false "'bob'", 'starts_with', "'o'"
|
||||
|
||||
ensure
|
||||
Condition.operators.delete 'starts_with'
|
||||
end
|
||||
|
||||
def test_left_or_right_may_contain_operators
|
||||
@context = Liquid::Context.new
|
||||
@context['one'] = @context['another'] = "gnomeslab-and-or-liquid"
|
||||
|
||||
assert_evalutes_true "one", '==', "another"
|
||||
end
|
||||
|
||||
private
|
||||
def assert_evalutes_true(left, op, right)
|
||||
assert Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
|
||||
|
||||
@@ -150,4 +150,10 @@ class IfElseTest < Test::Unit::TestCase
|
||||
ensure
|
||||
Condition.operators.delete 'contains'
|
||||
end
|
||||
|
||||
# def test_operators_are_ignored_unless_isolated
|
||||
# Condition.operators['contains'] = :[]
|
||||
#
|
||||
# assert_template_result('yes', %({% if 'gnomeslab' == 'gnomeslab' %}yes{% endif %}))
|
||||
# end
|
||||
end # IfElseTest
|
||||
|
||||
@@ -6,6 +6,7 @@ require 'test/unit'
|
||||
require 'test/unit/assertions'
|
||||
require 'caller'
|
||||
require 'breakpoint'
|
||||
require 'ruby-debug'
|
||||
require File.join File.dirname(__FILE__), '..', 'lib', 'liquid'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user