on master help sign in
Add getCategory tests
commit779fa66c7b1719e071dc3f4d38a4cc2feb9492c6 authorDavid Parrish <daveparrish@tutanota.com> dateSun 25 Aug 2019, 09:02 (7 years ago) parente8ea8cd
4 files changed+46−1
hakyll.cabal+1 lib/Hakyll/Web/Tags.hs+1−1 tests/Hakyll/Web/Tags/Tests.hs+42 tests/TestSuite.hs+2
hakyll.cabal+1
@@ -254,6 +254,7 @@ Test-suite hakyll-tests
254254 Hakyll.Web.CompressCss.Tests
255255 Hakyll.Web.Html.RelativizeUrls.Tests
256256 Hakyll.Web.Html.Tests
257+ Hakyll.Web.Tags.Tests
257258 Hakyll.Web.Template.Context.Tests
258259 Hakyll.Web.Template.Tests
259260 TestSuite.Util
lib/Hakyll/Web/Tags.hs+1−1
@@ -113,7 +113,7 @@ getTags identifier = do
113113
114114
115115--------------------------------------------------------------------------------
116−-- | Obtain categories from a page.
116+-- | Obtain category from a page.
117117getCategory :: MonadMetadata m => Identifier -> m [String]
118118getCategory = return . return . takeBaseName . takeDirectory . toFilePath
119119
tests/Hakyll/Web/Tags/Tests.hsnew file+42
@@ -0,0 +1,42 @@
1+--------------------------------------------------------------------------------
2+{-# LANGUAGE OverloadedStrings #-}
3+module Hakyll.Web.Tags.Tests
4+ ( tests
5+ ) where
6+
7+--------------------------------------------------------------------------------
8+import Test.Tasty (TestTree, testGroup)
9+import Test.Tasty.HUnit (Assertion, testCase, (@?=))
10+
11+--------------------------------------------------------------------------------
12+import Hakyll.Core.Identifier
13+import Hakyll.Core.Provider
14+import Hakyll.Core.Store (Store)
15+import Hakyll.Web.Tags
16+import TestSuite.Util
17+
18+tests :: TestTree
19+tests = testGroup "Hakyll.Web.Tags"
20+ [ testCase "testGetCategory" testGetCategory
21+ ]
22+
23+testGetCategory :: Assertion
24+testGetCategory = do
25+ store <- newTestStore
26+ provider <- newTestProvider store
27+
28+ noCategory <- testCategoryDone store provider "example.md"
29+ noCategory @?= [""]
30+
31+ oneCategory1 <- testCategoryDone store provider "posts/2010-08-26-birthday.md"
32+ oneCategory1 @?= ["posts"]
33+
34+ oneCategory2 <- testCategoryDone store provider "posts/2019/05/10/tomorrow.md"
35+ oneCategory2 @?= ["10"]
36+
37+ cleanTestEnv
38+
39+--------------------------------------------------------------------------------
40+testCategoryDone :: Store -> Provider -> Identifier -> IO [String]
41+testCategoryDone store provider identifier =
42+ testCompilerDone store provider identifier $ getCategory identifier
tests/TestSuite.hs+2
@@ -28,6 +28,7 @@ import qualified Hakyll.Web.Pandoc.FileType.Tests
2828#endif
2929import qualified Hakyll.Web.Template.Context.Tests
3030import qualified Hakyll.Web.Template.Tests
31+import qualified Hakyll.Web.Tags.Tests
3132
3233
3334--------------------------------------------------------------------------------
@@ -49,6 +50,7 @@ main = defaultMain $ testGroup "Hakyll"
4950#ifdef USE_PANDOC
5051 , Hakyll.Web.Pandoc.FileType.Tests.tests
5152#endif
53+ , Hakyll.Web.Tags.Tests.tests
5254 , Hakyll.Web.Template.Context.Tests.tests
5355 , Hakyll.Web.Template.Tests.tests
5456 ]