diff options
-rw-r--r-- | src/Hakyll/Core/Identifier/Pattern.hs | 17 | ||||
-rw-r--r-- | tests/Hakyll/Core/Identifier/Tests.hs | 8 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/Hakyll/Core/Identifier/Pattern.hs b/src/Hakyll/Core/Identifier/Pattern.hs index e770d13..5f97215 100644 --- a/src/Hakyll/Core/Identifier/Pattern.hs +++ b/src/Hakyll/Core/Identifier/Pattern.hs @@ -36,13 +36,19 @@ -- function. -- module Hakyll.Core.Identifier.Pattern - ( Pattern + ( -- * The pattern type + Pattern , castPattern + + -- * Creating patterns , parseGlob , predicate , list , regex , inGroup + , complement + + -- * Applying patterns , matches , filterMatches , capture @@ -131,6 +137,15 @@ regex str = predicate $ fromMaybe False . (=~~ str) . toFilePath inGroup :: Maybe String -> Pattern a inGroup group = predicate $ (== group) . identifierGroup +-- | Inverts a pattern, e.g. +-- +-- > complement "foo/bar.html" +-- +-- will match /anything/ except @\"foo\/bar.html\"@ +-- +complement :: Pattern a -> Pattern a +complement p = predicate (not . matches p) + -- | Check if an identifier matches a pattern -- matches :: Pattern a -> Identifier a -> Bool diff --git a/tests/Hakyll/Core/Identifier/Tests.hs b/tests/Hakyll/Core/Identifier/Tests.hs index 4060b1f..c496a98 100644 --- a/tests/Hakyll/Core/Identifier/Tests.hs +++ b/tests/Hakyll/Core/Identifier/Tests.hs @@ -37,8 +37,10 @@ captureTests = fromAssertions "capture" matchesTests :: [Test] matchesTests = fromAssertions "matches" - [ True @=? matches (regex "^foo/[^x]*$") "foo/bar" - , False @=? matches (regex "^foo/[^x]*$") "foo/barx" - , True @=? matches (list ["foo.markdown"]) "foo.markdown" + [ True @=? matches (list ["foo.markdown"]) "foo.markdown" , False @=? matches (list ["foo"]) (Identifier (Just "foo") "foo") + , True @=? matches (regex "^foo/[^x]*$") "foo/bar" + , False @=? matches (regex "^foo/[^x]*$") "foo/barx" + , True @=? matches (complement "foo.markdown") "bar.markdown" + , False @=? matches (complement "foo.markdown") "foo.markdown" ] |