gemmula-0.1.0.0: test/Main.hs
{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
import Data.Text.Lazy (Text)
import Control.Monad
import System.Exit
import Test.HUnit
import Text.RawString.QQ
import Text.Gemini (GemDocument, GemItem (..))
import qualified Text.Gemini as G
-- | Query the test functions.
main :: IO ()
main = do
count <- runTestTT $ TestList
[ gemDecode
, gemEncode
]
when (failures count > 0) exitFailure
-- | Test the decoding of Gemtext documents.
gemDecode :: Test
gemDecode = TestCase $ assertEqual "Comparing the expected result of Gemtext decoding," document $ G.decode raw
-- | Test the encoding of Gemtext documents.
gemEncode :: Test
gemEncode = TestCase $ assertEqual "Comparing the expected result of Gemtext encoding," pretty $ G.encode document
-- | The raw document to test decoding on.
raw :: Text
raw = [r| text!!
another text
=>link.gmi a link
=> gemini://geminiprotocol.net/index.gmi
=>
# heading
## sub-heading
###
###subsubheading but it works
#### same as level 3
*text
* also text!
* list item
* another item
*
> quote
>
```alt
> preformat with alt
```
```
* preformat without alt
```
>qq
```empty
```ignored
|]
-- | The expected encode output to compare against.
pretty :: Text
pretty = [r| text!!
another text
=> link.gmi a link
=> gemini://geminiprotocol.net/index.gmi
=>
# heading
## sub-heading
###
### subsubheading but it works
### same as level 3
*text
* also text!
* list item
* another item
*
> quote
>
```alt
> preformat with alt
```
```
* preformat without alt
```
> qq
```empty
```
|]
-- | The expected decoded document to compare against.
document :: GemDocument
document = [ GemText " text!!"
, GemText "another text"
, GemLink "link.gmi" (Just "a link")
, GemLink "gemini://geminiprotocol.net/index.gmi" Nothing
, GemText "=>"
, GemHeading 1 "heading"
, GemHeading 2 "sub-heading"
, GemText "###"
, GemHeading 3 "subsubheading but it works"
, GemHeading 3 "same as level 3"
, GemText ""
, GemText "*text"
, GemText " * also text!"
, GemList ["list item", "another item"]
, GemText "*"
, GemQuote "quote"
, GemText ">"
, GemPre ["> preformat with alt"] (Just "alt")
, GemPre ["", "* preformat without alt"] Nothing
, GemQuote "qq"
, GemPre [] (Just "empty")
]