2020-09-17 16:41:59 +03:00
|
|
|
module Test.Util
|
2021-04-28 18:36:00 +03:00
|
|
|
( posixToSystemFp,
|
|
|
|
posixToWindowsFp,
|
|
|
|
)
|
|
|
|
where
|
2020-09-17 16:41:59 +03:00
|
|
|
|
2021-04-28 18:36:00 +03:00
|
|
|
import Fixtures (systemFpRoot)
|
|
|
|
import qualified System.FilePath as FP
|
2020-10-02 18:22:56 +03:00
|
|
|
import qualified System.FilePath.Windows as FPW
|
|
|
|
|
2020-09-17 16:41:59 +03:00
|
|
|
-- | 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
|
2021-04-28 18:36:00 +03:00
|
|
|
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
|
2020-10-02 18:22:56 +03:00
|
|
|
|
|
|
|
-- | Takes posix path and converts it into windows path.
|
|
|
|
posixToWindowsFp :: FilePath -> FilePath
|
|
|
|
posixToWindowsFp posixFp = maybeWinRoot ++ winFpRootless
|
2021-04-28 18:36:00 +03:00
|
|
|
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
|