mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 17:30:43 -07:00
Upgrade rubocop
This commit is contained in:
@@ -1,29 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class BlockUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_blankspace
|
||||
template = Liquid::Template.parse(" ")
|
||||
assert_equal [" "], template.root.nodelist
|
||||
template = Liquid::Template.parse(' ')
|
||||
assert_equal [' '], template.root.nodelist
|
||||
end
|
||||
|
||||
def test_variable_beginning
|
||||
template = Liquid::Template.parse("{{funk}} ")
|
||||
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
|
||||
end
|
||||
|
||||
def test_variable_end
|
||||
template = Liquid::Template.parse(" {{funk}}")
|
||||
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
|
||||
end
|
||||
|
||||
def test_variable_middle
|
||||
template = Liquid::Template.parse(" {{funk}} ")
|
||||
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
|
||||
@@ -31,21 +33,21 @@ class BlockUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_variable_many_embedded_fragments
|
||||
template = Liquid::Template.parse(" {{funk}} {{so}} {{brother}} ")
|
||||
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
|
||||
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
|
||||
template = Liquid::Template.parse(' {% comment %} {% endcomment %} ')
|
||||
assert_equal [String, Comment, String], block_types(template.root.nodelist)
|
||||
assert_equal 3, template.root.nodelist.size
|
||||
end
|
||||
|
||||
def test_with_custom_tag
|
||||
with_custom_tag('testtag', Block) do
|
||||
assert Liquid::Template.parse("{% testtag %} {% endtesttag %}")
|
||||
assert Liquid::Template.parse('{% testtag %} {% endtesttag %}')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -57,11 +59,11 @@ class BlockUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
with_custom_tag('blabla', klass1) do
|
||||
template = Liquid::Template.parse("{% blabla %} bla {% endblabla %}")
|
||||
template = Liquid::Template.parse('{% blabla %} bla {% endblabla %}')
|
||||
|
||||
assert_equal 'hello', template.render
|
||||
|
||||
buf = ''
|
||||
buf = ''.dup
|
||||
output = template.render({}, output: buf)
|
||||
assert_equal 'hello', output
|
||||
assert_equal 'hello', buf
|
||||
@@ -75,11 +77,11 @@ class BlockUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
with_custom_tag('blabla', klass2) do
|
||||
template = Liquid::Template.parse("{% blabla %} foo {% endblabla %}")
|
||||
template = Liquid::Template.parse('{% blabla %} foo {% endblabla %}')
|
||||
|
||||
assert_equal 'foohellobar', template.render
|
||||
|
||||
buf = ''
|
||||
buf = ''.dup
|
||||
output = template.render({}, output: buf)
|
||||
assert_equal 'foohellobar', output
|
||||
assert_equal 'foohellobar', buf
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class ConditionUnitTest < Minitest::Test
|
||||
@@ -24,9 +26,9 @@ class ConditionUnitTest < Minitest::Test
|
||||
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
|
||||
@@ -68,14 +70,14 @@ class ConditionUnitTest < Minitest::Test
|
||||
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' => 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['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
|
||||
@@ -84,7 +86,7 @@ class ConditionUnitTest < Minitest::Test
|
||||
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', '1'
|
||||
end
|
||||
|
||||
def test_contains_returns_false_for_nil_operands
|
||||
@@ -107,11 +109,11 @@ class ConditionUnitTest < Minitest::Test
|
||||
|
||||
assert_equal false, condition.evaluate
|
||||
|
||||
condition.or Condition.new(2, '==', 1)
|
||||
condition.or(Condition.new(2, '==', 1))
|
||||
|
||||
assert_equal false, condition.evaluate
|
||||
|
||||
condition.or Condition.new(1, '==', 1)
|
||||
condition.or(Condition.new(1, '==', 1))
|
||||
|
||||
assert_equal true, condition.evaluate
|
||||
end
|
||||
@@ -121,41 +123,41 @@ class ConditionUnitTest < Minitest::Test
|
||||
|
||||
assert_equal true, condition.evaluate
|
||||
|
||||
condition.and Condition.new(2, '==', 2)
|
||||
condition.and(Condition.new(2, '==', 2))
|
||||
|
||||
assert_equal true, condition.evaluate
|
||||
|
||||
condition.and Condition.new(2, '==', 1)
|
||||
condition.and(Condition.new(2, '==', 1))
|
||||
|
||||
assert_equal false, condition.evaluate
|
||||
end
|
||||
|
||||
def test_should_allow_custom_proc_operator
|
||||
Condition.operators['starts_with'] = proc { |cond, left, right| left =~ %r{^#{right}} }
|
||||
Condition.operators['starts_with'] = proc { |_cond, left, right| left =~ /^#{right}/ }
|
||||
|
||||
assert_evaluates_true 'bob', 'starts_with', 'b'
|
||||
assert_evaluates_false 'bob', 'starts_with', 'o'
|
||||
ensure
|
||||
Condition.operators.delete 'starts_with'
|
||||
Condition.operators.delete('starts_with')
|
||||
end
|
||||
|
||||
def test_left_or_right_may_contain_operators
|
||||
@context = Liquid::Context.new
|
||||
@context['one'] = @context['another'] = "gnomeslab-and-or-liquid"
|
||||
@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}"
|
||||
"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}"
|
||||
"Evaluated true: #{left} #{op} #{right}"
|
||||
end
|
||||
|
||||
def assert_evaluates_argument_error(left, op, right)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class HundredCentes
|
||||
@@ -49,8 +51,7 @@ class CounterDrop < Liquid::Drop
|
||||
end
|
||||
|
||||
class ArrayLike
|
||||
def fetch(index)
|
||||
end
|
||||
def fetch(index); end
|
||||
|
||||
def [](index)
|
||||
@counts ||= []
|
||||
@@ -83,7 +84,7 @@ class ContextUnitTest < Minitest::Test
|
||||
@context['date'] = Date.today
|
||||
assert_equal Date.today, @context['date']
|
||||
|
||||
now = DateTime.now
|
||||
now = Time.now
|
||||
@context['datetime'] = now
|
||||
assert_equal now, @context['datetime']
|
||||
|
||||
@@ -162,10 +163,10 @@ 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
|
||||
@@ -185,7 +186,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
|
||||
@@ -201,14 +202,14 @@ class ContextUnitTest < Minitest::Test
|
||||
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" })
|
||||
@context.merge('test' => 'test')
|
||||
assert_equal 'test', @context['test']
|
||||
@context.merge({ "test" => "newvalue", "foo" => "bar" })
|
||||
@context.merge('test' => 'newvalue', 'foo' => 'bar')
|
||||
assert_equal 'newvalue', @context['test']
|
||||
assert_equal 'bar', @context['foo']
|
||||
end
|
||||
@@ -235,10 +236,10 @@ class ContextUnitTest < Minitest::Test
|
||||
|
||||
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' => %w[003366 336699 6699CC 99CCFF],
|
||||
'Green' => %w[003300 336633 669966 99CC99],
|
||||
'Yellow' => %w[CC9900 FFCC00 FFFF99 FFFFCC],
|
||||
'Red' => %w[660000 993333 CC6666 FF9999],
|
||||
}
|
||||
|
||||
assert_equal '003366', @context['colors.Blue[0]']
|
||||
@@ -262,8 +263,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' => %w[deepsnow freestyle] }
|
||||
@context['product'] = { 'variants' => [{ 'title' => 'draft151cm' }, { 'title' => 'element151cm' }] }
|
||||
|
||||
assert_equal 5, @context['products["count"]']
|
||||
assert_equal 'deepsnow', @context['products["tags"][0]']
|
||||
@@ -285,7 +286,7 @@ class ContextUnitTest < Minitest::Test
|
||||
def test_access_hashes_with_hash_access_variables
|
||||
@context['var'] = 'tags'
|
||||
@context['nested'] = { 'var' => 'tags' }
|
||||
@context['products'] = { 'count' => 5, 'tags' => ['deepsnow', 'freestyle'] }
|
||||
@context['products'] = { 'count' => 5, 'tags' => %w[deepsnow freestyle] }
|
||||
|
||||
assert_equal 'deepsnow', @context['products[var].first']
|
||||
assert_equal 'freestyle', @context['products[nested.var].last']
|
||||
@@ -301,7 +302,7 @@ 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']
|
||||
@@ -310,55 +311,55 @@ class ContextUnitTest < Minitest::Test
|
||||
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
|
||||
|
||||
@@ -391,7 +392,7 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_nested_lambda_as_variable
|
||||
@context['dynamic'] = { "lambda" => proc { 'Hello' } }
|
||||
@context['dynamic'] = { 'lambda' => proc { 'Hello' } }
|
||||
|
||||
assert_equal 'Hello', @context['dynamic.lambda']
|
||||
end
|
||||
@@ -403,7 +404,11 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_lambda_is_called_once
|
||||
@context['callcount'] = proc { @global ||= 0; @global += 1; @global.to_s }
|
||||
@context['callcount'] = proc {
|
||||
@global ||= 0
|
||||
@global += 1
|
||||
@global.to_s
|
||||
}
|
||||
|
||||
assert_equal '1', @context['callcount']
|
||||
assert_equal '1', @context['callcount']
|
||||
@@ -413,7 +418,11 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_nested_lambda_is_called_once
|
||||
@context['callcount'] = { "lambda" => proc { @global ||= 0; @global += 1; @global.to_s } }
|
||||
@context['callcount'] = { 'lambda' => proc {
|
||||
@global ||= 0
|
||||
@global += 1
|
||||
@global.to_s
|
||||
} }
|
||||
|
||||
assert_equal '1', @context['callcount.lambda']
|
||||
assert_equal '1', @context['callcount.lambda']
|
||||
@@ -423,7 +432,11 @@ 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]']
|
||||
@@ -433,15 +446,15 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_access_to_context_from_proc
|
||||
@context.registers[:magic] = 345392
|
||||
@context.registers[:magic] = 345_392
|
||||
|
||||
@context['magic'] = proc { @context.registers[:magic] }
|
||||
|
||||
assert_equal 345392, @context['magic']
|
||||
assert_equal 345_392, @context['magic']
|
||||
end
|
||||
|
||||
def test_to_liquid_and_context_at_first_level
|
||||
@context['category'] = Category.new("foobar")
|
||||
@context['category'] = Category.new('foobar')
|
||||
assert_kind_of CategoryDrop, @context['category']
|
||||
assert_equal @context, @context['category'].context
|
||||
end
|
||||
@@ -453,7 +466,7 @@ class ContextUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_context_initialization_with_a_proc_in_environment
|
||||
contx = Context.new([test: ->(c) { c['poutine'] }], { test: :foo })
|
||||
contx = Context.new([test: ->(c) { c['poutine'] }], test: :foo)
|
||||
|
||||
assert contx
|
||||
assert_nil contx['poutine']
|
||||
@@ -476,9 +489,7 @@ class ContextUnitTest < Minitest::Test
|
||||
private
|
||||
|
||||
def assert_no_object_allocations
|
||||
unless RUBY_ENGINE == 'ruby'
|
||||
skip "stackprof needed to count object allocations"
|
||||
end
|
||||
skip 'stackprof needed to count object allocations' unless RUBY_ENGINE == 'ruby'
|
||||
require 'stackprof'
|
||||
|
||||
profile = StackProf.run(mode: :object) do
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class FileSystemUnitTest < Minitest::Test
|
||||
@@ -5,31 +7,31 @@ class FileSystemUnitTest < Minitest::Test
|
||||
|
||||
def test_default
|
||||
assert_raises(FileSystemError) do
|
||||
BlankFileSystem.new.read_template_file("dummy")
|
||||
BlankFileSystem.new.read_template_file('dummy')
|
||||
end
|
||||
end
|
||||
|
||||
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")
|
||||
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_raises(FileSystemError) do
|
||||
file_system.full_path("../dir/mypartial")
|
||||
file_system.full_path('../dir/mypartial')
|
||||
end
|
||||
|
||||
assert_raises(FileSystemError) do
|
||||
file_system.full_path("/dir/../../dir/mypartial")
|
||||
file_system.full_path('/dir/../../dir/mypartial')
|
||||
end
|
||||
|
||||
assert_raises(FileSystemError) do
|
||||
file_system.full_path("/etc/passwd")
|
||||
file_system.full_path('/etc/passwd')
|
||||
end
|
||||
end
|
||||
|
||||
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")
|
||||
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')
|
||||
end
|
||||
end # FileSystemTest
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class I18nUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def setup
|
||||
@i18n = I18n.new(fixture("en_locale.yml"))
|
||||
@i18n = I18n.new(fixture('en_locale.yml'))
|
||||
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
|
||||
@@ -27,7 +29,7 @@ class I18nUnitTest < Minitest::Test
|
||||
|
||||
def test_raises_unknown_translation
|
||||
assert_raises I18n::TranslationError do
|
||||
@i18n.translate("doesnt_exist")
|
||||
@i18n.translate('doesnt_exist')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class LexerUnitTest < Minitest::Test
|
||||
@@ -45,7 +47,7 @@ class LexerUnitTest < Minitest::Test
|
||||
|
||||
def test_unexpected_character
|
||||
assert_raises(SyntaxError) do
|
||||
Lexer.new("%").tokenize
|
||||
Lexer.new('%').tokenize
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class ParserUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_consume
|
||||
p = Parser.new("wat: 7")
|
||||
p = Parser.new('wat: 7')
|
||||
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 = Parser.new('wat: 7')
|
||||
p.jump(2)
|
||||
assert_equal '7', p.consume(:number)
|
||||
end
|
||||
|
||||
def test_consume?
|
||||
p = Parser.new("wat: 7")
|
||||
p = Parser.new('wat: 7')
|
||||
assert_equal 'wat', p.consume?(:id)
|
||||
assert_equal false, p.consume?(:dot)
|
||||
assert_equal ':', p.consume(:colon)
|
||||
@@ -25,7 +27,7 @@ class ParserUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_id?
|
||||
p = Parser.new("wat 6 Peter Hegemon")
|
||||
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)
|
||||
@@ -34,7 +36,7 @@ class ParserUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_look
|
||||
p = Parser.new("wat 6 Peter Hegemon")
|
||||
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)
|
||||
@@ -44,7 +46,7 @@ class ParserUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_expressions
|
||||
p = Parser.new("hi.there hi?[5].there? hi.there.bob")
|
||||
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
|
||||
@@ -57,7 +59,7 @@ class ParserUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_ranges
|
||||
p = Parser.new("(5..7) (1.5..9.6) (young..old) (hi[5].wat..old)")
|
||||
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
|
||||
@@ -65,7 +67,7 @@ class ParserUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
def test_arguments
|
||||
p = Parser.new("filter: hi.there[5], keyarg: 7")
|
||||
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
|
||||
@@ -75,7 +77,7 @@ class ParserUnitTest < Minitest::Test
|
||||
|
||||
def test_invalid_expression
|
||||
assert_raises(SyntaxError) do
|
||||
p = Parser.new("==")
|
||||
p = Parser.new('==')
|
||||
p.expression
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,44 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class RegexpUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_empty
|
||||
assert_equal [], ''.scan(QuotedFragment)
|
||||
assert_equal [], ''.scan(QUOTED_FRAGMENT)
|
||||
end
|
||||
|
||||
def test_quote
|
||||
assert_equal ['"arg 1"'], '"arg 1"'.scan(QuotedFragment)
|
||||
assert_equal ['"arg 1"'], '"arg 1"'.scan(QUOTED_FRAGMENT)
|
||||
end
|
||||
|
||||
def test_words
|
||||
assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment)
|
||||
assert_equal %w[arg1 arg2], 'arg1 arg2'.scan(QUOTED_FRAGMENT)
|
||||
end
|
||||
|
||||
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 ['<tr>', '</tr>'], '<tr> </tr>'.scan(QUOTED_FRAGMENT)
|
||||
assert_equal ['<tr></tr>'], '<tr></tr>'.scan(QUOTED_FRAGMENT)
|
||||
assert_equal ['<style', 'class="hello">', '</style>'], %(<style class="hello">' </style>).scan(QUOTED_FRAGMENT)
|
||||
end
|
||||
|
||||
def test_double_quoted_words
|
||||
assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment)
|
||||
assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QUOTED_FRAGMENT)
|
||||
end
|
||||
|
||||
def test_single_quoted_words
|
||||
assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment)
|
||||
assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QUOTED_FRAGMENT)
|
||||
end
|
||||
|
||||
def test_quoted_words_in_the_middle
|
||||
assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QuotedFragment)
|
||||
assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QUOTED_FRAGMENT)
|
||||
end
|
||||
|
||||
def test_variable_parser
|
||||
assert_equal ['var'], 'var'.scan(VariableParser)
|
||||
assert_equal ['var', 'method'], 'var.method'.scan(VariableParser)
|
||||
assert_equal ['var', '[method]'], 'var[method]'.scan(VariableParser)
|
||||
assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VariableParser)
|
||||
assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser)
|
||||
assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser)
|
||||
assert_equal ['var'], 'var'.scan(VARIABLE_PARSER)
|
||||
assert_equal %w[var method], 'var.method'.scan(VARIABLE_PARSER)
|
||||
assert_equal ['var', '[method]'], 'var[method]'.scan(VARIABLE_PARSER)
|
||||
assert_equal ['var', '[method]', '[0]'], 'var[method][0]'.scan(VARIABLE_PARSER)
|
||||
assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VARIABLE_PARSER)
|
||||
assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VARIABLE_PARSER)
|
||||
end
|
||||
end # RegexpTest
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class StrainerUnitTest < Minitest::Test
|
||||
@@ -5,11 +7,11 @@ class StrainerUnitTest < Minitest::Test
|
||||
|
||||
module AccessScopeFilters
|
||||
def public_filter
|
||||
"public"
|
||||
'public'
|
||||
end
|
||||
|
||||
def private_filter
|
||||
"private"
|
||||
'private'
|
||||
end
|
||||
private :private_filter
|
||||
end
|
||||
@@ -19,24 +21,25 @@ 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 'public', strainer.invoke('public_filter')
|
||||
end
|
||||
|
||||
def test_stainer_raises_argument_error
|
||||
strainer = Strainer.create(nil)
|
||||
assert_raises(Liquid::ArgumentError) do
|
||||
strainer.invoke("public_filter", 1)
|
||||
strainer.invoke('public_filter', 1)
|
||||
end
|
||||
end
|
||||
|
||||
def test_stainer_argument_error_contains_backtrace
|
||||
strainer = Strainer.create(nil)
|
||||
begin
|
||||
strainer.invoke("public_filter", 1)
|
||||
strainer.invoke('public_filter', 1)
|
||||
rescue Liquid::ArgumentError => e
|
||||
assert_match(
|
||||
/\ALiquid error: wrong number of arguments \((1 for 0|given 1, expected 0)\)\z/,
|
||||
e.message)
|
||||
e.message
|
||||
)
|
||||
assert_equal e.backtrace[0].split(':')[0], __FILE__
|
||||
end
|
||||
end
|
||||
@@ -52,20 +55,20 @@ class StrainerUnitTest < Minitest::Test
|
||||
|
||||
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
|
||||
@@ -92,7 +95,7 @@ class StrainerUnitTest < Minitest::Test
|
||||
private
|
||||
|
||||
def public_filter
|
||||
"overriden as private"
|
||||
'overriden as private'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -109,7 +112,7 @@ class StrainerUnitTest < Minitest::Test
|
||||
protected
|
||||
|
||||
def public_filter
|
||||
"overriden as protected"
|
||||
'overriden as protected'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -124,7 +127,7 @@ class StrainerUnitTest < Minitest::Test
|
||||
|
||||
module PublicMethodOverrideFilter
|
||||
def public_filter
|
||||
"public"
|
||||
'public'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -135,8 +138,8 @@ class StrainerUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
module LateAddedFilter
|
||||
def late_added_filter(input)
|
||||
"filtered"
|
||||
def late_added_filter(_input)
|
||||
'filtered'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -150,7 +153,7 @@ class StrainerUnitTest < Minitest::Test
|
||||
mod = Module.new do
|
||||
class << self
|
||||
attr_accessor :include_count
|
||||
def included(mod)
|
||||
def included(_mod)
|
||||
self.include_count += 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class TagUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_tag
|
||||
tag = Tag.parse('tag', "", Tokenizer.new(""), ParseContext.new)
|
||||
tag = Tag.parse('tag', '', Tokenizer.new(''), ParseContext.new)
|
||||
assert_equal 'liquid::tag', tag.name
|
||||
assert_equal '', tag.render(Context.new)
|
||||
end
|
||||
|
||||
def test_return_raw_text_of_tag
|
||||
tag = Tag.parse("long_tag", "param1, param2, param3", Tokenizer.new(""), ParseContext.new)
|
||||
assert_equal("long_tag param1, param2, param3", tag.raw)
|
||||
tag = Tag.parse('long_tag', 'param1, param2, param3', Tokenizer.new(''), ParseContext.new)
|
||||
assert_equal('long_tag param1, param2, param3', tag.raw)
|
||||
end
|
||||
|
||||
def test_tag_name_should_return_name_of_the_tag
|
||||
tag = Tag.parse("some_tag", "", Tokenizer.new(""), ParseContext.new)
|
||||
tag = Tag.parse('some_tag', '', Tokenizer.new(''), ParseContext.new)
|
||||
assert_equal 'some_tag', tag.tag_name
|
||||
end
|
||||
|
||||
@@ -27,11 +29,11 @@ class TagUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
with_custom_tag('blabla', klass1) do
|
||||
template = Liquid::Template.parse("{% blabla %}")
|
||||
template = Liquid::Template.parse('{% blabla %}')
|
||||
|
||||
assert_equal 'hello', template.render
|
||||
|
||||
buf = ''
|
||||
buf = ''.dup
|
||||
output = template.render({}, output: buf)
|
||||
assert_equal 'hello', output
|
||||
assert_equal 'hello', buf
|
||||
@@ -45,11 +47,11 @@ class TagUnitTest < Minitest::Test
|
||||
end
|
||||
|
||||
with_custom_tag('blabla', klass2) do
|
||||
template = Liquid::Template.parse("{% blabla %}")
|
||||
template = Liquid::Template.parse('{% blabla %}')
|
||||
|
||||
assert_equal 'foohellobar', template.render
|
||||
|
||||
buf = ''
|
||||
buf = ''.dup
|
||||
output = template.render({}, output: buf)
|
||||
assert_equal 'foohellobar', output
|
||||
assert_equal 'foohellobar', buf
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class CaseTagUnitTest < Minitest::Test
|
||||
@@ -5,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 %w[WHEN ELSE], template.root.nodelist[0].nodelist.map(&:nodelist).flatten
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class ForTagUnitTest < Minitest::Test
|
||||
@@ -8,6 +10,6 @@ class ForTagUnitTest < Minitest::Test
|
||||
|
||||
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 %w[FOR ELSE], template.root.nodelist[0].nodelist.map(&:nodelist).flatten
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class IfTagUnitTest < Minitest::Test
|
||||
def test_if_nodelist
|
||||
template = Liquid::Template.parse('{% if true %}IF{% else %}ELSE{% endif %}')
|
||||
assert_equal ['IF', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten
|
||||
assert_equal(%w[IF ELSE], template.root.nodelist[0].nodelist.map(&:nodelist).flatten)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class TemplateUnitTest < Minitest::Test
|
||||
@@ -11,11 +13,11 @@ class TemplateUnitTest < Minitest::Test
|
||||
|
||||
def test_sets_default_localization_in_context_with_quick_initialization
|
||||
t = Template.new
|
||||
t.parse('{%comment%}{%endcomment%}', locale: I18n.new(fixture("en_locale.yml")))
|
||||
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_equal fixture('en_locale.yml'), locale.path
|
||||
end
|
||||
|
||||
def test_with_cache_classes_tags_returns_the_same_class
|
||||
@@ -71,7 +73,7 @@ class TemplateUnitTest < Minitest::Test
|
||||
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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class TokenizerTest < Minitest::Test
|
||||
@@ -18,12 +20,12 @@ class TokenizerTest < Minitest::Test
|
||||
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 %} ')
|
||||
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], 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
|
||||
@@ -33,7 +35,7 @@ class TokenizerTest < Minitest::Test
|
||||
def tokenize(source)
|
||||
tokenizer = Liquid::Tokenizer.new(source)
|
||||
tokens = []
|
||||
while t = tokenizer.shift
|
||||
while (t = tokenizer.shift)
|
||||
tokens << t
|
||||
end
|
||||
tokens
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class VariableUnitTest < Minitest::Test
|
||||
@@ -67,7 +69,7 @@ class VariableUnitTest < Minitest::Test
|
||||
|
||||
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 [['replace', %w[foo bar]], ['textileze', []]], var.filters
|
||||
end
|
||||
|
||||
def test_symbol
|
||||
@@ -132,7 +134,7 @@ class VariableUnitTest < Minitest::Test
|
||||
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 [['pluralize', %w[comment comments]]], var.filters
|
||||
end
|
||||
|
||||
def test_strict_filter_argument_parsing
|
||||
@@ -145,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 %w[b c], lookup.lookups
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user