summaryrefslogtreecommitdiff
path: root/test/UnitTests.hs
diff options
context:
space:
mode:
authorAndor Penzes <andor.penzes@gmail.com>2016-01-07 11:51:07 +0100
committerAndor Penzes <andor.penzes@gmail.com>2016-01-07 11:51:21 +0100
commit95589d8e5a5738f227c6697aabab970d80070e37 (patch)
tree810605ddd95164b3c9df74c4c067e1d2dca8704c /test/UnitTests.hs
parent63cc26dc33374722148e1339a1afe770f943d360 (diff)
raname Main.hs to UnitTests.hs
Diffstat (limited to 'test/UnitTests.hs')
-rw-r--r--test/UnitTests.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/UnitTests.hs b/test/UnitTests.hs
new file mode 100644
index 00000000..59a95601
--- /dev/null
+++ b/test/UnitTests.hs
@@ -0,0 +1,42 @@
1module Main where
2
3import Data.Monoid
4import Text.Parsec.Pos (SourcePos(..), newPos, sourceName, sourceLine, sourceColumn)
5
6import Test.QuickCheck
7import Test.Tasty
8import Test.Tasty.QuickCheck
9
10import Infer
11
12
13main = defaultMain $ testGroup "Compiler"
14 [ testGroup "Infer" [
15 testProperty "SI Monoid Identity" (propMonoidIdentity (arbitrary :: Gen SI))
16 , testProperty "SI Monoid Associativity" (propMonoidAssociativity (arbitrary :: Gen SI))
17 ]
18 ]
19
20----------------------------------------------------------------- Arbitraries
21
22instance Arbitrary SourcePos where
23 arbitrary = newPos <$> arbitrary <*> arbitrary <*> arbitrary
24 shrink pos
25 | n <- sourceName pos, l <- sourceLine pos, c <- sourceColumn pos
26 = [newPos n' l' c' | n' <- shrink n, l' <- shrink l, c' <- shrink c]
27 -- TODO: Diagonalize shrink
28
29instance Arbitrary SI where
30 arbitrary = oneof [return NoSI, Range <$> arbitrary]
31 shrink NoSI = []
32 shrink (Range r) = NoSI:map Range (shrink r)
33
34----------------------------------------------------------------- Properties
35
36-- * Monoid
37
38propMonoidIdentity :: (Eq m, Monoid m, Show m) => Gen m -> Property
39propMonoidIdentity gen = forAll gen (\x -> x === x <> mempty)
40
41propMonoidAssociativity :: (Arbitrary m, Eq m, Monoid m, Show m) => Gen m -> Property
42propMonoidAssociativity gen = forAll gen (\x y z -> (x <> y) <> z == x <> (y <> z))