Skip to content

Commit

Permalink
Expose/add combineAlways and (</>)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Dec 3, 2021
1 parent 0b87163 commit 94ce707
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["<\\>", "</>","<.>","-<.>"]


---------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions System/FilePath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ module System.FilePath(
takeBaseName, replaceBaseName,
takeDirectory, replaceDirectory,
combine, (</>),
combineAlways, (<\>),
splitPath, joinPath, splitDirectories,

-- * Drive functions
Expand Down Expand Up @@ -131,6 +132,7 @@ module System.FilePath(
takeBaseName, replaceBaseName,
takeDirectory, replaceDirectory,
combine, (</>),
combineAlways, (<\>),
splitPath, joinPath, splitDirectories,

-- * Drive functions
Expand Down
20 changes: 20 additions & 0 deletions System/FilePath/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module System.FilePath.MODULE_NAME
takeBaseName, replaceBaseName,
takeDirectory, replaceDirectory,
combine, (</>),
combineAlways, (<\>),
splitPath, joinPath, splitDirectories,

-- * Drive functions
Expand Down Expand Up @@ -117,6 +118,7 @@ import System.Environment(getEnv)

infixr 7 <.>, -<.>
infixr 5 </>
infixr 5 <\>



Expand Down Expand Up @@ -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"]
Expand Down
20 changes: 20 additions & 0 deletions System/FilePath/Posix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module System.FilePath.Posix
takeBaseName, replaceBaseName,
takeDirectory, replaceDirectory,
combine, (</>),
combineAlways, (<\>),
splitPath, joinPath, splitDirectories,

-- * Drive functions
Expand Down Expand Up @@ -117,6 +118,7 @@ import System.Environment(getEnv)

infixr 7 <.>, -<.>
infixr 5 </>
infixr 5 <\>



Expand Down Expand Up @@ -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"]
Expand Down
20 changes: 20 additions & 0 deletions System/FilePath/Windows.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module System.FilePath.Windows
takeBaseName, replaceBaseName,
takeDirectory, replaceDirectory,
combine, (</>),
combineAlways, (<\>),
splitPath, joinPath, splitDirectories,

-- * Drive functions
Expand Down Expand Up @@ -117,6 +118,7 @@ import System.Environment(getEnv)

infixr 7 <.>, -<.>
infixr 5 </>
infixr 5 <\>



Expand Down Expand Up @@ -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"]
Expand Down
13 changes: 13 additions & 0 deletions tests/TestGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 94ce707

Please sign in to comment.