on master help sign in
Add getCategory tests
779fa66David Parrish
hakyll.cabal+1
@@ -254,6 +254,7 @@ Test-suite hakyll-tests
254 Hakyll.Web.CompressCss.Tests
254 Hakyll.Web.CompressCss.Tests
255 Hakyll.Web.Html.RelativizeUrls.Tests
255 Hakyll.Web.Html.RelativizeUrls.Tests
256 Hakyll.Web.Html.Tests
256 Hakyll.Web.Html.Tests
257+ Hakyll.Web.Tags.Tests
257 Hakyll.Web.Template.Context.Tests
258 Hakyll.Web.Template.Context.Tests
258 Hakyll.Web.Template.Tests
259 Hakyll.Web.Template.Tests
259 TestSuite.Util
260 TestSuite.Util
lib/Hakyll/Web/Tags.hs+1−1
@@ -113,7 +113,7 @@ getTags identifier = do
113
113
114
114
115--------------------------------------------------------------------------------
115--------------------------------------------------------------------------------
116−-- | Obtain categories from a page.
116+-- | Obtain category from a page.
117getCategory :: MonadMetadata m => Identifier -> m [String]
117getCategory :: MonadMetadata m => Identifier -> m [String]
118getCategory = return . return . takeBaseName . takeDirectory . toFilePath
118getCategory = return . return . takeBaseName . takeDirectory . toFilePath
119
119
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
28#endif
28#endif
29import qualified Hakyll.Web.Template.Context.Tests
29import qualified Hakyll.Web.Template.Context.Tests
30import qualified Hakyll.Web.Template.Tests
30import qualified Hakyll.Web.Template.Tests
31+import qualified Hakyll.Web.Tags.Tests
31
32
32
33
33--------------------------------------------------------------------------------
34--------------------------------------------------------------------------------
@@ -49,6 +50,7 @@ main = defaultMain $ testGroup "Hakyll"
49#ifdef USE_PANDOC
50#ifdef USE_PANDOC
50 , Hakyll.Web.Pandoc.FileType.Tests.tests
51 , Hakyll.Web.Pandoc.FileType.Tests.tests
51#endif
52#endif
53+ , Hakyll.Web.Tags.Tests.tests
52 , Hakyll.Web.Template.Context.Tests.tests
54 , Hakyll.Web.Template.Context.Tests.tests
53 , Hakyll.Web.Template.Tests.tests
55 , Hakyll.Web.Template.Tests.tests
54 ]
56 ]