Skip to content
This repository
Browse code

Added test for case described in 688

  • Loading branch information...
commit 3be9e098a6e7c9c2c862e35bc270b5a77f7deee2 1 parent 62639db
Florian R. Hanke floere authored

Showing 1 changed file with 35 additions and 29 deletions. Show diff stats Hide diff stats

  1. +35 29 test/compile_test.rb
64 test/compile_test.rb
@@ -6,7 +6,7 @@ class CompileTest < Test::Unit::TestCase
6 6 def self.converts pattern, expected_regexp
7 7 it "generates #{expected_regexp.source} from #{pattern}" do
8 8 compiled, _ = compiled pattern
9   - assert_equal expected_regexp, compiled
  9 + assert_equal expected_regexp, compiled, "Pattern #{pattern} is not compiled into #{expected_regexp.source}. Was #{compiled.source}."
10 10 end
11 11 end
12 12 def self.parses pattern, example, expected_params
@@ -27,7 +27,7 @@ def self.parses pattern, example, expected_params
27 27 hash
28 28 end
29 29
30   - assert_equal(expected_params, params)
  30 + assert_equal expected_params, params, "Pattern #{pattern} does not match path #{example}."
31 31 end
32 32 end
33 33 def self.fails pattern, example
@@ -45,10 +45,10 @@ def compiled pattern
45 45
46 46 converts "/", %r{\A/\z}
47 47 parses "/", "/", {}
48   -
  48 +
49 49 converts "/foo", %r{\A/foo\z}
50 50 parses "/foo", "/foo", {}
51   -
  51 +
