summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorisovector <>2019-05-06 18:21:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-05-06 18:21:00 (GMT)
commit76a4b83979c0744337dc8999813552679cf09930 (patch)
treea9883cc87de93f5882829a405b90b36dc11555a8 /tests
version 0.1.0.0HEAD0.1.0.0master
Diffstat (limited to 'tests')
-rw-r--r--tests/Test.hs53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/Test.hs b/tests/Test.hs
new file mode 100644
index 0000000..c0d6932
--- /dev/null
+++ b/tests/Test.hs
@@ -0,0 +1,53 @@
+{-# LANGUAGE QuasiQuotes, ExtendedDefaultRules, OverloadedStrings, IncoherentInstances #-}
+
+module Main where
+
+import Data.ByteString.Char8 as BS(ByteString, pack)
+import Data.Text as T(Text, pack)
+import GHC.Exts(fromString)
+import Test.HUnit
+import Text.InterpolatedString.QQ2
+
+data Foo = Foo Int String deriving Show
+
+t1 :: String
+t1 = "字元"
+
+testEmpty = assertBool "" ([qc||] == "")
+testCharLiteral = assertBool "" ([qc|#{1+2}|] == "3")
+testString = assertBool "" ([qc|a string #{t1} is here|] == "a string 字元 is here")
+testEscape = assertBool "" ([qc|\#{ }|] == "#{ }")
+testComplex = assertBool "" ([qc|
+ \ok
+#{Foo 4 "Great!" : [Foo 3 "Scott!"]}
+ then
+|] == ("\n" ++
+ " \\ok\n" ++
+ "[Foo 4 \"Great!\",Foo 3 \"Scott!\"]\n" ++
+ " then\n"))
+testConvert = assertBool ""
+ (([qc|#{fromString "a"::Text} #{fromString "b"::ByteString}|] :: String)
+ == "a b")
+
+tests = TestList
+ [ TestLabel "Empty String" $ TestCase testEmpty
+ , TestLabel "Character Literal" $ TestCase testCharLiteral
+ , TestLabel "String Variable" $ TestCase testString
+ , TestLabel "Escape Sequences" $ TestCase testEscape
+ , TestLabel "Complex Expression" $ TestCase testComplex
+ , TestLabel "String Conversion" $ TestCase testConvert
+ , TestLabel "ByteString Test" $ TestCase testByteString
+ , TestLabel "Text Test" $ TestCase testText
+ ]
+
+main = runTestTT tests
+
+
+-- the primary purpose of these tests is to ensure that
+-- the Text and ByteString rewrite rules are firing, to avoid
+-- needlessly converting string types
+testByteString = assertBool "" $ [qc|#{"a" :: ByteString} #{"b" :: ByteString}|]
+ == BS.pack ("a b")
+testText = assertBool "" $ [qc|#{"a" :: Text} #{"b" :: Text}|]
+ == T.pack ("a b")
+