packages feed

strong-path 1.1.2.0 → 1.1.3.0

raw patch · 4 files changed

+45/−1 lines, 4 filesdep +hashable

Dependencies added: hashable

Files

src/StrongPath.hs view
@@ -270,6 +270,7 @@ where  import StrongPath.FilePath+import StrongPath.Instances () import StrongPath.Operations import StrongPath.TH import StrongPath.Types
+ src/StrongPath/Instances.hs view
@@ -0,0 +1,20 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++module StrongPath.Instances where++import Data.Hashable+import StrongPath.FilePath+import StrongPath.Types++-- Hashable instance for Path declared here, as an orphaned instance, instead of+-- in StronPath.Internal to avoid cyclic dependency between StrongPath.FilePath+-- and StrongPath.Internal. (This cycle would arise due to the use of+-- `toFilePath` from FilePath in the instance declaration and the dependency of+-- the FilePath module on the types from the Internal module)++-- |+-- Caveat: For two relative Paths, that only differ in the Directory, that they+-- are relative to, this Hashable instance will return the same hash even though+-- they are different paths.+instance Hashable (Path s b t) where+  hashWithSalt salt = hashWithSalt salt . toFilePath
strong-path.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           strong-path-version:        1.1.2.0+version:        1.1.3.0 synopsis:       Strongly typed paths in Haskell. description:    Replacement for a FilePath that enables you to handle filepaths in your code in a type-safe manner. You can specify at type level if they are relative, absolute, file, directory, posix, windows, and even to which file or directory they point to or are relative to. category:       System, Filesystem, FilePath@@ -31,6 +31,7 @@   exposed-modules:       StrongPath       StrongPath.FilePath+      StrongPath.Instances       StrongPath.Internal       StrongPath.Operations       StrongPath.Path@@ -45,6 +46,7 @@       base >=4.7 && <5     , exceptions ==0.10.*     , filepath ==1.4.*+    , hashable ==1.3.*     , path >=0.9.2 && <0.10     , template-haskell >=2.16 && <2.18   default-language: Haskell2010@@ -55,6 +57,7 @@   other-modules:       PathTest       StrongPath.FilePathTest+      StrongPath.InstanceTest       StrongPath.InternalTest       StrongPath.PathTest       StrongPath.THTest@@ -67,6 +70,7 @@   build-depends:       base >=4.7 && <5     , filepath+    , hashable ==1.3.*     , hspec >=2.7 && <2.10     , path     , strong-path
+ test/StrongPath/InstanceTest.hs view
@@ -0,0 +1,19 @@+module StrongPath.InstanceTest where++import Data.Hashable+import StrongPath+import Test.Hspec+import Test.Tasty (TestTree)+import Test.Tasty.Hspec (testSpec)++test_StrongPathInstance :: IO TestTree+test_StrongPathInstance = testSpec "StrongPath.Instance" $ do+  it "Different paths have different hash" $ do+    aPath <- parseRelDir "a"+    bPath <- parseRelDir "b"+    hash aPath `shouldNotBe` hash bPath+  it "Concatenated Paths have same hash as Path directly constructed from parts" $ do+    aPath <- parseRelDir "a"+    bPath <- parseRelDir "b"+    abPath <- parseRelDir "a/b"+    hash (aPath </> bPath) `shouldBe` hash abPath