Skip to content

Commit

Permalink
Ensure that toFilePath and fromFilePath are inverses (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Oct 24, 2024
1 parent 8059cb2 commit e0c19ef
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/Hakyll/Core/Identifier/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ module Hakyll.Core.Identifier.Tests


--------------------------------------------------------------------------------
import qualified Test.QuickCheck as Q
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit ((@=?))
import Test.Tasty.QuickCheck (testProperty)


--------------------------------------------------------------------------------
import Hakyll.Core.Identifier
import Hakyll.Core.Identifier.Pattern
import System.FilePath ((</>))
import System.FilePath ((</>), isValid, equalFilePath, pathSeparators)
import TestSuite.Util


Expand All @@ -22,6 +24,7 @@ tests :: TestTree
tests = testGroup "Hakyll.Core.Identifier.Tests" $ concat
[ captureTests
, matchesTests
, [ testProperty "toFilePath . fromFilePath" filepathConversionProp ]
]


Expand Down Expand Up @@ -59,3 +62,16 @@ matchesTests = fromAssertions "matches"
, True @=? matches ("foo" .||. "bar") "bar"
, False @=? matches ("bar" .&&. hasNoVersion) (setVersion (Just "xz") "bar")
]


--------------------------------------------------------------------------------
-- Ensure that `fromFilePath` and `toFilePath` are inverses of each other (#791)
filepathConversionProp :: Q.Property
filepathConversionProp
= Q.forAll genFilePath
$ \fp -> toFilePath (fromFilePath fp) `equalFilePath` fp
where
genFilePath
= Q.listOf1 (Q.elements $ ['a'..'z'] <> pathSeparators)
`Q.suchThat`
isValid

0 comments on commit e0c19ef

Please sign in to comment.