module Roux.ParserSpec (spec) where import Data.List.NonEmpty (NonEmpty ((:|))) import Test.Hspec (Spec, describe, it, shouldBe) import Roux.Parser (parseCookFile) import Roux.Types spec :: Spec spec = describe "parseCookFile" $ do it "parses a single step of plain text" $ do let input = "Hello, world." expected = Right Recipe { recipeMetadata = emptyMetadata , recipeSections = Section { sectionName = Nothing , sectionSteps = Step { unStep = [StepText "Hello, world."] } :| [] } :| [] } parseCookFile input `shouldBe` expected it "parses multiple steps separated by a blank line" $ do let input = "Wash the potatoes.\n\nPeel and dice them." expected = Right Recipe { recipeMetadata = emptyMetadata , recipeSections = Section { sectionName = Nothing , sectionSteps = Step {unStep = [StepText "Wash the potatoes."]} :| [ Step {unStep = [StepText "Peel and dice them."]} ] } :| [] } parseCookFile input `shouldBe` expected it "handles empty input by returning an empty recipe" $ do let expected = Right Recipe { recipeMetadata = emptyMetadata , recipeSections = Section { sectionName = Nothing , sectionSteps = Step {unStep = []} :| [] } :| [] } parseCookFile "" `shouldBe` expected it "trims leading and trailing whitespace from each step" $ do let input = "\n\n Mix well. \n\n" expected = Right Recipe { recipeMetadata = emptyMetadata , recipeSections = Section { sectionName = Nothing , sectionSteps = Step {unStep = [StepText "Mix well."]} :| [] } :| [] } parseCookFile input `shouldBe` expected