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
|
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.String.HereSpec where
import Test.Hspec
import qualified Data.Char as Char
import qualified Data.ByteString as BS
import qualified Data.Text as T
import Data.String.Here
main :: IO ()
main = hspec spec
spec :: Spec
spec = do
describe "i quote" $ do
it "should interpolate a number" $ do
let val1 :: Int
val1 = 7878
expect :: String
expect = "value is 7878"
actual :: String
actual = [i|value is ${val1}|]
actual `shouldBe` expect
-- (from: https://github.com/tmhedberg/here#readme)
it "should interpolate a String expression" $ do
let foo :: String
foo = "foo"
expect :: String
expect = "\"foo\", when capitalized, is FOO!"
actual :: String
actual = [i|"foo", when capitalized, is ${map Char.toUpper foo}!|]
actual `shouldBe` expect
it "should interpolate a number to a ByteString" $ do
let val1 :: Int
val1 = 3535
expect :: BS.ByteString
expect = "value is 3535"
actual :: BS.ByteString
actual = [i|value is ${val1}|]
actual `shouldBe` expect
it "should interpolate a number to a Text" $ do
let val1 :: Int
val1 = 9988
expect :: T.Text
expect = "value is 9988"
actual :: T.Text
actual = [i|value is ${val1}|]
actual `shouldBe` expect
-- (from: https://github.com/tmhedberg/here#readme)
describe "here quote" $ do
it "should be here docs" $ do
let expect :: String
expect = "Hello world,\n\nI am a multiline here doc!"
actual :: String
actual = [here|
Hello world,
I am a multiline here doc!
|]
actual `shouldBe` expect
|