aboutsummaryrefslogtreecommitdiff
path: root/test/Tests/Writers/Jira.hs
blob: 0c6f488537929680c6481009089c0aedf6558005 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{-# LANGUAGE OverloadedStrings #-}
module Tests.Writers.Jira (tests) where

import Data.Text (unpack)
import Test.Tasty
import Test.Tasty.HUnit (HasCallStack)
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder

jira :: (ToPandoc a) => a -> String
jira = unpack . purely (writeJira def) . toPandoc

infix 4 =:
(=:) :: (ToString a, ToPandoc a, HasCallStack)
     => String -> (a, String) -> TestTree
(=:) = test jira

tests :: [TestTree]
tests =
  [ testGroup "inlines"
    [ "underlined text" =:
      underline "underlined text" =?>
      "+underlined text+"

    , "image with attributes" =:
      imageWith ("", [], [("align", "right"), ("height", "50")])
                "image.png" "" mempty =?>
      "!image.png|align=right, height=50!"

    , testGroup "links"
      [ "external link" =:
        link "https://example.com/test.php" "" "test" =?>
        "[test|https://example.com/test.php]"

      , "external link without description" =:
        link "https://example.com/tmp.js" "" "https://example.com/tmp.js" =?>
        "[https://example.com/tmp.js]"

      , "email link" =:
        link "mailto:me@example.com" "" "Jane" =?>
        "[Jane|mailto:me@example.com]"

      , "email link without description" =:
        link "mailto:me@example.com" "" "me@example.com" =?>
        "[mailto:me@example.com]"

      , "attachment link" =:
        linkWith ("", ["attachment"], []) "foo.txt" "" "My file" =?>
        "[My file^foo.txt]"

      , "attachment link without description" =:
        linkWith ("", ["attachment"], []) "foo.txt" "" "foo.txt" =?>
        "[^foo.txt]"

      , "user link" =:
        linkWith ("", ["user-account"], []) "~johndoe" "" "John Doe" =?>
        "[John Doe|~johndoe]"

      , "user link with user as description" =:
        linkWith ("", ["user-account"], []) "~johndoe" "" "~johndoe" =?>
        "[~johndoe]"
      ]

    , testGroup "spans"
      [ "id is used as anchor" =:
        spanWith ("unicorn", [], []) (str "Unicorn") =?>
        "{anchor:unicorn}Unicorn"
      ]

    , testGroup "code"
      [ "code block with known language" =:
        codeBlockWith ("", ["java"], []) "Book book = new Book(\"Algebra\")" =?>
        "{code:java}\nBook book = new Book(\"Algebra\")\n{code}"

      , "code block without language" =:
        codeBlockWith ("", [], []) "preformatted\n  text.\n" =?>
        "{noformat}\npreformatted\n  text.\n{noformat}"
      ]
    ]

  , testGroup "blocks"
    [ testGroup "div"
      [ "empty attributes" =:
        divWith nullAttr (para "interesting text") =?>
        "interesting text"

      , "just identifier" =:
        divWith ("a", [], []) (para "interesting text") =?>
        "{anchor:a}interesting text"

      , "with class 'panel'" =:
        divWith ("", ["panel"], []) (para "Contents!") =?>
        "{panel}\nContents\\!\n{panel}\n"

      , "panel with id" =:
        divWith ("b", ["panel"], []) (para "text") =?>
        "{panel}\n{anchor:b}text\n{panel}\n"

      , "title attribute" =:
        divWith ("", [], [("title", "Gimme!")]) (para "Contents!") =?>
        "{panel:title=Gimme!}\nContents\\!\n{panel}\n"

      , "nested panels" =:
        let panelAttr = ("", ["panel"], [])
        in divWith panelAttr (para "hi" <>
                              divWith panelAttr (para "wassup?")) =?>
        "{panel}\nhi\n\nwassup?\n{panel}\n"
      ]
    ]
  ]