2021-05-09 10:53:18 +01:00
|
|
|
{-# LANGUAGE BlockArguments #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module MarkdownTests where
|
|
|
|
|
|
|
|
import Data.Text (Text)
|
|
|
|
import Simplex.Chat.Markdown
|
|
|
|
import System.Console.ANSI.Types
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
markdownTests :: Spec
|
|
|
|
markdownTests = do
|
|
|
|
textFormat
|
|
|
|
secretText
|
|
|
|
textColor
|
2022-02-22 18:18:35 +00:00
|
|
|
textWithUri
|
2021-05-09 10:53:18 +01:00
|
|
|
|
|
|
|
textFormat :: Spec
|
|
|
|
textFormat = describe "text format (bold)" do
|
|
|
|
it "correct markdown" do
|
|
|
|
parseMarkdown "this is *bold formatted* text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is " <> markdown Bold "bold formatted" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "*bold formatted* text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` markdown Bold "bold formatted" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is *bold*"
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "this is " <> markdown Bold "bold"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown " *bold* text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` " " <> markdown Bold "bold" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown " *bold* text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` " " <> markdown Bold "bold" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is *bold* "
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "this is " <> markdown Bold "bold" <> " "
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is *bold* "
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "this is " <> markdown Bold "bold" <> " "
|
2021-05-09 10:53:18 +01:00
|
|
|
it "ignored as markdown" do
|
|
|
|
parseMarkdown "this is * unformatted * text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is * unformatted * text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is *unformatted * text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is *unformatted * text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is * unformatted* text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is * unformatted* text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is **unformatted** text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is **unformatted** text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is*unformatted* text"
|
|
|
|
`shouldBe` "this is*unformatted* text"
|
|
|
|
parseMarkdown "this is *unformatted text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is *unformatted text"
|
2021-05-09 10:53:18 +01:00
|
|
|
it "ignored internal markdown" do
|
|
|
|
parseMarkdown "this is *long _bold_ (not italic)* text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is " <> markdown Bold "long _bold_ (not italic)" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "snippet: `this is *bold text*`"
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "snippet: " <> markdown Snippet "this is *bold text*"
|
2021-05-09 10:53:18 +01:00
|
|
|
|
|
|
|
secretText :: Spec
|
|
|
|
secretText = describe "secret text" do
|
|
|
|
it "correct markdown" do
|
|
|
|
parseMarkdown "this is #black_secret# text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is " <> markdown Secret "black_secret" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "##black_secret### text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` markdown Secret "#black_secret##" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is #black secret# text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is " <> markdown Secret "black secret" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "##black secret### text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` markdown Secret "#black secret##" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is #secret#"
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "this is " <> markdown Secret "secret"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown " #secret# text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` " " <> markdown Secret "secret" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown " #secret# text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` " " <> markdown Secret "secret" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is #secret# "
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "this is " <> markdown Secret "secret" <> " "
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is #secret# "
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "this is " <> markdown Secret "secret" <> " "
|
2021-05-09 10:53:18 +01:00
|
|
|
it "ignored as markdown" do
|
|
|
|
parseMarkdown "this is # unformatted # text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is # unformatted # text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is #unformatted # text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is #unformatted # text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is # unformatted# text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is # unformatted# text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is ## unformatted ## text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is ## unformatted ## text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is#unformatted# text"
|
|
|
|
`shouldBe` "this is#unformatted# text"
|
|
|
|
parseMarkdown "this is #unformatted text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is #unformatted text"
|
2021-05-09 10:53:18 +01:00
|
|
|
it "ignored internal markdown" do
|
|
|
|
parseMarkdown "snippet: `this is #secret_text#`"
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "snippet: " <> markdown Snippet "this is #secret_text#"
|
2021-05-09 10:53:18 +01:00
|
|
|
|
|
|
|
red :: Text -> Markdown
|
2022-02-22 14:05:45 +00:00
|
|
|
red = markdown (colored Red)
|
2021-05-09 10:53:18 +01:00
|
|
|
|
|
|
|
textColor :: Spec
|
|
|
|
textColor = describe "text color (red)" do
|
|
|
|
it "correct markdown" do
|
|
|
|
parseMarkdown "this is !1 red color! text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is " <> red "red color" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "!1 red! text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` red "red" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is !1 red!"
|
|
|
|
`shouldBe` "this is " <> red "red"
|
|
|
|
parseMarkdown " !1 red! text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` " " <> red "red" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown " !1 red! text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` " " <> red "red" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is !1 red! "
|
|
|
|
`shouldBe` "this is " <> red "red" <> " "
|
|
|
|
parseMarkdown "this is !1 red! "
|
|
|
|
`shouldBe` "this is " <> red "red" <> " "
|
|
|
|
it "ignored as markdown" do
|
|
|
|
parseMarkdown "this is !1 unformatted ! text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is !1 unformatted ! text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is !1 unformatted ! text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is !1 unformatted ! text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "this is !1 unformatted! text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is !1 unformatted! text"
|
2021-05-09 10:53:18 +01:00
|
|
|
-- parseMarkdown "this is !!1 unformatted!! text"
|
|
|
|
-- `shouldBe` "this is " <> "!!1" <> "unformatted!! text"
|
|
|
|
parseMarkdown "this is!1 unformatted! text"
|
|
|
|
`shouldBe` "this is!1 unformatted! text"
|
|
|
|
parseMarkdown "this is !1 unformatted text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is !1 unformatted text"
|
2021-05-09 10:53:18 +01:00
|
|
|
it "ignored internal markdown" do
|
|
|
|
parseMarkdown "this is !1 long *red* (not bold)! text"
|
2022-02-22 18:18:35 +00:00
|
|
|
`shouldBe` "this is " <> red "long *red* (not bold)" <> " text"
|
2021-05-09 10:53:18 +01:00
|
|
|
parseMarkdown "snippet: `this is !1 red text!`"
|
2022-02-22 14:05:45 +00:00
|
|
|
`shouldBe` "snippet: " <> markdown Snippet "this is !1 red text!"
|
2022-02-22 18:18:35 +00:00
|
|
|
|
|
|
|
uri :: Text -> Markdown
|
|
|
|
uri = Markdown $ Just Uri
|
|
|
|
|
|
|
|
textWithUri :: Spec
|
|
|
|
textWithUri = describe "text with Uri" do
|
|
|
|
it "correct markdown" do
|
|
|
|
parseMarkdown "https://simplex.chat" `shouldBe` uri "https://simplex.chat"
|
|
|
|
parseMarkdown "http://simplex.chat" `shouldBe` uri "http://simplex.chat"
|
|
|
|
parseMarkdown "this is https://simplex.chat" `shouldBe` "this is " <> uri "https://simplex.chat"
|
|
|
|
parseMarkdown "https://simplex.chat site" `shouldBe` uri "https://simplex.chat" <> " site"
|
|
|
|
it "ignored as markdown" do
|
|
|
|
parseMarkdown "_https://simplex.chat" `shouldBe` "_https://simplex.chat"
|
|
|
|
parseMarkdown "this is _https://simplex.chat" `shouldBe` "this is _https://simplex.chat"
|