Debian Codegraph @

tests/Hakyll/Core/Identifier/Tests.hs

raw
1 --------------------------------------------------------------------------------
2 {-# LANGUAGE OverloadedStrings #-}
3 module Hakyll.Core.Identifier.Tests
4 ( tests
5 ) where
6
7
8 --------------------------------------------------------------------------------
9 import qualified Test.QuickCheck as Q
10 import Test.Tasty (TestTree, testGroup)
11 import Test.Tasty.HUnit ((@=?))
12 import Test.Tasty.QuickCheck (testProperty)
13
14
15 --------------------------------------------------------------------------------
16 import Hakyll.Core.Identifier
17 import Hakyll.Core.Identifier.Pattern
18 import System.FilePath ((</>), isValid, equalFilePath, pathSeparators)
19 import TestSuite.Util
20
21
22 --------------------------------------------------------------------------------
23 tests :: TestTree
24 tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat
25 [ captureTests
26 , matchesTests
27 , [ testProperty "toFilePath . fromFilePath" filepathConversionProp ]
28 ]
29
30
31 --------------------------------------------------------------------------------
32 captureTests :: [TestTree]
33 captureTests = fromAssertions "capture"
34 [ Just ["bar"] @=? capture "foo/**" "foo/bar"
35 , Just ["foo" </> "bar"] @=? capture "**" "foo/bar"
36 , Nothing @=? capture "*" "foo/bar"
37 , Just [] @=? capture "foo" "foo"
38 , Just ["foo"] @=? capture "*/bar" "foo/bar"
39 , Just ["foo" </> "bar"] @=? capture "**/qux" "foo/bar/qux"
40 , Just ["foo" </> "bar", "qux"] @=? capture "**/*" "foo/bar/qux"
41 , Just ["foo", "bar" </> "qux"] @=? capture "*/**" "foo/bar/qux"
42 , Just ["foo"] @=? capture "*.html" "foo.html"
43 , Nothing @=? capture "*.html" "foo/bar.html"
44 , Just ["foo" </> "bar"] @=? capture "**.html" "foo/bar.html"
45 , Just ["foo" </> "bar", "wut"] @=? capture "**/qux/*" "foo/bar/qux/wut"
46 , Just ["lol", "fun" </> "large"] @=? capture "*cat/**.jpg" "lolcat/fun/large.jpg"
47 , Nothing @=? capture "\\*.jpg" "foo.jpg"
48 , Just ["xyz","42"] @=? capture (fromRegex "cat-([a-z]+)/foo([0-9]+).jpg") "cat-xyz/foo42.jpg"
49 ]
50
51
52 --------------------------------------------------------------------------------
53 matchesTests :: [TestTree]
54 matchesTests = fromAssertions "matches"
55 [ True @=? matches (fromList ["foo.markdown"]) "foo.markdown"
56 , False @=? matches (fromList ["foo"]) (setVersion (Just "x") "foo")
57 , True @=? matches (fromVersion (Just "xz")) (setVersion (Just "xz") "bar")
58 , True @=? matches (fromRegex "^foo/[^x]*$") "foo/bar"
59 , False @=? matches (fromRegex "^foo/[^x]*$") "foo/barx"
60 , True @=? matches (complement "foo.markdown") "bar.markdown"
61 , False @=? matches (complement "foo.markdown") "foo.markdown"
62 , True @=? matches ("foo" .||. "bar") "bar"
63 , False @=? matches ("bar" .&&. hasNoVersion) (setVersion (Just "xz") "bar")
64 ]
65
66
67 --------------------------------------------------------------------------------
68 -- Ensure that `fromFilePath` and `toFilePath` are inverses of each other (#791)
69 filepathConversionProp :: Q.Property
70 filepathConversionProp
71 = Q.forAll genFilePath
72 $ \fp -> toFilePath (fromFilePath fp) `equalFilePath` fp
73 where
74 genFilePath
75 = Q.listOf1 (Q.elements $ ['a'..'z'] <> pathSeparators)
76 `Q.suchThat`
77 isValid