on master help sign in
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.

commit2da9009512c41f58b55b50a6f996bb802c96bca7 authorMax New <maxsnew@gmail.com> dateSun 29 Dec 2013, 15:18 (13 years ago) parent1408d92
6 files changed+83−5
.gitignore+1 Elm.cabal+31−2 compiler/SourceSyntax/Literal.hs+2−2 tests/Main.hs+4−1 tests/Tests/Property.hs+22 tests/Tests/Property/Arbitrary.hs+23
.gitignore+1
@@ -10,3 +10,4 @@ cabal-dev
1010data
1111*/ElmFiles/*
1212.DS_Store
13+*~
Elm.cabal+31−2
@@ -228,12 +228,41 @@ Executable elm-doc
228228
229229Test-Suite test-elm
230230 Type: exitcode-stdio-1.0
231− Hs-Source-Dirs: tests
231+ Hs-Source-Dirs: tests, compiler
232232 Main-is: Main.hs
233+ other-modules: Tests.Compiler
234+ Tests.Property
235+ Tests.Property.Arbitrary
236+ SourceSyntax.Helpers
237+ SourceSyntax.Literal
238+ SourceSyntax.PrettyPrint
233239 build-depends: base,
234240 directory,
235241 Elm,
236242 test-framework,
237243 test-framework-hunit,
244+ test-framework-quickcheck2,
238245 HUnit,
239− filemanip
246+ pretty,
247+ QuickCheck >= 2 && < 3,
248+ filemanip,
249+ aeson,
250+ base >=4.2 && <5,
251+ binary >= 0.6.4.0,
252+ blaze-html == 0.5.* || == 0.6.*,
253+ blaze-markup == 0.5.1.*,
254+ bytestring,
255+ cmdargs,
256+ containers >= 0.3,
257+ directory,
258+ filepath,
259+ indents,
260+ language-ecmascript >=0.15 && < 1.0,
261+ mtl >= 2,
262+ pandoc >= 1.10,
263+ parsec >= 3.1.1,
264+ pretty,
265+ text,
266+ transformers >= 0.2,
267+ union-find,
268+ unordered-containers
compiler/SourceSyntax/Literal.hs+2−2
@@ -8,7 +8,7 @@ data Literal = IntNum Int
88 | Chr Char
99 | Str String
1010 | Boolean Bool
11− deriving (Eq, Ord, Show)
11+ deriving (Eq, Ord, Show)
1212
1313instance Pretty Literal where
1414 pretty literal =
@@ -17,4 +17,4 @@ instance Pretty Literal where
1717 FloatNum n -> PP.double n
1818 Chr c -> PP.quotes (PP.char c)
1919 Str s -> PP.text (show s)
20− Boolean bool -> PP.text (show bool)
20+ Boolean bool -> PP.text (show bool)
tests/Main.hs+4−1
@@ -3,6 +3,9 @@ module Main where
33import Test.Framework
44
55import Tests.Compiler
6+import Tests.Property
67
78main :: IO ()
8−main = defaultMain [ compilerTests ]
9+main = defaultMain [ compilerTests
10+ , propertyTests
11+ ]
tests/Tests/Property.hsnew file+22
@@ -0,0 +1,22 @@
1+module Tests.Property where
2+
3+import Test.Framework
4+import Test.Framework.Providers.QuickCheck2
5+import Test.QuickCheck
6+
7+import SourceSyntax.Literal (Literal)
8+import SourceSyntax.PrettyPrint (pretty)
9+import Parse.Helpers (iParse)
10+import Parse.Literal (literal)
11+import Tests.Property.Arbitrary
12+
13+propertyTests :: Test
14+propertyTests =
15+ testGroup "Parse/Print Agreement Tests"
16+ [
17+ testProperty "Literal test" prop_literal_parse_print
18+ ]
19+
20+prop_literal_parse_print :: Literal -> Bool
21+prop_literal_parse_print l =
22+ either (const False) (== l) . iParse literal . show . pretty $ l
tests/Tests/Property/Arbitrary.hsnew file+23
@@ -0,0 +1,23 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2+module Tests.Property.Arbitrary where
3+
4+import Control.Applicative ((<$>))
5+import Test.QuickCheck.Arbitrary
6+import Test.QuickCheck.Gen
7+
8+import SourceSyntax.Literal
9+
10+instance Arbitrary Literal where
11+ arbitrary = oneof [ IntNum <$> arbitrary
12+ , FloatNum <$> arbitrary
13+ , Chr <$> arbitrary
14+ , Str <$> arbitrary
15+ -- Booleans aren't actually source syntax
16+ -- , Boolean <$> arbitrary
17+ ]
18+ shrink l = case l of
19+ IntNum n -> IntNum <$> shrink n
20+ FloatNum f -> FloatNum <$> shrink f
21+ Chr c -> Chr <$> shrink c
22+ Str s -> Str <$> shrink s
23+ Boolean b -> Boolean <$> shrink b