Fix bad range parsing.

This commit is contained in:
Tristan Hume
2013-09-04 18:13:31 -04:00
parent e8b41c8856
commit 7c5b3e0c3b
3 changed files with 11 additions and 2 deletions
+2
View File
@@ -15,6 +15,7 @@ module Liquid
SINGLE_STRING_LITERAL = /'[^\']*'/
DOUBLE_STRING_LITERAL = /"[^\"]*"/
NUMBER_LITERAL = /-?\d+(\.\d+)?/
DOTDOT = /\.\./
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains/
def initialize(input)
@@ -32,6 +33,7 @@ module Liquid
when t = @ss.scan(DOUBLE_STRING_LITERAL) then [:string, t]
when t = @ss.scan(NUMBER_LITERAL) then [:number, t]
when t = @ss.scan(IDENTIFIER) then [:id, t]
when t = @ss.scan(DOTDOT) then [:dotdot, t]
else
c = @ss.getch
if s = SPECIALS[c]
+1 -2
View File
@@ -53,8 +53,7 @@ module Liquid
elsif token.first == :open_round
consume
first = expression
consume(:dot)
consume(:dot)
consume(:dotdot)
last = expression
consume(:close_round)
"(#{first}..#{last})"
+8
View File
@@ -56,6 +56,14 @@ class ParserTest < Test::Unit::TestCase
assert_equal '"wut"', p.expression
end
def test_ranges
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
assert_equal '(hi[5].wat..old)', p.expression
end
def test_arguments
p = Parser.new("filter: hi.there[5], keyarg: 7")
assert_equal 'filter', p.consume(:id)