aboutsummaryrefslogtreecommitdiff
path: root/tests/Tests
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-05-10 22:53:35 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-06-24 20:29:41 -0700
commitf869f7e08dad315945d52be3fcacf6ff0c05c5c1 (patch)
tree4c426ebf5a30b51499859f9d41a890534b6a18a6 /tests/Tests
parente32a8f5981969bb6d0a11bd945188c35817e4d96 (diff)
downloadpandoc-f869f7e08dad315945d52be3fcacf6ff0c05c5c1.tar.gz
Use new flexible metadata type.
* Depend on pandoc 1.12. * Added yaml dependency. * `Text.Pandoc.XML`: Removed `stripTags`. (API change.) * `Text.Pandoc.Shared`: Added `metaToJSON`. This will be used in writers to create a JSON object for use in the templates from the pandoc metadata. * Revised readers and writers to use the new Meta type. * `Text.Pandoc.Options`: Added `Ext_yaml_title_block`. * Markdown reader: Added support for YAML metadata block. Note that it must come at the beginning of the document. * `Text.Pandoc.Parsing.ParserState`: Replace `stateTitle`, `stateAuthors`, `stateDate` with `stateMeta`. * RST reader: Improved metadata. Treat initial field list as metadata when standalone specified. Previously ALL fields "title", "author", "date" in field lists were treated as metadata, even if not at the beginning. Use `subtitle` metadata field for subtitle. * `Text.Pandoc.Templates`: Export `renderTemplate'` that takes a string instead of a compiled template.. * OPML template: Use 'for' loop for authors. * Org template: '#+TITLE:' is inserted before the title. Previously the writer did this.
Diffstat (limited to 'tests/Tests')
-rw-r--r--tests/Tests/Arbitrary.hs11
-rw-r--r--tests/Tests/Helpers.hs6
-rw-r--r--tests/Tests/Readers/RST.hs34
-rw-r--r--tests/Tests/Writers/Native.hs2
4 files changed, 35 insertions, 18 deletions
diff --git a/tests/Tests/Arbitrary.hs b/tests/Tests/Arbitrary.hs
index d0000dcee..5939d088d 100644
--- a/tests/Tests/Arbitrary.hs
+++ b/tests/Tests/Arbitrary.hs
@@ -150,10 +150,13 @@ instance Arbitrary QuoteType where
instance Arbitrary Meta where
arbitrary
- = do x1 <- arbitrary
- x2 <- liftM (filter (not . null)) arbitrary
- x3 <- arbitrary
- return (Meta x1 x2 x3)
+ = do (x1 :: Inlines) <- arbitrary
+ (x2 :: [Inlines]) <- liftM (filter (not . isNull)) arbitrary
+ (x3 :: Inlines) <- arbitrary
+ return $ setMeta "title" x1
+ $ setMeta "author" x2
+ $ setMeta "date" x3
+ $ nullMeta
instance Arbitrary Alignment where
arbitrary
diff --git a/tests/Tests/Helpers.hs b/tests/Tests/Helpers.hs
index af64f5148..b48c8af3a 100644
--- a/tests/Tests/Helpers.hs
+++ b/tests/Tests/Helpers.hs
@@ -20,6 +20,7 @@ import Text.Pandoc.Options
import Text.Pandoc.Writers.Native (writeNative)
import qualified Test.QuickCheck.Property as QP
import Data.Algorithm.Diff
+import qualified Data.Map as M
test :: (ToString a, ToString b, ToString c)
=> (a -> b) -- ^ function to test
@@ -58,8 +59,9 @@ class ToString a where
instance ToString Pandoc where
toString d = writeNative def{ writerStandalone = s } $ toPandoc d
where s = case d of
- (Pandoc (Meta [] [] []) _) -> False
- _ -> True
+ (Pandoc (Meta m) _)
+ | M.null m -> False
+ | otherwise -> True
instance ToString Blocks where
toString = writeNative def . toPandoc
diff --git a/tests/Tests/Readers/RST.hs b/tests/Tests/Readers/RST.hs
index 2876f4270..a80dc32b7 100644
--- a/tests/Tests/Readers/RST.hs
+++ b/tests/Tests/Readers/RST.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
module Tests.Readers.RST (tests) where
import Text.Pandoc.Definition
@@ -7,9 +7,10 @@ import Tests.Helpers
import Tests.Arbitrary()
import Text.Pandoc.Builder
import Text.Pandoc
+import Data.Monoid (mempty)
rst :: String -> Pandoc
-rst = readRST def
+rst = readRST def{ readerStandalone = True }
infix 4 =:
(=:) :: ToString c
@@ -21,14 +22,12 @@ tests = [ "line block with blank line" =:
"| a\n|\n| b" =?> para (str "a") <>
para (str "\160b")
, "field list" =: unlines
- [ ":Hostname: media08"
+ [ "para"
+ , ""
+ , ":Hostname: media08"
, ":IP address: 10.0.0.19"
, ":Size: 3ru"
- , ":Date: 2001-08-16"
, ":Version: 1"
- , ":Authors: - Me"
- , " - Myself"
- , " - I"
, ":Indentation: Since the field marker may be quite long, the second"
, " and subsequent lines of the field body do not have to line up"
, " with the first line, but they must be indented relative to the"
@@ -36,10 +35,9 @@ tests = [ "line block with blank line" =:
, ":Parameter i: integer"
, ":Final: item"
, " on two lines" ]
- =?> ( setAuthors ["Me","Myself","I"]
- $ setDate "2001-08-16"
- $ doc
- $ definitionList [ (str "Hostname", [para "media08"])
+ =?> ( doc
+ $ para "para" <>
+ definitionList [ (str "Hostname", [para "media08"])
, (str "IP address", [para "10.0.0.19"])
, (str "Size", [para "3ru"])
, (str "Version", [para "1"])
@@ -47,6 +45,20 @@ tests = [ "line block with blank line" =:
, (str "Parameter i", [para "integer"])
, (str "Final", [para "item on two lines"])
])
+ , "initial field list" =: unlines
+ [ "====="
+ , "Title"
+ , "====="
+ , "--------"
+ , "Subtitle"
+ , "--------"
+ , ""
+ , ":Version: 1"
+ ]
+ =?> ( setMeta "version" (para "1")
+ $ setMeta "title" ("Title" :: Inlines)
+ $ setMeta "subtitle" ("Subtitle" :: Inlines)
+ $ doc mempty )
, "URLs with following punctuation" =:
("http://google.com, http://yahoo.com; http://foo.bar.baz.\n" ++
"http://foo.bar/baz_(bam) (http://foo.bar)") =?>
diff --git a/tests/Tests/Writers/Native.hs b/tests/Tests/Writers/Native.hs
index e199cf94e..9833bf5ae 100644
--- a/tests/Tests/Writers/Native.hs
+++ b/tests/Tests/Writers/Native.hs
@@ -12,7 +12,7 @@ p_write_rt d =
p_write_blocks_rt :: [Block] -> Bool
p_write_blocks_rt bs = length bs > 20 ||
- read (writeNative def (Pandoc (Meta [] [] []) bs)) ==
+ read (writeNative def (Pandoc nullMeta bs)) ==
bs
tests :: [Test]