test/path/test_pattern.rb in journey-1.0.0.rc2 vs test/path/test_pattern.rb in journey-1.0.0.rc3

- old
+ new

@@ -3,53 +3,53 @@ module Journey module Path class TestPattern < MiniTest::Unit::TestCase x = /.+/ { - '/:controller(/:action)' => %r{\A/(#{x}?)(?:/([^/.?]+))?\Z}, - '/:controller/foo' => %r{\A/(#{x}?)/foo\Z}, - '/:controller/:action' => %r{\A/(#{x}?)/([^/.?]+)\Z}, - '/:controller' => %r{\A/(#{x}?)\Z}, - '/:controller(/:action(/:id))' => %r{\A/(#{x}?)(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z}, - '/:controller/:action.xml' => %r{\A/(#{x}?)/([^/.?]+)\.xml\Z}, - '/:controller.:format' => %r{\A/(#{x}?)\.([^/.?]+)\Z}, - '/:controller(.:format)' => %r{\A/(#{x}?)(?:\.([^/.?]+))?\Z}, - '/:controller/*foo' => %r{\A/(#{x}?)/(.+)\Z}, - '/:controller/*foo/bar' => %r{\A/(#{x}?)/(.+)/bar\Z}, + '/:controller(/:action)' => %r{\A/(#{x})(?:/([^/.?]+))?\Z}, + '/:controller/foo' => %r{\A/(#{x})/foo\Z}, + '/:controller/:action' => %r{\A/(#{x})/([^/.?]+)\Z}, + '/:controller' => %r{\A/(#{x})\Z}, + '/:controller(/:action(/:id))' => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z}, + '/:controller/:action.xml' => %r{\A/(#{x})/([^/.?]+)\.xml\Z}, + '/:controller.:format' => %r{\A/(#{x})\.([^/.?]+)\Z}, + '/:controller(.:format)' => %r{\A/(#{x})(?:\.([^/.?]+))?\Z}, + '/:controller/*foo' => %r{\A/(#{x})/(.+)\Z}, + '/:controller/*foo/bar' => %r{\A/(#{x})/(.+)/bar\Z}, }.each do |path, expected| define_method(:"test_to_regexp_#{path}") do strexp = Router::Strexp.new( path, { :controller => /.+/ }, ["/", ".", "?"] ) path = Pattern.new strexp - assert_equal(expected, path.send(:to_regexp)) + assert_equal(expected, path.to_regexp) end end { - '/:controller(/:action)' => %r{\A/(#{x}?)(?:/([^/.?]+))?}, - '/:controller/foo' => %r{\A/(#{x}?)/foo}, - '/:controller/:action' => %r{\A/(#{x}?)/([^/.?]+)}, - '/:controller' => %r{\A/(#{x}?)}, - '/:controller(/:action(/:id))' => %r{\A/(#{x}?)(?:/([^/.?]+)(?:/([^/.?]+))?)?}, - '/:controller/:action.xml' => %r{\A/(#{x}?)/([^/.?]+)\.xml}, - '/:controller.:format' => %r{\A/(#{x}?)\.([^/.?]+)}, - '/:controller(.:format)' => %r{\A/(#{x}?)(?:\.([^/.?]+))?}, - '/:controller/*foo' => %r{\A/(#{x}?)/(.+)}, - '/:controller/*foo/bar' => %r{\A/(#{x}?)/(.+)/bar}, + '/:controller(/:action)' => %r{\A/(#{x})(?:/([^/.?]+))?}, + '/:controller/foo' => %r{\A/(#{x})/foo}, + '/:controller/:action' => %r{\A/(#{x})/([^/.?]+)}, + '/:controller' => %r{\A/(#{x})}, + '/:controller(/:action(/:id))' => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?}, + '/:controller/:action.xml' => %r{\A/(#{x})/([^/.?]+)\.xml}, + '/:controller.:format' => %r{\A/(#{x})\.([^/.?]+)}, + '/:controller(.:format)' => %r{\A/(#{x})(?:\.([^/.?]+))?}, + '/:controller/*foo' => %r{\A/(#{x})/(.+)}, + '/:controller/*foo/bar' => %r{\A/(#{x})/(.+)/bar}, }.each do |path, expected| define_method(:"test_to_non_anchored_regexp_#{path}") do strexp = Router::Strexp.new( path, { :controller => /.+/ }, ["/", ".", "?"], false ) path = Pattern.new strexp - assert_equal(expected, path.send(:to_regexp)) + assert_equal(expected, path.to_regexp) end end { '/:controller(/:action)' => %w{ controller action }, @@ -99,10 +99,21 @@ path = Pattern.new pattern assert_equal list.sort, path.optional_names.sort end end + def test_to_regexp_match_non_optional + strexp = Router::Strexp.new( + '/:name', + { :name => /\d+/ }, + ["/", ".", "?"] + ) + path = Pattern.new strexp + assert_match('/123', path) + refute_match('/', path) + end + def test_to_regexp_with_group strexp = Router::Strexp.new( '/page/:name', { :name => /(tender|love)/ }, ["/", ".", "?"] @@ -155,10 +166,21 @@ assert_equal '10', match[2] assert_equal 3, match.length assert_equal %w{ tender 10 }, match.captures end + def test_star_with_custom_re + z = /\d+/ + strexp = Router::Strexp.new( + '/page/*foo', + { :foo => z }, + ["/", ".", "?"] + ) + path = Pattern.new strexp + assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp) + end + def test_insensitive_regexp_with_group strexp = Router::Strexp.new( '/page/:name/aaron', { :name => /(tender|love)/i }, ["/", ".", "?"] @@ -178,10 +200,10 @@ end def test_to_regexp_defaults path = Pattern.new '/:controller(/:action(/:id))' expected = %r{\A/([^/.?]+)(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z} - assert_equal expected, path.send(:to_regexp) + assert_equal expected, path.to_regexp end def test_failed_match path = Pattern.new '/:controller(/:action(/:id(.:format)))' uri = 'content'