mirror of
https://github.com/kemko/liquid.git
synced 2026-01-06 10:15:40 +03:00
Rubocop
This commit is contained in:
@@ -34,7 +34,7 @@ class BlockUnitTest < Minitest::Test
|
||||
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)
|
||||
block_types(template.root.nodelist)
|
||||
end
|
||||
|
||||
def test_with_block
|
||||
@@ -45,11 +45,12 @@ class BlockUnitTest < Minitest::Test
|
||||
|
||||
def test_with_custom_tag
|
||||
Liquid::Template.register_tag("testtag", Block)
|
||||
assert Liquid::Template.parse( "{% testtag %} {% endtesttag %}")
|
||||
assert Liquid::Template.parse("{% testtag %} {% endtesttag %}")
|
||||
end
|
||||
|
||||
private
|
||||
def block_types(nodelist)
|
||||
nodelist.collect { |node| node.class }
|
||||
end
|
||||
|
||||
def block_types(nodelist)
|
||||
nodelist.collect(&:class)
|
||||
end
|
||||
end # VariableTest
|
||||
|
||||
@@ -62,15 +62,15 @@ class ConditionUnitTest < Minitest::Test
|
||||
|
||||
def test_contains_works_on_arrays
|
||||
@context = Liquid::Context.new
|
||||
@context['array'] = [1,2,3,4,5]
|
||||
@context['array'] = [1, 2, 3, 4, 5]
|
||||
array_expr = VariableLookup.new("array")
|
||||
|
||||
assert_evalutes_false array_expr, 'contains', 0
|
||||
assert_evalutes_true array_expr, 'contains', 1
|
||||
assert_evalutes_true array_expr, 'contains', 2
|
||||
assert_evalutes_true array_expr, 'contains', 3
|
||||
assert_evalutes_true array_expr, 'contains', 4
|
||||
assert_evalutes_true array_expr, 'contains', 5
|
||||
assert_evalutes_true array_expr, 'contains', 1
|
||||
assert_evalutes_true array_expr, 'contains', 2
|
||||
assert_evalutes_true array_expr, 'contains', 3
|
||||
assert_evalutes_true array_expr, 'contains', 4
|
||||
assert_evalutes_true array_expr, 'contains', 5
|
||||
assert_evalutes_false array_expr, 'contains', 6
|
||||
assert_evalutes_false array_expr, 'contains', "1"
|
||||
end
|
||||
@@ -114,9 +114,9 @@ class ConditionUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_should_allow_custom_proc_operator
|
||||
Condition.operators['starts_with'] = Proc.new { |cond, left, right| left =~ %r{^#{right}} }
|
||||
Condition.operators['starts_with'] = proc { |cond, left, right| left =~ %r{^#{right}} }
|
||||
|
||||
assert_evalutes_true 'bob', 'starts_with', 'b'
|
||||
assert_evalutes_true 'bob', 'starts_with', 'b'
|
||||
assert_evalutes_false 'bob', 'starts_with', 'o'
|
||||
ensure
|
||||
Condition.operators.delete 'starts_with'
|
||||
@@ -130,20 +130,21 @@ class ConditionUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
private
|
||||
def assert_evalutes_true(left, op, right)
|
||||
assert Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
|
||||
"Evaluated false: #{left} #{op} #{right}"
|
||||
end
|
||||
|
||||
def assert_evalutes_false(left, op, right)
|
||||
assert !Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
|
||||
"Evaluated true: #{left} #{op} #{right}"
|
||||
end
|
||||
def assert_evalutes_true(left, op, right)
|
||||
assert Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
|
||||
"Evaluated false: #{left} #{op} #{right}"
|
||||
end
|
||||
|
||||
def assert_evaluates_argument_error(left, op, right)
|
||||
assert_raises(Liquid::ArgumentError) do
|
||||
Condition.new(left, op, right).evaluate(@context || Liquid::Context.new)
|
||||
end
|
||||
def assert_evalutes_false(left, op, right)
|
||||
assert !Condition.new(left, op, right).evaluate(@context || Liquid::Context.new),
|
||||
"Evaluated true: #{left} #{op} #{right}"
|
||||
end
|
||||
|
||||
def assert_evaluates_argument_error(left, op, right)
|
||||
assert_raises(Liquid::ArgumentError) do
|
||||
Condition.new(left, op, right).evaluate(@context || Liquid::Context.new)
|
||||
end
|
||||
end
|
||||
|
||||
end # ConditionTest
|
||||
|
||||
@@ -122,30 +122,25 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_length_query
|
||||
|
||||
@context['numbers'] = [1,2,3,4]
|
||||
@context['numbers'] = [1, 2, 3, 4]
|
||||
|
||||
assert_equal 4, @context['numbers.size']
|
||||
|
||||
@context['numbers'] = {1 => 1,2 => 2,3 => 3,4 => 4}
|
||||
@context['numbers'] = { 1 => 1, 2 => 2, 3 => 3, 4 => 4 }
|
||||
|
||||
assert_equal 4, @context['numbers.size']
|
||||
|
||||
@context['numbers'] = {1 => 1,2 => 2,3 => 3,4 => 4, 'size' => 1000}
|
||||
@context['numbers'] = { 1 => 1, 2 => 2, 3 => 3, 4 => 4, 'size' => 1000 }
|
||||
|
||||
assert_equal 1000, @context['numbers.size']
|
||||
|
||||
end
|
||||
|
||||
def test_hyphenated_variable
|
||||
|
||||
@context['oh-my'] = 'godz'
|
||||
assert_equal 'godz', @context['oh-my']
|
||||
|
||||
end
|
||||
|
||||
def test_add_filter
|
||||
|
||||
filter = Module.new do
|
||||
def hi(output)
|
||||
output + ' hi!'
|
||||
@@ -161,11 +156,9 @@ class ContextUnitTest < Minitest::Test
|
||||
|
||||
context.add_filters(filter)
|
||||
assert_equal 'hi? hi!', context.invoke(:hi, 'hi?')
|
||||
|
||||
end
|
||||
|
||||
def test_only_intended_filters_make_it_there
|
||||
|
||||
filter = Module.new do
|
||||
def hi(output)
|
||||
output + ' hi!'
|
||||
@@ -196,7 +189,7 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_hierachical_data
|
||||
@context['hash'] = {"name" => 'tobi'}
|
||||
@context['hash'] = { "name" => 'tobi' }
|
||||
assert_equal 'tobi', @context['hash.name']
|
||||
assert_equal 'tobi', @context['hash["name"]']
|
||||
end
|
||||
@@ -225,7 +218,7 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_array_notation
|
||||
@context['test'] = [1,2,3,4,5]
|
||||
@context['test'] = [1, 2, 3, 4, 5]
|
||||
|
||||
assert_equal 1, @context['test[0]']
|
||||
assert_equal 2, @context['test[1]']
|
||||
@@ -235,21 +228,21 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_recoursive_array_notation
|
||||
@context['test'] = {'test' => [1,2,3,4,5]}
|
||||
@context['test'] = { 'test' => [1, 2, 3, 4, 5] }
|
||||
|
||||
assert_equal 1, @context['test.test[0]']
|
||||
|
||||
@context['test'] = [{'test' => 'worked'}]
|
||||
@context['test'] = [{ 'test' => 'worked' }]
|
||||
|
||||
assert_equal 'worked', @context['test[0].test']
|
||||
end
|
||||
|
||||
def test_hash_to_array_transition
|
||||
@context['colors'] = {
|
||||
'Blue' => ['003366','336699', '6699CC', '99CCFF'],
|
||||
'Green' => ['003300','336633', '669966', '99CC99'],
|
||||
'Yellow' => ['CC9900','FFCC00', 'FFFF99', 'FFFFCC'],
|
||||
'Red' => ['660000','993333', 'CC6666', 'FF9999']
|
||||
'Blue' => ['003366', '336699', '6699CC', '99CCFF'],
|
||||
'Green' => ['003300', '336633', '669966', '99CC99'],
|
||||
'Yellow' => ['CC9900', 'FFCC00', 'FFFF99', 'FFFFCC'],
|
||||
'Red' => ['660000', '993333', 'CC6666', 'FF9999']
|
||||
}
|
||||
|
||||
assert_equal '003366', @context['colors.Blue[0]']
|
||||
@@ -257,12 +250,12 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_try_first
|
||||
@context['test'] = [1,2,3,4,5]
|
||||
@context['test'] = [1, 2, 3, 4, 5]
|
||||
|
||||
assert_equal 1, @context['test.first']
|
||||
assert_equal 5, @context['test.last']
|
||||
|
||||
@context['test'] = {'test' => [1,2,3,4,5]}
|
||||
@context['test'] = { 'test' => [1, 2, 3, 4, 5] }
|
||||
|
||||
assert_equal 1, @context['test.test.first']
|
||||
assert_equal 5, @context['test.test.last']
|
||||
@@ -273,8 +266,8 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_access_hashes_with_hash_notation
|
||||
@context['products'] = {'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
|
||||
@context['product'] = {'variants' => [ {'title' => 'draft151cm'}, {'title' => 'element151cm'} ]}
|
||||
@context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
|
||||
@context['product'] = { 'variants' => [ { 'title' => 'draft151cm' }, { 'title' => 'element151cm' } ] }
|
||||
|
||||
assert_equal 5, @context['products["count"]']
|
||||
assert_equal 'deepsnow', @context['products["tags"][0]']
|
||||
@@ -294,18 +287,17 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_access_hashes_with_hash_access_variables
|
||||
|
||||
@context['var'] = 'tags'
|
||||
@context['nested'] = {'var' => 'tags'}
|
||||
@context['products'] = {'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
|
||||
@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']
|
||||
end
|
||||
|
||||
def test_hash_notation_only_for_hash_access
|
||||
@context['array'] = [1,2,3,4,5]
|
||||
@context['hash'] = {'first' => 'Hello'}
|
||||
@context['array'] = [1, 2, 3, 4, 5]
|
||||
@context['hash'] = { 'first' => 'Hello' }
|
||||
|
||||
assert_equal 1, @context['array.first']
|
||||
assert_equal nil, @context['array["first"]']
|
||||
@@ -313,66 +305,64 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_first_can_appear_in_middle_of_callchain
|
||||
|
||||
@context['product'] = {'variants' => [ {'title' => 'draft151cm'}, {'title' => 'element151cm'} ]}
|
||||
@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']
|
||||
|
||||
end
|
||||
|
||||
def test_cents
|
||||
@context.merge( "cents" => HundredCentes.new )
|
||||
@context.merge("cents" => HundredCentes.new)
|
||||
assert_equal 100, @context['cents']
|
||||
end
|
||||
|
||||
def test_nested_cents
|
||||
@context.merge( "cents" => { 'amount' => HundredCentes.new} )
|
||||
@context.merge("cents" => { 'amount' => HundredCentes.new })
|
||||
assert_equal 100, @context['cents.amount']
|
||||
|
||||
@context.merge( "cents" => { 'cents' => { 'amount' => HundredCentes.new} } )
|
||||
@context.merge("cents" => { 'cents' => { 'amount' => HundredCentes.new } })
|
||||
assert_equal 100, @context['cents.cents.amount']
|
||||
end
|
||||
|
||||
def test_cents_through_drop
|
||||
@context.merge( "cents" => CentsDrop.new )
|
||||
@context.merge("cents" => CentsDrop.new)
|
||||
assert_equal 100, @context['cents.amount']
|
||||
end
|
||||
|
||||
def test_nested_cents_through_drop
|
||||
@context.merge( "vars" => {"cents" => CentsDrop.new} )
|
||||
@context.merge("vars" => { "cents" => CentsDrop.new })
|
||||
assert_equal 100, @context['vars.cents.amount']
|
||||
end
|
||||
|
||||
def test_drop_methods_with_question_marks
|
||||
@context.merge( "cents" => CentsDrop.new )
|
||||
@context.merge("cents" => CentsDrop.new)
|
||||
assert @context['cents.non_zero?']
|
||||
end
|
||||
|
||||
def test_context_from_within_drop
|
||||
@context.merge( "test" => '123', "vars" => ContextSensitiveDrop.new )
|
||||
@context.merge("test" => '123', "vars" => ContextSensitiveDrop.new)
|
||||
assert_equal '123', @context['vars.test']
|
||||
end
|
||||
|
||||
def test_nested_context_from_within_drop
|
||||
@context.merge( "test" => '123', "vars" => {"local" => ContextSensitiveDrop.new } )
|
||||
@context.merge("test" => '123', "vars" => { "local" => ContextSensitiveDrop.new })
|
||||
assert_equal '123', @context['vars.local.test']
|
||||
end
|
||||
|
||||
def test_ranges
|
||||
@context.merge( "test" => '5' )
|
||||
@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)']
|
||||
end
|
||||
|
||||
def test_cents_through_drop_nestedly
|
||||
@context.merge( "cents" => {"cents" => CentsDrop.new} )
|
||||
@context.merge("cents" => { "cents" => CentsDrop.new })
|
||||
assert_equal 100, @context['cents.cents.amount']
|
||||
|
||||
@context.merge( "cents" => { "cents" => {"cents" => CentsDrop.new}} )
|
||||
@context.merge("cents" => { "cents" => { "cents" => CentsDrop.new } })
|
||||
assert_equal 100, @context['cents.cents.cents.amount']
|
||||
end
|
||||
|
||||
@@ -393,7 +383,7 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_proc_as_variable
|
||||
@context['dynamic'] = Proc.new { 'Hello' }
|
||||
@context['dynamic'] = proc { 'Hello' }
|
||||
|
||||
assert_equal 'Hello', @context['dynamic']
|
||||
end
|
||||
@@ -411,7 +401,7 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_array_containing_lambda_as_variable
|
||||
@context['dynamic'] = [1,2, proc { 'Hello' } ,4,5]
|
||||
@context['dynamic'] = [1, 2, proc { 'Hello' }, 4, 5]
|
||||
|
||||
assert_equal 'Hello', @context['dynamic[2]']
|
||||
end
|
||||
@@ -437,7 +427,7 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_lambda_in_array_is_called_once
|
||||
@context['callcount'] = [1,2, proc { @global ||= 0; @global += 1; @global.to_s } ,4,5]
|
||||
@context['callcount'] = [1, 2, proc { @global ||= 0; @global += 1; @global.to_s }, 4, 5]
|
||||
|
||||
assert_equal '1', @context['callcount[2]']
|
||||
assert_equal '1', @context['callcount[2]']
|
||||
@@ -472,11 +462,10 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_context_initialization_with_a_proc_in_environment
|
||||
contx = Context.new([:test => lambda { |c| c['poutine']}], {:test => :foo})
|
||||
contx = Context.new([:test => ->(c) { c['poutine'] }], { :test => :foo })
|
||||
|
||||
assert contx
|
||||
assert_nil contx['poutine']
|
||||
end
|
||||
|
||||
|
||||
end # ContextTest
|
||||
|
||||
@@ -11,7 +11,7 @@ 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/_mypartial.liquid", file_system.full_path("mypartial")
|
||||
assert_equal "/some/path/dir/_mypartial.liquid", file_system.full_path("dir/mypartial")
|
||||
|
||||
assert_raises(FileSystemError) do
|
||||
@@ -29,7 +29,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/mypartial.html", file_system.full_path("mypartial")
|
||||
assert_equal "/some/path/dir/mypartial.html", file_system.full_path("dir/mypartial")
|
||||
end
|
||||
end # FileSystemTest
|
||||
|
||||
@@ -24,7 +24,7 @@ class I18nUnitTest < Minitest::Test
|
||||
# @i18n.translate("whatever", :oopstypos => "yes")
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
def test_raises_unknown_translation
|
||||
assert_raises I18n::TranslationError do
|
||||
@i18n.translate("doesnt_exist")
|
||||
|
||||
@@ -4,23 +4,23 @@ class LexerUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
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
|
||||
tokens = Lexer.new(%( 'this is a test""' "wat 'lol'")).tokenize
|
||||
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
|
||||
@@ -40,7 +40,7 @@ class LexerUnitTest < Minitest::Test
|
||||
|
||||
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
|
||||
|
||||
@@ -5,9 +5,11 @@ class TestClassA
|
||||
def allowedA
|
||||
'allowedA'
|
||||
end
|
||||
|
||||
def restrictedA
|
||||
'restrictedA'
|
||||
end
|
||||
|
||||
def chainedB
|
||||
TestClassB.new
|
||||
end
|
||||
@@ -18,6 +20,7 @@ class TestClassB
|
||||
def allowedB
|
||||
'allowedB'
|
||||
end
|
||||
|
||||
def chainedC
|
||||
TestClassC.new
|
||||
end
|
||||
@@ -77,11 +80,11 @@ class ModuleExUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_should_use_regular_objects_as_drops
|
||||
assert_template_result 'allowedA', "{{ a.allowedA }}", 'a'=>@a
|
||||
assert_template_result 'allowedB', "{{ a.chainedB.allowedB }}", 'a'=>@a
|
||||
assert_template_result 'allowedC', "{{ a.chainedB.chainedC.allowedC }}", 'a'=>@a
|
||||
assert_template_result 'another_allowedC', "{{ a.chainedB.chainedC.another_allowedC }}", 'a'=>@a
|
||||
assert_template_result '', "{{ a.restricted }}", 'a'=>@a
|
||||
assert_template_result '', "{{ a.unknown }}", 'a'=>@a
|
||||
assert_template_result 'allowedA', "{{ a.allowedA }}", 'a' => @a
|
||||
assert_template_result 'allowedB', "{{ a.chainedB.allowedB }}", 'a' => @a
|
||||
assert_template_result 'allowedC', "{{ a.chainedB.chainedC.allowedC }}", 'a' => @a
|
||||
assert_template_result 'another_allowedC', "{{ a.chainedB.chainedC.another_allowedC }}", 'a' => @a
|
||||
assert_template_result '', "{{ a.restricted }}", 'a' => @a
|
||||
assert_template_result '', "{{ a.unknown }}", 'a' => @a
|
||||
end
|
||||
end # ModuleExTest
|
||||
|
||||
@@ -18,7 +18,7 @@ class RegexpUnitTest < Minitest::Test
|
||||
def test_tags
|
||||
assert_equal ['<tr>', '</tr>'], '<tr> </tr>'.scan(QuotedFragment)
|
||||
assert_equal ['<tr></tr>'], '<tr></tr>'.scan(QuotedFragment)
|
||||
assert_equal ['<style', 'class="hello">', '</style>'], %|<style class="hello">' </style>|.scan(QuotedFragment)
|
||||
assert_equal ['<style', 'class="hello">', '</style>'], %(<style class="hello">' </style>).scan(QuotedFragment)
|
||||
end
|
||||
|
||||
def test_double_quoted_words
|
||||
|
||||
@@ -59,7 +59,7 @@ class StrainerUnitTest < Minitest::Test
|
||||
def test_strainer_uses_a_class_cache_to_avoid_method_cache_invalidation
|
||||
a = Module.new
|
||||
b = Module.new
|
||||
strainer = Strainer.create(nil, [a,b])
|
||||
strainer = Strainer.create(nil, [a, b])
|
||||
assert_kind_of Strainer, strainer
|
||||
assert_kind_of a, strainer
|
||||
assert_kind_of b, strainer
|
||||
|
||||
@@ -11,59 +11,59 @@ class VariableUnitTest < Minitest::Test
|
||||
def test_filters
|
||||
var = Variable.new('hello | textileze')
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
assert_equal [['textileze',[]]], var.filters
|
||||
assert_equal [['textileze', []]], var.filters
|
||||
|
||||
var = Variable.new('hello | textileze | paragraph')
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
assert_equal [['textileze',[]], ['paragraph',[]]], var.filters
|
||||
assert_equal [['textileze', []], ['paragraph', []]], var.filters
|
||||
|
||||
var = Variable.new(%! hello | strftime: '%Y'!)
|
||||
var = Variable.new(%( hello | strftime: '%Y'))
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
assert_equal [['strftime',['%Y']]], var.filters
|
||||
assert_equal [['strftime', ['%Y']]], var.filters
|
||||
|
||||
var = Variable.new(%! 'typo' | link_to: 'Typo', true !)
|
||||
var = Variable.new(%( 'typo' | link_to: 'Typo', true ))
|
||||
assert_equal 'typo', var.name
|
||||
assert_equal [['link_to',['Typo', true]]], var.filters
|
||||
assert_equal [['link_to', ['Typo', true]]], var.filters
|
||||
|
||||
var = Variable.new(%! 'typo' | link_to: 'Typo', false !)
|
||||
var = Variable.new(%( 'typo' | link_to: 'Typo', false ))
|
||||
assert_equal 'typo', var.name
|
||||
assert_equal [['link_to',['Typo', false]]], var.filters
|
||||
assert_equal [['link_to', ['Typo', false]]], var.filters
|
||||
|
||||
var = Variable.new(%! 'foo' | repeat: 3 !)
|
||||
var = Variable.new(%( 'foo' | repeat: 3 ))
|
||||
assert_equal 'foo', var.name
|
||||
assert_equal [['repeat',[3]]], var.filters
|
||||
assert_equal [['repeat', [3]]], var.filters
|
||||
|
||||
var = Variable.new(%! 'foo' | repeat: 3, 3 !)
|
||||
var = Variable.new(%( 'foo' | repeat: 3, 3 ))
|
||||
assert_equal 'foo', var.name
|
||||
assert_equal [['repeat',[3,3]]], var.filters
|
||||
assert_equal [['repeat', [3, 3]]], var.filters
|
||||
|
||||
var = Variable.new(%! 'foo' | repeat: 3, 3, 3 !)
|
||||
var = Variable.new(%( 'foo' | repeat: 3, 3, 3 ))
|
||||
assert_equal 'foo', var.name
|
||||
assert_equal [['repeat',[3,3,3]]], var.filters
|
||||
assert_equal [['repeat', [3, 3, 3]]], var.filters
|
||||
|
||||
var = Variable.new(%! hello | strftime: '%Y, okay?'!)
|
||||
var = Variable.new(%( hello | strftime: '%Y, okay?'))
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
assert_equal [['strftime',['%Y, okay?']]], var.filters
|
||||
assert_equal [['strftime', ['%Y, okay?']]], var.filters
|
||||
|
||||
var = Variable.new(%! hello | things: "%Y, okay?", 'the other one'!)
|
||||
var = Variable.new(%( 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 [['things', ['%Y, okay?', 'the other one']]], var.filters
|
||||
end
|
||||
|
||||
def test_filter_with_date_parameter
|
||||
var = Variable.new(%! '2006-06-06' | date: "%m/%d/%Y"!)
|
||||
var = Variable.new(%( '2006-06-06' | date: "%m/%d/%Y"))
|
||||
assert_equal '2006-06-06', var.name
|
||||
assert_equal [['date',['%m/%d/%Y']]], var.filters
|
||||
assert_equal [['date', ['%m/%d/%Y']]], var.filters
|
||||
end
|
||||
|
||||
def test_filters_without_whitespace
|
||||
var = Variable.new('hello | textileze | paragraph')
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
assert_equal [['textileze',[]], ['paragraph',[]]], var.filters
|
||||
assert_equal [['textileze', []], ['paragraph', []]], var.filters
|
||||
|
||||
var = Variable.new('hello|textileze|paragraph')
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
assert_equal [['textileze',[]], ['paragraph',[]]], var.filters
|
||||
assert_equal [['textileze', []], ['paragraph', []]], var.filters
|
||||
|
||||
var = Variable.new("hello|replace:'foo','bar'|textileze")
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
@@ -73,32 +73,32 @@ class VariableUnitTest < Minitest::Test
|
||||
def test_symbol
|
||||
var = Variable.new("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 [['image', ['med']]], var.filters
|
||||
end
|
||||
|
||||
def test_string_to_filter
|
||||
var = Variable.new("'http://disney.com/logo.gif' | image: 'med' ")
|
||||
assert_equal 'http://disney.com/logo.gif', var.name
|
||||
assert_equal [['image',['med']]], var.filters
|
||||
assert_equal [['image', ['med']]], var.filters
|
||||
end
|
||||
|
||||
def test_string_single_quoted
|
||||
var = Variable.new(%| "hello" |)
|
||||
var = Variable.new(%( "hello" ))
|
||||
assert_equal 'hello', var.name
|
||||
end
|
||||
|
||||
def test_string_double_quoted
|
||||
var = Variable.new(%| 'hello' |)
|
||||
var = Variable.new(%( 'hello' ))
|
||||
assert_equal 'hello', var.name
|
||||
end
|
||||
|
||||
def test_integer
|
||||
var = Variable.new(%| 1000 |)
|
||||
var = Variable.new(%( 1000 ))
|
||||
assert_equal 1000, var.name
|
||||
end
|
||||
|
||||
def test_float
|
||||
var = Variable.new(%| 1000.01 |)
|
||||
var = Variable.new(%( 1000.01 ))
|
||||
assert_equal 1000.01, var.name
|
||||
end
|
||||
|
||||
@@ -114,37 +114,37 @@ class VariableUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_string_with_special_chars
|
||||
var = Variable.new(%| 'hello! $!@.;"ddasd" ' |)
|
||||
var = Variable.new(%( 'hello! $!@.;"ddasd" ' ))
|
||||
assert_equal 'hello! $!@.;"ddasd" ', var.name
|
||||
end
|
||||
|
||||
def test_string_dot
|
||||
var = Variable.new(%| test.test |)
|
||||
var = Variable.new(%( test.test ))
|
||||
assert_equal VariableLookup.new('test.test'), var.name
|
||||
end
|
||||
|
||||
def test_filter_with_keyword_arguments
|
||||
var = Variable.new(%! hello | things: greeting: "world", farewell: 'goodbye'!)
|
||||
var = Variable.new(%( hello | things: greeting: "world", farewell: 'goodbye'))
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
assert_equal [['things', [], { 'greeting' => 'world', 'farewell' => 'goodbye' }]], var.filters
|
||||
end
|
||||
|
||||
def test_lax_filter_argument_parsing
|
||||
var = Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !, :error_mode => :lax)
|
||||
var = Variable.new(%( 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 [['pluralize', ['comment', 'comments']]], var.filters
|
||||
end
|
||||
|
||||
def test_strict_filter_argument_parsing
|
||||
with_error_mode(:strict) do
|
||||
assert_raises(SyntaxError) do
|
||||
Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
|
||||
Variable.new(%( number_of_comments | pluralize: 'comment': 'comments' ))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_output_raw_source_of_variable
|
||||
var = Variable.new(%! name_of_variable | upcase !)
|
||||
var = Variable.new(%( name_of_variable | upcase ))
|
||||
assert_equal " name_of_variable | upcase ", var.raw
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user