Permalink
Browse files

new generic tests

  • Loading branch information...
1 parent 4bec120 commit a17851417f4a0ba78fc00b5e961d222b0dff9bcd @joshbuddy committed Jun 29, 2011
View
@@ -3,7 +3,7 @@ require 'bundler'
Bundler::GemHelper.install_tasks
desc "Run all tests"
-task :test => ['test:integration', 'test:examples', 'test:rdoc_examples']
+task :test => ['test:generation', 'test:recognition', 'test:integration', 'test:examples', 'test:rdoc_examples']
require 'pp'
@@ -21,6 +21,21 @@ namespace :test do
require './test/helper'
Dir['./test/**/test_*.rb'].each { |test| require test }
end
+
+ desc "Run generic recognition tests"
+ task :recognition do
+ $: << 'lib'
+ require 'http_router'
+ require './test/recognition'
+ end
+
+ desc "Run generic recognition tests"
+ task :generation do
+ $: << 'lib'
+ require 'http_router'
+ require './test/generation'
+ end
+
desc "Run example tests"
task :examples do
$: << 'lib'
View
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'code_stats'
s.add_development_dependency 'rake', '~> 0.8.7'
s.add_development_dependency 'rbench'
+ s.add_development_dependency 'json'
s.add_development_dependency 'phocus'
s.add_development_dependency 'bundler', '~> 1.0.0'
s.add_development_dependency 'thin', '= 1.2.8'
@@ -0,0 +1,87 @@
+{"a": "/"}
+{"b": "/test"}
+{"c": "/test/time"}
+{"d": "/one/more/what"}
+{"e": "/test.html"}
+ ["/", "a"]
+ ["/test", "b"]
+ ["/test/time", "c"]
+ ["/one/more/what", "d"]
+ ["/test.html", "e"]
+
+{"a": "/:var"}
+ ["/test", "a", {"var":"test"}]
+ ["/test", "a", ["test"]]
+
+{"a": "/:var"}
+ ["/test?query=string", "a", {"var":"test", "query": "string"}]
+ ["/test?query=string", "a", ["test", {"query": "string"}]]
+
+{"a": "/:var/:baz"}
+ ["/one/two", "a", {"var":"one", "baz": "two"}]
+ ["/one/two", "a", ["one", "two"]]
+
+{"a": "/test.:format"}
+ ["/test.html", "a", {"format":"html"}]
+ ["/test.html", "a", ["html"]]
+
+{"a": "/test(.:format)"}
+ ["/test.html", "a", {"format":"html"}]
+ ["/test.html", "a", ["html"]]
+ ["/test", "a"]
+
+{"a": "/:var.:format"}
+ ["/test.html", "a", {"var": "test", "format":"html"}]
+ ["/test.html", "a", ["test", "html"]]
+ ["/test.html", "a", ["test", {"format": "html"}]]
+ [null, "a", {"format": "html"}]
+
+{"a": "/:var(.:format)"}
+ ["/test.html", "a", {"var": "test", "format":"html"}]
+ ["/test.html", "a", ["test", "html"]]
+ ["/test.html", "a", ["test", {"format": "html"}]]
+ ["/test", "a", ["test"]]
+ ["/test", "a", {"var": "test"}]
+ [null, "a", {"format": "html"}]
+ [null, "a"]
+
+{"a": "/:var1(/:var2)"}
+ ["/foo/bar", "a", {"var1": "foo", "var2":"bar"}]
+ [null, "a", ["foo", {"var1": "bar"}]]
+ ["/foo", "a", {"var1": "foo"}]
+ ["/foo", "a", ["foo"]]
+ ["/foo", "a", ["foo", null]]
+
+{"a": "/:var1(/:var2.:format)"}
+ ["/test/test2.html", "a", {"var1": "test", "var2": "test2", "format":"html"}]
+ ["/test/test2.html", "a", ["test", "test2", "html"]]
+ ["/test", "a", ["test"]]
+
+{"a": "/:var1(/:var2(/:var3))"}
+ ["/var/fooz/baz", "a", {"var1": "var", "var2":"fooz", "var3": "baz"}]
+ ["/var/fooz", "a", {"var1": "var", "var2":"fooz"}]
+ ["/var", "a", {"var1": "var"}]
+ ["/var/fooz/baz", "a", ["var", "fooz", "baz"]]
+ ["/var/fooz", "a", ["var", "fooz"]]
+ ["/var", "a", ["var"]]
+
+{"a": {"path":"/:var", "default":{"page":1}}}
+ ["/123?page=1", "a", [123]]
+
+{"a": {"path":"/:page/:entry", "default":{"page":1}}}
+ ["/1/123", "a", {"entry": "123"}]
+
+{"a": "/:var"}
+ ["/%C3%A4", "a", "ä"]
+
+{"a": {"path": ":var", "var": {"regex": "\\d+"}}}
+ [null, "a", "asd"]
+
+{"a": "/var"}
+ ["/var?foo%5B%5D=baz&foo%5B%5D=bar", "a", {"foo": ["baz", "bar"]}]
+
+{"a": "/var"}
+ ["/var?foo%5Baz%5D=baz", "a", {"foo": {"az": "baz"}}]
+
+{"a": "/var"}
+ ["/var?foo%5Baz%5D%5B%5D=baz", "a", {"foo": {"az": ["baz"]}}]
@@ -0,0 +1,261 @@
+{"route": ":one"}
+ ["route", "/two", {"one": "two"}]
+
+{"route": "test/:one"}
+ ["route", "/test/three", {"one": "three"}]
+
+{"static": "one"}
+{"dynamic": ":one"}
+ ["dynamic", "/two", {"one": "two"}]
+ ["static", "/one"]
+
+[{"variable": ":var/one"}, {"static": "one"}]
+ ["variable", "/two/one", {"var": "two"}]
+ ["static", "/one"]
+ [null, "/two"]
+
+[{"dynamic": "/foo/:id"}, {"static": "/foo"}]
+ ["dynamic", "/foo/id", {"id": "id"}]
+ ["static", "/foo"]
+
+[{"static": "/foo/foo"}, {"dynamic": "/:foo/foo2"}]
+ ["dynamic", "/foo/foo2", {"foo": "foo"}]
+ ["static", "/foo/foo"]
+
+[{"route": ":var"}]
+ ["route", "/%E6%AE%BA%E3%81%99", {"var": "殺す"}]
+
+[{"route": {"path":{"regex": "/(test123|\\d+)"}}}]
+ ["route", "/test123"]
+ ["route", "/123"]
+ [null, "/test123andmore"]
+ [null, "/lesstest123"]
+
+[{"route": "/test.:format"}]
+ ["route", "/test.html", {"format": "html"}]
+
+[{"route": "/test(.:format)"}]
+ ["route", "/test.html", {"format": "html"}]
+ ["route", "/test"]
+
+[{"route": "(.:format)"}]
+ ["route", "/.html", {"format": "html"}]
+ ["route", "/"]
+
+[{"route": "/:test.:format"}]
+ ["route", "/foo.bar", {"format": "bar", "test": "foo"}]
+
+[{"route": "/:test(.:format)"}]
+ ["route", "/foo", {"test": "foo"}]
+ ["route", "/foo.bar", {"format": "bar", "test": "foo"}]
+
+[{"route": {"path": "/:test(.:format)", "format": {"regex": "[^\\.]+"}}}]
+ ["route", "/asd@asd.com.json", {"test": "asd@asd.com", "format": "json"}]
+
+[{"route": "/test/*variable"}]
+ ["route", "/test/one/two/three", {"variable": ["one", "two", "three"]}]
+
+[{"route": "test/*variable/test"}]
+ [null, "/test/one/two/three"]
+ ["route", "/test/one/two/three/test", {"variable": ["one", "two", "three"]}]
+
+[{"route": "test/*variable/test/*variable2"}]
+ [null, "/test/one/two/three"]
+ ["route", "/test/one/two/three/test/four/five/six", {"variable": ["one", "two", "three"], "variable2": ["four", "five", "six"]}]
+
+[{"route": "/test/:test-*variable.:format"}]
+ ["route", "/test/one-two/three/four/five.six", {"test": "one", "variable": ["two", "three", "four", "five"], "format": "six"}]
+
+[{"route": {"path": "test/*variable", "variable": {"regex": "[a-z]+"}}}]
+ [null, "/test/asd/123"]
+ [null, "/test/asd/asd123"]
+ ["route", "/test/asd/qwe", {"variable": ["asd", "qwe"]}]
+
+[{"route": {"path": "test/*variable/test", "variable": {"regex": "[a-z]+"}}}]
+ [null, "/test/asd/123"]
+ [null, "/test/asd/asd123"]
+ [null, "/test/asd/qwe"]
+ ["route", "/test/asd/qwe/test", {"variable": ["asd", "qwe"]}]
+
+[{"route": {"path": "test/*variable/:test", "variable": {"regex": "[a-z]+"}}}]
+ ["route", "/test/asd/qwe/help", {"variable": ["asd", "qwe"], "test": "help"}]
+
+[{"route": {"path": "test/*variable.:format"}}]
+ ["route", "/test/asd/qwe.html", {"variable": ["asd", "qwe"], "format": "html"}]
+
+[{"route": {"path": "test/*variable.:format", "variable": {"regex": "[a-z]+"}}}]
+ [null, "/test/asd/123"]
+ [null, "/test/asd/asd123"]
+ [null, "/test/asd/qwe"]
+ ["route", "/test/asd/qwe.html", {"variable": ["asd", "qwe"], "format": "html"}]
+
+
+[{"route": {"path": "test/*variable(.:format)", "variable": {"regex": "[a-z]+"}}}]
+ [null, "/test/asd/123"]
+ [null, "/test/asd/asd123"]
+ ["route", "/test/asd/qwe", {"variable": ["asd", "qwe"]}]
+ ["route", "/test/asd/qwe.html", {"variable": ["asd", "qwe"], "format": "html"}]
+
+[{"route": {"path": "test/*variable.html"}}]
+ [null, "/test/asd/123"]
+ ["route", "/test/asd/qwe.html", {"variable": ["asd", "qwe"]}]
+
+[{"with_regex": {"path": "/:common_variable/:matched", "matched": {"regex": "\\d+"}}}, {"with_post": {"path": "/:common_variable/:matched", "conditions": {"request_method": "POST"}}}, {"without_regex": "/:common_variable/:unmatched"}]
+ ["with_regex", "/common/123", {"common_variable": "common", "matched": "123"}]
+ ["without_regex", "/common/other", {"common_variable": "common", "unmatched": "other"}]
+ ["with_regex", {"path": "/common/123", "method": "POST"}, {"common_variable": "common", "matched": "123"}]
+ ["with_post", {"path": "/common/other", "method": "POST"}, {"common_variable": "common", "matched": "other"}]
+
+[{"regex": {"path":":test/number", "test": {"regex": "\\d+"}}}, {"greedy": ":test/anything"}]
+ ["regex", "/123/number", {"test": "123"}]
+ ["greedy", "/123/anything", {"test": "123"}]
+
+[{"route": {"path": ":test", "test": {"regex": ".*"}}}]
+ ["route", "/test/", {"test": "test/"}]
+
+[{"route": {"path": "/:test", "test": {"regex": ".*"}}}]
+ ["route", "/test.html", {"test": "test.html"}]
+
+[{"route": {"path": ":test", "test": {"regex": "\\d+"}}}]
+ ["route", "/123", {"test": "123"}]
+ [null, "/a123"]
+
+[{"route": ""}]
+ ["route", "/"]
+ ["route", ""]
+
+[{"route": "/"}]
+ ["route", "/"]
+
+[{"route": "/test"}]
+ ["route", "/test"]
+
+[{"route": "/test/one"}]
+ ["route", "/test/one"]
+
+[{"route": "/test/one/two"}]
+ ["route", "/test/one/two"]
+
+[{"route": "/test.html"}]
+ ["route", "/test.html"]
+
+[{"route": ".html"}]
+ ["route", "/.html"]
+
+[{"route": "one(/two(/three(/four)(/five)))"}]
+ ["route", "/one"]
+ ["route", "/one/two"]
+ ["route", "/one/two/three"]
+ ["route", "/one/two/three/four"]
+ ["route", "/one/two/three/five"]
+ ["route", "/one/two/three/four/five"]
+ [null, "/one/two/four/five"]
+
+[{"route": "test\\(:variable\\)"}]
+ ["route", "/test(hello)", {"variable": "hello"}]
+
+[{"route": "test\\:variable"}]
+ ["route", "/test:variable"]
+
+[{"route": "test\\*variable"}]
+ ["route", "/test*variable"]
+
+[{"route": "/føø"}]
+ ["route", "/f%C3%B8%C3%B8"]
+
+[{"route": "/test*"}]
+ ["route", "/test/optional", {"PATH_INFO": "/optional"}]
+ ["route", "/test", {"PATH_INFO": "/"}]
+
+[{"route": "/*"}]
+ ["route", "/optional", {"PATH_INFO": "/optional"}]
+ ["route", "/", {"PATH_INFO": "/"}]
+
+[{"test": "/test*"}, {"root": "/*"}]
+ ["test", "/test/optional", {"PATH_INFO": "/optional"}]
+ ["test", "/test/optional/", {"PATH_INFO": "/optional/"}]
+ ["root", "/testing/optional", {"PATH_INFO": "/testing/optional"}]
+
+[{"route": "/one-:variable-time"}]
+ ["route", "one-value-time", {"variable": "value"}]
+
+[{"route": {"path": "/one-:variable-time", "variable": {"regex": "\\d+"}}}]
+ ["route", "one-123-time", {"variable": "123"}]
+ [null, "one-value-time"]
+
+[{"route": {"path": "/one-:variable-time", "variable": {"regex": "\\d+"}}}]
+ ["route", "one-123-time", {"variable": "123"}]
+ [null, "one-value-time"]
+
+[{"route": "hey.:greed.html"}]
+ ["route", "/hey.greedybody.html", {"greed": "greedybody"}]
+
+[{"r6": "/:v1-:v2-:v3-:v4-:v5-:v6"}, {"r5": "/:v1-:v2-:v3-:v4-:v5"}, {"r4": "/:v1-:v2-:v3-:v4"}, {"r3": "/:v1-:v2-:v3"}, {"r2": "/:v1-:v2"}, {"r1":"/:v1"}]
+ ["r1", "/one", {"v1": "one"}]
+ ["r2", "/one-two", {"v1": "one", "v2": "two"}]
+ ["r3", "/one-two-three", {"v1": "one", "v2":"two", "v3":"three"}]
+ ["r4", "/one-two-three-four", {"v1": "one", "v2":"two", "v3":"three", "v4":"four"}]
+ ["r5", "/one-two-three-four-five", {"v1": "one", "v2":"two", "v3":"three", "v4":"four", "v5":"five"}]
+ ["r6", "/one-two-three-four-five-six", {"v1": "one", "v2":"two", "v3":"three", "v4":"four", "v5":"five", "v6":"six"}]
+
+{"with_regex": {"path": "/:common_variable.:matched", "matched": {"regex": "\\d+"}}}
+{"without_regex": "/:common_variable.:unmatched"}
+ ["with_regex", "/common.123", {"common_variable": "common", "matched": "123"}]
+ ["without_regex", "/common.other", {"common_variable": "common", "unmatched": "other"}]
+
+[{"router":{"path":"/test", "conditions": {"request_method": "POST"}}}]
+ ["router", {"path": "/test", "method": "POST"}]
+ [[405, {"Allow": "POST"}], {"path": "/test", "method": "GET"}]
+
+{"router": {"path": "/test", "conditions": {"request_method": ["POST", "GET"]}}}
+ ["router", {"path": "/test", "method": "POST"}]
+ ["router", {"path": "/test", "method": "GET"}]
+ [[405, {"Allow": "GET, POST"}], {"path": "/test", "method": "PUT"}]
+
+{"get": {"path": "/test(.:format)", "conditions": {"request_method": "GET"}}}
+{"post": {"path": "/test(.:format)", "conditions": {"request_method": "POST"}}}
+{"delete": {"path": "/test(.:format)", "conditions": {"request_method": "DELETE"}}}
+ ["get", {"path": "/test", "method": "GET"}]
+ ["post", {"path": "/test", "method": "POST"}]
+ ["delete", {"path": "/test", "method": "DELETE"}]
+ ["get", {"path": "/test.html", "method": "GET"}, {"format": "html"}]
+ ["post", {"path": "/test.html", "method": "POST"}, {"format": "html"}]
+ ["delete", {"path": "/test.html", "method": "DELETE"}, {"format": "html"}]
+ [[405, {"Allow": "DELETE, GET, POST"}], {"path": "/test", "method": "PUT"}]
+
+{"post": {"path": "/test", "conditions": {"request_method": "POST"}}}
+{"post_2": {"path": "/test/post", "conditions": {"request_method": "POST"}}}
+{"get": {"path": "/test", "conditions": {"request_method": "GET"}}}
+{"get_2": {"path": "/test/post", "conditions": {"request_method": "GET"}}}
+{"any_2": "/test/post"}
+{"any": "/test"}
+ ["post", {"path": "/test", "method": "POST"}]
+ ["get", {"path": "/test", "method": "GET"}]
+ ["any", {"path": "/test", "method": "PUT"}]
+ ["post_2", {"path": "/test/post", "method": "POST"}]
+ ["get_2", {"path": "/test/post", "method": "GET"}]
+ ["any_2", {"path": "/test/post", "method": "PUT"}]
+
+{"post": {"path": "/test", "conditions": {"request_method": "POST"}}}
+{"any": "/test"}
+ ["post", {"path": "/test", "method": "POST"}]
+ ["any", {"path": "/test", "method": "PUT"}]
+
+{"host2_post": {"path": "/test", "conditions": {"request_method": "POST", "host": "host2"}}}
+{"host2_get": {"path": "/test", "conditions": {"request_method": "GET", "host": "host2"}}}
+{"host2": {"path": "/test", "conditions": {"host": "host2"}}}
+{"post": {"path": "/test", "conditions": {"request_method": "POST"}}}
+ ["host2", {"path": "http://host2/test", "method": "PUT"}]
+ ["post", {"path": "http://host1/test", "method": "POST"}]
+ ["host2_get", {"path": "http://host2/test", "method": "GET"}]
+ ["host2_post", {"path": "http://host2/test", "method": "POST"}]
+
+{"with": {"path": "/test", "conditions": {"request_method": "GET", "host": {"regex": "host1"}}}}
+{"without": {"path": "/test", "conditions": {"request_method": "GET"}}}
+ ["without", "http://host2/test"]
+ ["with", "http://host2.host1.com/test"]
+
+{"http": {"path": "/test", "conditions": {"scheme": "http"}}}
+{"https": {"path": "/test", "conditions": {"scheme": "https"}}}
+ ["http", {"path": "/test", "scheme": "http"}]
+ ["https", {"path": "/test", "scheme": "https"}]
Oops, something went wrong.

0 comments on commit a178514

Please sign in to comment.