summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert+github@zeitkraut.de>2017-11-18 22:24:06 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-11-18 13:24:06 -0800
commit53aafd66434d97f5e0e9209650581177e2c79a91 (patch)
treeaa703574e2b659a13c608f67cc35b93376da4fa2 /test
parent6018a2324d4eddc3844aa4c00b17294e85003750 (diff)
Lua filters: preload text module (#4077)
The `text` module is preloaded in lua. The module contains some UTF-8 aware string functions, implemented in Haskell. The module is loaded on request only, e.g.: text = require 'text' function Str (s) s.text = text.upper(s.text) return s end
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Lua.hs12
-rw-r--r--test/lua/uppercase-header.lua9
2 files changed, 18 insertions, 3 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index f9f0e9753..e380be6bb 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -7,9 +7,9 @@ import Test.Tasty (TestTree, localOption)
import Test.Tasty.HUnit (Assertion, assertEqual, testCase)
import Test.Tasty.QuickCheck (QuickCheckTests (..), ioProperty, testProperty)
import Text.Pandoc.Arbitrary ()
-import Text.Pandoc.Builder (bulletList, doc, doubleQuoted, emph, linebreak,
- para, plain, rawBlock, singleQuoted, space, str,
- strong, (<>))
+import Text.Pandoc.Builder (bulletList, doc, doubleQuoted, emph, header,
+ linebreak, para, plain, rawBlock, singleQuoted,
+ space, str, strong, (<>))
import Text.Pandoc.Class (runIOorExplode)
import Text.Pandoc.Definition (Block, Inline, Meta, Pandoc)
import Text.Pandoc.Lua
@@ -77,6 +77,12 @@ tests = map (localOption (QuickCheckTests 20))
"block-count.lua"
(doc $ para "one" <> para "two")
(doc $ para "2")
+
+ , testCase "Convert header upper case" $
+ assertFilterConversion "converting header to upper case failed"
+ "uppercase-header.lua"
+ (doc $ header 1 "les états-unis" <> para "text")
+ (doc $ header 1 "LES ÉTATS-UNIS" <> para "text")
]
assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion
diff --git a/test/lua/uppercase-header.lua b/test/lua/uppercase-header.lua
new file mode 100644
index 000000000..8e86911c0
--- /dev/null
+++ b/test/lua/uppercase-header.lua
@@ -0,0 +1,9 @@
+local text = require 'text'
+
+local function str_to_uppercase (s)
+ return pandoc.Str(text.upper(s.text))
+end
+
+function Header (el)
+ return pandoc.walk_block(el, {Str = str_to_uppercase})
+end