Expose name, lookups, and command flags from VariableLookup

This commit is contained in:
Justin Li
2015-04-20 17:36:04 -04:00
parent 881f86d698
commit e5dd63e1fc
2 changed files with 14 additions and 0 deletions

View File

@@ -3,6 +3,8 @@ module Liquid
SQUARE_BRACKETED = /\A\[(.*)\]\z/m
COMMAND_METHODS = ['size'.freeze, 'first'.freeze, 'last'.freeze]
attr_reader :name, :lookups, :command_flags
def self.parse(markup)
new(markup)
end

View File

@@ -147,4 +147,16 @@ class VariableUnitTest < Minitest::Test
var = Variable.new(%! name_of_variable | upcase !)
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 0, lookup.command_flags
lookup = VariableLookup.new('a.first.size')
assert_equal 'a', lookup.name
assert_equal ['first', 'size'], lookup.lookups
assert_equal 0b11, lookup.command_flags
end
end