From 94ce707d1be0845c292ac154282fef93fde2aab4 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Fri, 3 Dec 2021 17:50:34 +0100 Subject: [PATCH] Expose/add combineAlways and () --- Generate.hs | 2 +- System/FilePath.hs | 2 ++ System/FilePath/Internal.hs | 20 ++++++++++++++++++++ System/FilePath/Posix.hs | 20 ++++++++++++++++++++ System/FilePath/Windows.hs | 20 ++++++++++++++++++++ tests/TestGen.hs | 13 +++++++++++++ 6 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Generate.hs b/Generate.hs index 6937b2ae..67523c5c 100755 --- a/Generate.hs +++ b/Generate.hs @@ -87,7 +87,7 @@ qualify pw str where prelude = ["elem","uncurry","snd","fst","not","null","if","then","else" ,"True","False","Just","Nothing","fromJust","concat","isPrefixOf","isSuffixOf","any","foldr"] - fpops = ["","<.>","-<.>"] + fpops = ["<\\>", "","<.>","-<.>"] --------------------------------------------------------------------- diff --git a/System/FilePath.hs b/System/FilePath.hs index 0feea8da..430f0d36 100644 --- a/System/FilePath.hs +++ b/System/FilePath.hs @@ -85,6 +85,7 @@ module System.FilePath( takeBaseName, replaceBaseName, takeDirectory, replaceDirectory, combine, (), + combineAlways, (<\>), splitPath, joinPath, splitDirectories, -- * Drive functions @@ -131,6 +132,7 @@ module System.FilePath( takeBaseName, replaceBaseName, takeDirectory, replaceDirectory, combine, (), + combineAlways, (<\>), splitPath, joinPath, splitDirectories, -- * Drive functions diff --git a/System/FilePath/Internal.hs b/System/FilePath/Internal.hs index 4f7dea42..955075e3 100644 --- a/System/FilePath/Internal.hs +++ b/System/FilePath/Internal.hs @@ -84,6 +84,7 @@ module System.FilePath.MODULE_NAME takeBaseName, replaceBaseName, takeDirectory, replaceDirectory, combine, (), + combineAlways, (<\>), splitPath, joinPath, splitDirectories, -- * Drive functions @@ -117,6 +118,7 @@ import System.Environment(getEnv) infixr 7 <.>, -<.> infixr 5 +infixr 5 <\> @@ -744,6 +746,24 @@ combineAlways a b | null a = b () = combine +-- | Combine two paths, assuming rhs is NOT absolute. +-- +-- > Posix: "/directory" <\> "file.ext" == "/directory/file.ext" +-- > Windows: "/directory" <\> "file.ext" == "/directory\\file.ext" +-- > Valid x => (takeDirectory x <\> takeFileName x) `equalFilePath` x +-- > Posix: "/" <\> "test" == "/test" +-- > Posix: "home" <\> "bob" == "home/bob" +-- > Posix: "x:" <\> "foo" == "x:/foo" +-- > Windows: "C:\\foo" <\> "bar" == "C:\\foo\\bar" +-- > Windows: "home" <\> "bob" == "home\\bob" +-- > Posix: "home" <\> "/bob" == "home//bob" +-- > Windows: "home" <\> "C:\\bob" == "home\\C:\\bob" +-- > Windows: "D:\\foo" <\> "C:bar" == "D:\\foo\\C:bar" +-- > Windows: "C:\\foo" <\> "C:bar" == "C:\\foo\\C:bar" +(<\>) :: FilePath -> FilePath -> FilePath +(<\>) = combineAlways + + -- | Split a path by the directory separator. -- -- > splitPath "/directory/file.ext" == ["/","directory/","file.ext"] diff --git a/System/FilePath/Posix.hs b/System/FilePath/Posix.hs index 1889c46b..87dea27e 100644 --- a/System/FilePath/Posix.hs +++ b/System/FilePath/Posix.hs @@ -84,6 +84,7 @@ module System.FilePath.Posix takeBaseName, replaceBaseName, takeDirectory, replaceDirectory, combine, (), + combineAlways, (<\>), splitPath, joinPath, splitDirectories, -- * Drive functions @@ -117,6 +118,7 @@ import System.Environment(getEnv) infixr 7 <.>, -<.> infixr 5 +infixr 5 <\> @@ -744,6 +746,24 @@ combineAlways a b | null a = b () = combine +-- | Combine two paths, assuming rhs is NOT absolute. +-- +-- > Posix: "/directory" <\> "file.ext" == "/directory/file.ext" +-- > Windows: "/directory" <\> "file.ext" == "/directory\\file.ext" +-- > Valid x => (takeDirectory x <\> takeFileName x) `equalFilePath` x +-- > Posix: "/" <\> "test" == "/test" +-- > Posix: "home" <\> "bob" == "home/bob" +-- > Posix: "x:" <\> "foo" == "x:/foo" +-- > Windows: "C:\\foo" <\> "bar" == "C:\\foo\\bar" +-- > Windows: "home" <\> "bob" == "home\\bob" +-- > Posix: "home" <\> "/bob" == "home//bob" +-- > Windows: "home" <\> "C:\\bob" == "home\\C:\\bob" +-- > Windows: "D:\\foo" <\> "C:bar" == "D:\\foo\\C:bar" +-- > Windows: "C:\\foo" <\> "C:bar" == "C:\\foo\\C:bar" +(<\>) :: FilePath -> FilePath -> FilePath +(<\>) = combineAlways + + -- | Split a path by the directory separator. -- -- > splitPath "/directory/file.ext" == ["/","directory/","file.ext"] diff --git a/System/FilePath/Windows.hs b/System/FilePath/Windows.hs index c5e56557..2643bcdc 100644 --- a/System/FilePath/Windows.hs +++ b/System/FilePath/Windows.hs @@ -84,6 +84,7 @@ module System.FilePath.Windows takeBaseName, replaceBaseName, takeDirectory, replaceDirectory, combine, (), + combineAlways, (<\>), splitPath, joinPath, splitDirectories, -- * Drive functions @@ -117,6 +118,7 @@ import System.Environment(getEnv) infixr 7 <.>, -<.> infixr 5 +infixr 5 <\> @@ -744,6 +746,24 @@ combineAlways a b | null a = b () = combine +-- | Combine two paths, assuming rhs is NOT absolute. +-- +-- > Posix: "/directory" <\> "file.ext" == "/directory/file.ext" +-- > Windows: "/directory" <\> "file.ext" == "/directory\\file.ext" +-- > Valid x => (takeDirectory x <\> takeFileName x) `equalFilePath` x +-- > Posix: "/" <\> "test" == "/test" +-- > Posix: "home" <\> "bob" == "home/bob" +-- > Posix: "x:" <\> "foo" == "x:/foo" +-- > Windows: "C:\\foo" <\> "bar" == "C:\\foo\\bar" +-- > Windows: "home" <\> "bob" == "home\\bob" +-- > Posix: "home" <\> "/bob" == "home//bob" +-- > Windows: "home" <\> "C:\\bob" == "home\\C:\\bob" +-- > Windows: "D:\\foo" <\> "C:bar" == "D:\\foo\\C:bar" +-- > Windows: "C:\\foo" <\> "C:bar" == "C:\\foo\\C:bar" +(<\>) :: FilePath -> FilePath -> FilePath +(<\>) = combineAlways + + -- | Split a path by the directory separator. -- -- > splitPath "/directory/file.ext" == ["/","directory/","file.ext"] diff --git a/tests/TestGen.hs b/tests/TestGen.hs index 0fe5ce38..37a25ff7 100755 --- a/tests/TestGen.hs +++ b/tests/TestGen.hs @@ -336,6 +336,19 @@ tests = ,("\"C:\\\\home\" W. \"\\\\bob\" == \"\\\\bob\"", property $ "C:\\home" W. "\\bob" == "\\bob") ,("\"D:\\\\foo\" W. \"C:bar\" == \"C:bar\"", property $ "D:\\foo" W. "C:bar" == "C:bar") ,("\"C:\\\\foo\" W. \"C:bar\" == \"C:bar\"", property $ "C:\\foo" W. "C:bar" == "C:bar") + ,("\"/directory\" P.<\\> \"file.ext\" == \"/directory/file.ext\"", property $ "/directory" P.<\> "file.ext" == "/directory/file.ext") + ,("\"/directory\" W.<\\> \"file.ext\" == \"/directory\\\\file.ext\"", property $ "/directory" W.<\> "file.ext" == "/directory\\file.ext") + ,("(P.takeDirectory x P.<\\> P.takeFileName x) `P.equalFilePath` x", property $ \(QFilePathValidP x) -> (P.takeDirectory x P.<\> P.takeFileName x) `P.equalFilePath` x) + ,("(W.takeDirectory x W.<\\> W.takeFileName x) `W.equalFilePath` x", property $ \(QFilePathValidW x) -> (W.takeDirectory x W.<\> W.takeFileName x) `W.equalFilePath` x) + ,("\"/\" P.<\\> \"test\" == \"/test\"", property $ "/" P.<\> "test" == "/test") + ,("\"home\" P.<\\> \"bob\" == \"home/bob\"", property $ "home" P.<\> "bob" == "home/bob") + ,("\"x:\" P.<\\> \"foo\" == \"x:/foo\"", property $ "x:" P.<\> "foo" == "x:/foo") + ,("\"C:\\\\foo\" W.<\\> \"bar\" == \"C:\\\\foo\\\\bar\"", property $ "C:\\foo" W.<\> "bar" == "C:\\foo\\bar") + ,("\"home\" W.<\\> \"bob\" == \"home\\\\bob\"", property $ "home" W.<\> "bob" == "home\\bob") + ,("\"home\" P.<\\> \"/bob\" == \"home//bob\"", property $ "home" P.<\> "/bob" == "home//bob") + ,("\"home\" W.<\\> \"C:\\\\bob\" == \"home\\\\C:\\\\bob\"", property $ "home" W.<\> "C:\\bob" == "home\\C:\\bob") + ,("\"D:\\\\foo\" W.<\\> \"C:bar\" == \"D:\\\\foo\\\\C:bar\"", property $ "D:\\foo" W.<\> "C:bar" == "D:\\foo\\C:bar") + ,("\"C:\\\\foo\" W.<\\> \"C:bar\" == \"C:\\\\foo\\\\C:bar\"", property $ "C:\\foo" W.<\> "C:bar" == "C:\\foo\\C:bar") ,("P.splitPath \"/directory/file.ext\" == [\"/\", \"directory/\", \"file.ext\"]", property $ P.splitPath "/directory/file.ext" == ["/", "directory/", "file.ext"]) ,("W.splitPath \"/directory/file.ext\" == [\"/\", \"directory/\", \"file.ext\"]", property $ W.splitPath "/directory/file.ext" == ["/", "directory/", "file.ext"]) ,("concat (P.splitPath x) == x", property $ \(QFilePath x) -> concat (P.splitPath x) == x)