1{-# LANGUAGE OverloadedStrings #-}
3Copyright (C) 2012-2021 John MacFarlane <jgm@berkeley.edu>
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20import Text.Pandoc.MIME
21import Control.DeepSeq (force)
22import Control.Monad.Except (throwError)
23import qualified Text.Pandoc.UTF8 as UTF8
24import qualified Data.ByteString as B
25import qualified Data.Text as T
26import Test.Tasty.Bench
28import qualified Data.ByteString.Lazy as BL
29import Data.Maybe (mapMaybe)
30import Data.List (sortOn)
36 | name `elem` ["bibtex", "biblatex", "csljson"] = Nothing
37readerBench doc name = either (const Nothing) Just $
39 (rdr, rexts) <- getReader name
40 (wtr, wexts) <- getWriter name
42 (TextReader r, TextWriter w) -> do
43 inp <- w def{ writerWrapText = WrapAuto
44 , writerExtensions = wexts } doc
45 return $ bench (T.unpack name) $
46 nf (either (error . show) id . runPure . r def) inp
47 (ByteStringReader r, ByteStringWriter w) -> do
48 tmpl <- Just <$> compileDefaultTemplate name
49 inp <- w def{ writerWrapText = WrapAuto
50 , writerExtensions = wexts
51 , writerTemplate = tmpl } doc
52 return $ bench (T.unpack name) $
53 nf (either (error . show) id .
54 runPure . r def{readerExtensions = rexts}) inp
55 _ -> throwError $ PandocSomeError $ "text/bytestring format mismatch: "
58getImages :: IO [(FilePath, MimeType, BL.ByteString)]
60 ll <- B.readFile "test/lalune.jpg"
61 mv <- B.readFile "test/movie.jpg"
62 return [("lalune.jpg", "image/jpg", BL.fromStrict ll)
63 ,("movie.jpg", "image/jpg", BL.fromStrict mv)]
65writerBench :: [(FilePath, MimeType, BL.ByteString)]
70 | name `elem` ["bibtex", "biblatex", "csljson"] = Nothing
71writerBench imgs doc name = either (const Nothing) Just $
73 (wtr, wexts) <- getWriter name
75 TextWriter writerFun ->
76 return $ bench (T.unpack name)
77 $ nf (\d -> either (error . show) id $
79 mapM_ (\(fp,mt,bs) -> insertMedia fp (Just mt) bs) imgs
80 writerFun def{ writerExtensions = wexts} d)
82 ByteStringWriter writerFun ->
83 return $ bench (T.unpack name)
84 $ nf (\d -> either (error . show) id $
86 mapM_ (\(fp,mt,bs) -> insertMedia fp (Just mt) bs) imgs
87 writerFun def{ writerExtensions = wexts} d)
92 inp <- UTF8.toText <$> B.readFile "test/testsuite.txt"
94 let doc = either (error . show) force $ runPure $ readMarkdown opts inp
96 [ env getImages $ \imgs ->
97 bgroup "writers" $ mapMaybe (writerBench imgs doc . fst)
99 writers :: [(T.Text, Writer PandocPure)])
100 , bgroup "readers" $ mapMaybe (readerBench doc . fst)
102 readers :: [(T.Text, Reader PandocPure)])
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list