validity-path 0.2.0.2 → 0.3.0.0
raw patch · 4 files changed
+176/−123 lines, 4 filesdep +genvalidity-hspecdep +hspecdep +validity-pathdep ~basedep ~validity
Dependencies added: genvalidity-hspec, hspec, validity-path
Dependency ranges changed: base, validity
Files
- src/Data/Validity/Path.hs +43/−98
- test/Data/Validity/PathSpec.hs +80/−0
- test/Spec.hs +1/−0
- validity-path.cabal +52/−25
src/Data/Validity/Path.hs view
@@ -9,11 +9,7 @@ import Path import Path.Internal -import Data.List ( isInfixOf-#if MIN_VERSION_path(0,6,0)- , isSuffixOf-#endif- )+import Data.List (isInfixOf, isSuffixOf) import qualified System.FilePath as FilePath @@ -23,39 +19,27 @@ -- * Its path is an absolute path -- * Its path has no trailing path separators -- * Its path is valid according to 'System.FilePath's definition.-#if MIN_VERSION_path(0,6,0) -- * Its path does not end in '/.'+#if MIN_VERSION_path(0,6,0) -- * Its path is not '.' #endif -- * Its path does not contain '..'. -- * Parsing the path and rendering it again results in the same path. instance Validity (Path Abs File) where- isValid p@(Path fp) =- and- [ FilePath.isAbsolute fp- , not (FilePath.hasTrailingPathSeparator fp)- , FilePath.isValid fp-#if MIN_VERSION_path(0,6,0)- , not ("/." `isSuffixOf` fp)- , fp /= "."-#endif- , not (".." `isInfixOf` fp)- , parseAbsFile fp == Just p- ] validate p@(Path fp) = mconcat- [ FilePath.isAbsolute fp <?@> "The path is absolute."- , not (FilePath.hasTrailingPathSeparator fp) <?@>- "The path has no trailing path separator."- , FilePath.isValid fp <?@>- "System.FilePath considers the path valid."+ [ declare "The path is absolute." $ FilePath.isAbsolute fp+ , declare "The path has no trailing path separator." $+ not (FilePath.hasTrailingPathSeparator fp)+ , declare "System.FilePath considers the path valid." $+ FilePath.isValid fp+ , declare "The path does not end in /." $ not ("/." `isSuffixOf` fp) #if MIN_VERSION_path(0,6,0)- , not ("/." `isSuffixOf` fp) <?@> "The path does not end in /."- , fp /= "." <?@> "The path does not equal \".\""+ , declare "The path does not equal \".\"" $ fp /= "." #endif- , not (".." `isInfixOf` fp) <?@> "The path does not contain '..'."- , (parseAbsFile fp == Just p) <?@>- "The path can be identically parsed as an absolute file path."+ , declare "The path does not contain '..'." $ not (".." `isInfixOf` fp)+ , declare "The path can be identically parsed as an absolute file path." $+ parseAbsFile fp == Just p ] -- | A relative path to a file is valid if:@@ -63,45 +47,30 @@ -- * Its path is a relative path -- * Its path does not have a trailing path separator -- * Its path is valid according to 'System.FilePath's definition.+-- * Its path is not '.'+-- * Its path is not empty #if MIN_VERSION_path(0,6,0) -- * Its path does not end in '/.'--- * Its path is not '.'--- * Its path is not '' #endif -- * Its path is not '.' -- * Its path does not contain '..'. -- * Parsing the path and rendering it again results in the same path. instance Validity (Path Rel File) where- isValid p@(Path fp) =- and- [ FilePath.isRelative fp- , not (FilePath.hasTrailingPathSeparator fp)- , FilePath.isValid fp-#if MIN_VERSION_path(0,6,0)- , not ("/." `isSuffixOf` fp)- , fp /= "."- , fp /= ""-#endif- , fp /= "."- , not (".." `isInfixOf` fp)- , parseRelFile fp == Just p- ] validate p@(Path fp) = mconcat- [ FilePath.isRelative fp <?@> "The path is relative."- , not (FilePath.hasTrailingPathSeparator fp) <?@>- "The path has no trailing path separator."- , FilePath.isValid fp <?@>- "System.FilePath considers the path valid."- , fp /= "." <?@> "The path does not equal \".\"."+ [ declare "The path is relative." $ FilePath.isRelative fp+ , declare "The path has no trailing path separator." $+ not (FilePath.hasTrailingPathSeparator fp)+ , declare "System.FilePath considers the path valid." $+ FilePath.isValid fp+ , declare "The path does not equal \".\"" $ fp /= "."+ , declare "The path is not empty" $ not (null fp) #if MIN_VERSION_path(0,6,0)- , not ("/." `isSuffixOf` fp) <?@> "The path does not end in /."- , fp /= "." <?@> "The path is not '.'"- , fp /= "" <?@> "The path is not ''"+ , declare "The path does not end in /." $ not ("/." `isSuffixOf` fp) #endif- , not (".." `isInfixOf` fp) <?@> "The path does not contain '..'."- , (parseRelFile fp == Just p) <?@>- "The path can be identically parsed as a relative file path."+ , declare "The path does not contain '..'." $ not (".." `isInfixOf` fp)+ , declare "The path can be identically parsed as a relative file path." $+ parseRelFile fp == Just p ] -- | An absolute path to a directory is valid if:@@ -112,24 +81,16 @@ -- * Its path does not contain '..'. -- * Parsing the path and rendering it again results in the same path. instance Validity (Path Abs Dir) where- isValid p@(Path fp) =- and- [ FilePath.isAbsolute fp- , FilePath.hasTrailingPathSeparator fp- , FilePath.isValid fp- , not (".." `isInfixOf` fp)- , parseAbsDir fp == Just p- ] validate p@(Path fp) = mconcat- [ FilePath.isAbsolute fp <?@> "The path is absolute."- , FilePath.hasTrailingPathSeparator fp <?@>- "The path has a trailing path separator."- , FilePath.isValid fp <?@>- "System.FilePath considers the path valid."- , not (".." `isInfixOf` fp) <?@> "The path does not contain '..'."- , (parseAbsDir fp == Just p) <?@>- "The path can be identically parsed as an absolute directory path."+ [ declare "The path is absolute." $ FilePath.isAbsolute fp+ , declare "The path has a trailing path separator." $+ FilePath.hasTrailingPathSeparator fp+ , declare "System.FilePath considers the path valid." $+ FilePath.isValid fp+ , declare "The path does not contain '..'." $ not (".." `isInfixOf` fp)+ , declare "The path can be identically parsed as an absolute directory path." $+ parseAbsDir fp == Just p ] -- | A relative path to a directory is valid if:@@ -138,41 +99,25 @@ -- * Its path has a trailing path separator -- * Its path is valid according to 'System.FilePath's definition. #if MIN_VERSION_path(0,6,0)--- * Its path is not '' #else -- * Its path is not '.' #endif -- * Its path does not contain '..'. -- * Parsing the path and rendering it again results in the same path. instance Validity (Path Rel Dir) where- isValid p@(Path fp) =- and- [ FilePath.isRelative fp- , FilePath.hasTrailingPathSeparator fp- , FilePath.isValid fp- , not (null fp)-#if MIN_VERSION_path(0,6,0)- , fp /= "."-#else- , fp /= ""-#endif- , not (".." `isInfixOf` fp)- , parseRelDir fp == Just p- ] validate p@(Path fp) = mconcat- [ FilePath.isRelative fp <?@> "The path is relattive."- , FilePath.hasTrailingPathSeparator fp <?@>- "The path has a trailing path separator."- , FilePath.isValid fp <?@>- "System.FilePath considers the path valid."- , not (null fp) <?@> "The path is not empty."+ [ declare "The path is relative." $ FilePath.isRelative fp+ , declare "The path has a trailing path separator." $+ FilePath.hasTrailingPathSeparator fp+ , declare "System.FilePath considers the path valid." $+ FilePath.isValid fp+ , declare "The path is not empty." $ not (null fp) #if MIN_VERSION_path(0,6,0)- , fp /= "." <?@> "The path does not equal \".\"." #else- , fp /= "" <?@> "The path does not equal \"\"."+ , declare "The path does not equal \".\"" $ fp /= "." #endif- , not (".." `isInfixOf` fp) <?@> "The path does not contain '..'."- , (parseRelDir fp == Just p) <?@>- "The path can be identically parsed as a relative directory path."+ , declare "The path does not contain '..'." $ not (".." `isInfixOf` fp)+ , declare "The path can be identically parsed as a relative directory path." $+ parseRelDir fp == Just p ]
+ test/Data/Validity/PathSpec.hs view
@@ -0,0 +1,80 @@+module Data.Validity.PathSpec+ ( spec+ ) where++import Test.Hspec+import Test.Validity++import qualified System.FilePath++import Control.Monad++import Data.Validity.Path ()++import Path+import Path.Internal++spec :: Spec+spec = do+ describe "Path Abs File" $ do+ let p :: String -> Path Abs File+ p = Path+ it "negatively checks for absolute paths" $ shouldBeInvalid $ p "./test"+ it "positively checks for absolute paths" $ shouldBeValid $ p "/test"+ it "checks for absolute paths" $+ forAllValid $ \path ->+ unless (System.FilePath.isAbsolute path) $+ shouldBeInvalid $ p path+ it "negatively checks for trailing path separators" $+ shouldBeInvalid $ p "/test/"+ it "positively checks for trailing path separators" $+ shouldBeValid $ p "/test"+ it "negatively checks for being \".\"" $ shouldBeInvalid $ p "."+ it "negatively checks for ending in \"/.\"" $+ shouldBeInvalid $ p "/test/."+ it "negatively checks for containing \"..\"" $+ shouldBeInvalid $ p "/test/../file"+ it "checks for isValid from System.FilePath" $+ forAllValid $ \path ->+ unless (System.FilePath.isValid path) $ shouldBeInvalid $ p path+ describe "Path Rel File" $ do+ let p :: String -> Path Rel File+ p = Path+ it "checks for relative paths" $+ forAllValid $ \path ->+ unless (System.FilePath.isRelative path) $+ shouldBeInvalid $ p path+ it "checks that the path is not empty" $ shouldBeInvalid $ p ""+ it "negatively checks for being \".\"" $ shouldBeInvalid $ p "."+ it "negatively checks for ending in \"/.\"" $+ shouldBeInvalid $ p "test/."+ it "negatively checks for containing \"..\"" $+ shouldBeInvalid $ p "/test/../file"+ it "checks for isValid from System.FilePath" $+ forAllValid $ \path ->+ unless (System.FilePath.isValid path) $ shouldBeInvalid $ p path+ describe "Path Abs Dir" $ do+ let p :: String -> Path Abs Dir+ p = Path+ it "checks for absolute paths" $+ forAllValid $ \path ->+ unless (System.FilePath.isAbsolute path) $+ shouldBeInvalid $ p path+ it "negatively checks for containing \"..\"" $+ shouldBeInvalid $ p "/test/../dir"+ it "checks for isValid from System.FilePath" $+ forAllValid $ \path ->+ unless (System.FilePath.isValid path) $ shouldBeInvalid $ p path+ describe "Path Rel Dir" $ do+ let p :: String -> Path Rel Dir+ p = Path+ it "checks for relative paths" $+ forAllValid $ \path ->+ unless (System.FilePath.isRelative path) $+ shouldBeInvalid $ p path+ it "checks that the path is not empty" $ shouldBeInvalid $ p ""+ it "negatively checks for containing \"..\"" $+ shouldBeInvalid $ p "test/../dir"+ it "checks for isValid from System.FilePath" $+ forAllValid $ \path ->+ unless (System.FilePath.isValid path) $ shouldBeInvalid $ p path
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
validity-path.cabal view
@@ -1,30 +1,57 @@-name: validity-path-version: 0.2.0.2-cabal-version: >=1.10-build-type: Simple-license: MIT-license-file: LICENSE-copyright: Copyright: (c) 2016 Tom Sydney Kerckhove-maintainer: syd.kerckhove@gmail.com-homepage: https://github.com/NorfairKing/validity#readme-synopsis: Validity instances for Path-description:- Please see README.md-category: Validity-author: Tom Sydney Kerckhove+-- This file has been generated from package.yaml by hpack version 0.20.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: b49abc1f65b60f196d83c1d39427089005710f59b9f0eeabde8beea232e32ab1 +name: validity-path+version: 0.3.0.0+synopsis: Validity instances for Path+description: Please see README.md+category: Validity+homepage: https://github.com/NorfairKing/validity#readme+bug-reports: https://github.com/NorfairKing/validity/issues+author: Tom Sydney Kerckhove+maintainer: syd.kerckhove@gmail.com+copyright: Copyright: (c) 2016-2018 Tom Sydney Kerckhove+license: MIT+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10+ source-repository head- type: git- location: https://github.com/NorfairKing/validity+ type: git+ location: https://github.com/NorfairKing/validity library- exposed-modules:- Data.Validity.Path- build-depends:- base >=4.7 && <5,- validity >=0.4 && <0.5,- path >=0.5 && <0.7,- filepath >=1.3 && <1.5- default-language: Haskell2010- hs-source-dirs: src+ hs-source-dirs:+ src+ build-depends:+ base >=4.7 && <5+ , filepath >=1.3 && <1.5+ , path >=0.5 && <0.7+ , validity >=0.5 && <0.6+ exposed-modules:+ Data.Validity.Path+ other-modules:+ Paths_validity_path+ default-language: Haskell2010 +test-suite validity-path-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ hs-source-dirs:+ test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall+ build-depends:+ base+ , filepath >=1.3 && <1.5+ , genvalidity-hspec+ , hspec+ , path >=0.5 && <0.7+ , validity >=0.5 && <0.6+ , validity-path+ other-modules:+ Data.Validity.PathSpec+ Paths_validity_path+ default-language: Haskell2010