File: Inline.hs

package info (click to toggle)
haskell-markdown 0.1.17.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 528 kB
  • sloc: haskell: 1,189; makefile: 4
file content (75 lines) | stat: -rw-r--r-- 3,090 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{-# LANGUAGE OverloadedStrings #-}
module Inline
    ( inlineSpecs
    ) where

import Test.Hspec
import Text.Markdown.Inline
import Data.Text (Text)
import Data.Monoid (mempty)

check :: Text -> [Inline] -> Expectation
check md ins = toInline mempty md `shouldBe` ins

inlineSpecs :: Spec
inlineSpecs = do
    describe "raw text" $ do
        it "simple"
            $ check "raw text" [InlineText "raw text"]
        it "multiline"
            $ check "raw\ntext" [InlineText "raw\ntext"]
    describe "italic" $ do
        it "asterisk"
            $ check "raw *text*" [InlineText "raw ", InlineItalic [InlineText "text"]]
        it "underline"
            $ check "raw _text_" [InlineText "raw ", InlineItalic [InlineText "text"]]
        it "multiline"
            $ check "*raw\ntext*" [InlineItalic [InlineText "raw\ntext"]]
        it "mismatched"
            $ check "*foo* *bar" [InlineItalic [InlineText "foo"], InlineText " *bar"]
    describe "bold" $ do
        it "asterisk"
            $ check "raw **text**" [InlineText "raw ", InlineBold [InlineText "text"]]
        it "underline"
            $ check "raw __text__" [InlineText "raw ", InlineBold [InlineText "text"]]
        it "multiline"
            $ check "**raw\ntext**" [InlineBold [InlineText "raw\ntext"]]
        it "mismatched"
            $ check "**foo** *bar" [InlineBold [InlineText "foo"], InlineText " *bar"]
    describe "nested" $ do
        it "bold inside italic"
            $ check "*i __ib__ i*" [InlineItalic [InlineText "i ", InlineBold [InlineText "ib"], InlineText " i"]]
        it "bold inside italic swap"
            $ check "_i **ib** i_" [InlineItalic [InlineText "i ", InlineBold [InlineText "ib"], InlineText " i"]]
        it "italic inside bold"
            $ check "**b _ib_ b**" [InlineBold [InlineText "b ", InlineItalic [InlineText "ib"], InlineText " b"]]
        it "italic inside bold swap"
            $ check "__b *ib* b__" [InlineBold [InlineText "b ", InlineItalic [InlineText "ib"], InlineText " b"]]
    describe "code" $ do
        it "takes all characters"
            $ check "`foo*__*bar` baz`"
                [ InlineCode "foo*__*bar"
                , InlineText " baz`"
                ]
    describe "escaping" $ do
        it "asterisk"
            $ check "\\*foo*\\\\" [InlineText "*foo*\\"]
    describe "links" $ do
        it "simple" $ check "[bar](foo)" [InlineLink "foo" Nothing [InlineText "bar"]]
        it "title" $ check
            "[bar](foo \"baz\")"
            [InlineLink "foo" (Just "baz") [InlineText "bar"]]
            {-
        it "escaped href" $ check
            "<p><a href=\"foo)\" title=\"baz\">bar</a></p>"
            "[bar](foo\\) \"baz\")"
        it "escaped title" $ check
            "<p><a href=\"foo)\" title=\"baz&quot;\">bar</a></p>"
            "[bar](foo\\) \"baz\\\"\")"
        it "inside a paragraph" $ check
            "<p>Hello <a href=\"foo\">bar</a> World</p>"
            "Hello [bar](foo) World"
        it "not a link" $ check
            "<p>Not a [ link</p>"
            "Not a [ link"
            -}