on master help sign in
tests
commit32efcfa941d6cff73ee88323ffda3af4e0932753 authortechtangents <dylan@techtangents.com> dateSun 17 Mar 2013, 21:48 (14 years ago) parentcda0a68
3 files changed+37−5
elm/testRepl+5 elm/tests/Main.hs+22−5 elm/tests/Util/Arbs.hs+10
elm/testReplnew file+5
@@ -0,0 +1,5 @@
1+#!/bin/sh
2+
3+here=`cd \`dirname $0\` && pwd`
4+cd "$here/tests" &&
5+ghci
elm/tests/Main.hs+22−5
@@ -10,6 +10,7 @@ import Text.InterpolatedString.Perl6 (qq)
1010import Parse.Parser
1111import Util.Arbs
1212
13+import Debug.Trace
1314
1415main :: IO ()
1516main = defaultMain tests
@@ -17,6 +18,7 @@ main = defaultMain tests
1718parses :: String -> Bool
1819parses code = either (const False) (const True) (parseProgram code)
1920
21+parseFails :: String -> Bool
2022parseFails = not . parses
2123
2224tests :: [TF.Test]
@@ -24,14 +26,29 @@ tests = [
2426 testGroup "String Assignments" [
2527 testProperty "prop_assignString" prop_assignString
2628 , testProperty "prop_invalidIdent" prop_invalidIdent
29+ , testProperty "prop_emptyList" prop_emptyList
30+ , testProperty "prop_record" prop_record
2731 ]
2832 ]
2933
3034prop_assignString :: ValidIdent -> StringLiteral -> Bool
31−prop_assignString i s =
32− parses [qq|{i} = {s}|]
35+prop_assignString i s = parses [qq|
36+{i} = {s}
37+|]
3338
3439prop_invalidIdent :: ValidIdent -> InvalidIdentChar -> StringLiteral -> Bool
35−prop_invalidIdent i z s =
36− parseFails [qq|{i}{z} = {s}|]
37−
40+prop_invalidIdent i z s = parseFails [qq|
41+{i}{z} = {s}
42+|]
43+
44+prop_emptyList :: ValidIdent -> Bool
45+prop_emptyList i = parses [qq|
46+{i}=[]
47+|]
48+
49+prop_record :: ValidIdent -> ValidIdent -> ValidIdent -> ValidIdent -> StringLiteral -> Bool
50+prop_record a b c k v = parses [qq|
51+{a} = \{{k} = {v} \}
52+{b} = .{k} {a}
53+{c} = {a}.{k}
54+|]
elm/tests/Util/Arbs.hs+10
@@ -33,3 +33,13 @@ instance ShowQ InvalidIdentChar where
3333
3434instance Arbitrary InvalidIdentChar where
3535 arbitrary = InvalidIdentChar <$> elements "!@#$%^&*()-=+\\|/?.>,<`~"
36+
37+
38+newtype BuiltinType = BuiltinType String deriving (Eq, Show)
39+
40+instance ShowQ BuiltinType where
41+ showQ (BuiltinType v) = v
42+
43+instance Arbitrary BuiltinType where
44+ -- TODO: add others
45+ arbitrary = BuiltinType <$> elements ["Char", "String"]