mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Move tests for VariableLookup
This commit is contained in:
@@ -110,11 +110,12 @@ module Liquid
|
||||
def to_s
|
||||
str = name.dup
|
||||
lookups.each do |lookup|
|
||||
if lookup.instance_of?(String)
|
||||
str += '.' + lookup
|
||||
else
|
||||
str += '[' + lookup.to_s + ']'
|
||||
end
|
||||
str +=
|
||||
if lookup.instance_of?(String)
|
||||
'.' + lookup
|
||||
else
|
||||
'[' + lookup.to_s + ']'
|
||||
end
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
36
test/unit/variable_lookup_unit_test.rb
Normal file
36
test/unit/variable_lookup_unit_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class VariableLookupUnitTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_variable_lookup_parsing
|
||||
lookup = parse_variable_lookup('a.b.c')
|
||||
assert_equal('a', lookup.name)
|
||||
assert_equal(['b', 'c'], lookup.lookups)
|
||||
|
||||
lookup = parse_variable_lookup('a[b]')
|
||||
assert_equal('a', lookup.name)
|
||||
assert_equal([parse_variable_lookup('b')], lookup.lookups)
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
lookup = parse_variable_lookup('a.b.c')
|
||||
assert_equal('a.b.c', lookup.to_s)
|
||||
|
||||
lookup = parse_variable_lookup('a[b.c].d')
|
||||
assert_equal('a[b.c].d', lookup.to_s)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_variable_lookup(markup)
|
||||
if Liquid::Template.error_mode == :strict
|
||||
p = Liquid::Parser.new(markup)
|
||||
VariableLookup.strict_parse(p)
|
||||
else
|
||||
VariableLookup.lax_parse(markup)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -152,12 +152,6 @@ class VariableUnitTest < Minitest::Test
|
||||
assert_equal(" name_of_variable | upcase ", var.raw)
|
||||
end
|
||||
|
||||
def test_variable_lookup_interface
|
||||
lookup = parse_variable_lookup('a.b.c')
|
||||
assert_equal('a', lookup.name)
|
||||
assert_equal(['b', 'c'], lookup.lookups)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_variable_lookup(markup)
|
||||
|
||||
Reference in New Issue
Block a user