on master help sign in
Add To/FromJSON instances for Verbosity
e6e7655Alexey Khudyakov
katip/src/Katip/Core.hs+15
@@ -179,6 +179,21 @@ instance FromJSON Severity where
179 Just x -> return x
179 Just x -> return x
180 Nothing -> fail $ "Invalid Severity " ++ toS t
180 Nothing -> fail $ "Invalid Severity " ++ toS t
181
181
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+
182
197
183-------------------------------------------------------------------------------
198-------------------------------------------------------------------------------
184-- | Log message with Builder underneath; use '<>' to concat in O(1).
199-- | Log message with Builder underneath; use '<>' to concat in O(1).
katip/test/Katip/Tests.hs+6
@@ -42,6 +42,8 @@ tests = testGroup "Katip"
42 [
42 [
43 testProperty "JSON cycle Item" $ \(i :: Item ()) ->
43 testProperty "JSON cycle Item" $ \(i :: Item ()) ->
44 prop_json_cycle i
44 prop_json_cycle i
45+ , testProperty "JSON cycle verbosity" $ \(v :: Verbosity) ->
46+ prop_json_cycle v
45 , eqItemTests
47 , eqItemTests
46 , testProperty "renderSeverity/textToSeverity cycle" $ \sev ->
48 , testProperty "renderSeverity/textToSeverity cycle" $ \sev ->
47 textToSeverity(renderSeverity sev) === Just sev
49 textToSeverity(renderSeverity sev) === Just sev
@@ -259,6 +261,10 @@ instance Arbitrary Loc where
259 return $ Loc f p m s s
261 return $ Loc f p m s s
260
262
261
263
264+-------------------------------------------------------------------------------
265+instance Arbitrary Verbosity where
266+ arbitrary = oneof $ map pure [V0, V1, V2, V3]
267+
262-------------------------------------------------------------------------------
268-------------------------------------------------------------------------------
263instance Arbitrary Severity where
269instance Arbitrary Severity where
264 arbitrary = oneof $ map pure [ DebugS
270 arbitrary = oneof $ map pure [ DebugS