summaryrefslogtreecommitdiff
path: root/test/Tests/Readers/Org/Meta.hs
blob: 3ad6f5d8b15ddad0677dfe189ba3d8bb64a43aa9 (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
{-# LANGUAGE OverloadedStrings #-}
module Tests.Readers.Org.Meta (tests) where

import Test.Tasty (TestTree)
import Tests.Helpers ((=?>))
import Tests.Readers.Org.Shared ((=:), spcSep)
import Text.Pandoc
import Text.Pandoc.Builder
import qualified Data.Text as T

tests :: [TestTree]
tests =
  [ "Comment" =:
      "# Nothing to see here" =?>
      (mempty::Blocks)

  , "Not a comment" =:
      "#-tag" =?>
      para "#-tag"

  , "Comment surrounded by Text" =:
      T.unlines [ "Before"
                , "# Comment"
                , "After"
                ] =?>
      mconcat [ para "Before"
              , para "After"
              ]

  , "Title" =:
    "#+TITLE: Hello, World" =?>
    let titleInline = toList $ "Hello," <> space <> "World"
        meta = setMeta "title" (MetaInlines titleInline) $ nullMeta
    in Pandoc meta mempty

  , "Author" =:
    "#+author: John /Emacs-Fanboy/ Doe" =?>
    let author = toList . spcSep $ [ "John", emph "Emacs-Fanboy", "Doe" ]
        meta = setMeta "author" (MetaList [MetaInlines author]) $ nullMeta
    in Pandoc meta mempty

  , "Multiple authors" =:
    "#+author: James Dewey Watson, Francis Harry Compton Crick " =?>
    let watson = MetaInlines $ toList "James Dewey Watson"
        crick = MetaInlines $ toList "Francis Harry Compton Crick"
        meta = setMeta "author" (MetaList [watson, crick]) $ nullMeta
    in Pandoc meta mempty

  , "Date" =:
    "#+Date: Feb. *28*, 2014" =?>
    let date = toList . spcSep $ [ "Feb.", (strong "28") <> ",", "2014" ]
        meta = setMeta "date" (MetaInlines date) $ nullMeta
    in Pandoc meta mempty

  , "Description" =:
    "#+DESCRIPTION: Explanatory text" =?>
    let description = "Explanatory text"
        meta = setMeta "description" (MetaString description) $ nullMeta
    in Pandoc meta mempty

  , "Properties drawer" =:
      T.unlines [ "  :PROPERTIES:"
                , "  :setting: foo"
                , "  :END:"
                ] =?>
      (mempty::Blocks)

  , "LaTeX_headers options are translated to header-includes" =:
      "#+LaTeX_header: \\usepackage{tikz}" =?>
      let latexInlines = rawInline "latex" "\\usepackage{tikz}"
          inclList = MetaList [MetaInlines (toList latexInlines)]
          meta = setMeta "header-includes" inclList nullMeta
      in Pandoc meta mempty

  , "LaTeX_class option is translated to documentclass" =:
      "#+LATEX_CLASS: article" =?>
      let meta = setMeta "documentclass" (MetaString "article") nullMeta
      in Pandoc meta mempty

  , "LaTeX_class_options is translated to classoption" =:
      "#+LATEX_CLASS_OPTIONS: [a4paper]" =?>
      let meta = setMeta "classoption" (MetaString "a4paper") nullMeta
      in Pandoc meta mempty

  , "LaTeX_class_options is translated to classoption" =:
      "#+html_head: <meta/>" =?>
      let html = rawInline "html" "<meta/>"
          inclList = MetaList [MetaInlines (toList html)]
          meta = setMeta "header-includes" inclList nullMeta
      in Pandoc meta mempty

  , "later meta definitions take precedence" =:
      T.unlines [ "#+AUTHOR: this will not be used"
                , "#+author: Max"
                ] =?>
      let author = MetaInlines [Str "Max"]
          meta = setMeta "author" (MetaList [author]) $ nullMeta
      in Pandoc meta mempty

  , "Logbook drawer" =:
      T.unlines [ "  :LogBook:"
                , "  - State \"DONE\"       from \"TODO\"       [2014-03-03 Mon 11:00]"
                , "  :END:"
                ] =?>
      (mempty::Blocks)

  , "Drawer surrounded by text" =:
      T.unlines [ "Before"
                , ":PROPERTIES:"
                , ":END:"
                , "After"
                ] =?>
      para "Before" <> para "After"

  , "Drawer markers must be the only text in the line" =:
      T.unlines [ "  :LOGBOOK: foo"
                , "  :END: bar"
                ] =?>
      para (":LOGBOOK: foo" <> softbreak <> ":END: bar")

  , "Drawers can be arbitrary" =:
      T.unlines [ ":FOO:"
                , "/bar/"
                , ":END:"
                ] =?>
      divWith (mempty, ["FOO", "drawer"], mempty) (para $ emph "bar")

  , "Anchor reference" =:
      T.unlines [ "<<link-here>> Target."
                , ""
                , "[[link-here][See here!]]"
                ] =?>
      (para (spanWith ("link-here", [], []) mempty <> "Target.") <>
       para (link "#link-here" "" ("See" <> space <> "here!")))

  , "Search links are read as emph" =:
      "[[Wally][Where's Wally?]]" =?>
      (para (emph $ "Where's" <> space <> "Wally?"))

  , "Link to nonexistent anchor" =:
      T.unlines [ "<<link-here>> Target."
                , ""
                , "[[link$here][See here!]]"
                ] =?>
      (para (spanWith ("link-here", [], []) mempty <> "Target.") <>
       para (emph ("See" <> space <> "here!")))

  , "Link abbreviation" =:
      T.unlines [ "#+LINK: wp https://en.wikipedia.org/wiki/%s"
                , "[[wp:Org_mode][Wikipedia on Org-mode]]"
                ] =?>
      (para (link "https://en.wikipedia.org/wiki/Org_mode" ""
                  ("Wikipedia" <> space <> "on" <> space <> "Org-mode")))

  , "Link abbreviation, defined after first use" =:
      T.unlines [ "[[zl:non-sense][Non-sense articles]]"
                , "#+LINK: zl http://zeitlens.com/tags/%s.html"
                ] =?>
      (para (link "http://zeitlens.com/tags/non-sense.html" ""
                  ("Non-sense" <> space <> "articles")))

  , "Link abbreviation, URL encoded arguments" =:
      T.unlines [ "#+link: expl http://example.com/%h/foo"
                , "[[expl:Hello, World!][Moin!]]"
                ] =?>
      (para (link "http://example.com/Hello%2C%20World%21/foo" "" "Moin!"))

  , "Link abbreviation, append arguments" =:
      T.unlines [ "#+link: expl http://example.com/"
                , "[[expl:foo][bar]]"
                ] =?>
      (para (link "http://example.com/foo" "" "bar"))
  ]