2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2012-12-19 15:54:47 -05:00
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
module Journey
|
|
|
|
module Definition
|
2012-12-31 12:36:30 -05:00
|
|
|
class TestParser < ActiveSupport::TestCase
|
2012-12-19 15:54:47 -05:00
|
|
|
def setup
|
|
|
|
@parser = Parser.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_slash
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal :SLASH, @parser.parse("/").type
|
|
|
|
assert_round_trip "/"
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip "/foo"
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segments
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip "/foo/bar"
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_symbol
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip "/foo/:id"
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_symbol
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip "/:foo"
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_group
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip "(/:foo)"
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_groups
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip "(/:foo)(/:bar)"
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_nested_groups
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip "(/:foo(/:bar))"
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dot_symbol
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip(".:format")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_dot_literal
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip(".xml")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_dot
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("/foo.:bar")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_group_dot
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("/foo(.:bar)")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_group
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("/foo(/:action)")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_groups
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("/foo(/:action)(/:bar)")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_segment_nested_groups
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("/foo(/:action(/:bar))")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_group_followed_by_path
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("/foo(/:action)/:bar")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_star
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("*foo")
|
|
|
|
assert_round_trip("/*foo")
|
|
|
|
assert_round_trip("/bar/*foo")
|
|
|
|
assert_round_trip("/bar/(*foo)")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_or
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("a|b")
|
|
|
|
assert_round_trip("a|b|c")
|
|
|
|
assert_round_trip("(a|b)|c")
|
|
|
|
assert_round_trip("a|(b|c)")
|
|
|
|
assert_round_trip("*a|(b|c)")
|
|
|
|
assert_round_trip("*a|:b|c")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_arbitrary
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_round_trip("/bar/*foo#")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_literal_dot_paren
|
|
|
|
assert_round_trip "/sprockets.js(.:format)"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_groups_with_dot
|
|
|
|
assert_round_trip "/(:locale)(.:format)"
|
|
|
|
end
|
|
|
|
|
2016-08-06 14:20:22 -04:00
|
|
|
def assert_round_trip(str)
|
2012-12-19 15:54:47 -05:00
|
|
|
assert_equal str, @parser.parse(str).to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|