Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New tests for the new map.

  • Loading branch information...
commit 9219fee9d01e11604dfcee2af814524c7679dfa6 1 parent eafc4e5
@favonia authored
Showing with 29 additions and 0 deletions.
  1. +29 −0 test/suite/Snap/Internal/Routing/Tests.hs
View
29 test/suite/Snap/Internal/Routing/Tests.hs
@@ -57,6 +57,8 @@ tests = [ testRouting1
, testRouteUrlDecode
, testRouteUrlEncodedPath
, testRouteEmptyCapture
+ , testRouteNestedCaptures1
+ , testRouteNestedCaptures2
]
@@ -136,9 +138,20 @@ routesEmptyCapture = route [ ("foo/:id", fooCapture) ]
------------------------------------------------------------------------------
+routesNestedCaptures1 :: Snap (Maybe [ByteString])
+routesNestedCaptures1 = route [ ("foo/:id", route [ (":id", dumpCapture "id") ] ) ]
+
+
+------------------------------------------------------------------------------
+routesNestedCaptures2 :: Snap (Maybe [ByteString])
+routesNestedCaptures2 = route [ ("foo/:id", route [ (":id", dumpParam "id") ] ) ]
+
+
+------------------------------------------------------------------------------
topTop, topFoo, fooBar, fooCapture, getRqPathInfo, bar,
getRqContextPath, barQuux, dblA, zabc, topCapture,
fooCapture2 :: Snap ByteString
+dumpCapture, dumpParam :: ByteString -> Snap (Maybe [ByteString])
dblA = do
ma <- getParam "a"
@@ -172,6 +185,8 @@ getRqPathInfo = liftM rqPathInfo getRequest
getRqContextPath = liftM rqContextPath getRequest
barQuux = return "barQuux"
bar = return "bar"
+dumpCapture str = liftM (rqCaptureParam str) getRequest
+dumpParam str = liftM (rqParam str) getRequest
-----------
@@ -414,3 +429,17 @@ testRouteEmptyCapture = testCase "route/emptyCapture" $ do
where
expected = "ZOMG_OK"
m = routesEmptyCapture <|> return expected
+
+
+------------------------------------------------------------------------------
+testRouteNestedCaptures1 :: Test
+testRouteNestedCaptures1 = testCase "route/nestedCaptures1" $ do
+ r <- go routesNestedCaptures1 "/foo/outer/inner"
+ assertEqual "nested captures (rqCaptureParams)" (Just ["inner", "outer"]) r
+
+
+------------------------------------------------------------------------------
+testRouteNestedCaptures2 :: Test
+testRouteNestedCaptures2 = testCase "route/nestedCaptures2" $ do
+ r <- go routesNestedCaptures2 "/foo/outer/inner"
+ assertEqual "nested captures (rqParams)" (Just ["inner", "outer"]) r
Please sign in to comment.
Something went wrong with that request. Please try again.