0
@@ -40,6 +40,28 @@ class CategoryDrop
0
+class CounterDrop < Liquid::Drop
0
class ContextTest < Test::Unit::TestCase
0
@@ -299,6 +321,14 @@ class ContextTest < Test::Unit::TestCase
0
assert_equal 'freestyle', @context['products[nested.var].last']
0
+ def test_hash_notation_only_for_hash_access
0
+ @context['array'] = [1,2,3,4,5]
0
+ @context['hash'] = {'first' => 'Hello'}
0
+ assert_equal 1, @context['array.first']
0
+ assert_equal nil, @context['array["first"]']
0
+ assert_equal 'Hello', @context['hash["first"]']
0
def test_first_can_appear_in_middle_of_callchain
0
@@ -364,6 +394,22 @@ class ContextTest < Test::Unit::TestCase
0
assert_equal 100, @context['cents.cents.cents.amount']
0
+ def test_drop_with_variable_called_only_once
0
+ @context['counter'] = CounterDrop.new
0
+ assert_equal 1, @context['counter.count']
0
+ assert_equal 2, @context['counter.count']
0
+ assert_equal 3, @context['counter.count']
0
+ def test_drop_with_key_called_only_once
0
+ @context['counter'] = CounterDrop.new
0
+ assert_equal 1, @context['counter["count"]']
0
+ assert_equal 2, @context['counter["count"]']
0
+ assert_equal 3, @context['counter["count"]']
0
def test_proc_as_variable
0
@context['dynamic'] = Proc.new { 'Hello' }
0
@@ -382,6 +428,12 @@ class ContextTest < Test::Unit::TestCase
0
assert_equal 'Hello', @context['dynamic.lambda']
0
+ def test_array_containing_lambda_as_variable
0
+ @context['dynamic'] = [1,2, lambda { 'Hello' } ,4,5]
0
+ assert_equal 'Hello', @context['dynamic[2]']
0
def test_lambda_is_called_once
0
@context['callcount'] = lambda { @global ||= 0; @global += 1; @global.to_s }
0
@@ -402,6 +454,16 @@ class ContextTest < Test::Unit::TestCase
0
+ def test_lambda_in_array_is_called_once
0
+ @context['callcount'] = [1,2, lambda { @global ||= 0; @global += 1; @global.to_s } ,4,5]
0
+ assert_equal '1', @context['callcount[2]']
0
+ assert_equal '1', @context['callcount[2]']
0
+ assert_equal '1', @context['callcount[2]']
0
def test_access_to_context_from_proc
0
@context.registers[:magic] = 345392