on master help sign in
Bringing a quasiquoter in for string interpolation in tests. Added a .ghci file to load tests in ghci.
commit3e30c85fedbda99fc4a76ae87671b775b1d8c535 authortechtangents <dylan@techtangents.com> dateSun 17 Mar 2013, 20:45 (14 years ago) parentfb6f334
4 files changed+24−33
elm/Elm.cabal+2−1 elm/tests/.ghci+5 elm/tests/Main.hs+9−25 elm/tests/Util/Arbs.hs+8−7
elm/Elm.cabal+2−1
@@ -149,7 +149,8 @@ test-suite Main
149149 QuickCheck >= 2.4,
150150 test-framework >= 0.4.1,
151151 test-framework-quickcheck2,
152− regex-compat
152+ regex-compat,
153+ interpolatedstring-perl6 >= 0.9
153154
154155 hs-source-dirs: src, tests
155156 main-is: Main.hs
elm/tests/.ghcinew file+5
@@ -0,0 +1,5 @@
1+:set -i../src -i.
2+:l Main Parse.Parser
3+:m + Test.QuickCheck Main
4+:set prompt "test>> "
5+:set -Wall
elm/tests/Main.hs+9−25
@@ -1,27 +1,14 @@
1−{-# LANGUAGE GeneralizedNewtypeDeriving, TypeSynonymInstances, FlexibleInstances #-}
1+{-# LANGUAGE GeneralizedNewtypeDeriving, TypeSynonymInstances, FlexibleInstances, QuasiQuotes, ExtendedDefaultRules #-}
22
3−module Main where
4−
5−import Control.Applicative
63
7−import Data.Maybe (listToMaybe, isJust)
8−import Data.Functor.Identity
9−import Data.Text
4+module Main where
105
116import Test.Framework as TF (defaultMain, testGroup, Test)
127import Test.Framework.Providers.QuickCheck2 (testProperty)
13−import Test.QuickCheck
14−import Test.QuickCheck.Property
15−
16−import Text.Regex
178
9+import Text.InterpolatedString.Perl6 (qq)
1810import Parse.Parser
19−
20−import Debug.Trace
21−
2211import Util.Arbs
23−import Util.CharGens
24−import Util.Stringable
2512
2613
2714main :: IO ()
@@ -33,18 +20,15 @@ parses code = either (const False) (const True) (parseProgram code)
3320tests :: [TF.Test]
3421tests = [
3522 testGroup "String Assignments" [
36− testProperty "prop_assignString" prop_assignString,
37− testProperty "prop_invalidIdent" prop_invalidIdent
23+ testProperty "prop_assignString" prop_assignString
24+ , testProperty "prop_invalidIdent" prop_invalidIdent
3825 ]
3926 ]
4027
41−-- TODO: variable whitespace?
4228prop_assignString :: ValidIdent -> StringValue -> Bool
43−prop_assignString vi sv =
44− parses $ vi +- " = \"" +- sv +- "\""
45−
29+prop_assignString i s =
30+ parses [qq|{i} = "{s}"|]
4631
4732prop_invalidIdent :: ValidIdent -> InvalidIdentChar -> StringValue -> Bool
48−prop_invalidIdent vi i s =
49− (not . parses) $ vi +- i +- " = \"" +- s +- "\""
50−
33+prop_invalidIdent i z s =
34+ (not . parses) [qq|{i}{z} = "{s}"|]
elm/tests/Util/Arbs.hs+8−7
@@ -3,14 +3,15 @@ module Util.Arbs where
33import Control.Applicative
44import Test.QuickCheck
55import Util.CharGens
6−import Util.Stringable
76import Util.String
87
8+import Text.InterpolatedString.Perl6 (ShowQ(showQ))
9+
910
1011newtype ValidIdent = ValidIdent String deriving (Eq, Show)
1112
12−instance Stringable ValidIdent where
13− stringify (ValidIdent v) = v
13+instance ShowQ ValidIdent where
14+ showQ (ValidIdent v) = v
1415
1516instance Arbitrary ValidIdent where
1617 arbitrary = ValidIdent <$> ((:) <$> lowerAlpha <*> (listOf alphaNumUnderPrime))
@@ -18,8 +19,8 @@ instance Arbitrary ValidIdent where
1819
1920newtype StringValue = StringValue String deriving (Eq, Show)
2021
21−instance Stringable StringValue where
22− stringify (StringValue v) = v
22+instance ShowQ StringValue where
23+ showQ (StringValue v) = v
2324
2425instance Arbitrary StringValue where
2526 arbitrary = StringValue <$> escape <$> arbitrary
@@ -27,8 +28,8 @@ instance Arbitrary StringValue where
2728
2829newtype InvalidIdentChar = InvalidIdentChar Char deriving (Eq, Show)
2930
30−instance Stringable InvalidIdentChar where
31− stringify (InvalidIdentChar c) = [c]
31+instance ShowQ InvalidIdentChar where
32+ showQ (InvalidIdentChar c) = [c]
3233
3334instance Arbitrary InvalidIdentChar where
3435 arbitrary = InvalidIdentChar <$> elements "!@#$%^&*()-=+\\|/?.>,<`~"