{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Tests.Features.Output
( tests
) where
import Data.Aeson (encode)
import qualified Data.ByteString.Lazy as B
import Data.Maybe
import Features
import Test.Tasty
import Test.Tasty.HUnit
dummy :: Feature "dummy" Bool
dummy :: Feature "dummy" Bool
dummy = forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
dummy2 :: Feature "dummy2" Bool
dummy2 :: Feature "dummy2" Bool
dummy2 = forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
setManyAttributes
[ ("dummy2", ''Bool, emptyAttributes)
, ("dummy", ''Bool, MkAttributes "some Label" "longer label..." "a description" emptyPurpose )]
d :: ByteString
d = ByteString
"\"data\":true"
n :: a -> a
n a
n = a
"\"name\":" forall a. Semigroup a => a -> a -> a
<> a
n
t :: ByteString
t = ByteString
"\"type\":\"Bool\""
a :: a -> a -> a -> a
a a
derv a
ll a
sl =
a
"\"attrs\":{\
\\"getDerivation\":"
forall a. Semigroup a => a -> a -> a
<> a
derv
forall a. Semigroup a => a -> a -> a
<> a
",\
\\"getLongLabel\":"
forall a. Semigroup a => a -> a -> a
<> a
ll
forall a. Semigroup a => a -> a -> a
<> a
",\
\\"getPurpose\":{\"getRole\":[],\"getTags\":[]},\
\\"getShortLabel\":"
forall a. Semigroup a => a -> a -> a
<> a
sl
forall a. Semigroup a => a -> a -> a
<> a
"\
\}"
o :: a -> a -> a -> a -> a
o a
a a
d a
n a
t = a
"{" forall a. Semigroup a => a -> a -> a
<> a
a forall a. Semigroup a => a -> a -> a
<> a
"," forall a. Semigroup a => a -> a -> a
<> a
d forall a. Semigroup a => a -> a -> a
<> a
"," forall a. Semigroup a => a -> a -> a
<> a
n forall a. Semigroup a => a -> a -> a
<> a
"," forall a. Semigroup a => a -> a -> a
<> a
t forall a. Semigroup a => a -> a -> a
<> a
"}"
tests :: TestTree
tests :: TestTree
tests = String -> [TestTree] -> TestTree
testGroup
String
"Unit tests on features outputs as JSON"
[ String -> Assertion -> TestTree
testCase String
"dummy encodes correctly"
forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> ByteString
encode Feature "dummy" Bool
dummy
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= forall {a}. (Semigroup a, IsString a) => a -> a -> a -> a -> a
o (forall {a}. (Semigroup a, IsString a) => a -> a -> a -> a
a ByteString
"\"a description\"" ByteString
"\"longer label...\"" ByteString
"\"some Label\"")
ByteString
d
(forall {a}. (Semigroup a, IsString a) => a -> a
n ByteString
"\"dummy\"")
ByteString
t
, String -> Assertion -> TestTree
testCase String
"dummy2 encodes correctly"
forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> ByteString
encode Feature "dummy2" Bool
dummy2
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= forall {a}. (Semigroup a, IsString a) => a -> a -> a -> a -> a
o (forall {a}. (Semigroup a, IsString a) => a -> a -> a -> a
a ByteString
"\"\"" ByteString
"\"\"" ByteString
"\"\"") ByteString
d (forall {a}. (Semigroup a, IsString a) => a -> a
n ByteString
"\"dummy2\"") ByteString
t
]