| 1 |
{-# LANGUAGE QuasiQuotes #-} |
| 2 |
{-# LANGUAGE OverloadedStrings #-} |
| 3 |
|
| 4 |
module Data.String.HereSpec where |
| 5 |
|
| 6 |
import Test.Hspec |
| 7 |
|
| 8 |
import qualified Data.Char as Char |
| 9 |
import qualified Data.ByteString as BS |
| 10 |
import qualified Data.Text as T |
| 11 |
|
| 12 |
import Data.String.Here |
| 13 |
|
| 14 |
main :: IO () |
| 15 |
main = hspec spec |
| 16 |
|
| 17 |
spec :: Spec |
| 18 |
spec = do |
| 19 |
describe "i quote" $ do |
| 20 |
it "should interpolate a number" $ do |
| 21 |
let val1 :: Int |
| 22 |
val1 = 7878 |
| 23 |
expect :: String |
| 24 |
expect = "value is 7878" |
| 25 |
actual :: String |
| 26 |
actual = [i|value is ${val1}|] |
| 27 |
actual `shouldBe` expect |
| 28 |
|
| 29 |
-- (from: https://github.com/tmhedberg/here#readme) |
| 30 |
it "should interpolate a String expression" $ do |
| 31 |
let foo :: String |
| 32 |
foo = "foo" |
| 33 |
expect :: String |
| 34 |
expect = "\"foo\", when capitalized, is FOO!" |
| 35 |
actual :: String |
| 36 |
actual = [i|"foo", when capitalized, is ${map Char.toUpper foo}!|] |
| 37 |
actual `shouldBe` expect |
| 38 |
|
| 39 |
it "should interpolate a number to a ByteString" $ do |
| 40 |
let val1 :: Int |
| 41 |
val1 = 3535 |
| 42 |
expect :: BS.ByteString |
| 43 |
expect = "value is 3535" |
| 44 |
actual :: BS.ByteString |
| 45 |
actual = [i|value is ${val1}|] |
| 46 |
actual `shouldBe` expect |
| 47 |
|
| 48 |
it "should interpolate a number to a Text" $ do |
| 49 |
let val1 :: Int |
| 50 |
val1 = 9988 |
| 51 |
expect :: T.Text |
| 52 |
expect = "value is 9988" |
| 53 |
actual :: T.Text |
| 54 |
actual = [i|value is ${val1}|] |
| 55 |
actual `shouldBe` expect |
| 56 |
|
| 57 |
-- (from: https://github.com/tmhedberg/here#readme) |
| 58 |
describe "here quote" $ do |
| 59 |
it "should be here docs" $ do |
| 60 |
let expect :: String |
| 61 |
expect = "Hello world,\n\nI am a multiline here doc!" |
| 62 |
actual :: String |
| 63 |
actual = [here| |
| 64 |
Hello world, |
| 65 |
|
| 66 |
I am a multiline here doc! |
| 67 |
|] |
| 68 |
actual `shouldBe` expect |