diff options
| author | Albert Krewinkel <albert@zeitkraut.de> | 2022-10-07 21:37:57 +0200 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2022-10-10 09:39:18 -0700 |
| commit | a088cbf5637596a461ba9f99b49210235d6c0a68 (patch) | |
| tree | d4703d158cf07e4dd45b96fff16166d5ea9abf31 /pandoc-lua-engine/test/Tests | |
| parent | e1e07cce65a0bb007da934245e74be1b1c8a0f6e (diff) | |
Lua: support extensions in custom writers
Custom writers can define the extensions that they support via the
global `writer_extensions`. The variable's value must be a table with
all supported extensions as keys, and their default status as values.
E.g., the below specifies that the writer support the extensions `smart`
and `sourcepos`, but only the `smart` extension is enabled by default:
writer_extensions = {
smart = true,
sourcepos = false,
}
Diffstat (limited to 'pandoc-lua-engine/test/Tests')
| -rw-r--r-- | pandoc-lua-engine/test/Tests/Lua/Writer.hs | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/pandoc-lua-engine/test/Tests/Lua/Writer.hs b/pandoc-lua-engine/test/Tests/Lua/Writer.hs index 18d4e700d..8b6e82816 100644 --- a/pandoc-lua-engine/test/Tests/Lua/Writer.hs +++ b/pandoc-lua-engine/test/Tests/Lua/Writer.hs @@ -1,12 +1,10 @@ {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} {- | Module : Tests.Lua.Writer Copyright : © 2019-2022 Albert Krewinkel License : GNU GPL, version 2 or above - Maintainer : Albert Krewinkel <albert@zeitkraut.de> -Stability : alpha -Portability : portable Tests for custom Lua writers. -} @@ -14,13 +12,19 @@ module Tests.Lua.Writer (tests) where import Data.Default (Default (def)) import Text.Pandoc.Class (runIOorExplode, readFileStrict) +import Text.Pandoc.Extensions (Extension (..)) +import Text.Pandoc.Format (ExtensionsDiff (..), FlavoredFormat (..), + applyExtensionsDiff) import Text.Pandoc.Lua (writeCustom) +import Text.Pandoc.Options (WriterOptions (..)) import Text.Pandoc.Readers (readNative) import Text.Pandoc.Writers (Writer (ByteStringWriter, TextWriter)) import Test.Tasty (TestTree) import Test.Tasty.Golden (goldenVsString) +import Test.Tasty.HUnit (testCase, (@?=)) import qualified Data.ByteString.Lazy as BL +import qualified Text.Pandoc.Builder as B import qualified Text.Pandoc.UTF8 as UTF8 tests :: [TestTree] @@ -31,7 +35,7 @@ tests = source <- UTF8.toText <$> readFileStrict "testsuite.native" doc <- readNative def source txt <- writeCustom "sample.lua" >>= \case - TextWriter f -> f def doc + (TextWriter f, _) -> f def doc _ -> error "Expected a text writer" pure $ BL.fromStrict (UTF8.fromText txt)) @@ -41,7 +45,7 @@ tests = source <- UTF8.toText <$> readFileStrict "tables.native" doc <- readNative def source txt <- writeCustom "sample.lua" >>= \case - TextWriter f -> f def doc + (TextWriter f, _) -> f def doc _ -> error "Expected a text writer" pure $ BL.fromStrict (UTF8.fromText txt)) @@ -49,7 +53,29 @@ tests = "bytestring.bin" (runIOorExplode $ do txt <- writeCustom "bytestring.lua" >>= \case - ByteStringWriter f -> f def mempty - _ -> error "Expected a bytestring writer" + (ByteStringWriter f, _) -> f def mempty + _ -> error "Expected a bytestring writer" pure txt) + + , testCase "preset extensions" $ do + let ediff = ExtensionsDiff{extsToEnable = [], extsToDisable = []} + let format = FlavoredFormat "extensions.lua" ediff + result <- runIOorExplode $ writeCustom "extensions.lua" >>= \case + (TextWriter write, extsConf) -> do + exts <- applyExtensionsDiff extsConf format + write def{writerExtensions = exts} (B.doc mempty) + _ -> error "Expected a text writer" + result @?= "smart extension is enabled;\ncitations extension is disabled\n" + , testCase "modified extensions" $ do + let ediff = ExtensionsDiff + { extsToEnable = [Ext_citations] + , extsToDisable = [] + } + let format = FlavoredFormat "extensions.lua" ediff + result <- runIOorExplode $ writeCustom "extensions.lua" >>= \case + (TextWriter write, extsConf) -> do + exts <- applyExtensionsDiff extsConf format + write def{writerExtensions = exts} (B.doc mempty) + _ -> error "Expected a text writer" + result @?= "smart extension is enabled;\ncitations extension is enabled\n" ] |
