From 98ef21b4ccd788c9d429312318ac6506e9c00d0a Mon Sep 17 00:00:00 2001 From: Florian Hanke Date: Mon, 18 Jun 2012 16:43:14 +1000 Subject: [PATCH] =?UTF-8?q?"splat"=20param=20now=20contains=20all=20matche?= =?UTF-8?q?s=20in=20an=20array,=20f=C3=B6=C3=B6=20test=20now=20conforms=20?= =?UTF-8?q?to=20the=20original=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/compile_test.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/compile_test.rb b/test/compile_test.rb index 07045931..55085268 100644 --- a/test/compile_test.rb +++ b/test/compile_test.rb @@ -14,7 +14,19 @@ class CompileTest < Test::Unit::TestCase 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 @@ class CompileTest < Test::Unit::TestCase 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 @@ class CompileTest < Test::Unit::TestCase 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}