hscaffold 0.4.2.0 → 0.4.3.0
raw patch · 4 files changed
+29/−19 lines, 4 files
Files
- hscaffold.cabal +1/−1
- src/Hscaffold.hs +1/−0
- src/Hscaffold/Generator/Directory.hs +8/−14
- test/HscaffoldSpec.hs +19/−4
hscaffold.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: hscaffold-version: 0.4.2.0+version: 0.4.3.0 synopsis: Very simple file/directory structure scaffolding writer monad EDSL description: See our README on GitHub at <https://github.com/yamadapc/hscaffold> homepage: https://github.com/yamadapc/hscaffold#readme
src/Hscaffold.hs view
@@ -18,6 +18,7 @@ , readHsfiles -- * Convert a directory to Hscaffold , hscaffoldFromDirectory+ , hscaffoldFromDirectoryWith -- * Compile Hscaffold to Haskell code , hscaffoldToHaskell -- ** Finer grained runners
src/Hscaffold/Generator/Directory.hs view
@@ -17,26 +17,20 @@ hscaffoldFromDirectoryWith :: ([FilePath] -> [FilePath]) -> FilePath -> IO (ScaffoldAction e)-hscaffoldFromDirectoryWith =- hscaffoldFromDirectoryWith' False--hscaffoldFromDirectoryWith' :: Traversable t- => Bool- -> ([FilePath] -> t FilePath)- -> FilePath- -> IO [ScaffoldActionType e]-hscaffoldFromDirectoryWith' isRecur p root = do+hscaffoldFromDirectoryWith p root = do ls <- p <$> getDirectoryContents root concat <$> mapM classify ls where- fromFile fp' fp = do+ fromFile fp fp' = do txt <- Text.readFile fp'- return [ File (normalise fp) txt ]- fromDir = hscaffoldFromDirectoryWith' True p+ return [ File fp txt ]+ fromDir fp fp' = do+ children <- hscaffoldFromDirectoryWith p fp'+ return [ Directory fp children ] classify fp = do let fp' = root </> fp isfl <- doesFileExist fp' isdir <- doesDirectoryExist fp' if isfl- then fromFile fp' (if isRecur then fp' else fp)- else if isdir then fromDir fp' else return []+ then fromFile fp fp'+ else if isdir then fromDir fp fp' else return []
test/HscaffoldSpec.hs view
@@ -4,6 +4,7 @@ import Control.Exception import Control.Monad+import Data.List import Data.Maybe import qualified Data.Text as Text import Hscaffold@@ -135,12 +136,26 @@ it "ignores git" $ do h <- hscaffoldFromDirectory "." :: IO (ScaffoldActionV) let ms = mapMaybe (\x -> case x of- File fp _ -> Just fp+ File fp _ -> Just ("file", fp)+ Directory fp _ -> Just ("directory", fp) _ -> Nothing) h- ms `shouldNotContain` [ ".git/index" ]- ms `shouldContain` [ "README.md" ]- ms `shouldContain` [ "test/Spec.hs" ]+ ms `shouldNotContain` [ ("directory", ".git") ]+ ms `shouldContain` [ ("file", "README.md") ]+ ms `shouldContain` [ ("directory", "test") ]++ let (Just (Directory _ fs)) = find (\d -> case d of+ Directory "src" _ -> True+ _ -> False+ ) h+ map (\x -> case x of Directory f _ -> f ; File f _ -> f) fs+ `shouldBe` ["Hscaffold", "Hscaffold.hs"]+ let (Just (Directory _ fs')) = find (\d -> case d of+ Directory "Hscaffold" _ -> True+ _ -> False+ ) fs+ map (\x -> case x of Directory f _ -> f ; File f _ -> f) fs'+ `shouldBe` ["EDSL.hs", "Generator", "Interpreter", "Types.hs"] describe "the runner" $ describe "runAction" $ do