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

import Prelude
import Data.Text (Text)
import Test.Tasty
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder
import Text.Pandoc.Readers.Man

man :: Text -> Pandoc
man = purely $ readMan def

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

tests :: [TestTree]
tests = [
  -- .SH "HEllo bbb" "aaa"" as"
  testGroup "Macros" [
      "Bold" =:
      ".B foo"
      =?> (para $ strong "foo")
    , "Italic" =:
      ".I bar\n"
      =?> (para $ emph "bar")
    , "BoldItalic" =:
      ".BI foo bar"
      =?> (para $ strong $ emph $ str "foo bar")
    , "H1" =:
      ".SH The header\n"
      =?> header 2 (str "The" <> space <> str "header")
    , "H2" =:
      ".SS \"The header 2\""
      =?> header 3 (str "The header 2")
    , "Macro args" =:
      ".B \"single arg with \"\"Q\"\"\""
      =?> (para $ strong $ str "single arg with \"Q\"")
    , "comment" =:
      ".\\\"bla\naaa"
      =?> (para $ space <> str "aaa")
    , "link" =:
      ".BR aa (1)"
      =?> (para $ link "../1/aa.1" "aa" (strong $ str "aa") <> (strong $ str " (1)"))
    ],
  testGroup "Escapes" [
      "fonts" =:
      "aa\\fIbb\\fRcc"
      =?> (para $ str "aa" <> (emph $ str "bb") <> str "cc")
    , "skip" =:
      "a\\%\\{\\}\\\n\\:b\\0"
      =?> (para $ str "ab")
    , "replace" =:
      "\\-\\ \\\\\\[lq]\\[rq]\\[em]\\[en]\\*(lq\\*(rq"
      =?> (para $ str "- \\“”—–«»")
    , "replace2" =:
      "\\t\\e\\`\\^\\|\\'"
      =?> (para $ str "\t\\`  `")
    ],
  testGroup "Lists" [
      "bullet" =:
      ".IP\nfirst\n.IP\nsecond"
      =?> bulletList [plain $ str "first", plain $ str "second"]
    , "odrered" =:
      ".IP 1 a\nfirst\n.IP 2 a\nsecond"
      =?> orderedListWith (1,Decimal,DefaultDelim) [plain $ str "first", plain $ str "second"]
    , "upper" =:
      ".IP A a\nfirst\n.IP B a\nsecond"
      =?> orderedListWith (1,UpperAlpha,DefaultDelim) [plain $ str "first", plain $ str "second"]
    , "nested" =:
      ".IP\nfirst\n.RS\n.IP\n1a\n.IP\n1b\n.RE"
      =?> bulletList [(plain $ str "first") <> (bulletList [plain $ str "1a", plain $ str "1b"])]
    ],
  testGroup "CodeBlocks" [
      "cb1"=:
      ".nf\naa\n\tbb\n.fi"
      =?> codeBlock "aa\n\tbb"
    ]
  ]