From b384871b242cef11e717f2671e0128f75887e3b0 Mon Sep 17 00:00:00 2001 From: remeike Date: Mon, 5 Aug 2024 09:07:59 -0400 Subject: [PATCH 1/3] Fix regex match operator (#336) --- src/Rel8/Expr/Text.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Rel8/Expr/Text.hs b/src/Rel8/Expr/Text.hs index 0218ae4f..7458bd8b 100644 --- a/src/Rel8/Expr/Text.hs +++ b/src/Rel8/Expr/Text.hs @@ -58,9 +58,9 @@ infixr 6 ++. -- | Matches regular expression, case sensitive -- --- Corresponds to the @~.@ operator. +-- Corresponds to the @~@ operator. (~.) :: Expr Text -> Expr Text -> Expr Bool -(~.) = binaryOperator "~." +(~.) = binaryOperator "~" infix 2 ~. From d9a624441743b74c3fc35fac5d9e096c07168ae8 Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Wed, 7 Aug 2024 14:52:39 +0100 Subject: [PATCH 2/3] Fix fromRational bug (#338) Postgresql and Haskell differ in how they print numbers at the limits of a double's precision. When these numbers have whole digits, we have less precision to give to the decimal part, so we need to be less accurate than 1e15. --- tests/Main.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/Main.hs b/tests/Main.hs index 9020a840..8e2a4b33 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -625,7 +625,14 @@ testFromRational = databasePropertyTest "fromRational" \transaction -> do pure $ fromRational rational diff result (~=) double where - a ~= b = abs (a - b) < 1e-15 + wholeDigits x = fromIntegral $ length $ show $ round x + -- A Double gives us between 15-17 decimal digits of precision. + -- It's tempting to say that two numbers are equal if they differ by less than 1e15. + -- But this doesn't hold. + -- The precision is split between the whole numer part and the decimal part of the number. + -- For instance, a number between 10 and 99 only has around 13 digits of precision in its decimal part. + -- Postgres and Haskell show differing amounts of digits in these cases, + a ~= b = abs (a - b) < 10**(-15 + wholeDigits a) infix 4 ~= From 9580b6ffb3d019c2dbf7d33451f8f55defeee1ce Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Wed, 7 Aug 2024 14:54:55 +0100 Subject: [PATCH 3/3] Disallow NULL characters in Hedgehog generated text values (#339) These are not permitted by postgresql and they lead to a runtime error. --- tests/Main.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/Main.hs b/tests/Main.hs index 8e2a4b33..e4358cc8 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -81,6 +81,7 @@ import Test.Tasty.Hedgehog ( testProperty ) -- text import Data.Text ( Text, pack, unpack ) +import qualified Data.Text as T import qualified Data.Text.Lazy import Data.Text.Encoding ( decodeUtf8 ) @@ -430,14 +431,18 @@ instance Rel8.DBComposite Composite where compositeTypeName = "composite" compositeFields = Rel8.namesFromLabels +-- | Postgres doesn't support the NULL character (not to be confused with a NULL value) inside strings. +removeNull :: Text -> Text +removeNull = T.filter (/='\0') + testDBType :: IO TmpPostgres.DB -> TestTree testDBType getTestDatabase = testGroup "DBType instances" [ dbTypeTest "Bool" Gen.bool , dbTypeTest "ByteString" $ Gen.bytes (Range.linear 0 128) , dbTypeTest "CalendarDiffTime" genCalendarDiffTime - , dbTypeTest "CI Lazy Text" $ mk . Data.Text.Lazy.fromStrict <$> Gen.text (Range.linear 0 10) Gen.unicode - , dbTypeTest "CI Text" $ mk <$> Gen.text (Range.linear 0 10) Gen.unicode + , dbTypeTest "CI Lazy Text" $ mk . Data.Text.Lazy.fromStrict . removeNull <$> Gen.text (Range.linear 0 10) Gen.unicode + , dbTypeTest "CI Text" $ mk .removeNull <$> Gen.text (Range.linear 0 10) Gen.unicode , dbTypeTest "Composite" genComposite , dbTypeTest "Day" genDay , dbTypeTest "Double" $ (/ 10) . fromIntegral @Int @Double <$> Gen.integral (Range.linear (-100) 100) @@ -446,10 +451,10 @@ testDBType getTestDatabase = testGroup "DBType instances" , dbTypeTest "Int32" $ Gen.integral @_ @Int32 Range.linearBounded , dbTypeTest "Int64" $ Gen.integral @_ @Int64 Range.linearBounded , dbTypeTest "Lazy ByteString" $ Data.ByteString.Lazy.fromStrict <$> Gen.bytes (Range.linear 0 128) - , dbTypeTest "Lazy Text" $ Data.Text.Lazy.fromStrict <$> Gen.text (Range.linear 0 10) Gen.unicode + , dbTypeTest "Lazy Text" $ Data.Text.Lazy.fromStrict . removeNull <$> Gen.text (Range.linear 0 10) Gen.unicode , dbTypeTest "LocalTime" genLocalTime , dbTypeTest "Scientific" $ (/ 10) . fromIntegral @Int @Scientific <$> Gen.integral (Range.linear (-100) 100) - , dbTypeTest "Text" $ Gen.text (Range.linear 0 10) Gen.unicode + , dbTypeTest "Text" $ removeNull <$> Gen.text (Range.linear 0 10) Gen.unicode , dbTypeTest "TimeOfDay" genTimeOfDay , dbTypeTest "UTCTime" $ UTCTime <$> genDay <*> genDiffTime , dbTypeTest "UUID" $ Data.UUID.fromWords <$> genWord32 <*> genWord32 <*> genWord32 <*> genWord32