From 60762c3493f1173eba7e6fde9321c4e6d6b8adf1 Mon Sep 17 00:00:00 2001 From: VegOwOtenks Date: Thu, 14 Aug 2025 09:21:50 +0200 Subject: [PATCH] feat[test]: roundtrips, test for read <-> show --- test/Test/Data/Map/Implicit.hs | 24 ++++++++++++++++++++++++ test/Test/QuickCheck/Roundtrip.hs | 7 +++++++ 2 files changed, 31 insertions(+) create mode 100644 test/Test/Data/Map/Implicit.hs create mode 100644 test/Test/QuickCheck/Roundtrip.hs diff --git a/test/Test/Data/Map/Implicit.hs b/test/Test/Data/Map/Implicit.hs new file mode 100644 index 0000000..d474fec --- /dev/null +++ b/test/Test/Data/Map/Implicit.hs @@ -0,0 +1,24 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeApplications #-} +module Test.Data.Map.Implicit (prop_readShowIdentityRoundtrip, prop_readShowMaybeRoundtrip, runTests) where +import Test.QuickCheck.Roundtrip (roundtrips) +import Text.Show (show) +import Text.Read (read) +import Data.Map.Implicit (ImplicitMap) +import Data.Bool (Bool) +import Language.Scalie.Ast.Definition (Definition) +import Data.Functor.Identity (Identity) +import Test.QuickCheck.All (quickCheckAll) +import System.IO (IO) +import Control.Applicative (pure) +import Data.Maybe (Maybe) + +prop_readShowIdentityRoundtrip :: ImplicitMap (Definition Identity) -> Bool +prop_readShowIdentityRoundtrip = roundtrips read show + +prop_readShowMaybeRoundtrip :: ImplicitMap (Definition Maybe) -> Bool +prop_readShowMaybeRoundtrip = roundtrips read show + +pure [] +runTests :: IO Bool +runTests = $quickCheckAll diff --git a/test/Test/QuickCheck/Roundtrip.hs b/test/Test/QuickCheck/Roundtrip.hs new file mode 100644 index 0000000..0ae6093 --- /dev/null +++ b/test/Test/QuickCheck/Roundtrip.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE Safe #-} +module Test.QuickCheck.Roundtrip (roundtrips) where +import Data.Eq ((==), Eq) +import Data.Bool (Bool) + +roundtrips :: Eq t1 => (t2 -> t1) -> (t1 -> t2) -> t1 -> Bool +roundtrips back forth x = x == back (forth x)