on master help sign in
Add To/FromJSON instances for Verbosity

I gues missing instances were just an oversight

commite6e7655b2b60f95ec96c16cbde84e5109755dadd authorAlexey Khudyakov <alexey.skladnoy@gmail.com> dateTue 9 Oct 2018, 19:01 (8 years ago) parent2fb2e6a
2 files changed+21
katip/src/Katip/Core.hs+15 katip/test/Katip/Tests.hs+6
katip/src/Katip/Core.hs+15
@@ -179,6 +179,21 @@ instance FromJSON Severity where
179179 Just x -> return x
180180 Nothing -> fail $ "Invalid Severity " ++ toS t
181181
182+instance ToJSON Verbosity where
183+ toJSON s = A.String $ case s of
184+ V0 -> "V0"
185+ V1 -> "V1"
186+ V2 -> "V2"
187+ V3 -> "V3"
188+
189+instance FromJSON Verbosity where
190+ parseJSON = A.withText "Verbosity" $ \s -> case s of
191+ "V0" -> return V0
192+ "V1" -> return V1
193+ "V2" -> return V2
194+ "V3" -> return V3
195+ _ -> fail $ "Invalid Verbosity " ++ toS s
196+
182197
183198-------------------------------------------------------------------------------
184199-- | Log message with Builder underneath; use '<>' to concat in O(1).
katip/test/Katip/Tests.hs+6
@@ -42,6 +42,8 @@ tests = testGroup "Katip"
4242 [
4343 testProperty "JSON cycle Item" $ \(i :: Item ()) ->
4444 prop_json_cycle i
45+ , testProperty "JSON cycle verbosity" $ \(v :: Verbosity) ->
46+ prop_json_cycle v
4547 , eqItemTests
4648 , testProperty "renderSeverity/textToSeverity cycle" $ \sev ->
4749 textToSeverity(renderSeverity sev) === Just sev
@@ -259,6 +261,10 @@ instance Arbitrary Loc where
259261 return $ Loc f p m s s
260262
261263
264+-------------------------------------------------------------------------------
265+instance Arbitrary Verbosity where
266+ arbitrary = oneof $ map pure [V0, V1, V2, V3]
267+
262268-------------------------------------------------------------------------------
263269instance Arbitrary Severity where
264270 arbitrary = oneof $ map pure [ DebugS