Merge branch 'master' into fix-constants

This commit is contained in:
Mike Angell
2019-10-21 22:57:44 +10:00
committed by GitHub
83 changed files with 1552 additions and 1402 deletions
+18 -18
View File
@@ -7,42 +7,42 @@ class BlockUnitTest < Minitest::Test
def test_blankspace
template = Liquid::Template.parse(" ")
assert_equal [" "], template.root.nodelist
assert_equal([" "], template.root.nodelist)
end
def test_variable_beginning
template = Liquid::Template.parse("{{funk}} ")
assert_equal 2, template.root.nodelist.size
assert_equal Variable, template.root.nodelist[0].class
assert_equal String, template.root.nodelist[1].class
assert_equal(2, template.root.nodelist.size)
assert_equal(Variable, template.root.nodelist[0].class)
assert_equal(String, template.root.nodelist[1].class)
end
def test_variable_end
template = Liquid::Template.parse(" {{funk}}")
assert_equal 2, template.root.nodelist.size
assert_equal String, template.root.nodelist[0].class
assert_equal Variable, template.root.nodelist[1].class
assert_equal(2, template.root.nodelist.size)
assert_equal(String, template.root.nodelist[0].class)
assert_equal(Variable, template.root.nodelist[1].class)
end
def test_variable_middle
template = Liquid::Template.parse(" {{funk}} ")
assert_equal 3, template.root.nodelist.size
assert_equal String, template.root.nodelist[0].class
assert_equal Variable, template.root.nodelist[1].class
assert_equal String, template.root.nodelist[2].class
assert_equal(3, template.root.nodelist.size)
assert_equal(String, template.root.nodelist[0].class)
assert_equal(Variable, template.root.nodelist[1].class)
assert_equal(String, template.root.nodelist[2].class)
end
def test_variable_many_embedded_fragments
template = Liquid::Template.parse(" {{funk}} {{so}} {{brother}} ")
assert_equal 7, template.root.nodelist.size
assert_equal [String, Variable, String, Variable, String, Variable, String],
block_types(template.root.nodelist)
assert_equal(7, template.root.nodelist.size)
assert_equal([String, Variable, String, Variable, String, Variable, String],
block_types(template.root.nodelist))
end
def test_with_block
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
assert_equal [String, Comment, String], block_types(template.root.nodelist)
assert_equal 3, template.root.nodelist.size
assert_equal([String, Comment, String], block_types(template.root.nodelist))
assert_equal(3, template.root.nodelist.size)
end
def test_with_custom_tag
@@ -63,7 +63,7 @@ class BlockUnitTest < Minitest::Test
assert_equal 'hello', template.render
buf = +''
buf = +''
output = template.render({}, output: buf)
assert_equal 'hello', output
assert_equal 'hello', buf
@@ -81,7 +81,7 @@ class BlockUnitTest < Minitest::Test
assert_equal 'foohellobar', template.render
buf = +''
buf = +''
output = template.render({}, output: buf)
assert_equal 'foohellobar', output
assert_equal 'foohellobar', buf
+69 -69
View File
@@ -10,154 +10,154 @@ class ConditionUnitTest < Minitest::Test
end
def test_basic_condition
assert_equal false, Condition.new(1, '==', 2).evaluate
assert_equal true, Condition.new(1, '==', 1).evaluate
assert_equal(false, Condition.new(1, '==', 2).evaluate)
assert_equal(true, Condition.new(1, '==', 1).evaluate)
end
def test_default_operators_evalute_true
assert_evaluates_true 1, '==', 1
assert_evaluates_true 1, '!=', 2
assert_evaluates_true 1, '<>', 2
assert_evaluates_true 1, '<', 2
assert_evaluates_true 2, '>', 1
assert_evaluates_true 1, '>=', 1
assert_evaluates_true 2, '>=', 1
assert_evaluates_true 1, '<=', 2
assert_evaluates_true 1, '<=', 1
assert_evaluates_true(1, '==', 1)
assert_evaluates_true(1, '!=', 2)
assert_evaluates_true(1, '<>', 2)
assert_evaluates_true(1, '<', 2)
assert_evaluates_true(2, '>', 1)
assert_evaluates_true(1, '>=', 1)
assert_evaluates_true(2, '>=', 1)
assert_evaluates_true(1, '<=', 2)
assert_evaluates_true(1, '<=', 1)
# negative numbers
assert_evaluates_true 1, '>', -1
assert_evaluates_true(1, '>', -1)
assert_evaluates_true(-1, '<', 1)
assert_evaluates_true 1.0, '>', -1.0
assert_evaluates_true(1.0, '>', -1.0)
assert_evaluates_true(-1.0, '<', 1.0)
end
def test_default_operators_evalute_false
assert_evaluates_false 1, '==', 2
assert_evaluates_false 1, '!=', 1
assert_evaluates_false 1, '<>', 1
assert_evaluates_false 1, '<', 0
assert_evaluates_false 2, '>', 4
assert_evaluates_false 1, '>=', 3
assert_evaluates_false 2, '>=', 4
assert_evaluates_false 1, '<=', 0
assert_evaluates_false 1, '<=', 0
assert_evaluates_false(1, '==', 2)
assert_evaluates_false(1, '!=', 1)
assert_evaluates_false(1, '<>', 1)
assert_evaluates_false(1, '<', 0)
assert_evaluates_false(2, '>', 4)
assert_evaluates_false(1, '>=', 3)
assert_evaluates_false(2, '>=', 4)
assert_evaluates_false(1, '<=', 0)
assert_evaluates_false(1, '<=', 0)
end
def test_contains_works_on_strings
assert_evaluates_true 'bob', 'contains', 'o'
assert_evaluates_true 'bob', 'contains', 'b'
assert_evaluates_true 'bob', 'contains', 'bo'
assert_evaluates_true 'bob', 'contains', 'ob'
assert_evaluates_true 'bob', 'contains', 'bob'
assert_evaluates_true('bob', 'contains', 'o')
assert_evaluates_true('bob', 'contains', 'b')
assert_evaluates_true('bob', 'contains', 'bo')
assert_evaluates_true('bob', 'contains', 'ob')
assert_evaluates_true('bob', 'contains', 'bob')
assert_evaluates_false 'bob', 'contains', 'bob2'
assert_evaluates_false 'bob', 'contains', 'a'
assert_evaluates_false 'bob', 'contains', '---'
assert_evaluates_false('bob', 'contains', 'bob2')
assert_evaluates_false('bob', 'contains', 'a')
assert_evaluates_false('bob', 'contains', '---')
end
def test_invalid_comparation_operator
assert_evaluates_argument_error 1, '~~', 0
assert_evaluates_argument_error(1, '~~', 0)
end
def test_comparation_of_int_and_str
assert_evaluates_argument_error '1', '>', 0
assert_evaluates_argument_error '1', '<', 0
assert_evaluates_argument_error '1', '>=', 0
assert_evaluates_argument_error '1', '<=', 0
assert_evaluates_argument_error('1', '>', 0)
assert_evaluates_argument_error('1', '<', 0)
assert_evaluates_argument_error('1', '>=', 0)
assert_evaluates_argument_error('1', '<=', 0)
end
def test_hash_compare_backwards_compatibility
assert_nil Condition.new({}, '>', 2).evaluate
assert_nil Condition.new(2, '>', {}).evaluate
assert_equal false, Condition.new({}, '==', 2).evaluate
assert_equal true, Condition.new({ 'a' => 1 }, '==', 'a' => 1).evaluate
assert_equal true, Condition.new({ 'a' => 2 }, 'contains', 'a').evaluate
assert_nil(Condition.new({}, '>', 2).evaluate)
assert_nil(Condition.new(2, '>', {}).evaluate)
assert_equal(false, Condition.new({}, '==', 2).evaluate)
assert_equal(true, Condition.new({ 'a' => 1 }, '==', 'a' => 1).evaluate)
assert_equal(true, Condition.new({ 'a' => 2 }, 'contains', 'a').evaluate)
end
def test_contains_works_on_arrays
@context = Liquid::Context.new
@context = Liquid::Context.new
@context['array'] = [1, 2, 3, 4, 5]
array_expr = VariableLookup.new("array")
array_expr = VariableLookup.new("array")
assert_evaluates_false array_expr, 'contains', 0
assert_evaluates_true array_expr, 'contains', 1
assert_evaluates_true array_expr, 'contains', 2
assert_evaluates_true array_expr, 'contains', 3
assert_evaluates_true array_expr, 'contains', 4
assert_evaluates_true array_expr, 'contains', 5
assert_evaluates_false array_expr, 'contains', 6
assert_evaluates_false array_expr, 'contains', "1"
assert_evaluates_false(array_expr, 'contains', 0)
assert_evaluates_true(array_expr, 'contains', 1)
assert_evaluates_true(array_expr, 'contains', 2)
assert_evaluates_true(array_expr, 'contains', 3)
assert_evaluates_true(array_expr, 'contains', 4)
assert_evaluates_true(array_expr, 'contains', 5)
assert_evaluates_false(array_expr, 'contains', 6)
assert_evaluates_false(array_expr, 'contains', "1")
end
def test_contains_returns_false_for_nil_operands
@context = Liquid::Context.new
assert_evaluates_false VariableLookup.new('not_assigned'), 'contains', '0'
assert_evaluates_false 0, 'contains', VariableLookup.new('not_assigned')
assert_evaluates_false(VariableLookup.new('not_assigned'), 'contains', '0')
assert_evaluates_false(0, 'contains', VariableLookup.new('not_assigned'))
end
def test_contains_return_false_on_wrong_data_type
assert_evaluates_false 1, 'contains', 0
assert_evaluates_false(1, 'contains', 0)
end
def test_contains_with_string_left_operand_coerces_right_operand_to_string
assert_evaluates_true ' 1 ', 'contains', 1
assert_evaluates_false ' 1 ', 'contains', 2
assert_evaluates_true(' 1 ', 'contains', 1)
assert_evaluates_false(' 1 ', 'contains', 2)
end
def test_or_condition
condition = Condition.new(1, '==', 2)
assert_equal false, condition.evaluate
assert_equal(false, condition.evaluate)
condition.or(Condition.new(2, '==', 1))
assert_equal false, condition.evaluate
assert_equal(false, condition.evaluate)
condition.or(Condition.new(1, '==', 1))
assert_equal true, condition.evaluate
assert_equal(true, condition.evaluate)
end
def test_and_condition
condition = Condition.new(1, '==', 1)
assert_equal true, condition.evaluate
assert_equal(true, condition.evaluate)
condition.and(Condition.new(2, '==', 2))
assert_equal true, condition.evaluate
assert_equal(true, condition.evaluate)
condition.and(Condition.new(2, '==', 1))
assert_equal false, condition.evaluate
assert_equal(false, condition.evaluate)
end
def test_should_allow_custom_proc_operator
Condition.operators['starts_with'] = proc { |_cond, left, right| left =~ /^#{right}/ }
assert_evaluates_true 'bob', 'starts_with', 'b'
assert_evaluates_false 'bob', 'starts_with', 'o'
assert_evaluates_true('bob', 'starts_with', 'b')
assert_evaluates_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 = Liquid::Context.new
@context['one'] = @context['another'] = "gnomeslab-and-or-liquid"
assert_evaluates_true VariableLookup.new("one"), '==', VariableLookup.new("another")
assert_evaluates_true(VariableLookup.new("one"), '==', VariableLookup.new("another"))
end
private
def assert_evaluates_true(left, op, right)
assert Condition.new(left, op, right).evaluate(@context),
"Evaluated false: #{left} #{op} #{right}"
assert(Condition.new(left, op, right).evaluate(@context),
"Evaluated false: #{left} #{op} #{right}")
end
def assert_evaluates_false(left, op, right)
assert !Condition.new(left, op, right).evaluate(@context),
"Evaluated true: #{left} #{op} #{right}"
assert(!Condition.new(left, op, right).evaluate(@context),
"Evaluated true: #{left} #{op} #{right}")
end
def assert_evaluates_argument_error(left, op, right)
+137 -137
View File
@@ -46,7 +46,7 @@ end
class CounterDrop < Liquid::Drop
def count
@count ||= 0
@count += 1
@count += 1
end
end
@@ -55,9 +55,9 @@ class ArrayLike
end
def [](index)
@counts ||= []
@counts ||= []
@counts[index] ||= 0
@counts[index] += 1
@counts[index] += 1
end
def to_liquid
@@ -74,34 +74,34 @@ class ContextUnitTest < Minitest::Test
def test_variables
@context['string'] = 'string'
assert_equal 'string', @context['string']
assert_equal('string', @context['string'])
@context['num'] = 5
assert_equal 5, @context['num']
assert_equal(5, @context['num'])
@context['time'] = Time.parse('2006-06-06 12:00:00')
assert_equal Time.parse('2006-06-06 12:00:00'), @context['time']
assert_equal(Time.parse('2006-06-06 12:00:00'), @context['time'])
@context['date'] = Date.today
assert_equal Date.today, @context['date']
assert_equal(Date.today, @context['date'])
now = Time.now
@context['datetime'] = now
assert_equal now, @context['datetime']
assert_equal(now, @context['datetime'])
@context['bool'] = true
assert_equal true, @context['bool']
assert_equal(true, @context['bool'])
@context['bool'] = false
assert_equal false, @context['bool']
assert_equal(false, @context['bool'])
@context['nil'] = nil
assert_nil @context['nil']
assert_nil @context['nil']
assert_nil(@context['nil'])
assert_nil(@context['nil'])
end
def test_variables_not_existing
assert_nil @context['does_not_exist']
assert_nil(@context['does_not_exist'])
end
def test_scoping
@@ -122,20 +122,20 @@ class ContextUnitTest < Minitest::Test
def test_length_query
@context['numbers'] = [1, 2, 3, 4]
assert_equal 4, @context['numbers.size']
assert_equal(4, @context['numbers.size'])
@context['numbers'] = { 1 => 1, 2 => 2, 3 => 3, 4 => 4 }
assert_equal 4, @context['numbers.size']
assert_equal(4, @context['numbers.size'])
@context['numbers'] = { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 'size' => 1000 }
assert_equal 1000, @context['numbers.size']
assert_equal(1000, @context['numbers.size'])
end
def test_hyphenated_variable
@context['oh-my'] = 'godz'
assert_equal 'godz', @context['oh-my']
assert_equal('godz', @context['oh-my'])
end
def test_add_filter
@@ -147,13 +147,13 @@ class ContextUnitTest < Minitest::Test
context = Context.new
context.add_filters(filter)
assert_equal 'hi? hi!', context.invoke(:hi, 'hi?')
assert_equal('hi? hi!', context.invoke(:hi, 'hi?'))
context = Context.new
assert_equal 'hi?', context.invoke(:hi, 'hi?')
assert_equal('hi?', context.invoke(:hi, 'hi?'))
context.add_filters(filter)
assert_equal 'hi? hi!', context.invoke(:hi, 'hi?')
assert_equal('hi? hi!', context.invoke(:hi, 'hi?'))
end
def test_only_intended_filters_make_it_there
@@ -164,75 +164,75 @@ class ContextUnitTest < Minitest::Test
end
context = Context.new
assert_equal "Wookie", context.invoke("hi", "Wookie")
assert_equal("Wookie", context.invoke("hi", "Wookie"))
context.add_filters(filter)
assert_equal "Wookie hi!", context.invoke("hi", "Wookie")
assert_equal("Wookie hi!", context.invoke("hi", "Wookie"))
end
def test_add_item_in_outer_scope
@context['test'] = 'test'
@context.push
assert_equal 'test', @context['test']
assert_equal('test', @context['test'])
@context.pop
assert_equal 'test', @context['test']
assert_equal('test', @context['test'])
end
def test_add_item_in_inner_scope
@context.push
@context['test'] = 'test'
assert_equal 'test', @context['test']
assert_equal('test', @context['test'])
@context.pop
assert_nil @context['test']
assert_nil(@context['test'])
end
def test_hierachical_data
@context['hash'] = { "name" => 'tobi' }
assert_equal 'tobi', @context['hash.name']
assert_equal 'tobi', @context['hash["name"]']
assert_equal('tobi', @context['hash.name'])
assert_equal('tobi', @context['hash["name"]'])
end
def test_keywords
assert_equal true, @context['true']
assert_equal false, @context['false']
assert_equal(true, @context['true'])
assert_equal(false, @context['false'])
end
def test_digits
assert_equal 100, @context['100']
assert_equal 100.00, @context['100.00']
assert_equal(100, @context['100'])
assert_equal(100.00, @context['100.00'])
end
def test_strings
assert_equal "hello!", @context['"hello!"']
assert_equal "hello!", @context["'hello!'"]
assert_equal("hello!", @context['"hello!"'])
assert_equal("hello!", @context["'hello!'"])
end
def test_merge
@context.merge("test" => "test")
assert_equal 'test', @context['test']
assert_equal('test', @context['test'])
@context.merge("test" => "newvalue", "foo" => "bar")
assert_equal 'newvalue', @context['test']
assert_equal 'bar', @context['foo']
assert_equal('newvalue', @context['test'])
assert_equal('bar', @context['foo'])
end
def test_array_notation
@context['test'] = [1, 2, 3, 4, 5]
assert_equal 1, @context['test[0]']
assert_equal 2, @context['test[1]']
assert_equal 3, @context['test[2]']
assert_equal 4, @context['test[3]']
assert_equal 5, @context['test[4]']
assert_equal(1, @context['test[0]'])
assert_equal(2, @context['test[1]'])
assert_equal(3, @context['test[2]'])
assert_equal(4, @context['test[3]'])
assert_equal(5, @context['test[4]'])
end
def test_recoursive_array_notation
@context['test'] = { 'test' => [1, 2, 3, 4, 5] }
assert_equal 1, @context['test.test[0]']
assert_equal(1, @context['test.test[0]'])
@context['test'] = [{ 'test' => 'worked' }]
assert_equal 'worked', @context['test[0].test']
assert_equal('worked', @context['test[0].test'])
end
def test_hash_to_array_transition
@@ -243,177 +243,177 @@ class ContextUnitTest < Minitest::Test
'Red' => ['660000', '993333', 'CC6666', 'FF9999'],
}
assert_equal '003366', @context['colors.Blue[0]']
assert_equal 'FF9999', @context['colors.Red[3]']
assert_equal('003366', @context['colors.Blue[0]'])
assert_equal('FF9999', @context['colors.Red[3]'])
end
def test_try_first
@context['test'] = [1, 2, 3, 4, 5]
assert_equal 1, @context['test.first']
assert_equal 5, @context['test.last']
assert_equal(1, @context['test.first'])
assert_equal(5, @context['test.last'])
@context['test'] = { 'test' => [1, 2, 3, 4, 5] }
assert_equal 1, @context['test.test.first']
assert_equal 5, @context['test.test.last']
assert_equal(1, @context['test.test.first'])
assert_equal(5, @context['test.test.last'])
@context['test'] = [1]
assert_equal 1, @context['test.first']
assert_equal 1, @context['test.last']
assert_equal(1, @context['test.first'])
assert_equal(1, @context['test.last'])
end
def test_access_hashes_with_hash_notation
@context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
@context['product'] = { 'variants' => [{ 'title' => 'draft151cm' }, { 'title' => 'element151cm' }] }
@context['product'] = { 'variants' => [{ 'title' => 'draft151cm' }, { 'title' => 'element151cm' }] }
assert_equal 5, @context['products["count"]']
assert_equal 'deepsnow', @context['products["tags"][0]']
assert_equal 'deepsnow', @context['products["tags"].first']
assert_equal 'draft151cm', @context['product["variants"][0]["title"]']
assert_equal 'element151cm', @context['product["variants"][1]["title"]']
assert_equal 'draft151cm', @context['product["variants"][0]["title"]']
assert_equal 'element151cm', @context['product["variants"].last["title"]']
assert_equal(5, @context['products["count"]'])
assert_equal('deepsnow', @context['products["tags"][0]'])
assert_equal('deepsnow', @context['products["tags"].first'])
assert_equal('draft151cm', @context['product["variants"][0]["title"]'])
assert_equal('element151cm', @context['product["variants"][1]["title"]'])
assert_equal('draft151cm', @context['product["variants"][0]["title"]'])
assert_equal('element151cm', @context['product["variants"].last["title"]'])
end
def test_access_variable_with_hash_notation
@context['foo'] = 'baz'
@context['bar'] = 'foo'
assert_equal 'baz', @context['["foo"]']
assert_equal 'baz', @context['[bar]']
assert_equal('baz', @context['["foo"]'])
assert_equal('baz', @context['[bar]'])
end
def test_access_hashes_with_hash_access_variables
@context['var'] = 'tags'
@context['nested'] = { 'var' => 'tags' }
@context['var'] = 'tags'
@context['nested'] = { 'var' => 'tags' }
@context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
assert_equal 'deepsnow', @context['products[var].first']
assert_equal 'freestyle', @context['products[nested.var].last']
assert_equal('deepsnow', @context['products[var].first'])
assert_equal('freestyle', @context['products[nested.var].last'])
end
def test_hash_notation_only_for_hash_access
@context['array'] = [1, 2, 3, 4, 5]
@context['hash'] = { 'first' => 'Hello' }
@context['hash'] = { 'first' => 'Hello' }
assert_equal 1, @context['array.first']
assert_nil @context['array["first"]']
assert_equal 'Hello', @context['hash["first"]']
assert_equal(1, @context['array.first'])
assert_nil(@context['array["first"]'])
assert_equal('Hello', @context['hash["first"]'])
end
def test_first_can_appear_in_middle_of_callchain
@context['product'] = { 'variants' => [{ 'title' => 'draft151cm' }, { 'title' => 'element151cm' }] }
assert_equal 'draft151cm', @context['product.variants[0].title']
assert_equal 'element151cm', @context['product.variants[1].title']
assert_equal 'draft151cm', @context['product.variants.first.title']
assert_equal 'element151cm', @context['product.variants.last.title']
assert_equal('draft151cm', @context['product.variants[0].title'])
assert_equal('element151cm', @context['product.variants[1].title'])
assert_equal('draft151cm', @context['product.variants.first.title'])
assert_equal('element151cm', @context['product.variants.last.title'])
end
def test_cents
@context.merge("cents" => HundredCentes.new)
assert_equal 100, @context['cents']
assert_equal(100, @context['cents'])
end
def test_nested_cents
@context.merge("cents" => { 'amount' => HundredCentes.new })
assert_equal 100, @context['cents.amount']
assert_equal(100, @context['cents.amount'])
@context.merge("cents" => { 'cents' => { 'amount' => HundredCentes.new } })
assert_equal 100, @context['cents.cents.amount']
assert_equal(100, @context['cents.cents.amount'])
end
def test_cents_through_drop
@context.merge("cents" => CentsDrop.new)
assert_equal 100, @context['cents.amount']
assert_equal(100, @context['cents.amount'])
end
def test_nested_cents_through_drop
@context.merge("vars" => { "cents" => CentsDrop.new })
assert_equal 100, @context['vars.cents.amount']
assert_equal(100, @context['vars.cents.amount'])
end
def test_drop_methods_with_question_marks
@context.merge("cents" => CentsDrop.new)
assert @context['cents.non_zero?']
assert(@context['cents.non_zero?'])
end
def test_context_from_within_drop
@context.merge("test" => '123', "vars" => ContextSensitiveDrop.new)
assert_equal '123', @context['vars.test']
assert_equal('123', @context['vars.test'])
end
def test_nested_context_from_within_drop
@context.merge("test" => '123', "vars" => { "local" => ContextSensitiveDrop.new })
assert_equal '123', @context['vars.local.test']
assert_equal('123', @context['vars.local.test'])
end
def test_ranges
@context.merge("test" => '5')
assert_equal (1..5), @context['(1..5)']
assert_equal (1..5), @context['(1..test)']
assert_equal (5..5), @context['(test..test)']
assert_equal((1..5), @context['(1..5)'])
assert_equal((1..5), @context['(1..test)'])
assert_equal((5..5), @context['(test..test)'])
end
def test_cents_through_drop_nestedly
@context.merge("cents" => { "cents" => CentsDrop.new })
assert_equal 100, @context['cents.cents.amount']
assert_equal(100, @context['cents.cents.amount'])
@context.merge("cents" => { "cents" => { "cents" => CentsDrop.new } })
assert_equal 100, @context['cents.cents.cents.amount']
assert_equal(100, @context['cents.cents.cents.amount'])
end
def test_drop_with_variable_called_only_once
@context['counter'] = CounterDrop.new
assert_equal 1, @context['counter.count']
assert_equal 2, @context['counter.count']
assert_equal 3, @context['counter.count']
assert_equal(1, @context['counter.count'])
assert_equal(2, @context['counter.count'])
assert_equal(3, @context['counter.count'])
end
def test_drop_with_key_called_only_once
@context['counter'] = CounterDrop.new
assert_equal 1, @context['counter["count"]']
assert_equal 2, @context['counter["count"]']
assert_equal 3, @context['counter["count"]']
assert_equal(1, @context['counter["count"]'])
assert_equal(2, @context['counter["count"]'])
assert_equal(3, @context['counter["count"]'])
end
def test_proc_as_variable
@context['dynamic'] = proc { 'Hello' }
assert_equal 'Hello', @context['dynamic']
assert_equal('Hello', @context['dynamic'])
end
def test_lambda_as_variable
@context['dynamic'] = proc { 'Hello' }
assert_equal 'Hello', @context['dynamic']
assert_equal('Hello', @context['dynamic'])
end
def test_nested_lambda_as_variable
@context['dynamic'] = { "lambda" => proc { 'Hello' } }
assert_equal 'Hello', @context['dynamic.lambda']
assert_equal('Hello', @context['dynamic.lambda'])
end
def test_array_containing_lambda_as_variable
@context['dynamic'] = [1, 2, proc { 'Hello' }, 4, 5]
assert_equal 'Hello', @context['dynamic[2]']
assert_equal('Hello', @context['dynamic[2]'])
end
def test_lambda_is_called_once
@context['callcount'] = proc {
@global ||= 0
@global += 1
@global += 1
@global.to_s
}
assert_equal '1', @context['callcount']
assert_equal '1', @context['callcount']
assert_equal '1', @context['callcount']
assert_equal('1', @context['callcount'])
assert_equal('1', @context['callcount'])
assert_equal('1', @context['callcount'])
@global = nil
end
@@ -421,13 +421,13 @@ class ContextUnitTest < Minitest::Test
def test_nested_lambda_is_called_once
@context['callcount'] = { "lambda" => proc {
@global ||= 0
@global += 1
@global += 1
@global.to_s
} }
assert_equal '1', @context['callcount.lambda']
assert_equal '1', @context['callcount.lambda']
assert_equal '1', @context['callcount.lambda']
assert_equal('1', @context['callcount.lambda'])
assert_equal('1', @context['callcount.lambda'])
assert_equal('1', @context['callcount.lambda'])
@global = nil
end
@@ -435,13 +435,13 @@ class ContextUnitTest < Minitest::Test
def test_lambda_in_array_is_called_once
@context['callcount'] = [1, 2, proc {
@global ||= 0
@global += 1
@global += 1
@global.to_s
}, 4, 5]
assert_equal '1', @context['callcount[2]']
assert_equal '1', @context['callcount[2]']
assert_equal '1', @context['callcount[2]']
assert_equal('1', @context['callcount[2]'])
assert_equal('1', @context['callcount[2]'])
assert_equal('1', @context['callcount[2]'])
@global = nil
end
@@ -451,13 +451,13 @@ class ContextUnitTest < Minitest::Test
@context['magic'] = proc { @context.registers[:magic] }
assert_equal 345392, @context['magic']
assert_equal(345392, @context['magic'])
end
def test_to_liquid_and_context_at_first_level
@context['category'] = Category.new("foobar")
assert_kind_of CategoryDrop, @context['category']
assert_equal @context, @context['category'].context
assert_kind_of(CategoryDrop, @context['category'])
assert_equal(@context, @context['category'].context)
end
def test_interrupt_avoids_object_allocations
@@ -469,8 +469,8 @@ class ContextUnitTest < Minitest::Test
def test_context_initialization_with_a_proc_in_environment
contx = Context.new([test: ->(c) { c['poutine'] }], test: :foo)
assert contx
assert_nil contx['poutine']
assert(contx)
assert_nil(contx['poutine'])
end
def test_apply_global_filter
@@ -479,7 +479,7 @@ class ContextUnitTest < Minitest::Test
context = Context.new
context.global_filter = global_filter_proc
assert_equal 'hi filtered', context.apply_global_filter('hi')
assert_equal('hi filtered', context.apply_global_filter('hi'))
end
def test_static_environments_are_read_with_lower_priority_than_environments
@@ -488,13 +488,13 @@ class ContextUnitTest < Minitest::Test
environments: { 'shadowed' => 'dynamic' }
)
assert_equal 'dynamic', context['shadowed']
assert_equal 'static', context['unshadowed']
assert_equal('dynamic', context['shadowed'])
assert_equal('static', context['unshadowed'])
end
def test_apply_global_filter_when_no_global_filter_exist
context = Context.new
assert_equal 'hi', context.apply_global_filter('hi')
assert_equal('hi', context.apply_global_filter('hi'))
end
def test_new_isolated_subcontext_does_not_inherit_variables
@@ -502,28 +502,28 @@ class ContextUnitTest < Minitest::Test
super_context['my_variable'] = 'some value'
subcontext = super_context.new_isolated_subcontext
assert_nil subcontext['my_variable']
assert_nil(subcontext['my_variable'])
end
def test_new_isolated_subcontext_inherits_static_environment
super_context = Context.build(static_environments: { 'my_environment_value' => 'my value' })
subcontext = super_context.new_isolated_subcontext
subcontext = super_context.new_isolated_subcontext
assert_equal 'my value', subcontext['my_environment_value']
assert_equal('my value', subcontext['my_environment_value'])
end
def test_new_isolated_subcontext_inherits_resource_limits
resource_limits = ResourceLimits.new({})
super_context = Context.new({}, {}, {}, false, resource_limits)
subcontext = super_context.new_isolated_subcontext
assert_equal resource_limits, subcontext.resource_limits
super_context = Context.new({}, {}, {}, false, resource_limits)
subcontext = super_context.new_isolated_subcontext
assert_equal(resource_limits, subcontext.resource_limits)
end
def test_new_isolated_subcontext_inherits_exception_renderer
super_context = Context.new
super_context.exception_renderer = ->(_e) { 'my exception message' }
subcontext = super_context.new_isolated_subcontext
assert_equal 'my exception message', subcontext.handle_error(Liquid::Error.new)
assert_equal('my exception message', subcontext.handle_error(Liquid::Error.new))
end
def test_new_isolated_subcontext_does_not_inherit_non_static_registers
@@ -532,21 +532,21 @@ class ContextUnitTest < Minitest::Test
}
super_context = Context.new({}, {}, StaticRegisters.new(registers))
super_context.registers[:my_register] = :my_alt_value
subcontext = super_context.new_isolated_subcontext
assert_equal :my_value, subcontext.registers[:my_register]
subcontext = super_context.new_isolated_subcontext
assert_equal(:my_value, subcontext.registers[:my_register])
end
def test_new_isolated_subcontext_inherits_static_registers
super_context = Context.build(registers: { my_register: :my_value })
subcontext = super_context.new_isolated_subcontext
assert_equal :my_value, subcontext.registers[:my_register]
subcontext = super_context.new_isolated_subcontext
assert_equal(:my_value, subcontext.registers[:my_register])
end
def test_new_isolated_subcontext_registers_do_not_pollute_context
super_context = Context.build(registers: { my_register: :my_value })
subcontext = super_context.new_isolated_subcontext
super_context = Context.build(registers: { my_register: :my_value })
subcontext = super_context.new_isolated_subcontext
subcontext.registers[:my_register] = :my_alt_value
assert_equal :my_value, super_context.registers[:my_register]
assert_equal(:my_value, super_context.registers[:my_register])
end
def test_new_isolated_subcontext_inherits_filters
@@ -558,22 +558,22 @@ class ContextUnitTest < Minitest::Test
super_context = Context.new
super_context.add_filters([my_filter])
subcontext = super_context.new_isolated_subcontext
template = Template.parse('{{ 123 | my_filter }}')
assert_equal 'my filter result', template.render(subcontext)
subcontext = super_context.new_isolated_subcontext
template = Template.parse('{{ 123 | my_filter }}')
assert_equal('my filter result', template.render(subcontext))
end
private
def assert_no_object_allocations
unless RUBY_ENGINE == 'ruby'
skip "stackprof needed to count object allocations"
skip("stackprof needed to count object allocations")
end
require 'stackprof'
profile = StackProf.run(mode: :object) do
yield
end
assert_equal 0, profile[:samples]
assert_equal(0, profile[:samples])
end
end # ContextTest
+4 -4
View File
@@ -13,8 +13,8 @@ class FileSystemUnitTest < Minitest::Test
def test_local
file_system = Liquid::LocalFileSystem.new("/some/path")
assert_equal "/some/path/_mypartial.liquid", file_system.full_path("mypartial")
assert_equal "/some/path/dir/_mypartial.liquid", file_system.full_path("dir/mypartial")
assert_equal("/some/path/_mypartial.liquid", file_system.full_path("mypartial"))
assert_equal("/some/path/dir/_mypartial.liquid", file_system.full_path("dir/mypartial"))
assert_raises(FileSystemError) do
file_system.full_path("../dir/mypartial")
@@ -31,7 +31,7 @@ class FileSystemUnitTest < Minitest::Test
def test_custom_template_filename_patterns
file_system = Liquid::LocalFileSystem.new("/some/path", "%s.html")
assert_equal "/some/path/mypartial.html", file_system.full_path("mypartial")
assert_equal "/some/path/dir/mypartial.html", file_system.full_path("dir/mypartial")
assert_equal("/some/path/mypartial.html", file_system.full_path("mypartial"))
assert_equal("/some/path/dir/mypartial.html", file_system.full_path("dir/mypartial"))
end
end # FileSystemTest
+4 -4
View File
@@ -10,15 +10,15 @@ class I18nUnitTest < Minitest::Test
end
def test_simple_translate_string
assert_equal "less is more", @i18n.translate("simple")
assert_equal("less is more", @i18n.translate("simple"))
end
def test_nested_translate_string
assert_equal "something wasn't right", @i18n.translate("errors.syntax.oops")
assert_equal("something wasn't right", @i18n.translate("errors.syntax.oops"))
end
def test_single_string_interpolation
assert_equal "something different", @i18n.translate("whatever", something: "different")
assert_equal("something different", @i18n.translate("whatever", something: "different"))
end
# def test_raises_translation_error_on_undefined_interpolation_key
@@ -34,6 +34,6 @@ class I18nUnitTest < Minitest::Test
end
def test_sets_default_path_to_en
assert_equal I18n::DEFAULT_LOCALE, I18n.new.path
assert_equal(I18n::DEFAULT_LOCALE, I18n.new.path)
end
end
+9 -9
View File
@@ -7,42 +7,42 @@ class LexerUnitTest < Minitest::Test
def test_strings
tokens = Lexer.new(%( 'this is a test""' "wat 'lol'")).tokenize
assert_equal [[:string, %('this is a test""')], [:string, %("wat 'lol'")], [:end_of_string]], tokens
assert_equal([[:string, %('this is a test""')], [:string, %("wat 'lol'")], [:end_of_string]], tokens)
end
def test_integer
tokens = Lexer.new('hi 50').tokenize
assert_equal [[:id, 'hi'], [:number, '50'], [:end_of_string]], tokens
assert_equal([[:id, 'hi'], [:number, '50'], [:end_of_string]], tokens)
end
def test_float
tokens = Lexer.new('hi 5.0').tokenize
assert_equal [[:id, 'hi'], [:number, '5.0'], [:end_of_string]], tokens
assert_equal([[:id, 'hi'], [:number, '5.0'], [:end_of_string]], tokens)
end
def test_comparison
tokens = Lexer.new('== <> contains ').tokenize
assert_equal [[:comparison, '=='], [:comparison, '<>'], [:comparison, 'contains'], [:end_of_string]], tokens
assert_equal([[:comparison, '=='], [:comparison, '<>'], [:comparison, 'contains'], [:end_of_string]], tokens)
end
def test_specials
tokens = Lexer.new('| .:').tokenize
assert_equal [[:pipe, '|'], [:dot, '.'], [:colon, ':'], [:end_of_string]], tokens
assert_equal([[:pipe, '|'], [:dot, '.'], [:colon, ':'], [:end_of_string]], tokens)
tokens = Lexer.new('[,]').tokenize
assert_equal [[:open_square, '['], [:comma, ','], [:close_square, ']'], [:end_of_string]], tokens
assert_equal([[:open_square, '['], [:comma, ','], [:close_square, ']'], [:end_of_string]], tokens)
end
def test_fancy_identifiers
tokens = Lexer.new('hi five?').tokenize
assert_equal [[:id, 'hi'], [:id, 'five?'], [:end_of_string]], tokens
assert_equal([[:id, 'hi'], [:id, 'five?'], [:end_of_string]], tokens)
tokens = Lexer.new('2foo').tokenize
assert_equal [[:number, '2'], [:id, 'foo'], [:end_of_string]], tokens
assert_equal([[:number, '2'], [:id, 'foo'], [:end_of_string]], tokens)
end
def test_whitespace
tokens = Lexer.new("five|\n\t ==").tokenize
assert_equal [[:id, 'five'], [:pipe, '|'], [:comparison, '=='], [:end_of_string]], tokens
assert_equal([[:id, 'five'], [:pipe, '|'], [:comparison, '=='], [:end_of_string]], tokens)
end
def test_unexpected_character
+35 -35
View File
@@ -7,72 +7,72 @@ class ParserUnitTest < Minitest::Test
def test_consume
p = Parser.new("wat: 7")
assert_equal 'wat', p.consume(:id)
assert_equal ':', p.consume(:colon)
assert_equal '7', p.consume(:number)
assert_equal('wat', p.consume(:id))
assert_equal(':', p.consume(:colon))
assert_equal('7', p.consume(:number))
end
def test_jump
p = Parser.new("wat: 7")
p.jump(2)
assert_equal '7', p.consume(:number)
assert_equal('7', p.consume(:number))
end
def test_consume?
p = Parser.new("wat: 7")
assert_equal 'wat', p.consume?(:id)
assert_equal false, p.consume?(:dot)
assert_equal ':', p.consume(:colon)
assert_equal '7', p.consume?(:number)
assert_equal('wat', p.consume?(:id))
assert_equal(false, p.consume?(:dot))
assert_equal(':', p.consume(:colon))
assert_equal('7', p.consume?(:number))
end
def test_id?
p = Parser.new("wat 6 Peter Hegemon")
assert_equal 'wat', p.id?('wat')
assert_equal false, p.id?('endgame')
assert_equal '6', p.consume(:number)
assert_equal 'Peter', p.id?('Peter')
assert_equal false, p.id?('Achilles')
assert_equal('wat', p.id?('wat'))
assert_equal(false, p.id?('endgame'))
assert_equal('6', p.consume(:number))
assert_equal('Peter', p.id?('Peter'))
assert_equal(false, p.id?('Achilles'))
end
def test_look
p = Parser.new("wat 6 Peter Hegemon")
assert_equal true, p.look(:id)
assert_equal 'wat', p.consume(:id)
assert_equal false, p.look(:comparison)
assert_equal true, p.look(:number)
assert_equal true, p.look(:id, 1)
assert_equal false, p.look(:number, 1)
assert_equal(true, p.look(:id))
assert_equal('wat', p.consume(:id))
assert_equal(false, p.look(:comparison))
assert_equal(true, p.look(:number))
assert_equal(true, p.look(:id, 1))
assert_equal(false, p.look(:number, 1))
end
def test_expressions
p = Parser.new("hi.there hi?[5].there? hi.there.bob")
assert_equal 'hi.there', p.expression
assert_equal 'hi?[5].there?', p.expression
assert_equal 'hi.there.bob', p.expression
assert_equal('hi.there', p.expression)
assert_equal('hi?[5].there?', p.expression)
assert_equal('hi.there.bob', p.expression)
p = Parser.new("567 6.0 'lol' \"wut\"")
assert_equal '567', p.expression
assert_equal '6.0', p.expression
assert_equal "'lol'", p.expression
assert_equal '"wut"', p.expression
assert_equal('567', p.expression)
assert_equal('6.0', p.expression)
assert_equal("'lol'", p.expression)
assert_equal('"wut"', p.expression)
end
def test_ranges
p = Parser.new("(5..7) (1.5..9.6) (young..old) (hi[5].wat..old)")
assert_equal '(5..7)', p.expression
assert_equal '(1.5..9.6)', p.expression
assert_equal '(young..old)', p.expression
assert_equal '(hi[5].wat..old)', p.expression
assert_equal('(5..7)', p.expression)
assert_equal('(1.5..9.6)', p.expression)
assert_equal('(young..old)', p.expression)
assert_equal('(hi[5].wat..old)', p.expression)
end
def test_arguments
p = Parser.new("filter: hi.there[5], keyarg: 7")
assert_equal 'filter', p.consume(:id)
assert_equal ':', p.consume(:colon)
assert_equal 'hi.there[5]', p.argument
assert_equal ',', p.consume(:comma)
assert_equal 'keyarg: 7', p.argument
assert_equal('filter', p.consume(:id))
assert_equal(':', p.consume(:colon))
assert_equal('hi.there[5]', p.argument)
assert_equal(',', p.consume(:comma))
assert_equal('keyarg: 7', p.argument)
end
def test_invalid_expression
+7 -7
View File
@@ -16,12 +16,12 @@ class PartialCacheUnitTest < Minitest::Test
parse_context: Liquid::ParseContext.new
)
assert_equal 'my partial body', partial.render
assert_equal('my partial body', partial.render)
end
def test_reads_from_the_file_system_only_once_per_file
file_system = StubFileSystem.new('my_partial' => 'some partial body')
context = Liquid::Context.build(
context = Liquid::Context.build(
registers: { file_system: file_system }
)
@@ -33,11 +33,11 @@ class PartialCacheUnitTest < Minitest::Test
)
end
assert_equal 1, file_system.file_read_count
assert_equal(1, file_system.file_read_count)
end
def test_cache_state_is_stored_per_context
parse_context = Liquid::ParseContext.new
parse_context = Liquid::ParseContext.new
shared_file_system = StubFileSystem.new(
'my_partial' => 'my shared value'
)
@@ -66,12 +66,12 @@ class PartialCacheUnitTest < Minitest::Test
parse_context: parse_context
)
assert_equal 2, shared_file_system.file_read_count
assert_equal(2, shared_file_system.file_read_count)
end
def test_cache_is_not_broken_when_a_different_parse_context_is_used
file_system = StubFileSystem.new('my_partial' => 'some partial body')
context = Liquid::Context.build(
context = Liquid::Context.build(
registers: { file_system: file_system }
)
@@ -88,6 +88,6 @@ class PartialCacheUnitTest < Minitest::Test
# Technically what we care about is that the file was parsed twice,
# but measuring file reads is an OK proxy for this.
assert_equal 1, file_system.file_read_count
assert_equal(1, file_system.file_read_count)
end
end
+84 -84
View File
@@ -6,10 +6,10 @@ class StaticRegistersUnitTest < Minitest::Test
include Liquid
def set
static_register = StaticRegisters.new
static_register[nil] = true
static_register[1] = :one
static_register[:one] = "one"
static_register = StaticRegisters.new
static_register[nil] = true
static_register[1] = :one
static_register[:one] = "one"
static_register["two"] = "three"
static_register["two"] = 3
static_register[false] = nil
@@ -22,23 +22,23 @@ class StaticRegistersUnitTest < Minitest::Test
def test_get
static_register = set
assert_equal true, static_register[nil]
assert_equal :one, static_register[1]
assert_equal "one", static_register[:one]
assert_equal 3, static_register["two"]
assert_nil static_register[false]
assert_nil static_register["unknown"]
assert_equal(true, static_register[nil])
assert_equal(:one, static_register[1])
assert_equal("one", static_register[:one])
assert_equal(3, static_register["two"])
assert_nil(static_register[false])
assert_nil(static_register["unknown"])
end
def test_delete
static_register = set
assert_equal true, static_register.delete(nil)
assert_equal :one, static_register.delete(1)
assert_equal "one", static_register.delete(:one)
assert_equal 3, static_register.delete("two")
assert_nil static_register.delete(false)
assert_nil static_register.delete("unknown")
assert_equal(true, static_register.delete(nil))
assert_equal(:one, static_register.delete(1))
assert_equal("one", static_register.delete(:one))
assert_equal(3, static_register.delete("two"))
assert_nil(static_register.delete(false))
assert_nil(static_register.delete("unknown"))
assert_equal({}, static_register.registers)
end
@@ -46,41 +46,41 @@ class StaticRegistersUnitTest < Minitest::Test
def test_fetch
static_register = set
assert_equal true, static_register.fetch(nil)
assert_equal :one, static_register.fetch(1)
assert_equal "one", static_register.fetch(:one)
assert_equal 3, static_register.fetch("two")
assert_nil static_register.fetch(false)
assert_nil static_register.fetch("unknown")
assert_equal(true, static_register.fetch(nil))
assert_equal(:one, static_register.fetch(1))
assert_equal("one", static_register.fetch(:one))
assert_equal(3, static_register.fetch("two"))
assert_nil(static_register.fetch(false))
assert_nil(static_register.fetch("unknown"))
end
def test_fetch_default
static_register = StaticRegisters.new
assert_equal true, static_register.fetch(nil, true)
assert_equal :one, static_register.fetch(1, :one)
assert_equal "one", static_register.fetch(:one, "one")
assert_equal 3, static_register.fetch("two", 3)
assert_nil static_register.fetch(false, nil)
assert_equal(true, static_register.fetch(nil, true))
assert_equal(:one, static_register.fetch(1, :one))
assert_equal("one", static_register.fetch(:one, "one"))
assert_equal(3, static_register.fetch("two", 3))
assert_nil(static_register.fetch(false, nil))
end
def test_key
static_register = set
assert_equal true, static_register.key?(nil)
assert_equal true, static_register.key?(1)
assert_equal true, static_register.key?(:one)
assert_equal true, static_register.key?("two")
assert_equal true, static_register.key?(false)
assert_equal false, static_register.key?("unknown")
assert_equal false, static_register.key?(true)
assert_equal(true, static_register.key?(nil))
assert_equal(true, static_register.key?(1))
assert_equal(true, static_register.key?(:one))
assert_equal(true, static_register.key?("two"))
assert_equal(true, static_register.key?(false))
assert_equal(false, static_register.key?("unknown"))
assert_equal(false, static_register.key?(true))
end
def set_with_static
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
static_register[nil] = false
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
static_register[nil] = false
static_register["two"] = 4
static_register[true] = "foo"
static_register[true] = "foo"
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
assert_equal({ nil => false, "two" => 4, true => "foo" }, static_register.registers)
@@ -91,22 +91,22 @@ class StaticRegistersUnitTest < Minitest::Test
def test_get_with_static
static_register = set_with_static
assert_equal false, static_register[nil]
assert_equal :one, static_register[1]
assert_equal "one", static_register[:one]
assert_equal 4, static_register["two"]
assert_equal "foo", static_register[true]
assert_nil static_register[false]
assert_equal(false, static_register[nil])
assert_equal(:one, static_register[1])
assert_equal("one", static_register[:one])
assert_equal(4, static_register["two"])
assert_equal("foo", static_register[true])
assert_nil(static_register[false])
end
def test_delete_with_static
static_register = set_with_static
assert_equal false, static_register.delete(nil)
assert_equal 4, static_register.delete("two")
assert_equal "foo", static_register.delete(true)
assert_nil static_register.delete("unknown")
assert_nil static_register.delete(:one)
assert_equal(false, static_register.delete(nil))
assert_equal(4, static_register.delete("two"))
assert_equal("foo", static_register.delete(true))
assert_nil(static_register.delete("unknown"))
assert_nil(static_register.delete(:one))
assert_equal({}, static_register.registers)
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
@@ -115,24 +115,24 @@ class StaticRegistersUnitTest < Minitest::Test
def test_fetch_with_static
static_register = set_with_static
assert_equal false, static_register.fetch(nil)
assert_equal :one, static_register.fetch(1)
assert_equal "one", static_register.fetch(:one)
assert_equal 4, static_register.fetch("two")
assert_equal "foo", static_register.fetch(true)
assert_nil static_register.fetch(false)
assert_equal(false, static_register.fetch(nil))
assert_equal(:one, static_register.fetch(1))
assert_equal("one", static_register.fetch(:one))
assert_equal(4, static_register.fetch("two"))
assert_equal("foo", static_register.fetch(true))
assert_nil(static_register.fetch(false))
end
def test_key_with_static
static_register = set_with_static
assert_equal true, static_register.key?(nil)
assert_equal true, static_register.key?(1)
assert_equal true, static_register.key?(:one)
assert_equal true, static_register.key?("two")
assert_equal true, static_register.key?(false)
assert_equal false, static_register.key?("unknown")
assert_equal true, static_register.key?(true)
assert_equal(true, static_register.key?(nil))
assert_equal(true, static_register.key?(1))
assert_equal(true, static_register.key?(:one))
assert_equal(true, static_register.key?("two"))
assert_equal(true, static_register.key?(false))
assert_equal(false, static_register.key?("unknown"))
assert_equal(true, static_register.key?(true))
end
def test_static_register_can_be_frozen
@@ -154,23 +154,23 @@ class StaticRegistersUnitTest < Minitest::Test
end
def test_new_static_retains_static
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
static_register["one"] = 1
static_register["two"] = 2
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
static_register["one"] = 1
static_register["two"] = 2
static_register["three"] = 3
new_register = StaticRegisters.new(static_register)
assert_equal({}, new_register.registers)
new_register["one"] = 4
new_register["two"] = 5
new_register["one"] = 4
new_register["two"] = 5
new_register["three"] = 6
newest_register = StaticRegisters.new(new_register)
assert_equal({}, newest_register.registers)
newest_register["one"] = 7
newest_register["two"] = 8
newest_register["one"] = 7
newest_register["two"] = 8
newest_register["three"] = 9
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
@@ -182,23 +182,23 @@ class StaticRegistersUnitTest < Minitest::Test
end
def test_multiple_instances_are_unique
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
static_register["one"] = 1
static_register["two"] = 2
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
static_register["one"] = 1
static_register["two"] = 2
static_register["three"] = 3
new_register = StaticRegisters.new(foo: :bar)
assert_equal({}, new_register.registers)
new_register["one"] = 4
new_register["two"] = 5
new_register["one"] = 4
new_register["two"] = 5
new_register["three"] = 6
newest_register = StaticRegisters.new(bar: :foo)
assert_equal({}, newest_register.registers)
newest_register["one"] = 7
newest_register["two"] = 8
newest_register["one"] = 7
newest_register["two"] = 8
newest_register["three"] = 9
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
@@ -210,9 +210,9 @@ class StaticRegistersUnitTest < Minitest::Test
end
def test_can_update_static_directly_and_updates_all_instances
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
static_register["one"] = 1
static_register["two"] = 2
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
static_register["one"] = 1
static_register["two"] = 2
static_register["three"] = 3
new_register = StaticRegisters.new(static_register)
@@ -220,9 +220,9 @@ class StaticRegistersUnitTest < Minitest::Test
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
new_register["one"] = 4
new_register["two"] = 5
new_register["three"] = 6
new_register["one"] = 4
new_register["two"] = 5
new_register["three"] = 6
new_register.static["four"] = 10
newest_register = StaticRegisters.new(new_register)
@@ -230,9 +230,9 @@ class StaticRegistersUnitTest < Minitest::Test
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 10 }, new_register.static)
newest_register["one"] = 7
newest_register["two"] = 8
newest_register["three"] = 9
newest_register["one"] = 7
newest_register["two"] = 8
newest_register["three"] = 9
new_register.static["four"] = 5
new_register.static["five"] = 15
+24 -24
View File
@@ -20,8 +20,8 @@ class StrainerUnitTest < Minitest::Test
def test_strainer
strainer = Strainer.create(nil)
assert_equal 5, strainer.invoke('size', 'input')
assert_equal "public", strainer.invoke("public_filter")
assert_equal(5, strainer.invoke('size', 'input'))
assert_equal("public", strainer.invoke("public_filter"))
end
def test_stainer_raises_argument_error
@@ -40,45 +40,45 @@ class StrainerUnitTest < Minitest::Test
/\ALiquid error: wrong number of arguments \((1 for 0|given 1, expected 0)\)\z/,
e.message
)
assert_equal e.backtrace[0].split(':')[0], __FILE__
assert_equal(e.backtrace[0].split(':')[0], __FILE__)
end
end
def test_strainer_only_invokes_public_filter_methods
strainer = Strainer.create(nil)
assert_equal false, strainer.class.invokable?('__test__')
assert_equal false, strainer.class.invokable?('test')
assert_equal false, strainer.class.invokable?('instance_eval')
assert_equal false, strainer.class.invokable?('__send__')
assert_equal true, strainer.class.invokable?('size') # from the standard lib
assert_equal(false, strainer.class.invokable?('__test__'))
assert_equal(false, strainer.class.invokable?('test'))
assert_equal(false, strainer.class.invokable?('instance_eval'))
assert_equal(false, strainer.class.invokable?('__send__'))
assert_equal(true, strainer.class.invokable?('size')) # from the standard lib
end
def test_strainer_returns_nil_if_no_filter_method_found
strainer = Strainer.create(nil)
assert_nil strainer.invoke("private_filter")
assert_nil strainer.invoke("undef_the_filter")
assert_nil(strainer.invoke("private_filter"))
assert_nil(strainer.invoke("undef_the_filter"))
end
def test_strainer_returns_first_argument_if_no_method_and_arguments_given
strainer = Strainer.create(nil)
assert_equal "password", strainer.invoke("undef_the_method", "password")
assert_equal("password", strainer.invoke("undef_the_method", "password"))
end
def test_strainer_only_allows_methods_defined_in_filters
strainer = Strainer.create(nil)
assert_equal "1 + 1", strainer.invoke("instance_eval", "1 + 1")
assert_equal "puts", strainer.invoke("__send__", "puts", "Hi Mom")
assert_equal "has_method?", strainer.invoke("invoke", "has_method?", "invoke")
assert_equal("1 + 1", strainer.invoke("instance_eval", "1 + 1"))
assert_equal("puts", strainer.invoke("__send__", "puts", "Hi Mom"))
assert_equal("has_method?", strainer.invoke("invoke", "has_method?", "invoke"))
end
def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation
a = Module.new
b = Module.new
strainer = Strainer.create(nil, [a, b])
assert_kind_of Strainer, strainer
assert_kind_of a, strainer
assert_kind_of b, strainer
assert_kind_of Liquid::StandardFilters, strainer
assert_kind_of(Strainer, strainer)
assert_kind_of(a, strainer)
assert_kind_of(b, strainer)
assert_kind_of(Liquid::StandardFilters, strainer)
end
def test_add_filter_when_wrong_filter_class
@@ -105,7 +105,7 @@ class StrainerUnitTest < Minitest::Test
error = assert_raises(Liquid::MethodOverrideError) do
strainer.class.add_filter(PrivateMethodOverrideFilter)
end
assert_equal 'Liquid error: Filter overrides registered public methods as non public: public_filter', error.message
assert_equal('Liquid error: Filter overrides registered public methods as non public: public_filter', error.message)
end
module ProtectedMethodOverrideFilter
@@ -122,7 +122,7 @@ class StrainerUnitTest < Minitest::Test
error = assert_raises(Liquid::MethodOverrideError) do
strainer.class.add_filter(ProtectedMethodOverrideFilter)
end
assert_equal 'Liquid error: Filter overrides registered public methods as non public: public_filter', error.message
assert_equal('Liquid error: Filter overrides registered public methods as non public: public_filter', error.message)
end
module PublicMethodOverrideFilter
@@ -134,7 +134,7 @@ class StrainerUnitTest < Minitest::Test
def test_add_filter_does_not_raise_when_module_overrides_previously_registered_method
strainer = Context.new.strainer
strainer.class.add_filter(PublicMethodOverrideFilter)
assert strainer.class.filter_methods.include?('public_filter')
assert(strainer.class.filter_methods.include?('public_filter'))
end
module LateAddedFilter
@@ -144,9 +144,9 @@ class StrainerUnitTest < Minitest::Test
end
def test_global_filter_clears_cache
assert_equal 'input', Strainer.create(nil).invoke('late_added_filter', 'input')
assert_equal('input', Strainer.create(nil).invoke('late_added_filter', 'input'))
Strainer.global_filter(LateAddedFilter)
assert_equal 'filtered', Strainer.create(nil).invoke('late_added_filter', 'input')
assert_equal('filtered', Strainer.create(nil).invoke('late_added_filter', 'input'))
end
def test_add_filter_does_not_include_already_included_module
@@ -162,6 +162,6 @@ class StrainerUnitTest < Minitest::Test
strainer = Context.new.strainer
strainer.class.add_filter(mod)
strainer.class.add_filter(mod)
assert_equal 1, mod.include_count
assert_equal(1, mod.include_count)
end
end # StrainerTest
+5 -5
View File
@@ -7,8 +7,8 @@ class TagUnitTest < Minitest::Test
def test_tag
tag = Tag.parse('tag', "", Tokenizer.new(""), ParseContext.new)
assert_equal 'liquid::tag', tag.name
assert_equal '', tag.render(Context.new)
assert_equal('liquid::tag', tag.name)
assert_equal('', tag.render(Context.new))
end
def test_return_raw_text_of_tag
@@ -18,7 +18,7 @@ class TagUnitTest < Minitest::Test
def test_tag_name_should_return_name_of_the_tag
tag = Tag.parse("some_tag", "", Tokenizer.new(""), ParseContext.new)
assert_equal 'some_tag', tag.tag_name
assert_equal('some_tag', tag.tag_name)
end
def test_custom_tags_have_a_default_render_to_output_buffer_method_for_backwards_compatibility
@@ -33,7 +33,7 @@ class TagUnitTest < Minitest::Test
assert_equal 'hello', template.render
buf = +''
buf = +''
output = template.render({}, output: buf)
assert_equal 'hello', output
assert_equal 'hello', buf
@@ -51,7 +51,7 @@ class TagUnitTest < Minitest::Test
assert_equal 'foohellobar', template.render
buf = +''
buf = +''
output = template.render({}, output: buf)
assert_equal 'foohellobar', output
assert_equal 'foohellobar', buf
+1 -1
View File
@@ -7,6 +7,6 @@ class CaseTagUnitTest < Minitest::Test
def test_case_nodelist
template = Liquid::Template.parse('{% case var %}{% when true %}WHEN{% else %}ELSE{% endcase %}')
assert_equal ['WHEN', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten
assert_equal(['WHEN', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten)
end
end
+2 -2
View File
@@ -5,11 +5,11 @@ require 'test_helper'
class ForTagUnitTest < Minitest::Test
def test_for_nodelist
template = Liquid::Template.parse('{% for item in items %}FOR{% endfor %}')
assert_equal ['FOR'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten
assert_equal(['FOR'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten)
end
def test_for_else_nodelist
template = Liquid::Template.parse('{% for item in items %}FOR{% else %}ELSE{% endfor %}')
assert_equal ['FOR', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten
assert_equal(['FOR', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten)
end
end
+10 -10
View File
@@ -8,7 +8,7 @@ class TemplateUnitTest < Minitest::Test
def test_sets_default_localization_in_document
t = Template.new
t.parse('{%comment%}{%endcomment%}')
assert_instance_of I18n, t.root.nodelist[0].options[:locale]
assert_instance_of(I18n, t.root.nodelist[0].options[:locale])
end
def test_sets_default_localization_in_context_with_quick_initialization
@@ -16,13 +16,13 @@ class TemplateUnitTest < Minitest::Test
t.parse('{%comment%}{%endcomment%}', locale: I18n.new(fixture("en_locale.yml")))
locale = t.root.nodelist[0].options[:locale]
assert_instance_of I18n, locale
assert_equal fixture("en_locale.yml"), locale.path
assert_instance_of(I18n, locale)
assert_equal(fixture("en_locale.yml"), locale.path)
end
def test_with_cache_classes_tags_returns_the_same_class
original_cache_setting = Liquid.cache_classes
Liquid.cache_classes = true
Liquid.cache_classes = true
original_klass = Class.new
Object.send(:const_set, :CustomTag, original_klass)
@@ -33,7 +33,7 @@ class TemplateUnitTest < Minitest::Test
new_klass = Class.new
Object.send(:const_set, :CustomTag, new_klass)
assert Template.tags['custom'].equal?(original_klass)
assert(Template.tags['custom'].equal?(original_klass))
ensure
Object.send(:remove_const, :CustomTag)
Template.tags.delete('custom')
@@ -42,7 +42,7 @@ class TemplateUnitTest < Minitest::Test
def test_without_cache_classes_tags_reloads_the_class
original_cache_setting = Liquid.cache_classes
Liquid.cache_classes = false
Liquid.cache_classes = false
original_klass = Class.new
Object.send(:const_set, :CustomTag, original_klass)
@@ -53,7 +53,7 @@ class TemplateUnitTest < Minitest::Test
new_klass = Class.new
Object.send(:const_set, :CustomTag, new_klass)
assert Template.tags['custom'].equal?(new_klass)
assert(Template.tags['custom'].equal?(new_klass))
ensure
Object.send(:remove_const, :CustomTag)
Template.tags.delete('custom')
@@ -64,16 +64,16 @@ class TemplateUnitTest < Minitest::Test
def test_tags_delete
Template.register_tag('fake', FakeTag)
assert_equal FakeTag, Template.tags['fake']
assert_equal(FakeTag, Template.tags['fake'])
Template.tags.delete('fake')
assert_nil Template.tags['fake']
assert_nil(Template.tags['fake'])
end
def test_tags_can_be_looped_over
Template.register_tag('fake', FakeTag)
result = Template.tags.map { |name, klass| [name, klass] }
assert result.include?(["fake", "TemplateUnitTest::FakeTag"])
assert(result.include?(["fake", "TemplateUnitTest::FakeTag"]))
ensure
Template.tags.delete('fake')
end
+16 -16
View File
@@ -4,37 +4,37 @@ require 'test_helper'
class TokenizerTest < Minitest::Test
def test_tokenize_strings
assert_equal [' '], tokenize(' ')
assert_equal ['hello world'], tokenize('hello world')
assert_equal([' '], tokenize(' '))
assert_equal(['hello world'], tokenize('hello world'))
end
def test_tokenize_variables
assert_equal ['{{funk}}'], tokenize('{{funk}}')
assert_equal [' ', '{{funk}}', ' '], tokenize(' {{funk}} ')
assert_equal [' ', '{{funk}}', ' ', '{{so}}', ' ', '{{brother}}', ' '], tokenize(' {{funk}} {{so}} {{brother}} ')
assert_equal [' ', '{{ funk }}', ' '], tokenize(' {{ funk }} ')
assert_equal(['{{funk}}'], tokenize('{{funk}}'))
assert_equal([' ', '{{funk}}', ' '], tokenize(' {{funk}} '))
assert_equal([' ', '{{funk}}', ' ', '{{so}}', ' ', '{{brother}}', ' '], tokenize(' {{funk}} {{so}} {{brother}} '))
assert_equal([' ', '{{ funk }}', ' '], tokenize(' {{ funk }} '))
end
def test_tokenize_blocks
assert_equal ['{%comment%}'], tokenize('{%comment%}')
assert_equal [' ', '{%comment%}', ' '], tokenize(' {%comment%} ')
assert_equal(['{%comment%}'], tokenize('{%comment%}'))
assert_equal([' ', '{%comment%}', ' '], tokenize(' {%comment%} '))
assert_equal [' ', '{%comment%}', ' ', '{%endcomment%}', ' '], tokenize(' {%comment%} {%endcomment%} ')
assert_equal [' ', '{% comment %}', ' ', '{% endcomment %}', ' '], tokenize(" {% comment %} {% endcomment %} ")
assert_equal([' ', '{%comment%}', ' ', '{%endcomment%}', ' '], tokenize(' {%comment%} {%endcomment%} '))
assert_equal([' ', '{% comment %}', ' ', '{% endcomment %}', ' '], tokenize(" {% comment %} {% endcomment %} "))
end
def test_calculate_line_numbers_per_token_with_profiling
assert_equal [1], tokenize_line_numbers("{{funk}}")
assert_equal [1, 1, 1], tokenize_line_numbers(" {{funk}} ")
assert_equal [1, 2, 2], tokenize_line_numbers("\n{{funk}}\n")
assert_equal [1, 1, 3], tokenize_line_numbers(" {{\n funk \n}} ")
assert_equal([1], tokenize_line_numbers("{{funk}}"))
assert_equal([1, 1, 1], tokenize_line_numbers(" {{funk}} "))
assert_equal([1, 2, 2], tokenize_line_numbers("\n{{funk}}\n"))
assert_equal([1, 1, 3], tokenize_line_numbers(" {{\n funk \n}} "))
end
private
def tokenize(source)
tokenizer = Liquid::Tokenizer.new(source)
tokens = []
tokens = []
while (t = tokenizer.shift)
tokens << t
end
@@ -42,7 +42,7 @@ class TokenizerTest < Minitest::Test
end
def tokenize_line_numbers(source)
tokenizer = Liquid::Tokenizer.new(source, true)
tokenizer = Liquid::Tokenizer.new(source, true)
line_numbers = []
loop do
line_number = tokenizer.line_number
+48 -48
View File
@@ -7,106 +7,106 @@ class VariableUnitTest < Minitest::Test
def test_variable
var = create_variable('hello')
assert_equal VariableLookup.new('hello'), var.name
assert_equal(VariableLookup.new('hello'), var.name)
end
def test_filters
var = create_variable('hello | textileze')
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['textileze', []]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['textileze', []]], var.filters)
var = create_variable('hello | textileze | paragraph')
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['textileze', []], ['paragraph', []]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['textileze', []], ['paragraph', []]], var.filters)
var = create_variable(%( hello | strftime: '%Y'))
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['strftime', ['%Y']]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['strftime', ['%Y']]], var.filters)
var = create_variable(%( 'typo' | link_to: 'Typo', true ))
assert_equal 'typo', var.name
assert_equal [['link_to', ['Typo', true]]], var.filters
assert_equal('typo', var.name)
assert_equal([['link_to', ['Typo', true]]], var.filters)
var = create_variable(%( 'typo' | link_to: 'Typo', false ))
assert_equal 'typo', var.name
assert_equal [['link_to', ['Typo', false]]], var.filters
assert_equal('typo', var.name)
assert_equal([['link_to', ['Typo', false]]], var.filters)
var = create_variable(%( 'foo' | repeat: 3 ))
assert_equal 'foo', var.name
assert_equal [['repeat', [3]]], var.filters
assert_equal('foo', var.name)
assert_equal([['repeat', [3]]], var.filters)
var = create_variable(%( 'foo' | repeat: 3, 3 ))
assert_equal 'foo', var.name
assert_equal [['repeat', [3, 3]]], var.filters
assert_equal('foo', var.name)
assert_equal([['repeat', [3, 3]]], var.filters)
var = create_variable(%( 'foo' | repeat: 3, 3, 3 ))
assert_equal 'foo', var.name
assert_equal [['repeat', [3, 3, 3]]], var.filters
assert_equal('foo', var.name)
assert_equal([['repeat', [3, 3, 3]]], var.filters)
var = create_variable(%( hello | strftime: '%Y, okay?'))
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['strftime', ['%Y, okay?']]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['strftime', ['%Y, okay?']]], var.filters)
var = create_variable(%( hello | things: "%Y, okay?", 'the other one'))
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['things', ['%Y, okay?', 'the other one']]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['things', ['%Y, okay?', 'the other one']]], var.filters)
end
def test_filter_with_date_parameter
var = create_variable(%( '2006-06-06' | date: "%m/%d/%Y"))
assert_equal '2006-06-06', var.name
assert_equal [['date', ['%m/%d/%Y']]], var.filters
assert_equal('2006-06-06', var.name)
assert_equal([['date', ['%m/%d/%Y']]], var.filters)
end
def test_filters_without_whitespace
var = create_variable('hello | textileze | paragraph')
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['textileze', []], ['paragraph', []]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['textileze', []], ['paragraph', []]], var.filters)
var = create_variable('hello|textileze|paragraph')
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['textileze', []], ['paragraph', []]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['textileze', []], ['paragraph', []]], var.filters)
var = create_variable("hello|replace:'foo','bar'|textileze")
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['replace', ['foo', 'bar']], ['textileze', []]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['replace', ['foo', 'bar']], ['textileze', []]], var.filters)
end
def test_symbol
var = create_variable("http://disney.com/logo.gif | image: 'med' ", error_mode: :lax)
assert_equal VariableLookup.new('http://disney.com/logo.gif'), var.name
assert_equal [['image', ['med']]], var.filters
assert_equal(VariableLookup.new('http://disney.com/logo.gif'), var.name)
assert_equal([['image', ['med']]], var.filters)
end
def test_string_to_filter
var = create_variable("'http://disney.com/logo.gif' | image: 'med' ")
assert_equal 'http://disney.com/logo.gif', var.name
assert_equal [['image', ['med']]], var.filters
assert_equal('http://disney.com/logo.gif', var.name)
assert_equal([['image', ['med']]], var.filters)
end
def test_string_single_quoted
var = create_variable(%( "hello" ))
assert_equal 'hello', var.name
assert_equal('hello', var.name)
end
def test_string_double_quoted
var = create_variable(%( 'hello' ))
assert_equal 'hello', var.name
assert_equal('hello', var.name)
end
def test_integer
var = create_variable(%( 1000 ))
assert_equal 1000, var.name
assert_equal(1000, var.name)
end
def test_float
var = create_variable(%( 1000.01 ))
assert_equal 1000.01, var.name
assert_equal(1000.01, var.name)
end
def test_dashes
assert_equal VariableLookup.new('foo-bar'), create_variable('foo-bar').name
assert_equal VariableLookup.new('foo-bar-2'), create_variable('foo-bar-2').name
assert_equal(VariableLookup.new('foo-bar'), create_variable('foo-bar').name)
assert_equal(VariableLookup.new('foo-bar-2'), create_variable('foo-bar-2').name)
with_error_mode :strict do
assert_raises(Liquid::SyntaxError) { create_variable('foo - bar') }
@@ -117,24 +117,24 @@ class VariableUnitTest < Minitest::Test
def test_string_with_special_chars
var = create_variable(%( 'hello! $!@.;"ddasd" ' ))
assert_equal 'hello! $!@.;"ddasd" ', var.name
assert_equal('hello! $!@.;"ddasd" ', var.name)
end
def test_string_dot
var = create_variable(%( test.test ))
assert_equal VariableLookup.new('test.test'), var.name
assert_equal(VariableLookup.new('test.test'), var.name)
end
def test_filter_with_keyword_arguments
var = create_variable(%( hello | things: greeting: "world", farewell: 'goodbye'))
assert_equal VariableLookup.new('hello'), var.name
assert_equal [['things', [], { 'greeting' => 'world', 'farewell' => 'goodbye' }]], var.filters
assert_equal(VariableLookup.new('hello'), var.name)
assert_equal([['things', [], { 'greeting' => 'world', 'farewell' => 'goodbye' }]], var.filters)
end
def test_lax_filter_argument_parsing
var = create_variable(%( number_of_comments | pluralize: 'comment': 'comments' ), error_mode: :lax)
assert_equal VariableLookup.new('number_of_comments'), var.name
assert_equal [['pluralize', ['comment', 'comments']]], var.filters
assert_equal(VariableLookup.new('number_of_comments'), var.name)
assert_equal([['pluralize', ['comment', 'comments']]], var.filters)
end
def test_strict_filter_argument_parsing
@@ -147,13 +147,13 @@ class VariableUnitTest < Minitest::Test
def test_output_raw_source_of_variable
var = create_variable(%( name_of_variable | upcase ))
assert_equal " name_of_variable | upcase ", var.raw
assert_equal(" name_of_variable | upcase ", var.raw)
end
def test_variable_lookup_interface
lookup = VariableLookup.new('a.b.c')
assert_equal 'a', lookup.name
assert_equal ['b', 'c'], lookup.lookups
assert_equal('a', lookup.name)
assert_equal(['b', 'c'], lookup.lookups)
end
private