From 788de39262809040ebf1096aff22190ad526dc1b Mon Sep 17 00:00:00 2001 From: defanor Date: Sat, 27 Jan 2024 23:04:26 +0300 Subject: Rewrite, version 0.2: use Parsec, focus on DSV --- test/Test.hs | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/test/Test.hs b/test/Test.hs index b8d4121..f8476d7 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -5,11 +5,9 @@ import Generic.Random (genericArbitraryU) import Test.Tasty import Test.Tasty.QuickCheck as QC import Data.Proxy -import Test.Tasty.Travis import Data.Word import Data.Int import Data.Complex -import Data.Either import Coalpit @@ -88,16 +86,11 @@ instance Arbitrary RecordStrings where arbitrary = genericArbitraryU printAndParse :: (Coalpit a, Eq a) => Options -> Proxy a -> a -> Bool -printAndParse opt _ r = Right r == fromArgs opt (toArgs opt r) - -printAndParseDSV :: (Coalpit a, Eq a) - -- It would take a long time to test with [a], so - -- just repeating it 0--2 times. - => Options -> Proxy a -> (a, Int) -> Bool -printAndParseDSV opt _ (x, n) = - let xs = (replicate (n `mod` 3) x) - in xs == (rights . map (readDSV opt) . lines . unlines . map (showDSV opt) $ xs) +printAndParse opt _ r = Right r == fromDSV opt (toDSV opt r) +printAndParseList :: (Coalpit a, Eq a) + => Options -> Proxy a -> [a] -> Bool +printAndParseList opt _ l = Right l == fromDSVList opt (toDSVList opt l) variousTypes :: (forall a. (Coalpit a, Eq a, Show a, Arbitrary a) => Proxy a -> String -> TestTree) @@ -122,24 +115,20 @@ variousTypes f = variousOptions :: (Options -> [TestTree]) -> [TestTree] variousOptions tt = - [ testGroup (concat [ "alwaysUseSelName = ", show ausn - , ", omitNamedOptions = ", show ono]) - (tt defOpt { alwaysUseSelName = ausn - , omitNamedOptions = ono }) - | ausn <- [True, False] - , ono <- [True, False] + [ testGroup (concat [ "selNamePolicy = ", show snpol ]) + (tt defOpt { selNamePolicy = snpol }) + | snpol <- [SNDisable, SNAvoid, SNPrefer, SNRequire] ] qcProps :: TestTree qcProps = testGroup "Quickcheck properties" - [ testGroup "Right == fromArgs opt . toArgs opt" + [ testGroup "Right == fromDSV opt . toDSV opt" (variousOptions $ \opt -> variousTypes $ \p n -> QC.testProperty n (printAndParse opt p)) - , testGroup - "id == rights . map (readDSV opt) . lines . unlines . map (showDSV opt)" + , testGroup "Right == fromDSVList opt . toDSVList opt" (variousOptions $ \opt -> - variousTypes $ \p n -> QC.testProperty n (printAndParseDSV opt p)) + variousTypes $ \p n -> QC.testProperty n (printAndParseList opt p)) ] main :: IO () -main = travisTestReporter defaultConfig [] qcProps +main = defaultMain qcProps -- cgit v1.2.3