This commit is contained in:
techtangents 2013-03-17 21:48:39 +10:00
parent cda0a68584
commit 32efcfa941
3 changed files with 36 additions and 4 deletions

5
elm/testRepl Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
here=`cd \`dirname $0\` && pwd`
cd "$here/tests" &&
ghci

View file

@ -10,6 +10,7 @@ import Text.InterpolatedString.Perl6 (qq)
import Parse.Parser
import Util.Arbs
import Debug.Trace
main :: IO ()
main = defaultMain tests
@ -17,6 +18,7 @@ main = defaultMain tests
parses :: String -> Bool
parses code = either (const False) (const True) (parseProgram code)
parseFails :: String -> Bool
parseFails = not . parses
tests :: [TF.Test]
@ -24,14 +26,29 @@ tests = [
testGroup "String Assignments" [
testProperty "prop_assignString" prop_assignString
, testProperty "prop_invalidIdent" prop_invalidIdent
, testProperty "prop_emptyList" prop_emptyList
, testProperty "prop_record" prop_record
]
]
prop_assignString :: ValidIdent -> StringLiteral -> Bool
prop_assignString i s =
parses [qq|{i} = {s}|]
prop_assignString i s = parses [qq|
{i} = {s}
|]
prop_invalidIdent :: ValidIdent -> InvalidIdentChar -> StringLiteral -> Bool
prop_invalidIdent i z s =
parseFails [qq|{i}{z} = {s}|]
prop_invalidIdent i z s = parseFails [qq|
{i}{z} = {s}
|]
prop_emptyList :: ValidIdent -> Bool
prop_emptyList i = parses [qq|
{i}=[]
|]
prop_record :: ValidIdent -> ValidIdent -> ValidIdent -> ValidIdent -> StringLiteral -> Bool
prop_record a b c k v = parses [qq|
{a} = \{{k} = {v} \}
{b} = .{k} {a}
{c} = {a}.{k}
|]

View file

@ -33,3 +33,13 @@ instance ShowQ InvalidIdentChar where
instance Arbitrary InvalidIdentChar where
arbitrary = InvalidIdentChar <$> elements "!@#$%^&*()-=+\\|/?.>,<`~"
newtype BuiltinType = BuiltinType String deriving (Eq, Show)
instance ShowQ BuiltinType where
showQ (BuiltinType v) = v
instance Arbitrary BuiltinType where
-- TODO: add others
arbitrary = BuiltinType <$> elements ["Char", "String"]