From bb0de3dec2a610a3789c0fd02dd9e018e239b487 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Sat, 18 Jan 2020 17:05:32 +0000 Subject: Begin tests for Haskell File module Cameron sent over some property tests for his File.split function, which is a part of a larger effort to port f.el, a nice library for working with file paths, over to Haskell. --- haskell-file/f.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'haskell-file/f.hs') diff --git a/haskell-file/f.hs b/haskell-file/f.hs index 9ddb930ee103..295575f3f48d 100644 --- a/haskell-file/f.hs +++ b/haskell-file/f.hs @@ -1,7 +1,14 @@ module F ( join + , split ) where +-------------------------------------------------------------------------------- +-- Dependencies +-------------------------------------------------------------------------------- + +import Data.List (span) +import System.FilePath (FilePath, pathSeparator) import System.FilePath.Posix (FilePath) import qualified System.FilePath.Posix as F @@ -25,6 +32,16 @@ simpleAssert x y = join :: [FilePath] -> FilePath join = F.joinPath +-- | Split path and return list containing parts. +split :: FilePath -> [String] +split = splitJoin . span (/= pathSeparator) + where + splitJoin :: (String, String) -> [String] + splitJoin ([], []) = [] + splitJoin (a, []) = [a] + splitJoin (a, [_]) = [a] + splitJoin (a, _:b) = a : split b + -------------------------------------------------------------------------------- -- Tests -------------------------------------------------------------------------------- -- cgit 1.4.1