packages feed

yaml-pretty-extras-0.0.1.3: test/Spec.hs

{-# LANGUAGE DeriveAnyClass #-}
import           Data.Yaml.Pretty.Extras
import           GHC.Generics
import           RIO
import qualified RIO.ByteString                as BS
import           Test.Hspec


data Person = Person {
  mood :: Text,
  job  :: Text
} deriving (Eq, Generic, FromJSON, Show, ToJSON)

data Conf = Conf {
  name :: Text,
  kind :: Text,
  people :: [Person]
} deriving (Eq, Generic, FromJSON, Show, ToJSON)

instance ToPrettyYaml Conf where
  fieldOrder = const ["name", "kind", "people", "mood", "job"]

main :: IO ()
main = hspec $ describe "Data.Yaml.Pretty.Extras" $ it "prints correctly" $ do
  Just x <- decodeFileThrow "test/mock.yaml" :: IO (Maybe Conf)
  BS.readFile "test/mock.yaml" `shouldReturn` toPrettyYaml x