module Test.Marionette.Context where
import Data.Aeson.Types
import GHC.Generics (Generic)
import Prelude
data Context = ContentContext | ChromeContext
deriving stock ((forall x. Context -> Rep Context x)
-> (forall x. Rep Context x -> Context) -> Generic Context
forall x. Rep Context x -> Context
forall x. Context -> Rep Context x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Context -> Rep Context x
from :: forall x. Context -> Rep Context x
$cto :: forall x. Rep Context x -> Context
to :: forall x. Rep Context x -> Context
Generic, Context -> Context -> Bool
(Context -> Context -> Bool)
-> (Context -> Context -> Bool) -> Eq Context
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Context -> Context -> Bool
== :: Context -> Context -> Bool
$c/= :: Context -> Context -> Bool
/= :: Context -> Context -> Bool
Eq, Int -> Context -> ShowS
[Context] -> ShowS
Context -> String
(Int -> Context -> ShowS)
-> (Context -> String) -> ([Context] -> ShowS) -> Show Context
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Context -> ShowS
showsPrec :: Int -> Context -> ShowS
$cshow :: Context -> String
show :: Context -> String
$cshowList :: [Context] -> ShowS
showList :: [Context] -> ShowS
Show, Context
Context -> Context -> Bounded Context
forall a. a -> a -> Bounded a
$cminBound :: Context
minBound :: Context
$cmaxBound :: Context
maxBound :: Context
Bounded, Int -> Context
Context -> Int
Context -> [Context]
Context -> Context
Context -> Context -> [Context]
Context -> Context -> Context -> [Context]
(Context -> Context)
-> (Context -> Context)
-> (Int -> Context)
-> (Context -> Int)
-> (Context -> [Context])
-> (Context -> Context -> [Context])
-> (Context -> Context -> [Context])
-> (Context -> Context -> Context -> [Context])
-> Enum Context
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Context -> Context
succ :: Context -> Context
$cpred :: Context -> Context
pred :: Context -> Context
$ctoEnum :: Int -> Context
toEnum :: Int -> Context
$cfromEnum :: Context -> Int
fromEnum :: Context -> Int
$cenumFrom :: Context -> [Context]
enumFrom :: Context -> [Context]
$cenumFromThen :: Context -> Context -> [Context]
enumFromThen :: Context -> Context -> [Context]
$cenumFromTo :: Context -> Context -> [Context]
enumFromTo :: Context -> Context -> [Context]
$cenumFromThenTo :: Context -> Context -> Context -> [Context]
enumFromThenTo :: Context -> Context -> Context -> [Context]
Enum)
instance FromJSON Context where
parseJSON :: Value -> Parser Context
parseJSON = String -> (Text -> Parser Context) -> Value -> Parser Context
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"Context" \case
Text
"content" -> Context -> Parser Context
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Context
ContentContext
Text
"chrome" -> Context -> Parser Context
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Context
ChromeContext
Text
other -> String -> Parser Context
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Context) -> String -> Parser Context
forall a b. (a -> b) -> a -> b
$ String
"Unknown context: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
other
instance ToJSON Context where
toJSON :: Context -> Value
toJSON Context
ContentContext = Text -> Value
String Text
"content"
toJSON Context
ChromeContext = Text -> Value
String Text
"chrome"