Move tests for VariableLookup

This commit is contained in:
Peter Zhu
2020-11-11 14:24:33 -05:00
parent 933a1f1e7e
commit 2c27c2a6e1
3 changed files with 42 additions and 11 deletions

View File

@@ -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

View 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

View File

@@ -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)