Replaced couple of last usages of Path with StrongPath.

This commit is contained in:
Martin Sosic 2021-07-05 17:37:43 +02:00 committed by Martin Šošić
parent 3bae54c3e8
commit eae7b20938
4 changed files with 17 additions and 22 deletions

View File

@ -1,11 +1,9 @@
module Path.Extra
module FilePath.Extra
( reversePosixPath,
toPosixFilePath,
)
where
import Control.Exception (assert)
import Path
import qualified System.FilePath.Posix as FPP
-- | For given posix path P, returns posix path P', such that (terminal pseudocode incoming)
@ -22,6 +20,3 @@ reversePosixPath path
where
parts :: [String]
parts = filter (/= ".") $ FPP.splitDirectories path
toPosixFilePath :: Path Rel a -> FilePath
toPosixFilePath path = map (\c -> if c == '\\' then '/' else c) $ toFilePath path

View File

@ -8,10 +8,10 @@ import Data.Maybe (fromJust)
import Data.Text (Text, unpack)
import qualified Data.Text as T
import qualified ExternalCode as EC
import FilePath.Extra (reversePosixPath)
import Generator.ExternalCodeGenerator.Common (GeneratedExternalCodeDir)
import qualified Generator.ExternalCodeGenerator.Common as C
import qualified Generator.FileDraft as FD
import Path.Extra (reversePosixPath)
import StrongPath (Dir, File', Path', Rel, (</>))
import qualified StrongPath as SP
import qualified Text.Regex.TDFA as TR

View File

@ -0,0 +1,15 @@
module FilePath.ExtraTest where
import qualified FilePath.Extra as PE
import StrongPath (reldirP, toFilePath)
import Test.Tasty.Hspec
spec_reversePosixPath :: Spec
spec_reversePosixPath = do
[reldirP|.|] ~> "."
[reldirP|foo|] ~> ".."
[reldirP|foo/bar|] ~> "../.."
[reldirP|./foo/bar/./test|] ~> "../../.."
where
path ~> expectedReversedPath = it (show path ++ " -> " ++ expectedReversedPath) $ do
PE.reversePosixPath (toFilePath path) `shouldBe` expectedReversedPath

View File

@ -1,15 +0,0 @@
module Path.ExtraTest where
import Path (reldir)
import qualified Path.Extra as PE
import Test.Tasty.Hspec
spec_reversePosixPath :: Spec
spec_reversePosixPath = do
[reldir|.|] ~> "."
[reldir|foo|] ~> ".."
[reldir|foo/bar|] ~> "../.."
[reldir|./foo/bar/./test|] ~> "../../.."
where
path ~> expectedReversedPath = it ((show path) ++ " -> " ++ expectedReversedPath) $ do
PE.reversePosixPath (PE.toPosixFilePath path) `shouldBe` expectedReversedPath