2018-02-26 21:09:51 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2019-02-04 22:52:31 +01:00
|
|
|
{- |
|
|
|
|
Module : Tests.Readers.Org.Inline.Citation
|
2021-01-08 18:38:20 +01:00
|
|
|
Copyright : © 2014-2021 Albert Krewinkel
|
2019-02-04 22:52:31 +01:00
|
|
|
License : GNU GPL, version 2 or above
|
|
|
|
|
|
|
|
Maintainer : Albert Krewinkel <albert@zeitkraut.de>
|
|
|
|
Stability : alpha
|
|
|
|
Portability : portable
|
|
|
|
|
|
|
|
Test parsing of citations in org input.
|
|
|
|
-}
|
2018-02-26 21:09:51 +01:00
|
|
|
module Tests.Readers.Org.Inline.Citation (tests) where
|
|
|
|
|
|
|
|
import Test.Tasty (TestTree, testGroup)
|
|
|
|
import Tests.Helpers ((=?>))
|
|
|
|
import Tests.Readers.Org.Shared ((=:))
|
|
|
|
import Text.Pandoc.Builder
|
|
|
|
|
|
|
|
tests :: [TestTree]
|
|
|
|
tests =
|
2021-12-14 10:40:24 -08:00
|
|
|
[ testGroup "Org-cite citations"
|
2018-02-26 21:09:51 +01:00
|
|
|
[ "Citation" =:
|
2021-12-14 10:40:24 -08:00
|
|
|
"[cite:@nonexistent]" =?>
|
2018-02-26 21:09:51 +01:00
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "nonexistent"
|
|
|
|
, citationPrefix = []
|
|
|
|
, citationSuffix = []
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0}
|
2021-12-14 10:40:24 -08:00
|
|
|
in (para $ cite [citation] "[cite:@nonexistent]")
|
2018-02-26 21:09:51 +01:00
|
|
|
|
|
|
|
, "Citation containing text" =:
|
2021-12-14 10:40:24 -08:00
|
|
|
"[cite:see @item1 p. 34-35]" =?>
|
2018-02-26 21:09:51 +01:00
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "item1"
|
|
|
|
, citationPrefix = [Str "see"]
|
|
|
|
, citationSuffix = [Space ,Str "p.",Space,Str "34-35"]
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0}
|
2021-12-14 10:40:24 -08:00
|
|
|
in (para $ cite [citation] "[cite:see @item1 p. 34-35]")
|
|
|
|
|
|
|
|
, "Author-in-text citation with locator and suffix" =:
|
|
|
|
"[cite/t:see @item1 p. 34-35 and *passim*; @item2]" =?>
|
|
|
|
let citations =
|
|
|
|
[ Citation
|
|
|
|
{ citationId = "item1"
|
|
|
|
, citationPrefix = [ Str "see" ]
|
|
|
|
, citationSuffix =
|
|
|
|
[ Str "p."
|
|
|
|
, Space
|
|
|
|
, Str "34-35"
|
|
|
|
, Space
|
|
|
|
, Str "and"
|
|
|
|
, Space
|
|
|
|
, Strong [ Str "passim" ]
|
|
|
|
]
|
|
|
|
, citationMode = AuthorInText
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
, Citation
|
|
|
|
{ citationId = "item2"
|
|
|
|
, citationPrefix = []
|
|
|
|
, citationSuffix = []
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
in (para $ cite citations "[cite/t:see @item1 p. 34-35 and *passim*; @item2]")
|
2018-02-26 21:09:51 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
, testGroup "org-ref citations"
|
|
|
|
[ "simple citation" =:
|
|
|
|
"cite:pandoc" =?>
|
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "pandoc"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = AuthorInText
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [citation] "cite:pandoc")
|
|
|
|
|
|
|
|
, "simple citation with underscores" =:
|
|
|
|
"cite:pandoc_org_ref" =?>
|
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "pandoc_org_ref"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = AuthorInText
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [citation] "cite:pandoc_org_ref")
|
|
|
|
|
|
|
|
, "simple citation succeeded by comma" =:
|
|
|
|
"cite:pandoc," =?>
|
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "pandoc"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = AuthorInText
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [citation] "cite:pandoc" <> str ",")
|
|
|
|
|
|
|
|
, "simple citation succeeded by dot" =:
|
|
|
|
"cite:pandoc." =?>
|
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "pandoc"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = AuthorInText
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [citation] "cite:pandoc" <> str ".")
|
|
|
|
|
|
|
|
, "simple citation succeeded by colon" =:
|
|
|
|
"cite:pandoc:" =?>
|
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "pandoc"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = AuthorInText
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [citation] "cite:pandoc" <> str ":")
|
|
|
|
|
|
|
|
, "simple citep citation" =:
|
|
|
|
"citep:pandoc" =?>
|
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "pandoc"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [citation] "citep:pandoc")
|
|
|
|
|
2021-02-18 21:53:19 +01:00
|
|
|
, "multiple simple citations" =:
|
|
|
|
"citep:picard,riker" =?>
|
|
|
|
let picard = Citation
|
|
|
|
{ citationId = "picard"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
riker = Citation
|
|
|
|
{ citationId = "riker"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [picard,riker] "citep:picard,riker")
|
|
|
|
|
|
|
|
, "multiple simple citations succeeded by comma" =:
|
|
|
|
"citep:picard,riker," =?>
|
|
|
|
let picard = Citation
|
|
|
|
{ citationId = "picard"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
riker = Citation
|
|
|
|
{ citationId = "riker"
|
|
|
|
, citationPrefix = mempty
|
|
|
|
, citationSuffix = mempty
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [picard,riker] "citep:picard,riker" <> str ",")
|
|
|
|
|
2018-02-26 21:09:51 +01:00
|
|
|
, "extended citation" =:
|
|
|
|
"[[citep:Dominik201408][See page 20::, for example]]" =?>
|
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "Dominik201408"
|
|
|
|
, citationPrefix = toList "See page 20"
|
|
|
|
, citationSuffix = toList ", for example"
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0
|
|
|
|
}
|
|
|
|
in (para $ cite [citation] "[[citep:Dominik201408][See page 20::, for example]]")
|
|
|
|
]
|
|
|
|
|
|
|
|
, "LaTeX citation" =:
|
|
|
|
"\\cite{Coffee}" =?>
|
|
|
|
let citation = Citation
|
|
|
|
{ citationId = "Coffee"
|
|
|
|
, citationPrefix = []
|
|
|
|
, citationSuffix = []
|
|
|
|
, citationMode = NormalCitation
|
|
|
|
, citationNoteNum = 0
|
|
|
|
, citationHash = 0}
|
|
|
|
in (para . cite [citation] $ rawInline "latex" "\\cite{Coffee}")
|
|
|
|
|
|
|
|
]
|