Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

"splat" param now contains all matches in an array, föö test now conf…

…orms to the original one
  • Loading branch information...
commit 98ef21b4ccd788c9d429312318ac6506e9c00d0a 1 parent de21260
@floere authored
Showing with 16 additions and 4 deletions.
  1. +16 −4 test/compile_test.rb
View
20 test/compile_test.rb
@@ -14,7 +14,19 @@ def self.parses pattern, example, expected_params
compiled, keys = compiled pattern
match = compiled.match(example)
fail %Q{"#{example}" does not parse on pattern "#{pattern}".} unless match
- params = Hash[keys.zip(match.captures)]
+
+ # Aggregate e.g. multiple splat values into one array.
+ #
+ params = keys.zip(match.captures).reduce({}) do |hash, mapping|
+ key, value = mapping
+ hash[key] = if existing = hash[key]
+ existing.respond_to?(:each) ? existing << value : [existing, value]
+ else
+ value
+ end
+ hash
+ end
+
assert_equal(expected_params, params)
end
end
@@ -46,8 +58,8 @@ def compiled pattern
fails "/:foo", "/"
fails "/:foo", "/foo/"
- # converts "/f\u00F6\u00F6", %r{\A/f%C3%B6%C3%B6\z} # TODO Fails in Ruby 1.8
- parses "/f\u00F6\u00F6", "/f%C3%B6%C3%B6", {}
+ converts "/föö", %r{\A/f%C3%B6%C3%B6\z}
+ parses "/föö", "/f%C3%B6%C3%B6", {}
converts "/:foo/:bar", %r{\A/([^/?#]+)/([^/?#]+)\z}
parses "/:foo/:bar", "/foo/bar", "foo" => "foo", "bar" => "bar"
@@ -95,7 +107,7 @@ def compiled pattern
parses "/:foo/*", "/hello%20world/how%20are%20you", "foo" => "hello%20world", "splat" => "how%20are%20you"
converts "/*/foo/*/*", %r{\A/(.*?)/foo/(.*?)/(.*?)\z}
- parses "/*/foo/*/*", "/bar/foo/bling/baz/boom", "splat" => "baz/boom" # TODO
+ parses "/*/foo/*/*", "/bar/foo/bling/baz/boom", "splat" => ["bar", "bling", "baz/boom"]
fails "/*/foo/*/*", "/bar/foo/baz"
converts "/test.bar", %r{\A/test(?:\.|%2E)bar\z}
Please sign in to comment.
Something went wrong with that request. Please try again.