wasp/waspc/test/Test/Util.hs

26 lines
1.0 KiB
Haskell
Raw Normal View History

module Test.Util
2021-04-28 18:36:00 +03:00
( posixToSystemFp,
posixToWindowsFp,
)
where
2021-04-28 18:36:00 +03:00
import Fixtures (systemFpRoot)
import qualified System.FilePath as FP
import qualified System.FilePath.Windows as FPW
-- | 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
-- | 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