packages feed

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

{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}

import Data.Text
import Data.Yaml.Pretty.Extras
import GHC.Generics
import Test.Hspec

import qualified Data.ByteString as BS

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 $ do
  describe "Data.Yaml.Pretty.Extras" $ do
   it "prints correctly" $ do
    Just x <- either (error . show) id <$> decodeFileEither "test/mock.yaml"  :: IO (Maybe Conf)
    BS.readFile "test/mock.yaml" `shouldReturn` (toPrettyYaml x)