Setup QuickCheck and add Literal Parse/Print test

Currently fails the prop tests: https://github.com/evancz/Elm/issues/420

Also ignore emacs backup files.
This commit is contained in:
Max New 2013-12-29 15:18:40 -06:00
parent 1408d928d5
commit 2da9009512
6 changed files with 83 additions and 5 deletions

1
.gitignore vendored
View file

@ -10,3 +10,4 @@ cabal-dev
data
*/ElmFiles/*
.DS_Store
*~

View file

@ -228,12 +228,41 @@ Executable elm-doc
Test-Suite test-elm
Type: exitcode-stdio-1.0
Hs-Source-Dirs: tests
Hs-Source-Dirs: tests, compiler
Main-is: Main.hs
other-modules: Tests.Compiler
Tests.Property
Tests.Property.Arbitrary
SourceSyntax.Helpers
SourceSyntax.Literal
SourceSyntax.PrettyPrint
build-depends: base,
directory,
Elm,
test-framework,
test-framework-hunit,
test-framework-quickcheck2,
HUnit,
filemanip
pretty,
QuickCheck >= 2 && < 3,
filemanip,
aeson,
base >=4.2 && <5,
binary >= 0.6.4.0,
blaze-html == 0.5.* || == 0.6.*,
blaze-markup == 0.5.1.*,
bytestring,
cmdargs,
containers >= 0.3,
directory,
filepath,
indents,
language-ecmascript >=0.15 && < 1.0,
mtl >= 2,
pandoc >= 1.10,
parsec >= 3.1.1,
pretty,
text,
transformers >= 0.2,
union-find,
unordered-containers

View file

@ -8,7 +8,7 @@ data Literal = IntNum Int
| Chr Char
| Str String
| Boolean Bool
deriving (Eq, Ord, Show)
deriving (Eq, Ord, Show)
instance Pretty Literal where
pretty literal =

View file

@ -3,6 +3,9 @@ module Main where
import Test.Framework
import Tests.Compiler
import Tests.Property
main :: IO ()
main = defaultMain [ compilerTests ]
main = defaultMain [ compilerTests
, propertyTests
]

22
tests/Tests/Property.hs Normal file
View file

@ -0,0 +1,22 @@
module Tests.Property where
import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.QuickCheck
import SourceSyntax.Literal (Literal)
import SourceSyntax.PrettyPrint (pretty)
import Parse.Helpers (iParse)
import Parse.Literal (literal)
import Tests.Property.Arbitrary
propertyTests :: Test
propertyTests =
testGroup "Parse/Print Agreement Tests"
[
testProperty "Literal test" prop_literal_parse_print
]
prop_literal_parse_print :: Literal -> Bool
prop_literal_parse_print l =
either (const False) (== l) . iParse literal . show . pretty $ l

View file

@ -0,0 +1,23 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Tests.Property.Arbitrary where
import Control.Applicative ((<$>))
import Test.QuickCheck.Arbitrary
import Test.QuickCheck.Gen
import SourceSyntax.Literal
instance Arbitrary Literal where
arbitrary = oneof [ IntNum <$> arbitrary
, FloatNum <$> arbitrary
, Chr <$> arbitrary
, Str <$> arbitrary
-- Booleans aren't actually source syntax
-- , Boolean <$> arbitrary
]
shrink l = case l of
IntNum n -> IntNum <$> shrink n
FloatNum f -> FloatNum <$> shrink f
Chr c -> Chr <$> shrink c
Str s -> Str <$> shrink s
Boolean b -> Boolean <$> shrink b