From 779fa66c7b1719e071dc3f4d38a4cc2feb9492c6 Mon Sep 17 00:00:00 2001 From: David Parrish Date: Sun, 25 Aug 2019 09:02:01 -0400 Subject: Add getCategory tests --- hakyll.cabal | 1 + lib/Hakyll/Web/Tags.hs | 2 +- tests/Hakyll/Web/Tags/Tests.hs | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/TestSuite.hs | 2 ++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/Hakyll/Web/Tags/Tests.hs diff --git a/hakyll.cabal b/hakyll.cabal index 5c9bf32..94405a8 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -254,6 +254,7 @@ Test-suite hakyll-tests Hakyll.Web.CompressCss.Tests Hakyll.Web.Html.RelativizeUrls.Tests Hakyll.Web.Html.Tests + Hakyll.Web.Tags.Tests Hakyll.Web.Template.Context.Tests Hakyll.Web.Template.Tests TestSuite.Util diff --git a/lib/Hakyll/Web/Tags.hs b/lib/Hakyll/Web/Tags.hs index 13e8cd3..43f6c4f 100644 --- a/lib/Hakyll/Web/Tags.hs +++ b/lib/Hakyll/Web/Tags.hs @@ -113,7 +113,7 @@ getTags identifier = do -------------------------------------------------------------------------------- --- | Obtain categories from a page. +-- | Obtain category from a page. getCategory :: MonadMetadata m => Identifier -> m [String] getCategory = return . return . takeBaseName . takeDirectory . toFilePath diff --git a/tests/Hakyll/Web/Tags/Tests.hs b/tests/Hakyll/Web/Tags/Tests.hs new file mode 100644 index 0000000..9b225e1 --- /dev/null +++ b/tests/Hakyll/Web/Tags/Tests.hs @@ -0,0 +1,42 @@ +-------------------------------------------------------------------------------- +{-# LANGUAGE OverloadedStrings #-} +module Hakyll.Web.Tags.Tests + ( tests + ) where + +-------------------------------------------------------------------------------- +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.HUnit (Assertion, testCase, (@?=)) + +-------------------------------------------------------------------------------- +import Hakyll.Core.Identifier +import Hakyll.Core.Provider +import Hakyll.Core.Store (Store) +import Hakyll.Web.Tags +import TestSuite.Util + +tests :: TestTree +tests = testGroup "Hakyll.Web.Tags" + [ testCase "testGetCategory" testGetCategory + ] + +testGetCategory :: Assertion +testGetCategory = do + store <- newTestStore + provider <- newTestProvider store + + noCategory <- testCategoryDone store provider "example.md" + noCategory @?= [""] + + oneCategory1 <- testCategoryDone store provider "posts/2010-08-26-birthday.md" + oneCategory1 @?= ["posts"] + + oneCategory2 <- testCategoryDone store provider "posts/2019/05/10/tomorrow.md" + oneCategory2 @?= ["10"] + + cleanTestEnv + +-------------------------------------------------------------------------------- +testCategoryDone :: Store -> Provider -> Identifier -> IO [String] +testCategoryDone store provider identifier = + testCompilerDone store provider identifier $ getCategory identifier diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs index 14e02d6..c3e32f8 100644 --- a/tests/TestSuite.hs +++ b/tests/TestSuite.hs @@ -28,6 +28,7 @@ import qualified Hakyll.Web.Pandoc.FileType.Tests #endif import qualified Hakyll.Web.Template.Context.Tests import qualified Hakyll.Web.Template.Tests +import qualified Hakyll.Web.Tags.Tests -------------------------------------------------------------------------------- @@ -49,6 +50,7 @@ main = defaultMain $ testGroup "Hakyll" #ifdef USE_PANDOC , Hakyll.Web.Pandoc.FileType.Tests.tests #endif + , Hakyll.Web.Tags.Tests.tests , Hakyll.Web.Template.Context.Tests.tests , Hakyll.Web.Template.Tests.tests ] -- cgit v1.2.3