Fixes to overlapping tests

This commit is contained in:
Michael Snoyman 2012-01-10 14:02:05 +02:00
parent e16ed57849
commit 4d45bfeb13
2 changed files with 24 additions and 4 deletions

View File

@ -25,15 +25,28 @@ hasSuffix r =
Methods Nothing _ -> False
overlaps :: [(CheckOverlap, Piece t)] -> [(CheckOverlap, Piece t)] -> Bool -> Bool -> Bool
overlaps [] [] False False = False
-- No pieces on either side, will overlap regardless of suffix
overlaps [] [] _ _ = True
-- No pieces on the left, will overlap if the left side has a suffix
overlaps [] _ suffixX _ = suffixX
-- Ditto for the right
overlaps _ [] _ suffixY = suffixY
overlaps ((False, _):xs) (_:ys) suffixX suffixY = overlaps xs ys suffixX suffixY
overlaps (_:xs) ((False, _):ys) suffixX suffixY = overlaps xs ys suffixX suffixY
-- As soon as we ignore a single piece (via CheckOverlap == False), we say that
-- the routes don't overlap at all. In other words, disabling overlap checking
-- on a single piece disables it on the whole route.
overlaps ((False, _):_) _ _ _ = False
overlaps _ ((False, _):_) _ _ = False
-- Compare the actual pieces
overlaps ((True, pieceX):xs) ((True, pieceY):ys) suffixX suffixY =
piecesOverlap pieceX pieceY || overlaps xs ys suffixX suffixY
piecesOverlap pieceX pieceY && overlaps xs ys suffixX suffixY
piecesOverlap :: Piece t -> Piece t -> Bool
-- Statics only match if they equal. Dynamics match with anything
piecesOverlap (Static x) (Static y) = x == y
piecesOverlap _ _ = True

View File

@ -306,6 +306,13 @@ main = hspecX $ do
/foo Foo1
/#!String Foo2
/!foo Foo3
|]
findOverlapNames routes @?= []
it "proper boolean logic" $ do
let routes = [parseRoutesNoCheck|
/foo/bar Foo1
/foo/baz Foo2
/bar/baz Foo3
|]
findOverlapNames routes @?= []