on master help sign in
Package juggling in tests
commitfb6f3346d2dfb6569ceac6f5e48c41fe1c625fb3 authortechtangents <dylan@techtangents.com> dateFri 15 Mar 2013, 23:54 (14 years ago) parent17d90a3
4 files changed+52−40
elm/tests/Main.hs+2−40 elm/tests/Util/Arbs.hs+34 elm/tests/Util/String.hs+15 elm/tests/Util/Stringable.hs+1
elm/tests/Main.hs+2−40
@@ -19,8 +19,9 @@ import Parse.Parser
1919
2020import Debug.Trace
2121
22−import Util.Stringable
22+import Util.Arbs
2323import Util.CharGens
24+import Util.Stringable
2425
2526
2627main :: IO ()
@@ -37,45 +38,6 @@ tests = [
3738 ]
3839 ]
3940
40−
41−newtype ValidIdent = ValidIdent String deriving (Eq, Show)
42−
43−instance Stringable ValidIdent where
44− stringify (ValidIdent v) = v
45−
46−instance Arbitrary ValidIdent where
47− arbitrary = ValidIdent <$> ((:) <$> lowerAlpha <*> (listOf alphaNumUnderPrime))
48−
49−
50−newtype StringValue = StringValue String deriving (Eq, Show)
51−
52−instance Stringable StringValue where
53− stringify (StringValue v) = v
54−
55−instance Arbitrary StringValue where
56− arbitrary = StringValue <$> escape <$> arbitrary
57−
58−
59−newtype InvalidIdentChar = InvalidIdentChar Char deriving (Eq, Show)
60−
61−instance Stringable InvalidIdentChar where
62− stringify (InvalidIdentChar c) = [c]
63−
64−instance Arbitrary InvalidIdentChar where
65− arbitrary = InvalidIdentChar <$> elements "!@#$%^&*()-=+\\|/?.>,<`~"
66−
67−
68−replace' :: String -> String -> String -> String
69−replace' a b c = unpack $ replace (pack a) (pack b) (pack c)
70−
71−escape :: String -> String
72−escape =
73− (replace' "\n" "\\n") .
74− (replace' "\t" "\\t") .
75− (replace' "\"" "\\\"") .
76− (replace' "\\" "\\\\")
77−
78−
7941-- TODO: variable whitespace?
8042prop_assignString :: ValidIdent -> StringValue -> Bool
8143prop_assignString vi sv =
elm/tests/Util/Arbs.hsnew file+34
@@ -0,0 +1,34 @@
1+module Util.Arbs where
2+
3+import Control.Applicative
4+import Test.QuickCheck
5+import Util.CharGens
6+import Util.Stringable
7+import Util.String
8+
9+
10+newtype ValidIdent = ValidIdent String deriving (Eq, Show)
11+
12+instance Stringable ValidIdent where
13+ stringify (ValidIdent v) = v
14+
15+instance Arbitrary ValidIdent where
16+ arbitrary = ValidIdent <$> ((:) <$> lowerAlpha <*> (listOf alphaNumUnderPrime))
17+
18+
19+newtype StringValue = StringValue String deriving (Eq, Show)
20+
21+instance Stringable StringValue where
22+ stringify (StringValue v) = v
23+
24+instance Arbitrary StringValue where
25+ arbitrary = StringValue <$> escape <$> arbitrary
26+
27+
28+newtype InvalidIdentChar = InvalidIdentChar Char deriving (Eq, Show)
29+
30+instance Stringable InvalidIdentChar where
31+ stringify (InvalidIdentChar c) = [c]
32+
33+instance Arbitrary InvalidIdentChar where
34+ arbitrary = InvalidIdentChar <$> elements "!@#$%^&*()-=+\\|/?.>,<`~"
elm/tests/Util/String.hsnew file+15
@@ -0,0 +1,15 @@
1+module Util.String where
2+
3+import qualified Data.Text as T
4+
5+replace :: String -> String -> String -> String
6+replace a b c = T.unpack (T.replace (T.pack a) (T.pack b) (T.pack c))
7+
8+escape :: String -> String
9+escape =
10+ (replace "\n" "\\n") .
11+ (replace "\t" "\\t") .
12+ (replace "\"" "\\\"") .
13+ (replace "\\" "\\\\")
14+
15+-- (a -> t) -> a -> b -> c -> (t -> t -> t -> z) -> z
elm/tests/Util/Stringable.hs+1
@@ -11,3 +11,4 @@ instance Stringable String where
1111infixr 5 +-
1212(+-) :: (Stringable a, Stringable b) => a -> b -> String
1313a +- b = (stringify a) ++ (stringify b)
14+