2015-01-06 12:42:54 +03:00
|
|
|
{-# OPTIONS -fno-warn-orphans #-}
|
|
|
|
|
2018-05-25 08:31:48 +03:00
|
|
|
import Language.SQL.Keyword
|
|
|
|
(Keyword (Sequence), DString, (<++>))
|
2015-01-06 12:42:54 +03:00
|
|
|
|
|
|
|
import Data.Monoid (Monoid, mempty, (<>))
|
|
|
|
import Data.String (fromString)
|
2015-06-16 02:35:32 +03:00
|
|
|
import Test.QuickCheck (Arbitrary (..), Testable)
|
|
|
|
import Test.QuickCheck.Simple (Test, qcTest, defaultMain)
|
|
|
|
|
2015-01-06 12:42:54 +03:00
|
|
|
|
2015-06-16 02:35:32 +03:00
|
|
|
prop :: Testable prop => String -> prop -> Test
|
|
|
|
prop = qcTest
|
2015-01-06 12:42:54 +03:00
|
|
|
|
|
|
|
leftId :: (Eq a, Monoid a) => a -> Bool
|
|
|
|
leftId a = mempty <> a == a
|
|
|
|
|
|
|
|
rightId :: (Eq a, Monoid a) => a -> Bool
|
|
|
|
rightId a = a <> mempty == a
|
|
|
|
|
|
|
|
assoc :: (Eq a, Monoid a) => a -> a -> a -> Bool
|
|
|
|
assoc a b c = (a <> b) <> c == a <> (b <> c)
|
|
|
|
|
|
|
|
dsLeftId :: DString -> Bool
|
|
|
|
dsLeftId = leftId
|
|
|
|
|
|
|
|
dsRightId :: DString -> Bool
|
|
|
|
dsRightId = rightId
|
|
|
|
|
|
|
|
dsAssoc :: DString -> DString -> DString -> Bool
|
|
|
|
dsAssoc = assoc
|
|
|
|
|
|
|
|
instance Arbitrary DString where
|
|
|
|
arbitrary = fmap read arbitrary
|
|
|
|
|
|
|
|
kwLeftId :: Keyword -> Bool
|
|
|
|
kwLeftId = leftId
|
|
|
|
|
|
|
|
kwRightId :: Keyword -> Bool
|
|
|
|
kwRightId = rightId
|
|
|
|
|
|
|
|
kwAssoc :: Keyword -> Keyword -> Keyword -> Bool
|
|
|
|
kwAssoc = assoc
|
|
|
|
|
|
|
|
instance Arbitrary Keyword where
|
|
|
|
arbitrary = fmap fromString arbitrary
|
|
|
|
|
2018-05-25 08:31:48 +03:00
|
|
|
concatCommutative :: DString -> DString -> Bool
|
|
|
|
concatCommutative x y =
|
|
|
|
Sequence x <++> Sequence y
|
|
|
|
==
|
|
|
|
Sequence (x <> y)
|
|
|
|
|
2015-06-16 02:35:32 +03:00
|
|
|
tests :: [Test]
|
|
|
|
tests = [ prop "DString left Id" dsLeftId
|
|
|
|
, prop "DString right Id" dsRightId
|
|
|
|
, prop "DString associativity" dsAssoc
|
|
|
|
, prop "Keyword left Id" kwLeftId
|
|
|
|
, prop "Keyword right Id" kwRightId
|
|
|
|
, prop "Keyword associativity" kwAssoc
|
2018-05-25 08:31:48 +03:00
|
|
|
, prop "concat commutative" concatCommutative
|
2015-06-16 02:35:32 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = defaultMain tests
|