@@ -13,9 +13,11 @@ import Test.Tasty.HUnit (Assertion, testCase, (@=?))
1313--------------------------------------------------------------------------------
1414import Hakyll.Core.Compiler
1515import Hakyll.Core.Identifier
16+import Hakyll.Core.Item
1617import Hakyll.Core.Provider
1718import Hakyll.Core.Store (Store)
1819import Hakyll.Web.Template.Context
20+import Hakyll.Web.Template.Internal
1921import TestSuite.Util
2022
2123
@@ -23,6 +25,7 @@ import TestSuite.Util
2325tests :: TestTree
2426tests = testGroup "Hakyll.Web.Template.Context.Tests"
2527 [ testCase "testDateField" testDateField
28+ , testCase "testOuerLoopContextAccess" testOuerLoopContextAccess
2629 ]
2730
2831
@@ -65,3 +68,28 @@ testContextDone store provider identifier key context =
6568 ListField _ _ -> error $
6669 "Hakyll.Web.Template.Context.Tests.testContextDone: " ++
6770 "Didn't expect ListField"
71+
72+--------------------------------------------------------------------------------
73+
74+testOuerLoopContextAccess :: Assertion
75+testOuerLoopContextAccess = do
76+ store <- newTestStore
77+ provider <- newTestProvider store
78+ test store provider ctx "baz"
79+ test store provider (ctx' <> ctx) "not baz"
80+ test store provider (ctx <> ctx') "baz"
81+
82+ cleanTestEnv
83+ where
84+ tpl = readTemplate "$for(foo)$$for(bar)$$qux$$endfor$$endfor$"
85+ ctx = mconcat [
86+ field "qux" $ const $ return "baz"
87+ , listField "foo" (listField "bar" mempty $ return [mockItem])
88+ $ return [mockItem]
89+ ]
90+ ctx' = field "qux" $ const $ return "not baz"
91+ mockItem = Item "" ()
92+ test store provider context str = do
93+ str' <- testCompilerDone store provider ""
94+ $ applyTemplate tpl context mockItem
95+ str @=? itemBody str'