checkStatics
This commit is contained in:
parent
3178a584d0
commit
691abb6823
@ -35,7 +35,14 @@ bcToDispatch (ByCount vec rest) sub mkey ts master toMaster =
|
||||
rhs = fromMaybe rest $ vec V.!? len
|
||||
|
||||
go [] = Nothing
|
||||
go (x:xs) = maybe (go xs) Just $ rhHandler x sub mkey ts master toMaster
|
||||
go (x:xs) = maybe (go xs) Just $ if checkStatics ts (rhPieces x) (rhHasMulti x) then rhHandler x sub mkey ts master toMaster else Nothing
|
||||
|
||||
checkStatics [] [] _ = True
|
||||
checkStatics [] _ _ = False
|
||||
checkStatics _ [] isMulti = isMulti
|
||||
checkStatics (_:paths) (SinglePiece:pieces) isMulti = checkStatics paths pieces isMulti
|
||||
checkStatics (path:paths) (StaticPiece piece:pieces) isMulti =
|
||||
path == piece && checkStatics paths pieces isMulti
|
||||
|
||||
data ByCount sub master res = ByCount
|
||||
{ bcVector :: !(V.Vector [RouteHandler sub master res])
|
||||
|
||||
@ -15,6 +15,18 @@ justRoot = toDispatch
|
||||
[ RouteHandler [] False $ result $ const $ Just 1
|
||||
]
|
||||
|
||||
twoStatics :: Dispatch Dummy Dummy Int
|
||||
twoStatics = toDispatch
|
||||
[ RouteHandler [StaticPiece "foo"] False $ result $ const $ Just 2
|
||||
, RouteHandler [StaticPiece "bar"] False $ result $ const $ Just 3
|
||||
]
|
||||
|
||||
multi :: Dispatch Dummy Dummy Int
|
||||
multi = toDispatch
|
||||
[ RouteHandler [StaticPiece "foo"] False $ result $ const $ Just 4
|
||||
, RouteHandler [StaticPiece "bar"] True $ result $ const $ Just 5
|
||||
]
|
||||
|
||||
test :: Dispatch Dummy Dummy Int -> [Text] -> Maybe Int
|
||||
test dispatch ts = dispatch Dummy Nothing ts Dummy id
|
||||
|
||||
@ -23,3 +35,14 @@ main = hspecX $ do
|
||||
describe "justRoot" $ do
|
||||
it "dispatches correctly" $ test justRoot [] @?= Just 1
|
||||
it "fails correctly" $ test justRoot ["foo"] @?= Nothing
|
||||
describe "twoStatics" $ do
|
||||
it "dispatches correctly to foo" $ test twoStatics ["foo"] @?= Just 2
|
||||
it "dispatches correctly to bar" $ test twoStatics ["bar"] @?= Just 3
|
||||
it "fails correctly (1)" $ test twoStatics [] @?= Nothing
|
||||
it "fails correctly (2)" $ test twoStatics ["bar", "baz"] @?= Nothing
|
||||
describe "multi" $ do
|
||||
it "dispatches correctly to foo" $ test multi ["foo"] @?= Just 4
|
||||
it "dispatches correctly to bar" $ test multi ["bar"] @?= Just 5
|
||||
it "dispatches correctly to bar/baz" $ test multi ["bar", "baz"] @?= Just 5
|
||||
it "fails correctly (1)" $ test multi [] @?= Nothing
|
||||
it "fails correctly (2)" $ test multi ["foo", "baz"] @?= Nothing
|
||||
|
||||
Loading…
Reference in New Issue
Block a user