on master help sign in
Setup QuickCheck and add Literal Parse/Print test
2da9009Max New
.gitignore+1
@@ -10,3 +10,4 @@ cabal-dev
10data
10data
11*/ElmFiles/*
11*/ElmFiles/*
12.DS_Store
12.DS_Store
13+*~
Elm.cabal+31−2
@@ -228,12 +228,41 @@ Executable elm-doc
228
228
229Test-Suite test-elm
229Test-Suite test-elm
230 Type: exitcode-stdio-1.0
230 Type: exitcode-stdio-1.0
231− Hs-Source-Dirs: tests
231+ Hs-Source-Dirs: tests, compiler
232 Main-is: Main.hs
232 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
233 build-depends: base,
239 build-depends: base,
234 directory,
240 directory,
235 Elm,
241 Elm,
236 test-framework,
242 test-framework,
237 test-framework-hunit,
243 test-framework-hunit,
244+ test-framework-quickcheck2,
238 HUnit,
245 HUnit,
246+ pretty,
247+ QuickCheck >= 2 && < 3,
239− filemanip
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
8 | Chr Char
8 | Chr Char
9 | Str String
9 | Str String
10 | Boolean Bool
10 | Boolean Bool
11− deriving (Eq, Ord, Show)
11+ deriving (Eq, Ord, Show)
12
12
13instance Pretty Literal where
13instance Pretty Literal where
14 pretty literal =
14 pretty literal =
@@ -17,4 +17,4 @@ instance Pretty Literal where
17 FloatNum n -> PP.double n
17 FloatNum n -> PP.double n
18 Chr c -> PP.quotes (PP.char c)
18 Chr c -> PP.quotes (PP.char c)
19 Str s -> PP.text (show s)
19 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
3import Test.Framework
3import Test.Framework
4
4
5import Tests.Compiler
5import Tests.Compiler
6+import Tests.Property
6
7
7main :: IO ()
8main :: 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