packages feed

strong-path 1.1.4.0 → 1.2.0.0

raw patch · 5 files changed

+63/−50 lines, 5 filesdep ~filepathdep ~hashabledep ~hspecnew-uploader

Dependency ranges changed: filepath, hashable, hspec, path, tasty, tasty-discover, tasty-hspec, tasty-quickcheck, template-haskell

Files

src/StrongPath/Internal.hs view
@@ -42,7 +42,7 @@ -- -- Some examples: ----- > Path System (Dir HomeDir) (File FooFile)+-- > Path System (Rel HomeDir) (File FooFile) -- > Path System Abs (Dir HomeDir) -- > Path Posix (Rel ProjectRoot) (File ()) data Path s b t
src/StrongPath/Operations.hs view
@@ -105,43 +105,55 @@ (</>) :: Path s b (Dir d) -> Path s (Rel d) t -> Path s b t ---- System lsp@(RelDir _ _) </> (RelFile rp rprefix) =-  let (RelDir lp' lprefix') = iterate parent lsp !! prefixNumParentDirs rprefix-   in RelFile (lp' P.</> rp) lprefix'+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (RelDir lp' lprefix') -> RelFile (lp' P.</> rp) lprefix'+    _ -> impossible lsp@(RelDir _ _) </> (RelDir rp rprefix) =-  let (RelDir lp' lprefix') = iterate parent lsp !! prefixNumParentDirs rprefix-   in RelDir (lp' P.</> rp) lprefix'+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (RelDir lp' lprefix') -> RelDir (lp' P.</> rp) lprefix'+    _ -> impossible lsp@(AbsDir _) </> (RelFile rp rprefix) =-  let (AbsDir lp') = iterate parent lsp !! prefixNumParentDirs rprefix-   in AbsFile (lp' P.</> rp)+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (AbsDir lp') -> AbsFile (lp' P.</> rp)+    _ -> impossible lsp@(AbsDir _) </> (RelDir rp rprefix) =-  let (AbsDir lp') = iterate parent lsp !! prefixNumParentDirs rprefix-   in AbsDir (lp' P.</> rp)+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (AbsDir lp') -> AbsDir (lp' P.</> rp)+    _ -> impossible ---- Windows lsp@(RelDirW _ _) </> (RelFileW rp rprefix) =-  let (RelDirW lp' lprefix') = iterate parent lsp !! prefixNumParentDirs rprefix-   in RelFileW (lp' PW.</> rp) lprefix'+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (RelDirW lp' lprefix') -> RelFileW (lp' PW.</> rp) lprefix'+    _ -> impossible lsp@(RelDirW _ _) </> (RelDirW rp rprefix) =-  let (RelDirW lp' lprefix') = iterate parent lsp !! prefixNumParentDirs rprefix-   in RelDirW (lp' PW.</> rp) lprefix'+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (RelDirW lp' lprefix') -> RelDirW (lp' PW.</> rp) lprefix'+    _ -> impossible lsp@(AbsDirW _) </> (RelFileW rp rprefix) =-  let (AbsDirW lp') = iterate parent lsp !! prefixNumParentDirs rprefix-   in AbsFileW (lp' PW.</> rp)+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (AbsDirW lp') -> AbsFileW (lp' PW.</> rp)+    _ -> impossible lsp@(AbsDirW _) </> (RelDirW rp rprefix) =-  let (AbsDirW lp') = iterate parent lsp !! prefixNumParentDirs rprefix-   in AbsDirW (lp' PW.</> rp)+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (AbsDirW lp') -> AbsDirW (lp' PW.</> rp)+    _ -> impossible ---- Posix lsp@(RelDirP _ _) </> (RelFileP rp rprefix) =-  let (RelDirP lp' lprefix') = iterate parent lsp !! prefixNumParentDirs rprefix-   in RelFileP (lp' PP.</> rp) lprefix'+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (RelDirP lp' lprefix') -> RelFileP (lp' PP.</> rp) lprefix'+    _ -> impossible lsp@(RelDirP _ _) </> (RelDirP rp rprefix) =-  let (RelDirP lp' lprefix') = iterate parent lsp !! prefixNumParentDirs rprefix-   in RelDirP (lp' PP.</> rp) lprefix'+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (RelDirP lp' lprefix') -> RelDirP (lp' PP.</> rp) lprefix'+    _ -> impossible lsp@(AbsDirP _) </> (RelFileP rp rprefix) =-  let (AbsDirP lp') = iterate parent lsp !! prefixNumParentDirs rprefix-   in AbsFileP (lp' PP.</> rp)+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (AbsDirP lp') -> AbsFileP (lp' PP.</> rp)+    _ -> impossible lsp@(AbsDirP _) </> (RelDirP rp rprefix) =-  let (AbsDirP lp') = iterate parent lsp !! prefixNumParentDirs rprefix-   in AbsDirP (lp' PP.</> rp)+  case iterate parent lsp !! prefixNumParentDirs rprefix of+    (AbsDirP lp') -> AbsDirP (lp' PP.</> rp)+    _ -> impossible _ </> _ = impossible  -- | Returns the most right member of the path once split by separators.@@ -233,7 +245,7 @@ -- Works well for \"normal\" relative paths like @\"a\\b\\c\"@ (Win) or @\"a\/b\/c\"@ (Posix). -- If path is weird but still considered relative, like just @\"C:\"@ on Win, -- results can be unexpected, most likely resulting with error thrown.-relDirToPosix :: MonadThrow m => Path s (Rel d1) (Dir d2) -> m (Path Posix (Rel d1) (Dir d2))+relDirToPosix :: (MonadThrow m) => Path s (Rel d1) (Dir d2) -> m (Path Posix (Rel d1) (Dir d2)) relDirToPosix sp@(RelDir _ _) = parseRelDirP $ FPP.joinPath $ FP.splitDirectories $ toFilePath sp relDirToPosix sp@(RelDirW _ _) = parseRelDirP $ FPP.joinPath $ FPW.splitDirectories $ toFilePath sp relDirToPosix (RelDirP p pr) = return $ RelDirP p pr@@ -241,7 +253,7 @@  -- | Converts relative file path to posix, if it is not already posix. -- Check 'relDirToPosix' for more details, they behave the same.-relFileToPosix :: MonadThrow m => Path s (Rel d1) (File f) -> m (Path Posix (Rel d1) (File f))+relFileToPosix :: (MonadThrow m) => Path s (Rel d1) (File f) -> m (Path Posix (Rel d1) (File f)) relFileToPosix sp@(RelFile _ _) = parseRelFileP $ FPP.joinPath $ FP.splitDirectories $ toFilePath sp relFileToPosix sp@(RelFileW _ _) = parseRelFileP $ FPP.joinPath $ FPW.splitDirectories $ toFilePath sp relFileToPosix (RelFileP p pr) = return $ RelFileP p pr
strong-path.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.37.0. -- -- see: https://github.com/sol/hpack  name:           strong-path-version:        1.1.4.0+version:        1.2.0.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@@ -18,7 +18,7 @@ license-file:   LICENSE build-type:     Simple tested-with:-    GHC == 8.10.7, GHC == 9.0.1+    GHC == 9.0.2, GHC == 9.12.2 extra-source-files:     README.md     ChangeLog.md@@ -45,10 +45,10 @@   build-depends:       base >=4.7 && <5     , exceptions ==0.10.*-    , filepath ==1.4.*-    , hashable ==1.3.*+    , filepath >=1.4 && <1.6+    , hashable >=1.3 && <1.6     , path >=0.9.2 && <0.10-    , template-haskell >=2.16 && <2.18+    , template-haskell >=2.17 && <2.24   default-language: Haskell2010  test-suite strong-path-test@@ -69,13 +69,13 @@   ghc-options: -threaded -rtsopts -with-rtsopts=-N   build-depends:       base >=4.7 && <5-    , filepath-    , hashable ==1.3.*-    , hspec >=2.7 && <2.10-    , path+    , filepath >=1.4 && <1.6+    , hashable >=1.3 && <1.6+    , hspec >=2.8 && <2.12+    , path >=0.9.2 && <0.10     , strong-path-    , tasty ==1.4.*-    , tasty-discover ==4.2.*-    , tasty-hspec >=1.1 && <1.3-    , tasty-quickcheck ==0.10.*+    , tasty >=1.4 && <1.6+    , tasty-discover >=4.2 && <5.3+    , tasty-hspec ==1.2.*+    , tasty-quickcheck >=0.10 && <0.12   default-language: Haskell2010
test/StrongPath/InstanceTest.hs view
test/Test/Utils.hs view
@@ -13,16 +13,17 @@  -- | Takes posix path and converts it into windows path if running on Windows or leaves as it is if on Unix. posixToSystemFp :: FilePath -> FilePath-posixToSystemFp posixFp = maybeSystemRoot ++ systemFpRootless-  where-    maybeSystemRoot = if head posixFp == '/' then systemFpRoot else ""-    posixFpRootless = if head posixFp == '/' then tail posixFp else posixFp-    systemFpRootless = map (\c -> if c == '/' then FP.pathSeparator else c) posixFpRootless+posixToSystemFp = convertPosixFp systemFpRoot FP.pathSeparator  -- | Takes posix path and converts it into windows path. posixToWindowsFp :: FilePath -> FilePath-posixToWindowsFp posixFp = maybeWinRoot ++ winFpRootless+posixToWindowsFp = convertPosixFp "C:\\" FPW.pathSeparator++convertPosixFp :: FilePath -> Char -> FilePath -> FilePath+convertPosixFp newRoot newSeparator posixFp =+  case posixFp of+    "" -> error "Empty string is not a valid posix path."+    '/' : restOfAbsPosixFp -> newRoot ++ map convertSeparator restOfAbsPosixFp+    relPosixFp -> map convertSeparator relPosixFp   where-    maybeWinRoot = if head posixFp == '/' then "C:\\" else ""-    posixFpRootless = if head posixFp == '/' then tail posixFp else posixFp-    winFpRootless = map (\c -> if c == '/' then FPW.pathSeparator else c) posixFpRootless+    convertSeparator c = if c == '/' then newSeparator else c