module ReadConfig.Tests where

-- This module is generated by cabal
import qualified Data.ByteString as BS
import qualified Data.Yaml as Yaml
import Paths_herms hiding (getDataDir)
import ReadConfig
import Test.HUnit ((@?))
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (testCase)
import qualified Text.Read as TR
import Types (Recipe)

tests :: TestTree
tests =
  testGroup
    "UnitConversions"
    [ testCase "testParseConfig" $ do
        path <- getDataFileName "config.hs"
        contents <- readFile path
        ( case TR.readEither (dropComments contents) :: Either String ConfigInfo of
            Left _ -> False
            Right _ -> True
          )
          @? "Couldn't parse config file",
      testCase "testParseRecipes" $ do
        path <- getDataFileName "recipes.yaml"
        contents <- BS.readFile path
        ( case (Yaml.decodeEither' contents :: Either Yaml.ParseException [Recipe]) of
            Left err -> False @? "Couldn't parse recipes: " ++ show err
            Right _ -> True @? "Success"
          )
    ]
