on master help sign in
Re-add some tests, cleanup...
commit1bcce776e786eb6688bace653ecafa1a5a4fb563 authorJasper Van der Jeugt <m@jaspervdj.be> dateMon 26 Nov 2012, 16:11 (14 years ago) parent25b8c8b
7 files changed+95−147
hakyll.cabal+4 src/Hakyll/Web/Page/List.hs−83 tests/Hakyll/Core/Routes/Tests.hs+14−7 tests/Hakyll/Core/Rules/Tests.hs+42−44 tests/Hakyll/Core/Util/String/Tests.hs+13−6 tests/Hakyll/Web/Util/Html/Tests.hs+13−6 tests/TestSuite.hs+9−1
hakyll.cabal+4
@@ -202,10 +202,14 @@ Test-suite hakyll-tests
202202 Hakyll.Core.Dependencies.Tests
203203 Hakyll.Core.Identifier.Tests
204204 Hakyll.Core.Provider.Tests
205+ Hakyll.Core.Routes.Tests
206+ Hakyll.Core.Rules.Tests
205207 Hakyll.Core.Runtime.Tests
206208 Hakyll.Core.Store.Tests
207209 Hakyll.Core.UnixFilter.Tests
210+ Hakyll.Core.Util.String.Tests
208211 Hakyll.Web.Template.Tests
209212 Hakyll.Web.Urls.Tests
210213 Hakyll.Web.Urls.Relativize.Tests
214+ Hakyll.Web.Util.Html.Tests
211215 TestSuite.Util
src/Hakyll/Web/Page/List.hsdeleted−83
@@ -1,83 +0,0 @@
1−-- TODO: Port
2−-- | Provides an easy way to combine several pages in a list. The applications
3−-- are obvious:
4−--
5−-- * A post list on a blog
6−--
7−-- * An image list in a gallery
8−--
9−-- * A sitemap
10−--
11−module Hakyll.Web.Page.List
12− ( setFieldPageList
13− , pageListCompiler
14− , chronological
15− , recentFirst
16− , sortByBaseName
17− ) where
18−
19−import Control.Arrow ((>>>), arr)
20−import Data.List (sortBy)
21−import Data.Monoid (Monoid, mconcat)
22−import Data.Ord (comparing)
23−import System.FilePath (takeBaseName)
24−
25−import Hakyll.Core.Compiler
26−import Hakyll.Core.Identifier
27−import Hakyll.Core.Identifier.Pattern
28−import Hakyll.Web.Page
29−import Hakyll.Web.Page.Metadata
30−import Hakyll.Web.Template
31−
32−-- | Set a field of a page to a listing of pages
33−--
34−setFieldPageList :: ([Page String] -> [Page String])
35− -- ^ Determines list order
36− -> Identifier Template
37− -- ^ Applied to every page
38− -> String
39− -- ^ Key indicating which field should be set
40− -> Pattern (Page String)
41− -- ^ Selects pages to include in the list
42− -> Compiler (Page String) (Page String)
43− -- ^ Compiler that sets the page list in a field
44−setFieldPageList sort template key pattern =
45− requireAllA pattern $ setFieldA key $ pageListCompiler sort template
46−
47−-- | Create a list of pages
48−--
49−pageListCompiler :: ([Page String] -> [Page String]) -- ^ Determine list order
50− -> Identifier Template -- ^ Applied to pages
51− -> Compiler [Page String] String -- ^ Compiles page list
52−pageListCompiler sort template =
53− arr sort >>> applyTemplateToList template >>> arr concatPages
54−
55−-- | Apply a template to every page in a list
56−--
57−applyTemplateToList :: Identifier Template
58− -> Compiler [Page String] [Page String]
59−applyTemplateToList identifier = require identifier $
60− \posts template -> map (applyTemplateToPage template) posts
61−
62−-- | Concatenate the bodies of a page list
63−--
64−concatPages :: Monoid m => [Page m] -> m
65−concatPages = mconcat . map pageBody
66−
67−-- | Sort pages chronologically. This function assumes that the pages have a
68−-- @year-month-day-title.extension@ naming scheme -- as is the convention in
69−-- Hakyll.
70−--
71−chronological :: [Page a] -> [Page a]
72−chronological = sortBy $ comparing $ takeBaseName . getField "path"
73−
74−-- | The reverse of 'chronological'
75−--
76−recentFirst :: [Page a] -> [Page a]
77−recentFirst = reverse . chronological
78−
79−-- | Deprecated, see 'chronological'
80−--
81−sortByBaseName :: [Page a] -> [Page a]
82−sortByBaseName = chronological
83−{-# DEPRECATED sortByBaseName "Use chronological" #-}
tests/Hakyll/Core/Routes/Tests.hs+14−7
@@ -1,17 +1,24 @@
1+--------------------------------------------------------------------------------
12{-# LANGUAGE OverloadedStrings #-}
23module Hakyll.Core.Routes.Tests
34 ( tests
45 ) where
56
6−import Test.Framework
7−import Test.HUnit hiding (Test)
87
9−import Hakyll.Core.Identifier
10−import Hakyll.Core.Routes
11−import TestSuite.Util
8+--------------------------------------------------------------------------------
9+import Test.Framework (Test, testGroup)
10+import Test.HUnit ((@=?))
1211
13−tests :: [Test]
14−tests = fromAssertions "runRoutes"
12+
13+--------------------------------------------------------------------------------
14+import Hakyll.Core.Identifier
15+import Hakyll.Core.Routes
16+import TestSuite.Util
17+
18+
19+--------------------------------------------------------------------------------
20+tests :: Test
21+tests = testGroup "Hakyll.Core.Routes.Tests" $ fromAssertions "runRoutes"
1522 [ Just "foo.html" @=? runRoutes (setExtension "html") "foo"
1623 , Just "foo.html" @=? runRoutes (setExtension ".html") "foo"
1724 , Just "foo.html" @=? runRoutes (setExtension "html") "foo.markdown"
tests/Hakyll/Core/Rules/Tests.hs+42−44
@@ -1,67 +1,65 @@
1+--------------------------------------------------------------------------------
12{-# LANGUAGE OverloadedStrings #-}
2−{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
33module Hakyll.Core.Rules.Tests
44 ( tests
55 ) where
66
7−import qualified Data.Map as M
8−import qualified Data.Set as S
97
10−import Test.Framework
11−import Test.Framework.Providers.HUnit
12−import Test.HUnit hiding (Test)
8+--------------------------------------------------------------------------------
9+import qualified Data.Set as S
10+import Test.Framework (Test, testGroup)
11+import Test.Framework.Providers.HUnit (testCase)
12+import Test.HUnit (Assertion, assert, (@=?))
1313
14−import Hakyll.Core.Rules
15−import Hakyll.Core.Rules.Internal
16−import Hakyll.Core.Identifier
17−import Hakyll.Core.Routes
18−import Hakyll.Core.Compiler
19−import Hakyll.Core.Resource.Provider
20−import Hakyll.Core.Resource.Provider.Dummy
21−import Hakyll.Web.Page
2214
23−tests :: [Test]
24−tests =
15+--------------------------------------------------------------------------------
16+import Hakyll.Core.Compiler
17+import Hakyll.Core.Identifier
18+import Hakyll.Core.Routes
19+import Hakyll.Core.Rules
20+import Hakyll.Core.Rules.Internal
21+import Hakyll.Web.Page
22+import TestSuite.Util
23+
24+
25+--------------------------------------------------------------------------------
26+tests :: Test
27+tests = testGroup "Hakyll.Core.Rules.Tests"
2528 [ testCase "runRules" rulesTest
2629 ]
2730
28−-- | Main test
29−--
31+
32+--------------------------------------------------------------------------------
3033rulesTest :: Assertion
31−rulesTest = do
32− p <- provider
33− let ruleSet = runRules rules p
34− assert $ expected == S.fromList (map fst (rulesCompilers ruleSet))
34+rulesTest = withTestStore $ \store -> do
35+ provider <- newTestProvider store
36+ ruleSet <- runRules rules provider
37+ let identifiers = S.fromList $ map fst $ rulesCompilers ruleSet
38+ routes = rulesRoutes ruleSet
39+
40+ -- Test that we have some identifiers and that the routes work out
41+ assert $ all (`S.member` identifiers) expected
42+ Just "example.html" @=? runRoutes routes "example.md"
43+ Just "example.md" @=? runRoutes routes (raw "example.md")
3544 where
36− expected = S.fromList
37− [ Identifier Nothing "posts/a-post.markdown"
38− , Identifier Nothing "posts/some-other-post.markdown"
39− , Identifier (Just "raw") "posts/a-post.markdown"
40− , Identifier (Just "raw") "posts/some-other-post.markdown"
45+ raw = setVersion (Just "raw")
46+ expected =
47+ [ "example.md"
48+ , "russian.md"
49+ , raw "example.md"
50+ , raw "russian.md"
4151 ]
4252
43−-- | Dummy resource provider
44−--
45−provider :: IO ResourceProvider
46−provider = dummyResourceProvider $ M.fromList $ map (flip (,) "No content")
47− [ "posts/a-post.markdown"
48− , "posts/some-other-post.markdown"
49− ]
5053
51−-- | Example rules
52−--
53−rules :: Rules
54+--------------------------------------------------------------------------------
55+rules :: Rules ()
5456rules = do
5557 -- Compile some posts
56− match "posts/*" $ do
58+ match "*.md" $ do
5759 route $ setExtension "html"
5860 compile pageCompiler
5961
6062 -- Compile them, raw
61− group "raw" $ do
63+ match "*.md" $ version "raw" $ do
6264 route idRoute
63− match "posts/*" $ do
64− route $ setExtension "html"
65− compile getResourceString
66−
67− return ()
65+ compile getResourceString
tests/Hakyll/Core/Util/String/Tests.hs+13−6
@@ -1,15 +1,22 @@
1+--------------------------------------------------------------------------------
12module Hakyll.Core.Util.String.Tests
23 ( tests
34 ) where
45
5−import Test.Framework (Test)
6−import Test.HUnit ((@=?))
76
8−import Hakyll.Core.Util.String
9−import TestSuite.Util
7+--------------------------------------------------------------------------------
8+import Test.Framework (Test, testGroup)
9+import Test.HUnit ((@=?))
1010
11−tests :: [Test]
12−tests = concat
11+
12+--------------------------------------------------------------------------------
13+import Hakyll.Core.Util.String
14+import TestSuite.Util
15+
16+
17+--------------------------------------------------------------------------------
18+tests :: Test
19+tests = testGroup "Hakyll.Core.Util.String.Tests" $ concat
1320 [ fromAssertions "trim"
1421 [ "foo" @=? trim " foo\n\t "
1522 ]
tests/Hakyll/Web/Util/Html/Tests.hs+13−6
@@ -1,15 +1,22 @@
1+--------------------------------------------------------------------------------
12module Hakyll.Web.Util.Html.Tests
23 ( tests
34 ) where
45
5−import Test.Framework
6−import Test.HUnit hiding (Test)
76
8−import Hakyll.Web.Util.Html
9−import TestSuite.Util
7+--------------------------------------------------------------------------------
8+import Test.Framework (Test, testGroup)
9+import Test.HUnit ((@=?))
1010
11−tests :: [Test]
12−tests = concat
11+
12+--------------------------------------------------------------------------------
13+import Hakyll.Web.Util.Html
14+import TestSuite.Util
15+
16+
17+--------------------------------------------------------------------------------
18+tests :: Test
19+tests = testGroup "Hakyll.Web.Util.Html" $ concat
1320 [ fromAssertions "stripTags"
1421 [ "foo" @=? stripTags "<p>foo</p>"
1522 , "foo bar" @=? stripTags "<p>foo</p> bar"
tests/TestSuite.hs+9−1
@@ -12,12 +12,16 @@ import Test.Framework (defaultMain)
1212import qualified Hakyll.Core.Dependencies.Tests
1313import qualified Hakyll.Core.Identifier.Tests
1414import qualified Hakyll.Core.Provider.Tests
15+import qualified Hakyll.Core.Routes.Tests
16+import qualified Hakyll.Core.Rules.Tests
1517import qualified Hakyll.Core.Runtime.Tests
1618import qualified Hakyll.Core.Store.Tests
1719import qualified Hakyll.Core.UnixFilter.Tests
20+import qualified Hakyll.Core.Util.String.Tests
1821import qualified Hakyll.Web.Template.Tests
1922import qualified Hakyll.Web.Urls.Relativize.Tests
2023import qualified Hakyll.Web.Urls.Tests
24+import qualified Hakyll.Web.Util.Html.Tests
2125
2226
2327--------------------------------------------------------------------------------
@@ -26,10 +30,14 @@ main = defaultMain
2630 [ Hakyll.Core.Dependencies.Tests.tests
2731 , Hakyll.Core.Identifier.Tests.tests
2832 , Hakyll.Core.Provider.Tests.tests
33+ , Hakyll.Core.Routes.Tests.tests
34+ , Hakyll.Core.Rules.Tests.tests
2935 , Hakyll.Core.Runtime.Tests.tests
3036 , Hakyll.Core.Store.Tests.tests
3137 , Hakyll.Core.UnixFilter.Tests.tests
38+ , Hakyll.Core.Util.String.Tests.tests
3239 , Hakyll.Web.Template.Tests.tests
33− , Hakyll.Web.Urls.Tests.tests
3440 , Hakyll.Web.Urls.Relativize.Tests.tests
41+ , Hakyll.Web.Urls.Tests.tests
42+ , Hakyll.Web.Util.Html.Tests.tests
3543 ]