Skip to content

Commit

Permalink
"splat" param now contains all matches in an array, föö test now conf…
Browse files Browse the repository at this point in the history
…orms to the original one
  • Loading branch information
floere committed Jun 18, 2012
1 parent de21260 commit 98ef21b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions test/compile_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 98ef21b

Please sign in to comment.