1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Tests.Readers.HTML (tests) where
7import qualified Data.Text as T
9import Test.Tasty.QuickCheck
10import Test.Tasty.Options (IsOption(defaultValue))
13import Text.Pandoc.Arbitrary ()
14import Text.Pandoc.Builder
15import Text.Pandoc.Walk (walk)
18html = purely $ readHtml def
20htmlNativeDivs :: Text -> Pandoc
21htmlNativeDivs = purely $ readHtml def { readerExtensions = enableExtension Ext_native_divs $ readerExtensions def }
23makeRoundTrip :: Block -> Block
24makeRoundTrip CodeBlock{} = Para [Str "code block was here"]
25makeRoundTrip LineBlock{} = Para [Str "line block was here"]
26makeRoundTrip RawBlock{} = Para [Str "raw block was here"]
29removeRawInlines :: Inline -> Inline
30removeRawInlines RawInline{} = Str "raw inline was here"
33roundTrip :: Blocks -> Bool
34roundTrip b = d'' == d'''
35 where d = walk removeRawInlines $
36 walk makeRoundTrip $ Pandoc nullMeta $ toList b
40 rewrite = html . T.pack . (++ "\n") . T.unpack .
41 purely (writeHtml5String def
42 { writerWrapText = WrapPreserve })
45tests = [ testGroup "base tag"
46 [ test html "simple" $
47 "<head><base href=\"http://www.w3schools.com/images/foo\" ></head><body><img src=\"stickman.gif\" alt=\"Stickman\"></head>" =?>
48 plain (image "http://www.w3schools.com/images/stickman.gif" "" (text "Stickman"))
49 , test html "slash at end of base" $
50 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"stickman.gif\" alt=\"Stickman\"></head>" =?>
51 plain (image "http://www.w3schools.com/images/stickman.gif" "" (text "Stickman"))
52 , test html "slash at beginning of href" $
53 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"/stickman.gif\" alt=\"Stickman\"></head>" =?>
54 plain (image "http://www.w3schools.com/stickman.gif" "" (text "Stickman"))
55 , test html "absolute URL" $
56 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"http://example.com/stickman.gif\" alt=\"Stickman\"></head>" =?>
57 plain (image "http://example.com/stickman.gif" "" (text "Stickman"))
60 [ test html "anchor without href" $ "<a name=\"anchor\"/>" =?>
61 plain (spanWith ("anchor",[],[]) mempty)
64 [ test html "lang on <html>" $ "<html lang=\"es\">hola" =?>
65 setMeta "lang" (text "es") (doc (plain (text "hola")))
66 , test html "xml:lang on <html>" $ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"es\"><head></head><body>hola</body></html>" =?>
67 setMeta "lang" (text "es") (doc (plain (text "hola")))
70 [ test htmlNativeDivs "<main> becomes <div role=main>" $ "<main>hello</main>" =?>
71 doc (divWith ("", [], [("role", "main")]) (plain (text "hello")))
72 , test htmlNativeDivs "<main role=X> becomes <div role=X>" $ "<main role=foobar>hello</main>" =?>
73 doc (divWith ("", [], [("role", "foobar")]) (plain (text "hello")))
74 , test htmlNativeDivs "<main> has attributes preserved" $ "<main id=foo class=bar data-baz=qux>hello</main>" =?>
75 doc (divWith ("foo", ["bar"], [("role", "main"), ("data-baz", "qux")]) (plain (text "hello")))
76 , test htmlNativeDivs "<main> closes <p>" $ "<p>hello<main>main content</main>" =?>
77 doc (para (text "hello") <> divWith ("", [], [("role", "main")]) (plain (text "main content")))
78 , test htmlNativeDivs "<main> followed by text" $ "<main>main content</main>non-main content" =?>
79 doc (divWith ("", [], [("role", "main")]) (plain (text "main content")) <> plain (text "non-main content"))
81 , askOption $ \(QuickCheckTests numtests) ->
82 testProperty "Round trip" $
83 withMaxSuccess (if QuickCheckTests numtests == defaultValue
85 else numtests) roundTrip
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list