mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-17 09:50:48 -07:00
- regexp engines are different from 1.8 to 1.9, fixed the literal shorthand regexp accordingly - changed the shorthand regexp text from a match to a string scan - test_helper now loads rubygems unless RUBY_VERSION is > 1.9
50 lines
1.8 KiB
Ruby
50 lines
1.8 KiB
Ruby
require 'test_helper'
|
|
|
|
class RegexpTest < Test::Unit::TestCase
|
|
include Liquid
|
|
|
|
def test_empty
|
|
assert_equal [], ''.scan(QuotedFragment)
|
|
end
|
|
|
|
def test_quote
|
|
assert_equal ['"arg 1"'], '"arg 1"'.scan(QuotedFragment)
|
|
end
|
|
|
|
def test_words
|
|
assert_equal ['arg1', 'arg2'], 'arg1 arg2'.scan(QuotedFragment)
|
|
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)
|
|
end
|
|
|
|
def test_quoted_words
|
|
assert_equal ['arg1', 'arg2', '"arg 3"'], 'arg1 arg2 "arg 3"'.scan(QuotedFragment)
|
|
end
|
|
|
|
def test_quoted_words
|
|
assert_equal ['arg1', 'arg2', "'arg 3'"], 'arg1 arg2 \'arg 3\''.scan(QuotedFragment)
|
|
end
|
|
|
|
def test_quoted_words_in_the_middle
|
|
assert_equal ['arg1', 'arg2', '"arg 3"', 'arg4'], 'arg1 arg2 "arg 3" arg4 '.scan(QuotedFragment)
|
|
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)
|
|
end
|
|
|
|
def test_literal_shorthand_regexp
|
|
assert_equal [["{% if 'gnomeslab' contains 'liquid' %}yes{% endif %}"]],
|
|
"{{{ {% if 'gnomeslab' contains 'liquid' %}yes{% endif %} }}}".scan(LiteralShorthand)
|
|
end
|
|
end # RegexpTest
|