{-
   Copyright 2015 Raghu Kaippully

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-}

{-# LANGUAGE OverloadedStrings #-}

module Codec.Laydown.Specs where

import Codec.Laydown
import Data.ByteString.Builder
import Test.Hspec

blocks :: SpecWith ()
blocks = do
  describe "hrule" $ do
    it "parses hrule with '-'" $
      laydown " -----" >>= (`shouldBe` Right (Document [HRule]))
    it "parses hrule with '='" $
      laydown " =====" >>= (`shouldBe` Right (Document [HRule]))

  describe "header" $ do
    it "parses h1" $
      laydown " # header" >>= (`shouldBe` Right (Document [Header 1 "header"]))
    it "parses h2" $
      laydown " ## header" >>= (`shouldBe` Right (Document [Header 2 "header"]))
    it "parses h3" $
      laydown " ### header" >>=
        (`shouldBe` Right (Document [Header 3 "header"]))
    it "parses h4" $
      laydown " #### header" >>=
        (`shouldBe` Right (Document [Header 4 "header"]))
    it "parses h5" $
      laydown " ##### header" >>=
        (`shouldBe` Right (Document [Header 5 "header"]))
    it "parses h6" $
      laydown " ###### header" >>=
        (`shouldBe` Right (Document [Header 6 "header"]))

  describe "code block" $ do
    it "parses code block with '~'" $
      laydown "~~~~ haskell\nmain = return ()\n~~~~" >>=
        (`shouldBe` Right (Document [CodeBlock "haskell" "main = return ()\n"]))
    it "parses code block with '`'" $
      laydown "```` haskell\nmain = return ()\n````" >>=
        (`shouldBe` Right (Document [CodeBlock "haskell" "main = return ()\n"]))

  describe "html block" $
    it "parses html block" $
      laydown " !!! \n<em>lay down!</em>\n !!!" >>=
      (`shouldBe` Right (Document [HtmlBlock "<em>lay down!</em>\n"]))

  describe "paragraph" $
    it "parses paragraph" $ do
      let txt = toLazyByteString . stringUtf8 $
                "Many were increasingly of the opinion that they'd all \n" ++
                "made a big mistake in coming down from the trees in the \n" ++
                "first place. And some said that even the trees had been \n" ++
                "a bad move, and that no one should ever have left the \n" ++
                "oceans.\n"
      laydown txt >>= (`shouldBe` Right (Document [Paragraph txt]))
