Files
roux/test/Roux/ParserSpec.hs
T
jbrechtel 235adce596 Add minimal Cooklang parser with first tests
- Create Roux.Parser with parseCookFile (splits paragraphs, treats
  each as a plain-text step, no metadata parsing yet)
- Add emptyMetadata to Roux.Types for convenience
- Add test dependencies: hspec, tasty-golden, tasty-hspec
- Add ParserSpec with 4 tests covering single step, multiple steps,
  empty input, and whitespace trimming
- Wire ParserSpec into test runner via tasty-hspec
2026-05-18 22:21:32 -04:00

74 lines
2.9 KiB
Haskell

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