2017-12-24 22:48:18 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2019-02-04 22:52:31 +01:00
|
|
|
{- |
|
|
|
|
Module : Tests.Readers.Org.Block.CodeBlock
|
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 org code blocks.
|
|
|
|
-}
|
2017-12-24 22:48:18 +01:00
|
|
|
module Tests.Readers.Org.Block.CodeBlock (tests) where
|
|
|
|
|
|
|
|
import Test.Tasty (TestTree)
|
|
|
|
import Tests.Helpers ((=?>))
|
|
|
|
import Tests.Readers.Org.Shared ((=:), spcSep)
|
|
|
|
import Text.Pandoc.Builder
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
|
|
|
tests :: [TestTree]
|
|
|
|
tests =
|
|
|
|
[ "Source block" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ " #+begin_src haskell"
|
2017-12-24 22:48:18 +01:00
|
|
|
, " main = putStrLn greeting"
|
|
|
|
, " where greeting = \"moin\""
|
2020-11-18 02:06:30 +08:00
|
|
|
, " #+end_src" ] =?>
|
2017-12-24 22:48:18 +01:00
|
|
|
let attr' = ("", ["haskell"], [])
|
|
|
|
code' = "main = putStrLn greeting\n" <>
|
|
|
|
" where greeting = \"moin\"\n"
|
|
|
|
in codeBlockWith attr' code'
|
|
|
|
|
|
|
|
, "Source block with indented code" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ " #+begin_src haskell"
|
2017-12-24 22:48:18 +01:00
|
|
|
, " main = putStrLn greeting"
|
|
|
|
, " where greeting = \"moin\""
|
2020-11-18 02:06:30 +08:00
|
|
|
, " #+end_src" ] =?>
|
2017-12-24 22:48:18 +01:00
|
|
|
let attr' = ("", ["haskell"], [])
|
|
|
|
code' = "main = putStrLn greeting\n" <>
|
|
|
|
" where greeting = \"moin\"\n"
|
|
|
|
in codeBlockWith attr' code'
|
|
|
|
|
|
|
|
, "Source block with tab-indented code" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "\t#+begin_src haskell"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "\tmain = putStrLn greeting"
|
|
|
|
, "\t where greeting = \"moin\""
|
2020-11-18 02:06:30 +08:00
|
|
|
, "\t#+end_src" ] =?>
|
2017-12-24 22:48:18 +01:00
|
|
|
let attr' = ("", ["haskell"], [])
|
|
|
|
code' = "main = putStrLn greeting\n" <>
|
|
|
|
" where greeting = \"moin\"\n"
|
|
|
|
in codeBlockWith attr' code'
|
|
|
|
|
|
|
|
, "Empty source block" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ " #+begin_src haskell"
|
|
|
|
, " #+end_src" ] =?>
|
2017-12-24 22:48:18 +01:00
|
|
|
let attr' = ("", ["haskell"], [])
|
|
|
|
code' = ""
|
|
|
|
in codeBlockWith attr' code'
|
|
|
|
|
|
|
|
, "Source block between paragraphs" =:
|
|
|
|
T.unlines [ "Low German greeting"
|
2020-11-18 02:06:30 +08:00
|
|
|
, " #+begin_src haskell"
|
2017-12-24 22:48:18 +01:00
|
|
|
, " main = putStrLn greeting"
|
|
|
|
, " where greeting = \"Moin!\""
|
2020-11-18 02:06:30 +08:00
|
|
|
, " #+end_src" ] =?>
|
2017-12-24 22:48:18 +01:00
|
|
|
let attr' = ("", ["haskell"], [])
|
|
|
|
code' = "main = putStrLn greeting\n" <>
|
|
|
|
" where greeting = \"Moin!\"\n"
|
|
|
|
in mconcat [ para $ spcSep [ "Low", "German", "greeting" ]
|
|
|
|
, codeBlockWith attr' code'
|
|
|
|
]
|
|
|
|
, "Source block with babel arguments" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src emacs-lisp :exports both"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "(progn (message \"Hello, World!\")"
|
|
|
|
, " (+ 23 42))"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src" ] =?>
|
2017-12-24 22:48:18 +01:00
|
|
|
let classes = [ "commonlisp" ] -- as kate doesn't know emacs-lisp syntax
|
|
|
|
params = [ ("org-language", "emacs-lisp")
|
|
|
|
, ("exports", "both")
|
|
|
|
]
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 16:12:37 -05:00
|
|
|
code' = T.unlines [ "(progn (message \"Hello, World!\")"
|
2017-12-24 22:48:18 +01:00
|
|
|
, " (+ 23 42))" ]
|
|
|
|
in codeBlockWith ("", classes, params) code'
|
|
|
|
|
|
|
|
, "Source block with results and :exports both" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src emacs-lisp :exports both"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "(progn (message \"Hello, World!\")"
|
|
|
|
, " (+ 23 42))"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
, ""
|
|
|
|
, "#+RESULTS:"
|
|
|
|
, ": 65"] =?>
|
|
|
|
let classes = [ "commonlisp" ]
|
|
|
|
params = [ ("org-language", "emacs-lisp")
|
|
|
|
, ("exports", "both")
|
|
|
|
]
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 16:12:37 -05:00
|
|
|
code' = T.unlines [ "(progn (message \"Hello, World!\")"
|
|
|
|
, " (+ 23 42))" ]
|
2017-12-24 22:48:18 +01:00
|
|
|
results' = "65\n"
|
|
|
|
in codeBlockWith ("", classes, params) code'
|
|
|
|
<>
|
|
|
|
codeBlockWith ("", ["example"], []) results'
|
|
|
|
|
|
|
|
, "Source block with results and :exports code" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src emacs-lisp :exports code"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "(progn (message \"Hello, World!\")"
|
|
|
|
, " (+ 23 42))"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
, ""
|
|
|
|
, "#+RESULTS:"
|
|
|
|
, ": 65" ] =?>
|
|
|
|
let classes = [ "commonlisp" ]
|
|
|
|
params = [ ("org-language", "emacs-lisp")
|
|
|
|
, ("exports", "code")
|
|
|
|
]
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 16:12:37 -05:00
|
|
|
code' = T.unlines [ "(progn (message \"Hello, World!\")"
|
|
|
|
, " (+ 23 42))" ]
|
2017-12-24 22:48:18 +01:00
|
|
|
in codeBlockWith ("", classes, params) code'
|
|
|
|
|
|
|
|
, "Source block with results and :exports results" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src emacs-lisp :exports results"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "(progn (message \"Hello, World!\")"
|
|
|
|
, " (+ 23 42))"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
, ""
|
|
|
|
, "#+RESULTS:"
|
|
|
|
, ": 65" ] =?>
|
|
|
|
let results' = "65\n"
|
|
|
|
in codeBlockWith ("", ["example"], []) results'
|
|
|
|
|
|
|
|
, "Source block with results and :exports none" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src emacs-lisp :exports none"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "(progn (message \"Hello, World!\")"
|
|
|
|
, " (+ 23 42))"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
, ""
|
|
|
|
, "#+RESULTS:"
|
|
|
|
, ": 65" ] =?>
|
|
|
|
(mempty :: Blocks)
|
|
|
|
|
|
|
|
, "Source block with toggling header arguments" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src sh :noeval"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "echo $HOME"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
] =?>
|
|
|
|
let classes = [ "bash" ]
|
|
|
|
params = [ ("org-language", "sh"), ("noeval", "yes") ]
|
|
|
|
in codeBlockWith ("", classes, params) "echo $HOME\n"
|
|
|
|
|
|
|
|
, "Source block with line number switch" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src sh -n 10"
|
2017-12-24 22:48:18 +01:00
|
|
|
, ":() { :|:& };:"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
] =?>
|
|
|
|
let classes = [ "bash", "numberLines" ]
|
|
|
|
params = [ ("org-language", "sh"), ("startFrom", "10") ]
|
|
|
|
in codeBlockWith ("", classes, params) ":() { :|:& };:\n"
|
|
|
|
|
|
|
|
, "Source block with multi-word parameter values" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src dot :cmdline -Kdot -Tpng "
|
2017-12-24 22:48:18 +01:00
|
|
|
, "digraph { id [label=\"ID\"] }"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
] =?>
|
|
|
|
let classes = [ "dot" ]
|
|
|
|
params = [ ("cmdline", "-Kdot -Tpng") ]
|
|
|
|
in codeBlockWith ("", classes, params) "digraph { id [label=\"ID\"] }\n"
|
|
|
|
|
|
|
|
, "Example block" =:
|
|
|
|
T.unlines [ "#+begin_example"
|
|
|
|
, "A chosen representation of"
|
|
|
|
, "a rule."
|
|
|
|
, "#+eND_exAMPle"
|
|
|
|
] =?>
|
|
|
|
codeBlockWith ("", ["example"], [])
|
|
|
|
"A chosen representation of\na rule.\n"
|
|
|
|
|
|
|
|
, "Code block with caption" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+caption: Functor laws in Haskell"
|
|
|
|
, "#+name: functor-laws"
|
|
|
|
, "#+begin_src haskell"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "fmap id = id"
|
|
|
|
, "fmap (p . q) = (fmap p) . (fmap q)"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
] =?>
|
|
|
|
divWith
|
2021-01-01 10:50:58 +01:00
|
|
|
("", ["captioned-content"], [] )
|
2017-12-24 22:48:18 +01:00
|
|
|
(mappend
|
2021-01-01 10:50:58 +01:00
|
|
|
(divWith ("", ["caption"], []) $
|
|
|
|
plain (spcSep [ "Functor", "laws", "in", "Haskell" ]))
|
2017-12-24 22:48:18 +01:00
|
|
|
(codeBlockWith ("functor-laws", ["haskell"], [])
|
Switch to new pandoc-types and use Text instead of String [API change].
PR #5884.
+ Use pandoc-types 1.20 and texmath 0.12.
+ Text is now used instead of String, with a few exceptions.
+ In the MediaBag module, some of the types using Strings
were switched to use FilePath instead (not Text).
+ In the Parsing module, new parsers `manyChar`, `many1Char`,
`manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`,
`mantyUntilChar` have been added: these are like their
unsuffixed counterparts but pack some or all of their output.
+ `glob` in Text.Pandoc.Class still takes String since it seems
to be intended as an interface to Glob, which uses strings.
It seems to be used only once in the package, in the EPUB writer,
so that is not hard to change.
2019-11-04 16:12:37 -05:00
|
|
|
(T.unlines [ "fmap id = id"
|
|
|
|
, "fmap (p . q) = (fmap p) . (fmap q)"
|
|
|
|
])))
|
2017-12-24 22:48:18 +01:00
|
|
|
|
|
|
|
, "Non-letter chars in source block parameters" =:
|
2020-11-18 02:06:30 +08:00
|
|
|
T.unlines [ "#+begin_src C :tangle xxxx.c :city Zürich"
|
2017-12-24 22:48:18 +01:00
|
|
|
, "code body"
|
2020-11-18 02:06:30 +08:00
|
|
|
, "#+end_src"
|
2017-12-24 22:48:18 +01:00
|
|
|
] =?>
|
|
|
|
let params = [ ("org-language", "C")
|
|
|
|
, ("tangle", "xxxx.c")
|
|
|
|
, ("city", "Zürich")
|
|
|
|
]
|
|
|
|
in codeBlockWith ( "", ["c"], params) "code body\n"
|
|
|
|
]
|