summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Web/Urls
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Hakyll/Web/Urls')
-rw-r--r--tests/Hakyll/Web/Urls/Relativize/Tests.hs20
-rw-r--r--tests/Hakyll/Web/Urls/Tests.hs38
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/Hakyll/Web/Urls/Relativize/Tests.hs b/tests/Hakyll/Web/Urls/Relativize/Tests.hs
new file mode 100644
index 0000000..00f5a0f
--- /dev/null
+++ b/tests/Hakyll/Web/Urls/Relativize/Tests.hs
@@ -0,0 +1,20 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Hakyll.Web.Urls.Relativize.Tests
+ ( tests
+ ) where
+
+import Test.Framework
+import Test.HUnit hiding (Test)
+
+import Hakyll.Web.Urls.Relativize
+import TestSuite.Util
+
+tests :: [Test]
+tests = fromAssertions "relativizeUrls"
+ [ "<a href=\"../foo\">bar</a>" @=?
+ relativizeUrls ".." "<a href=\"/foo\">bar</a>"
+ , "<img src=\"../../images/lolcat.png\"></img>" @=?
+ relativizeUrls "../.." "<img src=\"/images/lolcat.png\" />"
+ , "<a href=\"http://haskell.org\">Haskell</a>" @=?
+ relativizeUrls "../.." "<a href=\"http://haskell.org\">Haskell</a>"
+ ]
diff --git a/tests/Hakyll/Web/Urls/Tests.hs b/tests/Hakyll/Web/Urls/Tests.hs
new file mode 100644
index 0000000..db7a10b
--- /dev/null
+++ b/tests/Hakyll/Web/Urls/Tests.hs
@@ -0,0 +1,38 @@
+module Hakyll.Web.Urls.Tests
+ ( tests
+ ) where
+
+import Data.Char (toUpper)
+
+import Test.Framework
+import Test.HUnit hiding (Test)
+
+import Hakyll.Web.Urls
+import TestSuite.Util
+
+tests :: [Test]
+tests = concat
+ [ fromAssertions "withUrls"
+ [ "<a href=\"FOO\">bar</a>" @=?
+ withUrls (map toUpper) "<a href=\"foo\">bar</a>"
+ , "<img src=\"OH BAR\">" @=?
+ withUrls (map toUpper) "<img src=\"oh bar\">"
+ ]
+ , fromAssertions "toUrl"
+ [ "/foo/bar.html" @=? toUrl "foo/bar.html"
+ , "/" @=? toUrl "/"
+ , "/funny-pics.html" @=? toUrl "/funny-pics.html"
+ ]
+ , fromAssertions "toSiteRoot"
+ [ ".." @=? toSiteRoot "/foo/bar.html"
+ , "." @=? toSiteRoot "index.html"
+ , "." @=? toSiteRoot "/index.html"
+ , "../.." @=? toSiteRoot "foo/bar/qux"
+ ]
+ , fromAssertions "isExternal"
+ [ assert (isExternal "http://reddit.com")
+ , assert (isExternal "https://mail.google.com")
+ , assert (not (isExternal "../header.png"))
+ , assert (not (isExternal "/foo/index.html"))
+ ]
+ ]