packages feed

interpolatedstring-qq-0.1: tests/Test.hs

{-# LANGUAGE QuasiQuotes #-}

module Main where

import Text.InterpolatedString.QQ
import Test.HUnit

data Foo = Foo Int String deriving Show

t1 = "value"

testEmpty = assertBool "" ([$istr||] == "")
testNumLiteral = assertBool "" ([$istr|#{3}|] == "3")
testString     = assertBool "" ([$istr|a string #{t1} is here|] == "a string value is here")
testEscape     = assertBool "" ([$istr|#\{}|] == "#{}" && [$istr|\#{}|] == "#{}")
testComplex    = assertBool "" ([$istr|
        ok
#{Foo 4 "Great!" : [Foo 3 "Scott!"]}
        then
|] == ("\n" ++
    "        ok\n" ++
    "[Foo 4 \"Great!\",Foo 3 \"Scott!\"]\n" ++
    "        then\n"))


tests = TestList
    [ TestLabel "Empty String" $ TestCase testEmpty
    , TestLabel "Number Literal" $ TestCase testNumLiteral
    , TestLabel "String Variable" $ TestCase testString
    , TestLabel "Escape Sequences" $ TestCase testEscape
    , TestLabel "Complex Expression" $ TestCase testComplex
    ]

main = runTestTT tests