aboutsummaryrefslogtreecommitdiff
path: root/test/Tests/Writers/JATS.hs
blob: 572b164511e427c903b9e329467b751df8b88be3 (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
{-# LANGUAGE OverloadedStrings #-}
module Tests.Writers.JATS (tests) where

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

jats :: (ToPandoc a) => a -> String
jats = unpack . purely (writeJATS def{ writerWrapText = WrapNone }) . toPandoc

{-
  "my test" =: X =?> Y

is shorthand for

  test jats "my test" $ X =?> Y

which is in turn shorthand for

  test jats "my test" (X,Y)
-}

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

tests :: [TestTree]
tests = [ testGroup "inline code"
          [ "basic" =: code "@&" =?> "<p>\n  <monospace>@&amp;</monospace>\n</p>"
          , "lang" =: codeWith ("", ["c"], []) "@&" =?> "<p>\n  <code language=\"c\">@&amp;</code>\n</p>"
          ]
        , testGroup "block code"
          [ "basic" =: codeBlock "@&" =?> "<preformat>@&amp;</preformat>"
          , "lang" =: codeBlockWith ("", ["c"], []) "@&" =?> "<code language=\"c\">@&amp;</code>"
          ]
        , testGroup "images"
          [ "basic" =:
            image "/url" "title" mempty
            =?> "<graphic mimetype=\"image\" mime-subtype=\"\" xlink:href=\"/url\" xlink:title=\"title\" />"
          ]
        , testGroup "inlines"
          [ "Emphasis" =: emph "emphasized"
            =?> "<p>\n  <italic>emphasized</italic>\n</p>"
          ]
        , "bullet list" =: bulletList [ plain $ text "first"
                                      , plain $ text "second"
                                      , plain $ text "third"
                                      ]
            =?> "<list list-type=\"bullet\">\n\
                \  <list-item>\n\
                \    <p>\n\
                \      first\n\
                \    </p>\n\
                \  </list-item>\n\
                \  <list-item>\n\
                \    <p>\n\
                \      second\n\
                \    </p>\n\
                \  </list-item>\n\
                \  <list-item>\n\
                \    <p>\n\
                \      third\n\
                \    </p>\n\
                \  </list-item>\n\
                \</list>"
        , testGroup "definition lists"
          [ "with internal link" =: definitionList [(link "#go" "" (str "testing"),
             [plain (text "hi there")])] =?>
            "<def-list>\n\
            \  <def-item>\n\
            \    <term>\n\
            \      <xref alt=\"testing\" rid=\"go\">testing</xref>\n\
            \    </term>\n\
            \    <def>\n\
            \      <p>\n\
            \        hi there\n\
            \      </p>\n\
            \    </def>\n\
            \  </def-item>\n\
            \</def-list>"
          ]
        , testGroup "math"
          [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
            "<p>\n\
            \  <inline-formula><alternatives>\n\
            \  <tex-math><![CDATA[\\sigma|_{\\{x\\}}]]></tex-math>\n\
            \  <mml:math display=\"inline\" xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"><mml:mrow><mml:mi>σ</mml:mi><mml:msub><mml:mo stretchy=\"false\" form=\"prefix\">|</mml:mo><mml:mrow><mml:mo stretchy=\"false\" form=\"prefix\">{</mml:mo><mml:mi>x</mml:mi><mml:mo stretchy=\"false\" form=\"postfix\">}</mml:mo></mml:mrow></mml:msub></mml:mrow></mml:math></alternatives></inline-formula>\n\
            \</p>"
          ]
        , testGroup "headers"
          [ "unnumbered header" =:
            headerWith ("foo",["unnumbered"],[]) 1
              (text "Header 1" <> note (plain $ text "note")) =?>
            "<sec id=\"foo\">\n\
            \  <title>Header 1<fn>\n\
            \    <p>\n\
            \      note\n\
            \    </p>\n\
            \  </fn></title>\n\
            \</sec>"
          , "unnumbered sub header" =:
            headerWith ("foo",["unnumbered"],[]) 1
              (text "Header")
            <> headerWith ("foo",["unnumbered"],[]) 2
              (text "Sub-Header") =?>
            "<sec id=\"foo\">\n\
            \  <title>Header</title>\n\
            \  <sec id=\"foo\">\n\
            \    <title>Sub-Header</title>\n\
            \  </sec>\n\
            \</sec>"
          , "containing image" =:
            header 1 (image "imgs/foo.jpg" "" (text "Alt text")) =?>
            "<sec>\n\
            \  <title><inline-graphic mimetype=\"image\" mime-subtype=\"jpeg\" xlink:href=\"imgs/foo.jpg\" /></title>\n\
            \</sec>"
          ]
        ]