shikensu 0.3.6 → 0.3.7
raw patch · 9 files changed
+83/−50 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- shikensu.cabal +1/−1
- src/Shikensu.hs +2/−2
- src/Shikensu/Internal/Utilities.hs +1/−1
- tests/Test.hs +4/−4
- tests/Test/Contrib.hs +32/−21
- tests/Test/Example.hs +15/−8
- tests/Test/Helpers.hs +2/−2
- tests/Test/Shikensu.hs +13/−8
- tests/Test/Utilities.hs +13/−3
shikensu.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: shikensu-version: 0.3.6+version: 0.3.7 synopsis: Run a sequence of functions on in-memory representations of files description: See README at <https://github.com/icidasset/shikensu#readme> category: Filesystem
src/Shikensu.hs view
@@ -125,10 +125,10 @@ makeDefinition rootDirname pattern absolutePath = let workingDirname = commonDirectory pattern- rootWorkingDirname = combine rootDirname workingDirname+ rootWorkingDirname = (combine rootDirname workingDirname) <> [ pathSeparator ] theAbsolutePath = normalise absolutePath- theLocalPath = dropDrive (stripPrefix rootWorkingDirname theAbsolutePath)+ theLocalPath = stripPrefix rootWorkingDirname theAbsolutePath in Definition { basename = takeBaseName theLocalPath
src/Shikensu/Internal/Utilities.hs view
@@ -40,7 +40,7 @@ compileParentPath dirname = case dirname of "" -> Nothing- _ -> Just "../"+ _ -> Just $ addTrailingPathSeparator ".." {-| Path to root.
tests/Test.hs view
@@ -1,7 +1,7 @@ module Main where -import System.Directory (canonicalizePath, removePathForcibly)-import System.FilePath (combine)+import System.Directory (getCurrentDirectory, removePathForcibly)+import System.FilePath ((</>)) import Test.Contrib import Test.Example import Test.Shikensu@@ -11,8 +11,8 @@ main :: IO () main = do- root <- canonicalizePath "./"- _ <- removePathForcibly (combine root "tests/build")+ root <- getCurrentDirectory+ _ <- removePathForcibly (root </> "tests" </> "build") defaultMain tests
tests/Test/Contrib.hs view
@@ -3,8 +3,9 @@ ) where import Data.ByteString (ByteString)+import Data.Monoid ((<>)) import Flow-import System.FilePath (joinPath)+import System.FilePath import Test.Helpers import Test.Tasty import Test.Tasty.HUnit@@ -43,13 +44,13 @@ list :: String -> IO Shikensu.Dictionary-list pattern =- Shikensu.listRelative [pattern] "."+list thePattern =+ Shikensu.listRelative [thePattern] "." example_md :: IO Shikensu.Dictionary example_md =- list "tests/fixtures/example.md"+ list $ joinPath [ "tests", "fixtures", "example.md" ] renderer :: Shikensu.Definition -> Maybe ByteString@@ -63,7 +64,12 @@ |> fmap (\c -> BS.intercalate B.empty [openingTag, c, closingTag]) +upstairs :: String+upstairs =+ addTrailingPathSeparator ".." ++ -- Tests @@ -116,12 +122,12 @@ ) example_md - definition = fmap (List.reverse .> List.head) dictionary+ definition = fmap (List.reverse .> List.head) dictionary - lookupTitle = \def -> HashMap.lookup keyA (Shikensu.metadata def)- lookupHello = \def -> HashMap.lookup keyB (Shikensu.metadata def)- lookupRemoved = \def -> HashMap.lookup keyC (Shikensu.metadata def)- lookupBasename = \def -> HashMap.lookup keyBase (Shikensu.metadata def)+ lookupTitle def = HashMap.lookup keyA (Shikensu.metadata def)+ lookupHello def = HashMap.lookup keyB (Shikensu.metadata def)+ lookupRemoved def = HashMap.lookup keyC (Shikensu.metadata def)+ lookupBasename def = HashMap.lookup keyBase (Shikensu.metadata def) in testGroup "Metadata"@@ -149,13 +155,13 @@ testGroup "Permalink" [ testCase "Should have the correct `localPath`"- $ assertDef definition Shikensu.localPath "example/index.md"+ $ assertDef definition Shikensu.localPath ("example" </> "index.md") , testCase "Should have the correct `parentPath`"- $ assertDef definition Shikensu.parentPath (Just "../")+ $ assertDef definition Shikensu.parentPath (Just upstairs) , testCase "Should have the correct `pathToRoot`"- $ assertDef definition Shikensu.pathToRoot "../"+ $ assertDef definition Shikensu.pathToRoot upstairs ] @@ -163,19 +169,22 @@ testPrefixDirname :: TestTree testPrefixDirname = let- dictionary = fmap (Contrib.prefixDirname "prefix/") (list "tests/**/example.md")+ thePrefix = addTrailingPathSeparator "prefix"+ thePattern = "tests" </> "**" </> "example.md"++ dictionary = fmap (Contrib.prefixDirname thePrefix) (list thePattern) definition = fmap List.head dictionary in testGroup "PrefixDirname" [ testCase "Should have the correct `dirname`"- $ assertDef definition Shikensu.dirname "prefix/fixtures"-- , testCase "Should have the correct `pathToRoot`"- $ assertDef definition Shikensu.pathToRoot "../../"+ $ assertDef definition Shikensu.dirname ("prefix" </> "fixtures") , testCase "Should have the correct `parentPath`"- $ assertDef definition Shikensu.parentPath (Just "../")+ $ assertDef definition Shikensu.parentPath (Just upstairs)++ , testCase "Should have the correct `pathToRoot`"+ $ assertDef definition Shikensu.pathToRoot (upstairs <> upstairs) ] @@ -228,8 +237,10 @@ testWrite :: TestTree testWrite = let- destination = "tests/build/"- dictionary = list "tests/**/example.md"+ destination = "tests" </> "build" <> [ pathSeparator ]+ thePattern = "tests" </> "**" </> "example.md"++ dictionary = list thePattern >>= Contrib.IO.read >>= Contrib.IO.write destination @@ -237,5 +248,5 @@ in testCase "Should `write`" $ fmap Shikensu.rootDirname definition- >>= \r -> readFile (joinPath [r, destination, "fixtures/example.md"])+ >>= \r -> readFile (joinPath [ r, destination, "fixtures", "example.md" ]) >>= \c -> assertEq "# Example\n" c
tests/Test/Example.hs view
@@ -3,14 +3,14 @@ ) where import Data.ByteString (ByteString)-import Data.Monoid ((<>)) import Data.Text (Text) import Flow import Prelude hiding (read) import Shikensu (Definition(..), Dictionary(..), list, makeDefinition) import Shikensu.Contrib (clone, copyPropsToMetadata, permalink, renameExt, renderContent) import Shikensu.Contrib.IO (read, write)-import System.Directory (canonicalizePath)+import System.Directory (getCurrentDirectory)+import System.FilePath ((</>), joinPath) import Test.Helpers import Test.Tasty import Test.Tasty.HUnit@@ -23,14 +23,21 @@ testCase "Example test" $ dictionaries >>= uncurry assertEq +thePattern :: String+thePattern =+ "fixtures" </> "*.md"++ dictionaries :: IO (Dictionary, Dictionary) dictionaries = do- root <- canonicalizePath "./tests"- dictA <- dictionary_io root+ root <- getCurrentDirectory - let absolute = root <> "/fixtures/example.md"- let dictB = [Shikensu.makeDefinition root "fixtures/*.md" absolute]+ let testsDir = root </> "tests"+ dictA <- dictionary_io testsDir + let absolute = testsDir </> "fixtures" </> "example.md"+ let dictB = [ Shikensu.makeDefinition testsDir thePattern absolute ]+ dictB_Read <- read dictB dictB_Final <- flow dictB_Read @@ -43,10 +50,10 @@ dictionary_io :: String -> IO Dictionary dictionary_io absolutePathToCwd =- Shikensu.list ["fixtures/*.md"] absolutePathToCwd+ Shikensu.list [thePattern] absolutePathToCwd >>= read >>= flow- >>= write "./build"+ >>= write "build" flow :: Dictionary -> IO Dictionary
tests/Test/Helpers.hs view
@@ -36,8 +36,8 @@ define :: String -> String -> IO Definition-define pattern root =+define thePattern root = root- |> Shikensu.listRelative [pattern]+ |> Shikensu.listRelative [ thePattern ] |> fmap (List.sortBy sortByAbsolutePath) |> fmap List.head
tests/Test/Shikensu.hs view
@@ -2,6 +2,7 @@ ( shikensuTests ) where +import System.FilePath ((</>)) import Test.Helpers import Test.Tasty import Test.Tasty.HUnit@@ -27,7 +28,8 @@ testRegular :: TestTree testRegular = let- definition = define "tests/**/*.md" "."+ thePattern = "tests" </> "**" </> "*.md"+ definition = define thePattern "." in testGroup "Test regular" [ testCase "Should have the correct basename"@@ -40,7 +42,7 @@ $ assertDef definition Shikensu.extname ".md" , testCase "Should have the correct pattern"- $ assertDef definition Shikensu.pattern "tests/**/*.md"+ $ assertDef definition Shikensu.pattern thePattern , testCase "Should have the correct workingDirname" $ assertDef definition Shikensu.workingDirname "tests"@@ -51,7 +53,8 @@ testDot :: TestTree testDot = let- definition = define "./tests/**/*.md" "."+ thePattern = "." </> "tests" </> "**" </> "*.md"+ definition = define thePattern "." in testGroup "Test dot" [ testCase "Should have the correct basename"@@ -64,7 +67,7 @@ $ assertDef definition Shikensu.extname ".md" , testCase "Should have the correct pattern"- $ assertDef definition Shikensu.pattern "./tests/**/*.md"+ $ assertDef definition Shikensu.pattern thePattern , testCase "Should have the correct workingDirname" $ assertDef definition Shikensu.workingDirname "tests"@@ -75,7 +78,8 @@ testWithoutWd :: TestTree testWithoutWd = let- definition = define "**/*.md" "./tests"+ thePattern = "**" </> "*.md"+ definition = define thePattern "tests" in testGroup "Test without workingDirname" [ testCase "Should have the correct basename"@@ -88,7 +92,7 @@ $ assertDef definition Shikensu.extname ".md" , testCase "Should have the correct pattern"- $ assertDef definition Shikensu.pattern "**/*.md"+ $ assertDef definition Shikensu.pattern thePattern , testCase "Should have the correct workingDirname" $ assertDef definition Shikensu.workingDirname ""@@ -99,7 +103,8 @@ testRootFile :: TestTree testRootFile = let- definition = define "*.md" "."+ thePattern = "*.md"+ definition = define thePattern "." in testGroup "Test file in root path" [ testCase "Should have the correct basename"@@ -112,7 +117,7 @@ $ assertDef definition Shikensu.extname ".md" , testCase "Should have the correct pattern"- $ assertDef definition Shikensu.pattern "*.md"+ $ assertDef definition Shikensu.pattern thePattern , testCase "Should have the correct workingDirname" $ assertDef definition Shikensu.workingDirname ""
tests/Test/Utilities.hs view
@@ -5,6 +5,7 @@ import Flow import Shikensu import Shikensu.Utilities as Utils+import System.FilePath ((</>)) import Test.Helpers import Test.Tasty import Test.Tasty.HUnit@@ -22,6 +23,15 @@ +-- Test data+++thePattern :: String+thePattern =+ "tests" </> "fixtures" </> "example.md"+++ -- Tests @@ -30,8 +40,8 @@ let result = Utils.lsequence- [ ( "a", Shikensu.listRelative ["tests/fixtures/example.md"] "." )- , ( "b", Shikensu.listRelative ["tests/fixtures/example.md"] "." )+ [ ( "a", Shikensu.listRelative [thePattern] "." )+ , ( "b", Shikensu.listRelative [thePattern] "." ) ] in testCase "Test lsequence"@@ -43,7 +53,7 @@ let definition = "."- |> define "tests/fixtures/example.md"+ |> define thePattern |> fmap (Contrib.insertMetadataDef $ HashMap.singleton "a" "Hi!") resultExisting =