git.iko.soy/typeable/pandoc
on master help sign in
tests, commented debug functions
commit3fed62611ea394b088c49c1de680e74978bb9f82 authorYan Pas <yanp.bugz@gmail.com> dateSun 14 Oct 2018, 00:57 (8 years ago) parent07b4d7b
2 files changed+70−30
src/Text/Pandoc/Readers/Man.hs+12−11 test/Tests/Readers/Man.hs+58−19
src/Text/Pandoc/Readers/Man.hs+12−11
@@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3131
3232Conversion of man to 'Pandoc' document.
3333-}
34−module Text.Pandoc.Readers.Man (readMan, testFile) where
34+module Text.Pandoc.Readers.Man (readMan) where --testFile
3535
3636import Prelude
3737import Control.Monad (liftM)
@@ -43,7 +43,7 @@ import Data.Maybe (catMaybes, fromMaybe, isNothing)
4343import Data.List (intersperse, intercalate)
4444import qualified Data.Text as T
4545
46−import Text.Pandoc.Class (PandocMonad(..), runIOorExplode)
46+import Text.Pandoc.Class (PandocMonad(..))
4747import Text.Pandoc.Definition
4848import Text.Pandoc.Error (PandocError (PandocParsecError))
4949import Text.Pandoc.Logging (LogMessage(..))
@@ -94,9 +94,9 @@ instance Default RoffState where
9494type ManLexer m = ParserT [Char] RoffState m
9595type ManParser m = ParserT [ManToken] ParserState m
9696
97−----
98−-- testStrr :: [Char] -> Either PandocError Pandoc
99−-- testStrr s = runPure $ readMan def (T.pack s)
97+---- debug functions
98+{-
99+import Text.Pandoc.Class (runIOorExplode)
100100
101101printPandoc :: Pandoc -> [Char]
102102printPandoc (Pandoc m content) =
@@ -104,16 +104,17 @@ printPandoc (Pandoc m content) =
104104 cnt = intercalate "\n" $ map show content
105105 in ttl ++ "\n" ++ cnt
106106
107−-- strrepr :: Either PandocError Pandoc -> [Char]
108−-- strrepr obj = case obj of
109−-- Right x -> printPandoc x
110−-- Left y -> show y
107+testStr :: String -> IO ()
108+testStr str = do
109+ pand <- runIOorExplode $ readMan def (T.pack str)
110+ putStrLn $ printPandoc pand
111111
112+
112113testFile :: FilePath -> IO ()
113114testFile fname = do
114115 cont <- readFile fname
115− pand <- runIOorExplode $ readMan def (T.pack cont)
116− putStrLn $ printPandoc pand
116+ testStr cont
117+-}
117118----
118119
119120
test/Tests/Readers/Man.hs+58−19
@@ -22,23 +22,62 @@ tests :: [TestTree]
2222tests = [
2323 -- .SH "HEllo bbb" "aaa"" as"
2424 testGroup "Macros" [
25− "Bold" =:
26− ".B foo"
27− =?> (para $ strong "foo")
28− , "Italic" =:
29− ".I bar\n"
30− =?> (para $ emph "bar")
31− , "BoldItalic" =:
32− ".BI foo bar"
33− =?> (para $ strong $ emph $ str "foo bar")
34− , "H1" =:
35− ".SH The header\n"
36− =?> header 2 (str "The header")
37− , "H2" =:
38− ".SS The header 2"
39− =?> header 3 (str "The header 2")
40− , "Macro args" =:
41− ".B \"single arg with \"\"Q\"\"\""
42− =?> (para $ strong $ str "single arg with \"Q\"")
43− ]
25+ "Bold" =:
26+ ".B foo"
27+ =?> (para $ strong "foo")
28+ , "Italic" =:
29+ ".I bar\n"
30+ =?> (para $ emph "bar")
31+ , "BoldItalic" =:
32+ ".BI foo bar"
33+ =?> (para $ strong $ emph $ str "foo bar")
34+ , "H1" =:
35+ ".SH The header\n"
36+ =?> header 2 (str "The" <> space <> str "header")
37+ , "H2" =:
38+ ".SS \"The header 2\""
39+ =?> header 3 (str "The header 2")
40+ , "Macro args" =:
41+ ".B \"single arg with \"\"Q\"\"\""
42+ =?> (para $ strong $ str "single arg with \"Q\"")
43+ , "comment" =:
44+ ".\\\"bla\naaa"
45+ =?> (para $ space <> str "aaa")
46+ , "link" =:
47+ ".BR aa (1)"
48+ =?> (para $ fromList [Link nullAttr [Strong [Str "aa"]] ("../1/aa.1","aa"), Strong [Str " (1)",Str ""]])
49+ ],
50+ testGroup "Escapes" [
51+ "fonts" =:
52+ "aa\\fIbb\\fRcc"
53+ =?> (para $ str "aa" <> (emph $ str "bb") <> str "cc")
54+ , "skip" =:
55+ "a\\%\\{\\}\\\n\\:b\\0"
56+ =?> (para $ fromList $ map Str ["a", "b"])
57+ , "replace" =:
58+ "\\-\\ \\\\\\[lq]\\[rq]\\[em]\\[en]\\*(lq\\*(rq"
59+ =?> (para $ fromList $ map Str ["-", " ", "\\", "“", "”", "—", "–", "«", "»"])
60+ , "replace2" =:
61+ "\\t\\e\\`\\^\\|\\'"
62+ =?> (para $ fromList $ map Str ["\t", "\\", "`", " ", " ", "`"])
63+ ],
64+ testGroup "Lists" [
65+ "bullet" =:
66+ ".IP\nfirst\n.IP\nsecond"
67+ =?> bulletList [plain $ str "first", plain $ str "second"]
68+ , "odrered" =:
69+ ".IP 1 a\nfirst\n.IP 2 a\nsecond"
70+ =?> orderedListWith (1,Decimal,DefaultDelim) [plain $ str "first", plain $ str "second"]
71+ , "upper" =:
72+ ".IP A a\nfirst\n.IP B a\nsecond"
73+ =?> orderedListWith (1,UpperAlpha,DefaultDelim) [plain $ str "first", plain $ str "second"]
74+ , "nested" =:
75+ ".IP\nfirst\n.RS\n.IP\n1a\n.IP\n1b\n.RE"
76+ =?> fromList [BulletList [[Plain [Str "first"],BulletList [[Plain [Str "1a"]],[Plain [Str "1b"]]]]]]
77+ ],
78+ testGroup "CodeBlocks" [
79+ "cb1"=:
80+ ".nf\naa\n\tbb\n.fi"
81+ =?> codeBlock "aa\n\tbb"
82+ ]
4483 ]