52 52 converts "/:foo", %r{\A/([^/?#]+)\z}
53 53 parses "/:foo", "/foo", "foo" => "foo"
54 54 parses "/:foo", "/foo.bar", "foo" => "foo.bar"
@@ -58,103 +58,103 @@ def compiled pattern
58 58 fails "/:foo", "/foo/bar"
59 59 fails "/:foo", "/"
60 60 fails "/:foo", "/foo/"
61   -
  61 +
62 62 converts "/föö", %r{\A/f%[Cc]3%[Bb]6%[Cc]3%[Bb]6\z}
63 63 parses "/föö", "/f%C3%B6%C3%B6", {}
64   -
  64 +
65 65 converts "/:foo/:bar", %r{\A/([^/?#]+)/([^/?#]+)\z}
66 66 parses "/:foo/:bar", "/foo/bar", "foo" => "foo", "bar" => "bar"
67   -
  67 +
68 68 converts "/hello/:person", %r{\A/hello/([^/?#]+)\z}
69 69 parses "/hello/:person", "/hello/Frank", "person" => "Frank"
70   -
  70 +
71 71 converts "/?:foo?/?:bar?", %r{\A/?([^/?#]+)?/?([^/?#]+)?\z}
72 72 parses "/?:foo?/?:bar?", "/hello/world", "foo" => "hello", "bar" => "world"
73 73 parses "/?:foo?/?:bar?", "/hello", "foo" => "hello", "bar" => nil
74 74 parses "/?:foo?/?:bar?", "/", "foo" => nil, "bar" => nil
75 75 parses "/?:foo?/?:bar?", "", "foo" => nil, "bar" => nil
76   -
  76 +
77 77 converts "/*", %r{\A/(.*?)\z}
78 78 parses "/*", "/", "splat" => ""
79 79 parses "/*", "/foo", "splat" => "foo"
80 80 parses "/*", "/foo/bar", "splat" => "foo/bar"
81   -
  81 +
82 82 converts "/:foo/*", %r{\A/([^/?#]+)/(.*?)\z}
83 83 parses "/:foo/*", "/foo/bar/baz", "foo" => "foo", "splat" => "bar/baz"
84   -
  84 +
85 85 converts "/:foo/:bar", %r{\A/([^/?#]+)/([^/?#]+)\z}
86 86 parses "/:foo/:bar", "/user@example.com/name", "foo" => "user@example.com", "bar" => "name"
87   -
  87 +
88 88 converts "/test$/", %r{\A/test(?:\$|%24)/\z}
89 89 parses "/test$/", "/test$/", {}
90   -
  90 +
91 91 converts "/te+st/", %r{\A/te(?:\+|%2[Bb])st/\z}
92 92 parses "/te+st/", "/te+st/", {}
93 93 fails "/te+st/", "/test/"
94 94 fails "/te+st/", "/teeest/"
95   -
  95 +
96 96 converts "/test(bar)/", %r{\A/test(?:\(|%28)bar(?:\)|%29)/\z}
97 97 parses "/test(bar)/", "/test(bar)/", {}
98   -
  98 +
99 99 converts "/path with spaces", %r{\A/path(?:%20|(?:\+|%2[Bb]))with(?:%20|(?:\+|%2[Bb]))spaces\z}
100 100 parses "/path with spaces", "/path%20with%20spaces", {}
101 101 parses "/path with spaces", "/path%2Bwith%2Bspaces", {}
102 102 parses "/path with spaces", "/path+with+spaces", {}
103   -
  103 +
104 104 converts "/foo&bar", %r{\A/foo(?:&|%26)bar\z}
105 105 parses "/foo&bar", "/foo&bar", {}
106   -
  106 +
107 107 converts "/:foo/*", %r{\A/([^/?#]+)/(.*?)\z}
108 108 parses "/:foo/*", "/hello%20world/how%20are%20you", "foo" => "hello%20world", "splat" => "how%20are%20you"
109   -
  109 +
110 110 converts "/*/foo/*/*", %r{\A/(.*?)/foo/(.*?)/(.*?)\z}
111 111 parses "/*/foo/*/*", "/bar/foo/bling/baz/boom", "splat" => ["bar", "bling", "baz/boom"]
112 112 fails "/*/foo/*/*", "/bar/foo/baz"
113   -
  113 +
114 114 converts "/test.bar", %r{\A/test(?:\.|%2[Ee])bar\z}
115 115 parses "/test.bar", "/test.bar", {}
116 116 fails "/test.bar", "/test0bar"
117   -
  117 +
118 118 converts "/:file.:ext", %r{\A/((?:[^\./?#%]|(?:%[^2].|%[2][^Ee]))+)(?:\.|%2[Ee])((?:[^\./?#%]|(?:%[^2].|%[2][^Ee]))+)\z}
119 119 parses "/:file.:ext", "/pony.jpg", "file" => "pony", "ext" => "jpg"
120 120 parses "/:file.:ext", "/pony%2Ejpg", "file" => "pony", "ext" => "jpg"
121 121 fails "/:file.:ext", "/.jpg"
122   -
  122 +
123 123 converts "/:name.?:format?", %r{\A/((?:[^\./?#%]|(?:%[^2].|%[2][^Ee]))+)(?:\.|%2[Ee])?((?:[^\./?#%]|(?:%[^2].|%[2][^Ee]))+)?\z}
124 124 parses "/:name.?:format?", "/foo", "name" => "foo", "format" => nil
125 125 parses "/:name.?:format?", "/foo.bar", "name" => "foo", "format" => "bar"
126 126 parses "/:name.?:format?", "/foo%2Ebar", "name" => "foo", "format" => "bar"
127 127 fails "/:name.?:format?", "/.bar"
128   -
  128 +
129 129 converts "/:user@?:host?", %r{\A/((?:[^@/?#%]|(?:%[^4].|%[4][^0]))+)(?:@|%40)?((?:[^@/?#%]|(?:%[^4].|%[4][^0]))+)?\z}
130 130 parses "/:user@?:host?", "/foo@bar", "user" => "foo", "host" => "bar"
131 131 parses "/:user@?:host?", "/foo.foo@bar", "user" => "foo.foo", "host" => "bar"
132 132 parses "/:user@?:host?", "/foo@bar.bar", "user" => "foo", "host" => "bar.bar"
133   -
  133 +
134 134 # From https://gist.github.com/2154980#gistcomment-169469.
135 135 #
136 136 # converts "/:name(.:format)?", %r{\A/([^\.%2E/?#]+)(?:\(|%28)(?:\.|%2E)([^\.%2E/?#]+)(?:\)|%29)?\z}
137 137 # parses "/:name(.:format)?", "/foo", "name" => "foo", "format" => nil
138 138 # parses "/:name(.:format)?", "/foo.bar", "name" => "foo", "format" => "bar"
139 139 fails "/:name(.:format)?", "/foo."
140   -
  140 +
141 141 parses "/:id/test.bar", "/3/test.bar", {"id" => "3"}
142 142 parses "/:id/test.bar", "/2/test.bar", {"id" => "2"}
143 143 parses "/:id/test.bar", "/2E/test.bar", {"id" => "2E"}
144 144 parses "/:id/test.bar", "/2e/test.bar", {"id" => "2e"}
145   - fails "/:id/test.bar", "/%2E/test.bar"
146   -
  145 + parses "/:id/test.bar", "/%2E/test.bar", {"id" => "%2E"}
  146 +
147 147 parses '/10/:id', '/10/test', "id" => "test"
148 148 parses '/10/:id', '/10/te.st', "id" => "te.st"
149   -
  149 +
150 150 parses '/10.1/:id', '/10.1/test', "id" => "test"
151 151 parses '/10.1/:id', '/10.1/te.st', "id" => "te.st"
152   -
  152 +
153 153 parses '/:a/:b.?:c?', '/a/b', "a" => "a", "b" => "b", "c" => nil
154 154 parses '/:a/:b.?:c?', '/a/b.c', "a" => "a", "b" => "b", "c" => "c"
155 155 parses '/:a/:b.?:c?', '/a.b/c', "a" => "a.b", "b" => "c", "c" => nil
156 156 parses '/:a/:b.?:c?', '/a.b/c.d', "a" => "a.b", "b" => "c", "c" => "d"
157   -
  157 +
158 158 parses "/:file.:ext", "/pony%2ejpg", "file" => "pony", "ext" => "jpg"
159 159 parses "/:file.:ext", "/pony%E6%AD%A3%2Ejpg", "file" => "pony%E6%AD%A3", "ext" => "jpg"
160 160 parses "/:file.:ext", "/pony%e6%ad%a3%2ejpg", "file" => "pony%e6%ad%a3", "ext" => "jpg"
@@ -162,4 +162,10 @@ def compiled pattern
162 162 parses "/:file.:ext", "/pony正%2ejpg", "file" => "pony正", "ext" => "jpg"
163 163 fails "/:file.:ext", "/pony正..jpg"
164 164 fails "/:file.:ext", "/pony正.%2ejpg"
  165 +
  166 + # parses "/:foo.:bar", "/file.tar.gz", "foo" => "file", "bar" => "tar.gz"
  167 +
  168 + # From issue #688.
  169 + #
  170 + parses "/articles/10.1103/:doi", "/articles/10.1103/PhysRevLett.110.026401", "doi" => "PhysRevLett.110.026401"
165 171 end

0 comments on commit 3be9e09

Please sign in to comment.
Something went wrong with that request. Please try again.