diff --git a/Data/Csv/Conversion.hs b/Data/Csv/Conversion.hs index 3079f2b..1e5c1eb 100644 --- a/Data/Csv/Conversion.hs +++ b/Data/Csv/Conversion.hs @@ -703,6 +703,17 @@ instance ToField Char where toField = toField . T.encodeUtf8 . T.singleton {-# INLINE toField #-} +instance FromField Bool where + parseField "True" = pure True + parseField "False" = pure False + parseField e = typeError "Bool" e Nothing + {-# INLINE parseField #-} + +instance ToField Bool where + toField True = "True" + toField False = "False" + {-# INLINE toField #-} + -- | Accepts same syntax as 'rational'. Ignores whitespace. instance FromField Double where parseField = parseDouble diff --git a/tests/UnitTests.hs b/tests/UnitTests.hs index 474940a..5f1fb0e 100644 --- a/tests/UnitTests.hs +++ b/tests/UnitTests.hs @@ -284,6 +284,7 @@ conversionTests :: [TF.Test] conversionTests = [ testGroup "roundTrip" [ testProperty "Char" (roundTrip :: Char -> Bool) + , testProperty "Bool" (roundTrip :: Bool -> Bool) , testProperty "ByteString" (roundTrip :: B.ByteString -> Bool) , testProperty "Int" (roundTrip :: Int -> Bool) , testProperty "Integer" (roundTrip :: Integer -> Bool)