aboutsummaryrefslogtreecommitdiff
path: root/test/Tests/Readers/Jira.hs
blob: b7194a3b916dd30c86d36f1b273b4351bfce1532 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}
{- |
   Module      : Tests.Readers.Jira
   Copyright   : © 2019-2021 Albert Krewinel
   License     : GNU GPL, version 2 or above

   Maintainer  : Albert Krewinkel <tarleb@zeitkraut.de>
   Stability   : alpha
   Portability : portable

Tests for the RST reader.
-}
module Tests.Readers.Jira (tests) where

import Prelude hiding (unlines)
import Data.Text (Text, unlines)
import Test.Tasty (TestTree, testGroup)
import Tests.Helpers (ToString, purely, test, (=?>))
import Text.Pandoc (def)
import Text.Pandoc.Readers.Jira (readJira)
import Text.Pandoc.Builder

jira :: Text -> Pandoc
jira = purely $ readJira def

infix 4 =:
(=:) :: ToString c
     => String -> (Text, c) -> TestTree
(=:) = test jira

tests :: [TestTree]
tests =
  [ testGroup "para"
    [ "Simple sentence" =:
      "Hello, World!" =?> para "Hello, World!"

    , "leading blank lines" =:
      "\n\ntext" =?> para "text"
    ]

  , testGroup "header"
    [ "header" =:
      "h1. Main\n" =?> header 1 "Main"
    ]

  , testGroup "list"
    [ "simple list" =:
      "* foo\n* bar\n" =?> bulletList [para "foo", para "bar"]

    , "list with minus as bullets" =:
      "- foo\n- bar\n" =?> bulletList [para "foo", para "bar"]

    , "ordered list / enumeration" =:
      "# first\n# second\n" =?> orderedList [para "first", para "second"]
    ]

  , testGroup "block quote"
    [ "simple block quote" =:
      "bq. _Don't_ quote me on this." =?>
      blockQuote (para $ emph "Don't" <> space <> "quote me on this.")

    , "block quote between paragraphs" =:
      unlines [ "Regular text."
              , "bq.This is a blockquote"
              , "More text."
              ] =?>
      mconcat [ para "Regular text."
              , blockQuote (para "This is a blockquote")
              , para "More text."
              ]
    ]

  , testGroup "table"
    [ "table without header" =:
      "| one | two |\n| three | four |\n" =?>
      simpleTable []
                  [ [para "one", para "two"]
                  , [para "three", para "four"]]

    , "table with header" =:
      "|| one || two ||\n| three | four |\n| five | six |\n" =?>
      simpleTable [para "one", para "two"]
                  [ [para "three", para "four"]
                  , [para "five", para "six"]]

    , "table with column header" =:
      "|| language | haskell | lua |\n|| type | static | dynamic |\n" =?>
      simpleTable []
                  [ [para "language", para "haskell", para "lua"]
                  , [para "type", para "static", para "dynamic"]]

    , "table after paragraph" =:
      "*tabletest*\n||Name|\n|Test|\n" =?>
      para (strong "tabletest") <>
      simpleTable [para "Name"] [[para "Test"]]
    ]

  , testGroup "panel"
    [ "simple panel" =:
      "{panel}\nInterviewer: Jane Doe{panel}\n" =?>
      divWith ("", ["panel"], []) (para "Interviewer: Jane Doe")
    ]

  , testGroup "inlines"
    [ "emphasis" =:
      "*quid pro quo*" =?>
      para (strong "quid pro quo")

    , "deleted" =:
      "-old-" =?>
      para (strikeout "old")

    , "monospaced" =:
      "{{this *is* monospace}}" =?>
      para (code "this is monospace")

    , "sub- and superscript" =:
      "HCO ~3~^-^" =?>
      para ("HCO " <> subscript "3" <> superscript "-")

    , "citation" =:
      "Et tu, Brute? ??Caesar??" =?>
      para ("Et tu, Brute? — " <> emph "Caesar")

    , "color" =:
      "This is {color:red}red{color}." =?>
      para ("This is " <> spanWith ("", [], [("color", "red")]) "red" <> ".")

    , "hexcolor" =:
      "{color:#00875A}green{color}" =?>
      para (spanWith ("", [], [("color", "#00875A")]) "green")

    , "linebreak" =:
      "first\nsecond" =?>
      para ("first" <> linebreak <> "second")

    , testGroup "links"
      [ "external" =:
        "[Example|https://example.org]" =?>
        para (link "https://example.org" "" "Example")

      , "URL in alias" =:
        "[See https://example.com|https://example.com]" =?>
        para (link "https://example.com" "" "See https://example.com")

      , "email" =:
        "[mailto:me@example.org]" =?>
        para (link "mailto:me@example.org" "" "me@example.org")

      , "email with description" =:
        "[email|mailto:me@example.org]" =?>
        para (link "mailto:me@example.org" "" "email")

      , "attachment" =:
        "[^example.txt]" =?>
        para (linkWith ("", ["attachment"], []) "example.txt" "" "example.txt")

      , "attachment with description" =:
        "[an example^example.txt]" =?>
        para (linkWith ("", ["attachment"], []) "example.txt" "" "an example")

      , "user" =:
        "[~johndoe]" =?>
        para (linkWith ("", ["user-account"], []) "~johndoe" "" "~johndoe")

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

      , "'smart' link" =:
        "[x|http://example.com|smart-link]" =?>
        para (linkWith ("", ["smart-link"], []) "http://example.com" "" "x")

      , "'smart' card" =:
        "[x|http://example.com|smart-card]" =?>
        para (linkWith ("", ["smart-card"], []) "http://example.com" "" "x")
      ]

    , "image" =:
      "!https://example.com/image.jpg!" =?>
      para (image "https://example.com/image.jpg" "" mempty)

    , "thumbnail image" =:
      "!image.jpg|thumbnail!" =?>
      para (imageWith ("", ["thumbnail"], []) "image.jpg" "" mempty)

    , "image with attributes" =:
      "!image.gif|align=right, vspace=4, title=Hello!" =?>
      let attr = ("", [], [("align", "right"), ("vspace", "4")])
      in para $ imageWith attr "image.gif" "Hello" mempty

    , "inserted text" =:
      "+the new version+" =?>
      para (underline "the new version")

    , "HTML entity" =:
      "me &amp; you" =?> para "me & you"

    , "non-strikeout dashes" =:
      "20.09-15 2-678" =?>
      para "20.09-15 2-678"
    ]
  ]