on master help sign in
Bringing a quasiquoter in for string interpolation in tests. Added a .ghci file to load tests in ghci.
3e30c85techtangents
elm/Elm.cabal+2−1
@@ -149,7 +149,8 @@ test-suite Main
149 QuickCheck >= 2.4,
149 QuickCheck >= 2.4,
150 test-framework >= 0.4.1,
150 test-framework >= 0.4.1,
151 test-framework-quickcheck2,
151 test-framework-quickcheck2,
152− regex-compat
152+ regex-compat,
153+ interpolatedstring-perl6 >= 0.9
153
154
154 hs-source-dirs: src, tests
155 hs-source-dirs: src, tests
155 main-is: Main.hs
156 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 #-}
2
2
3−module Main where
4−
5−import Control.Applicative
6
3
7−import Data.Maybe (listToMaybe, isJust)
4+module Main where
8−import Data.Functor.Identity
9−import Data.Text
10
5
11import Test.Framework as TF (defaultMain, testGroup, Test)
6import Test.Framework as TF (defaultMain, testGroup, Test)
12import Test.Framework.Providers.QuickCheck2 (testProperty)
7import Test.Framework.Providers.QuickCheck2 (testProperty)
13−import Test.QuickCheck
14−import Test.QuickCheck.Property
15−
16−import Text.Regex
17
8
9+import Text.InterpolatedString.Perl6 (qq)
18import Parse.Parser
10import Parse.Parser
19−
20−import Debug.Trace
21−
22import Util.Arbs
11import Util.Arbs
23−import Util.CharGens
24−import Util.Stringable
25
12
26
13
27main :: IO ()
14main :: IO ()
@@ -33,18 +20,15 @@ parses code = either (const False) (const True) (parseProgram code)
33tests :: [TF.Test]
20tests :: [TF.Test]
34tests = [
21tests = [
35 testGroup "String Assignments" [
22 testGroup "String Assignments" [
36− testProperty "prop_assignString" prop_assignString,
23+ testProperty "prop_assignString" prop_assignString
37− testProperty "prop_invalidIdent" prop_invalidIdent
24+ , testProperty "prop_invalidIdent" prop_invalidIdent
38 ]
25 ]
39 ]
26 ]
40
27
41−-- TODO: variable whitespace?
42prop_assignString :: ValidIdent -> StringValue -> Bool
28prop_assignString :: ValidIdent -> StringValue -> Bool
43−prop_assignString vi sv =
29+prop_assignString i s =
44− parses $ vi +- " = \"" +- sv +- "\""
30+ parses [qq|{i} = "{s}"|]
45−
46
31
47prop_invalidIdent :: ValidIdent -> InvalidIdentChar -> StringValue -> Bool
32prop_invalidIdent :: ValidIdent -> InvalidIdentChar -> StringValue -> Bool
48−prop_invalidIdent vi i s =
33+prop_invalidIdent i z s =
49− (not . parses) $ vi +- i +- " = \"" +- s +- "\""
34+ (not . parses) [qq|{i}{z} = "{s}"|]
50−
elm/tests/Util/Arbs.hs+8−7
@@ -3,14 +3,15 @@ module Util.Arbs where
3import Control.Applicative
3import Control.Applicative
4import Test.QuickCheck
4import Test.QuickCheck
5import Util.CharGens
5import Util.CharGens
6−import Util.Stringable
7import Util.String
6import Util.String
8
7
8+import Text.InterpolatedString.Perl6 (ShowQ(showQ))
9+
9
10
10newtype ValidIdent = ValidIdent String deriving (Eq, Show)
11newtype ValidIdent = ValidIdent String deriving (Eq, Show)
11
12
12−instance Stringable ValidIdent where
13+instance ShowQ ValidIdent where
13− stringify (ValidIdent v) = v
14+ showQ (ValidIdent v) = v
14
15
15instance Arbitrary ValidIdent where
16instance Arbitrary ValidIdent where
16 arbitrary = ValidIdent <$> ((:) <$> lowerAlpha <*> (listOf alphaNumUnderPrime))
17 arbitrary = ValidIdent <$> ((:) <$> lowerAlpha <*> (listOf alphaNumUnderPrime))
@@ -18,8 +19,8 @@ instance Arbitrary ValidIdent where
18
19
19newtype StringValue = StringValue String deriving (Eq, Show)
20newtype StringValue = StringValue String deriving (Eq, Show)
20
21
21−instance Stringable StringValue where
22+instance ShowQ StringValue where
22− stringify (StringValue v) = v
23+ showQ (StringValue v) = v
23
24
24instance Arbitrary StringValue where
25instance Arbitrary StringValue where
25 arbitrary = StringValue <$> escape <$> arbitrary
26 arbitrary = StringValue <$> escape <$> arbitrary
@@ -27,8 +28,8 @@ instance Arbitrary StringValue where
27
28
28newtype InvalidIdentChar = InvalidIdentChar Char deriving (Eq, Show)
29newtype InvalidIdentChar = InvalidIdentChar Char deriving (Eq, Show)
29
30
30−instance Stringable InvalidIdentChar where
31+instance ShowQ InvalidIdentChar where
31− stringify (InvalidIdentChar c) = [c]
32+ showQ (InvalidIdentChar c) = [c]
32
33
33instance Arbitrary InvalidIdentChar where
34instance Arbitrary InvalidIdentChar where
34 arbitrary = InvalidIdentChar <$> elements "!@#$%^&*()-=+\\|/?.>,<`~"
35 arbitrary = InvalidIdentChar <$> elements "!@#$%^&*()-=+\\|/?.>,<`~"