2011-01-21 20:50:18 -08:00
{- # LANGUAGE OverloadedStrings # -}
2011-01-12 19:10:56 +01:00
module Tests.Readers.LaTeX ( tests ) where
2011-01-12 14:16:35 +01:00
import Text.Pandoc.Definition
import Test.Framework
2011-01-13 10:59:44 -08:00
import Tests.Helpers
2011-01-22 13:40:18 -08:00
import Tests.Arbitrary ()
2011-01-18 23:34:34 -08:00
import Text.Pandoc.Builder
import Text.Pandoc
2011-01-21 20:50:18 -08:00
latex :: String -> Pandoc
2013-03-17 08:48:29 -07:00
latex = readLaTeX def
2011-01-21 20:50:18 -08:00
2012-02-05 13:23:06 -08:00
infix 4 =:
2011-01-21 20:50:18 -08:00
( =: ) :: ToString c
=> String -> ( String , c ) -> Test
( =: ) = test latex
2011-01-12 14:16:35 +01:00
tests :: [ Test ]
2011-01-13 11:11:55 -08:00
tests = [ testGroup " basic "
2011-01-18 23:34:34 -08:00
[ " simple " =:
2011-01-22 16:01:14 -08:00
" word " =?> para " word "
2011-01-18 23:34:34 -08:00
, " space " =:
2011-01-21 20:50:18 -08:00
" some text " =?> para ( " some text " )
2011-01-18 23:34:34 -08:00
, " emphasized " =:
2011-01-21 20:50:18 -08:00
" \ \ emph{emphasized} " =?> para ( emph " emphasized " )
2011-01-13 11:11:55 -08:00
]
, testGroup " headers "
2011-01-18 23:34:34 -08:00
[ " level 1 " =:
2013-09-01 09:13:31 -07:00
" \ \ section{header} " =?> headerWith ( " header " , [] , [] ) 1 " header "
2011-01-18 23:34:34 -08:00
, " level 2 " =:
2013-09-01 09:13:31 -07:00
" \ \ subsection{header} " =?> headerWith ( " header " , [] , [] ) 2 " header "
2011-01-18 23:34:34 -08:00
, " level 3 " =:
2013-09-01 09:13:31 -07:00
" \ \ subsubsection{header} " =?> headerWith ( " header " , [] , [] ) 3 " header "
2011-01-18 23:34:34 -08:00
, " emph " =:
2011-01-21 20:50:18 -08:00
" \ \ section{text \ \ emph{emph}} " =?>
2013-09-01 09:13:31 -07:00
headerWith ( " text-emph " , [] , [] ) 1 ( " text " <> space <> emph " emph " )
2011-01-18 23:34:34 -08:00
, " link " =:
2011-01-21 20:50:18 -08:00
" \ \ section{text \ \ href{/url}{link}} " =?>
2013-09-01 09:13:31 -07:00
headerWith ( " text-link " , [] , [] ) 1 ( " text " <> space <> link " /url " " " " link " )
2011-01-13 11:11:55 -08:00
]
2011-01-29 08:47:00 -08:00
2012-02-07 19:24:09 -08:00
, testGroup " math "
[ " escaped $ " =:
2012-02-07 19:24:09 -08:00
" $x= \ \ $4$ " =?> para ( math " x= \ \ $4 " )
2012-02-07 19:24:09 -08:00
]
2011-01-30 08:21:48 -08:00
, testGroup " space and comments "
[ " blank lines + space at beginning " =:
" \ n \ n hi " =?> para " hi "
, " blank lines + space + comments " =:
" % my comment \ n \ n \ n % another \ n \ n hi " =?> para " hi "
, " comment in paragraph " =:
" hi % this is a comment \ n there \ n " =?> para " hi there "
]
2013-08-22 20:15:36 +02:00
, testGroup " code blocks "
[ " identifier " =:
" \ \ begin{lstlisting}[label=test] \ \ end{lstlisting} " =?> codeBlockWith ( " test " , [] , [ ( " label " , " test " ) ] ) " "
, " no identifier " =:
" \ \ begin{lstlisting} \ \ end{lstlisting} " =?> codeBlock " "
]
2011-01-29 08:47:00 -08:00
, testGroup " citations "
[ natbibCitations
, biblatexCitations
]
2011-01-12 14:16:35 +01:00
]
2011-01-29 08:47:00 -08:00
baseCitation :: Citation
2012-10-21 23:16:23 -07:00
baseCitation = Citation { citationId = " item1 "
, citationPrefix = []
, citationSuffix = []
, citationMode = AuthorInText
, citationNoteNum = 0
2012-10-22 19:11:56 -07:00
, citationHash = 0
2012-10-28 09:36:15 -07:00
}
2011-01-29 08:47:00 -08:00
2012-02-06 12:41:34 -08:00
rt :: String -> Inlines
2013-03-17 08:48:29 -07:00
rt = rawInline " latex "
2012-02-06 12:41:34 -08:00
2011-01-29 08:47:00 -08:00
natbibCitations :: Test
natbibCitations = testGroup " natbib "
[ " citet " =: " \ \ citet{item1} "
2012-02-06 12:41:34 -08:00
=?> para ( cite [ baseCitation ] ( rt " \ \ citet{item1} " ) )
2011-01-29 08:47:00 -08:00
, " suffix " =: " \ \ citet[p.~30]{item1} "
=?> para
2013-07-21 11:44:49 -07:00
( cite [ baseCitation { citationSuffix = toList $ text " p. \ 160 \ & 30 " } ] ( rt " \ \ citet[p.~30]{item1} " ) )
2011-01-29 08:47:00 -08:00
, " suffix long " =: " \ \ citet[p.~30, with suffix]{item1} "
=?> para ( cite [ baseCitation { citationSuffix =
2013-07-21 11:44:49 -07:00
toList $ text " p. \ 160 \ & 30, with suffix " } ] ( rt " \ \ citet[p.~30, with suffix]{item1} " ) )
2011-01-29 08:47:00 -08:00
, " multiple " =: " \ \ citeauthor{item1} \ \ citetext{ \ \ citeyear{item1}; \ \ citeyear[p.~30]{item2}; \ \ citealp[see also][]{item3}} "
=?> para ( cite [ baseCitation { citationMode = AuthorInText }
, baseCitation { citationMode = SuppressAuthor
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " p. \ 160 \ & 30 " ]
2011-01-29 08:47:00 -08:00
, citationId = " item2 " }
, baseCitation { citationId = " item3 "
, citationPrefix = [ Str " see " , Space , Str " also " ]
, citationMode = NormalCitation }
2012-02-06 12:41:34 -08:00
] ( rt " \ \ citetext{ \ \ citeyear{item1}; \ \ citeyear[p.~30]{item2}; \ \ citealp[see also][]{item3}} " ) )
2011-01-29 08:47:00 -08:00
, " group " =: " \ \ citetext{ \ \ citealp[see][p.~34--35]{item1}; \ \ citealp[also][chap. 3]{item3}} "
=?> para ( cite [ baseCitation { citationMode = NormalCitation
, citationPrefix = [ Str " see " ]
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " p. \ 160 \ & 34 \ 8211 \ & 35 " ] }
2011-01-29 08:47:00 -08:00
, baseCitation { citationMode = NormalCitation
, citationId = " item3 "
, citationPrefix = [ Str " also " ]
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " chap. " , Space , Str " 3 " ] }
2012-02-06 12:41:34 -08:00
] ( rt " \ \ citetext{ \ \ citealp[see][p.~34--35]{item1}; \ \ citealp[also][chap. 3]{item3}} " ) )
2011-01-29 08:47:00 -08:00
, " suffix and locator " =: " \ \ citep[pp.~33, 35--37, and nowhere else]{item1} "
=?> para ( cite [ baseCitation { citationMode = NormalCitation
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " pp. \ 160 \ & 33, " , Space , Str " 35 \ 8211 \ & 37, " , Space , Str " and " , Space , Str " nowhere " , Space , Str " else " ] } ] ( rt " \ \ citep[pp.~33, 35--37, and nowhere else]{item1} " ) )
2011-01-29 08:47:00 -08:00
, " suffix only " =: " \ \ citep[and nowhere else]{item1} "
=?> para ( cite [ baseCitation { citationMode = NormalCitation
2013-07-21 11:44:49 -07:00
, citationSuffix = toList $ text " and nowhere else " } ] ( rt " \ \ citep[and nowhere else]{item1} " ) )
2011-01-29 08:47:00 -08:00
, " no author " =: " \ \ citeyearpar{item1}, and now Doe with a locator \ \ citeyearpar[p.~44]{item2} "
2012-02-06 12:41:34 -08:00
=?> para ( cite [ baseCitation { citationMode = SuppressAuthor } ] ( rt " \ \ citeyearpar{item1} " ) <>
2011-12-13 14:29:07 -08:00
text " , and now Doe with a locator " <>
2011-01-29 08:47:00 -08:00
cite [ baseCitation { citationMode = SuppressAuthor
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " p. \ 160 \ & 44 " ]
2012-02-06 12:41:34 -08:00
, citationId = " item2 " } ] ( rt " \ \ citeyearpar[p.~44]{item2} " ) )
2011-01-29 08:47:00 -08:00
, " markup " =: " \ \ citep[ \ \ emph{see}][p. \ \ textbf{32}]{item1} "
=?> para ( cite [ baseCitation { citationMode = NormalCitation
, citationPrefix = [ Emph [ Str " see " ] ]
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " p. " , Space ,
2012-02-06 12:41:34 -08:00
Strong [ Str " 32 " ] ] } ] ( rt " \ \ citep[ \ \ emph{see}][p. \ \ textbf{32}]{item1} " ) )
2011-01-29 08:47:00 -08:00
]
biblatexCitations :: Test
biblatexCitations = testGroup " biblatex "
2011-01-29 09:01:30 -08:00
[ " textcite " =: " \ \ textcite{item1} "
2012-02-06 12:41:34 -08:00
=?> para ( cite [ baseCitation ] ( rt " \ \ textcite{item1} " ) )
2011-01-29 09:01:30 -08:00
, " suffix " =: " \ \ textcite[p.~30]{item1} "
=?> para
2013-07-21 11:44:49 -07:00
( cite [ baseCitation { citationSuffix = toList $ text " p. \ 160 \ & 30 " } ] ( rt " \ \ textcite[p.~30]{item1} " ) )
2011-01-29 09:01:30 -08:00
, " suffix long " =: " \ \ textcite[p.~30, with suffix]{item1} "
=?> para ( cite [ baseCitation { citationSuffix =
2013-07-21 11:44:49 -07:00
toList $ text " p. \ 160 \ & 30, with suffix " } ] ( rt " \ \ textcite[p.~30, with suffix]{item1} " ) )
2011-01-29 09:01:30 -08:00
, " multiple " =: " \ \ textcites{item1}[p.~30]{item2}[see also][]{item3} "
=?> para ( cite [ baseCitation { citationMode = AuthorInText }
, baseCitation { citationMode = NormalCitation
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " p. \ 160 \ & 30 " ]
2011-01-29 09:01:30 -08:00
, citationId = " item2 " }
, baseCitation { citationId = " item3 "
, citationPrefix = [ Str " see " , Space , Str " also " ]
, citationMode = NormalCitation }
2012-02-06 12:41:34 -08:00
] ( rt " \ \ textcites{item1}[p.~30]{item2}[see also][]{item3} " ) )
2011-01-29 09:01:30 -08:00
, " group " =: " \ \ autocites[see][p.~34--35]{item1}[also][chap. 3]{item3} "
=?> para ( cite [ baseCitation { citationMode = NormalCitation
, citationPrefix = [ Str " see " ]
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " p. \ 160 \ & 34 \ 8211 \ & 35 " ] }
2011-01-29 09:01:30 -08:00
, baseCitation { citationMode = NormalCitation
, citationId = " item3 "
, citationPrefix = [ Str " also " ]
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " chap. " , Space , Str " 3 " ] }
2012-02-06 12:41:34 -08:00
] ( rt " \ \ autocites[see][p.~34--35]{item1}[also][chap. 3]{item3} " ) )
2011-01-29 09:01:30 -08:00
, " suffix and locator " =: " \ \ autocite[pp.~33, 35--37, and nowhere else]{item1} "
=?> para ( cite [ baseCitation { citationMode = NormalCitation
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " pp. \ 160 \ & 33, " , Space , Str " 35 \ 8211 \ & 37, " , Space , Str " and " , Space , Str " nowhere " , Space , Str " else " ] } ] ( rt " \ \ autocite[pp.~33, 35--37, and nowhere else]{item1} " ) )
2011-01-29 09:01:30 -08:00
, " suffix only " =: " \ \ autocite[and nowhere else]{item1} "
=?> para ( cite [ baseCitation { citationMode = NormalCitation
2013-07-21 11:44:49 -07:00
, citationSuffix = toList $ text " and nowhere else " } ] ( rt " \ \ autocite[and nowhere else]{item1} " ) )
2011-01-29 09:01:30 -08:00
, " no author " =: " \ \ autocite*{item1}, and now Doe with a locator \ \ autocite*[p.~44]{item2} "
2012-02-06 12:41:34 -08:00
=?> para ( cite [ baseCitation { citationMode = SuppressAuthor } ] ( rt " \ \ autocite*{item1} " ) <>
2011-12-13 14:29:07 -08:00
text " , and now Doe with a locator " <>
2011-01-29 09:01:30 -08:00
cite [ baseCitation { citationMode = SuppressAuthor
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " p. \ 160 \ & 44 " ]
2012-02-06 12:41:34 -08:00
, citationId = " item2 " } ] ( rt " \ \ autocite*[p.~44]{item2} " ) )
2011-01-29 09:01:30 -08:00
, " markup " =: " \ \ autocite[ \ \ emph{see}][p. \ \ textbf{32}]{item1} "
=?> para ( cite [ baseCitation { citationMode = NormalCitation
, citationPrefix = [ Emph [ Str " see " ] ]
2013-07-21 11:44:49 -07:00
, citationSuffix = [ Str " p. " , Space ,
2012-02-06 12:41:34 -08:00
Strong [ Str " 32 " ] ] } ] ( rt " \ \ autocite[ \ \ emph{see}][p. \ \ textbf{32}]{item1} " ) )
2011-01-29 09:01:30 -08:00
, " parencite " =: " \ \ parencite{item1} "
2012-02-06 12:41:34 -08:00
=?> para ( cite [ baseCitation { citationMode = NormalCitation } ] ( rt " \ \ parencite{item1} " ) )
2011-01-29 08:47:00 -08:00
]