1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE TupleSections #-}
5Copyright (C) 2012-2019 John MacFarlane <jgm@berkeley.edu>
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23import Text.Pandoc.MIME
24import Text.Pandoc.Error (PandocError(..))
25import Control.Monad.Except (throwError)
26import qualified Text.Pandoc.UTF8 as UTF8
27import qualified Data.ByteString as B
28import qualified Data.Text as T
30import Criterion.Types (Config(..))
31import Data.List (intersect)
32import Data.Maybe (mapMaybe)
33import System.Environment (getArgs)
34import qualified Data.ByteString.Lazy as BL
41 Right (readerFun, inp) ->
42 Just $ bench (T.unpack $ name <> " reader")
43 $ nf (\i -> either (error . show) id $ runPure (readerFun i))
46 where res = runPure $ do
47 (rdr, rexts) <- getReader name
48 (wtr, wexts) <- getWriter name
50 (TextReader r, TextWriter w) -> do
51 setResourcePath ["../test"]
52 inp <- w def{ writerWrapText = WrapAuto
53 , writerExtensions = wexts } doc
54 return $ (r def{ readerExtensions = rexts }, inp)
55 _ -> throwError $ PandocSomeError $ "not a text format: "
58getImages :: IO [(FilePath, MimeType, BL.ByteString)]
60 ll <- BL.readFile "test/lalune.jpg"
61 mv <- BL.readFile "test/movie.jpg"
62 return [("lalune.jpg", "image/jpg", ll)
63 ,("movie.jpg", "image/jpg", mv)]
71 Just $ env getImages $ \imgs ->
72 bench (T.unpack $ name <> " writer")
73 $ nf (\d -> either (error . show) id $
76 insertMedia fp (Just mt) bs)
80 where res = runPure $ do
81 (wtr, wexts) <- getWriter name
84 return $ w def{ writerExtensions = wexts }
85 _ -> throwError $ PandocSomeError
86 $ "could not get text writer for " <> name
90 args <- filter (\x -> T.take 1 x /= "-") . fmap T.pack <$> getArgs
92 let matchReader (n, TextReader _) =
93 null args || ("reader" `elem` args && n `elem` args)
95 let matchWriter (n, TextWriter _) =
96 null args || ("writer" `elem` args && n `elem` args)
98 let matchedReaders = map fst $ (filter matchReader readers
99 :: [(T.Text, Reader PandocPure)])
100 let matchedWriters = map fst $ (filter matchWriter writers
101 :: [(T.Text, Writer PandocPure)])
102 inp <- UTF8.toText <$> B.readFile "test/testsuite.txt"
104 let doc = either (error . show) id $ runPure $ readMarkdown opts inp
105 let readerBs = mapMaybe (readerBench doc)
106 $ filter (/="haddock")
107 (matchedReaders `intersect` matchedWriters)
108 -- we need the corresponding writer to generate
109 -- input for the reader
110 let writerBs = mapMaybe (writerBench doc) matchedWriters
111 defaultMainWith defaultConfig{ timeLimit = 6.0 }
112 (writerBs ++ readerBs)
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