aboutsummaryrefslogtreecommitdiffstats
path: root/tests/PropMime.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-02-21 14:18:13 +0100
committertv <tv@krebsco.de>2026-02-21 22:22:17 +0100
commit55d42f1dd83b428aa0f1352bc0ea1402b9c2b811 (patch)
tree81d5e80b385de42a0d1b48d3edd0d2b66d858b2d /tests/PropMime.hs
generate initial commit
Generate haskell-http-client from running g4f v-7.1.4. Server started like this: python -m g4f --port 8080 --debug Code generated like this: openapi-generator-cli generate \ -i http://localhost:8080/openapi.json \ -g haskell-http-client \ --skip-validate-spec \ -o g4f-client \ --additional-properties=cabalPackage=g4f-client,cabalVersion=7.1.4,baseModule=G4fApi
Diffstat (limited to 'tests/PropMime.hs')
-rw-r--r--tests/PropMime.hs51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/PropMime.hs b/tests/PropMime.hs
new file mode 100644
index 0000000..eccbfbe
--- /dev/null
+++ b/tests/PropMime.hs
@@ -0,0 +1,51 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE ConstraintKinds #-}
+{-# OPTIONS_GHC -fno-warn-unused-imports #-}
+
+module PropMime where
+
+import Data.Aeson
+import Data.Aeson.Types (parseEither)
+import Data.Monoid ((<>))
+import Data.Typeable (Proxy(..), typeOf, Typeable)
+import qualified Data.ByteString.Lazy.Char8 as BL8
+import Test.Hspec
+import Test.QuickCheck
+import Test.QuickCheck.Property
+import Test.Hspec.QuickCheck (prop)
+
+import G4fClient.MimeTypes
+
+import ApproxEq
+
+-- * Type Aliases
+
+type ArbitraryMime mime a = ArbitraryRoundtrip (MimeUnrender mime) (MimeRender mime) a
+
+type ArbitraryRoundtrip from to a = (from a, to a, Arbitrary' a)
+
+type Arbitrary' a = (Arbitrary a, Show a, Typeable a)
+
+-- * Mime
+
+propMime
+ :: forall a b mime.
+ (ArbitraryMime mime a, Testable b)
+ => String -> (a -> a -> b) -> mime -> Proxy a -> Spec
+propMime eqDescr eq m _ =
+ prop
+ (show (typeOf (undefined :: a)) <> " " <> show (typeOf (undefined :: mime)) <> " roundtrip " <> eqDescr) $
+ \(x :: a) ->
+ let rendered = mimeRender' m x
+ actual = mimeUnrender' m rendered
+ expected = Right x
+ failMsg =
+ "ACTUAL: " <> show actual <> "\nRENDERED: " <> BL8.unpack rendered
+ in counterexample failMsg $
+ either reject property (eq <$> actual <*> expected)
+ where
+ reject = property . const rejected
+
+propMimeEq :: (ArbitraryMime mime a, Eq a) => mime -> Proxy a -> Spec
+propMimeEq = propMime "(EQ)" (==)