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

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

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

defopts :: WriterOptions
defopts = def
  { writerExtensions = getDefaultExtensions "org"
  }

org :: (ToPandoc a) => a -> Text
org = orgWithOpts defopts

orgWithOpts :: (ToPandoc a) => WriterOptions -> a -> Text
orgWithOpts opts x = purely (writeOrg opts) $ toPandoc x


tests :: [TestTree]
tests =
  [ testGroup "links"
    -- See http://orgmode.org/manual/Internal-links.html#Internal-links
    [ "simple link"
      =: link "/url" "" "foo"
      =?> "[[/url][foo]]"
    , "internal link to anchor"
      =: link "#my-custom-id" "" "#my-custom-id"
      =?> "[[#my-custom-id]]"
    ]

  , testGroup "lists"
    [ "bullet task list"
      =: bulletList [plain "☐ a", plain "☒ b"]
      =?> T.unlines
          [ "- [ ] a"
          , "- [X] b"
          ]
    , "ordered task list"
      =: orderedList [plain ("☐" <> space <> "a"), plain "☒ b"]
      =?> T.unlines
          [ "1. [ ] a"
          , "2. [X] b"
          ]
    , test (orgWithOpts def) "bullet without task_lists" $
      bulletList [plain "☐ a", plain "☒ b"]
      =?> T.unlines
          [ "- ☐ a"
          , "- ☒ b"
          ]
    ]
  ]