mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -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:
@@ -17,7 +17,6 @@ module Liquid
|
|||||||
ExpressionsAndOperators = /(?:\b(?:and|or)\b|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
|
ExpressionsAndOperators = /(?:\b(?:and|or)\b|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/
|
||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
|
|
||||||
@blocks = []
|
@blocks = []
|
||||||
|
|
||||||
push_block('if', markup)
|
push_block('if', markup)
|
||||||
|
|||||||
@@ -55,9 +55,7 @@ class ConditionTest < Test::Unit::TestCase
|
|||||||
assert_evalutes_true "array", 'contains', '4'
|
assert_evalutes_true "array", 'contains', '4'
|
||||||
assert_evalutes_true "array", 'contains', '5'
|
assert_evalutes_true "array", 'contains', '5'
|
||||||
assert_evalutes_false "array", 'contains', '6'
|
assert_evalutes_false "array", 'contains', '6'
|
||||||
|
|
||||||
assert_evalutes_false "array", 'contains', '"1"'
|
assert_evalutes_false "array", 'contains', '"1"'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_contains_returns_false_for_nil_operands
|
def test_contains_returns_false_for_nil_operands
|
||||||
@@ -94,7 +92,6 @@ class ConditionTest < Test::Unit::TestCase
|
|||||||
assert_equal false, condition.evaluate
|
assert_equal false, condition.evaluate
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_should_allow_custom_proc_operator
|
def test_should_allow_custom_proc_operator
|
||||||
Condition.operators['starts_with'] = Proc.new { |cond, left, right| left =~ %r{^#{right}} }
|
Condition.operators['starts_with'] = Proc.new { |cond, left, right| left =~ %r{^#{right}} }
|
||||||
|
|
||||||
@@ -105,6 +102,13 @@ class ConditionTest < Test::Unit::TestCase
|
|||||||
Condition.operators.delete 'starts_with'
|
Condition.operators.delete 'starts_with'
|
||||||
end
|
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
|
private
|
||||||
def assert_evalutes_true(left, op, right)
|
def assert_evalutes_true(left, op, right)
|
||||||
assert Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
|
assert Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
|
||||||
|
|||||||
@@ -150,4 +150,10 @@ class IfElseTest < Test::Unit::TestCase
|
|||||||
ensure
|
ensure
|
||||||
Condition.operators.delete 'contains'
|
Condition.operators.delete 'contains'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# def test_operators_are_ignored_unless_isolated
|
||||||
|
# Condition.operators['contains'] = :[]
|
||||||
|
#
|
||||||
|
# assert_template_result('yes', %({% if 'gnomeslab' == 'gnomeslab' %}yes{% endif %}))
|
||||||
|
# end
|
||||||
end # IfElseTest
|
end # IfElseTest
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ require 'test/unit'
|
|||||||
require 'test/unit/assertions'
|
require 'test/unit/assertions'
|
||||||
require 'caller'
|
require 'caller'
|
||||||
require 'breakpoint'
|
require 'breakpoint'
|
||||||
|
require 'ruby-debug'
|
||||||
require File.join File.dirname(__FILE__), '..', 'lib', 'liquid'
|
require File.join File.dirname(__FILE__), '..', 'lib', 'liquid'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user