Add nytToCooklang conversion from NYTRecipe to Data.CookLang.Recipe
- Add nytToCooklang function to Roux.NYTimes - buildMetadata: maps title, URL, description, time, servings - buildSections: creates sections for ingredient groups then step groups - ingredientGroupToSection: converts NYT ingredient items to Cooklang step items with @ingredient references - stepGroupToSection: converts method steps into Cooklang steps - Add parseDuration, parseServings, parseNYTQuantity helpers - Add extractIngredientName heuristic for core ingredient extraction - Add 2 conversion tests verifying both example recipes - All 32 tests passing, hlint clean
This commit is contained in:
@@ -4,6 +4,7 @@ import qualified Data.Text.IO as TIO
|
||||
import Test.Hspec (Spec, describe, it, shouldBe, shouldSatisfy)
|
||||
|
||||
import Roux.NYTimes
|
||||
import Data.CookLang
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
@@ -70,6 +71,34 @@ spec = do
|
||||
[stepGroup] -> length (nytSteps stepGroup) `shouldBe` 7
|
||||
_ -> error "expected 1 step group"
|
||||
|
||||
describe "nytToCooklang" $ do
|
||||
it "converts fried-rice NYTRecipe to Cooklang Recipe" $ do
|
||||
html <- TIO.readFile "test-data/fried-rice.html"
|
||||
let result = do
|
||||
val <- extractNextData html
|
||||
nyt <- parseNYTRecipe val
|
||||
pure (nytToCooklang nyt)
|
||||
case result of
|
||||
Nothing -> error "failed to parse/convert fried-rice"
|
||||
Just recipe -> do
|
||||
metaTitle (recipeMetadata recipe) `shouldBe` Just "Fried Rice"
|
||||
metaSource (recipeMetadata recipe) `shouldBe` Just "https://cooking.nytimes.com/recipes/12177-fried-rice"
|
||||
metaTotalTime (recipeMetadata recipe) `shouldBe` Just (Duration 20 (Just "minutes"))
|
||||
length (recipeSections recipe) `shouldSatisfy` (> 0)
|
||||
|
||||
it "converts carrot-risotto NYTRecipe to Cooklang Recipe" $ do
|
||||
html <- TIO.readFile "test-data/carrot-risotto.html"
|
||||
let result = do
|
||||
val <- extractNextData html
|
||||
nyt <- parseNYTRecipe val
|
||||
pure (nytToCooklang nyt)
|
||||
case result of
|
||||
Nothing -> error "failed to parse/convert carrot-risotto"
|
||||
Just recipe -> do
|
||||
metaTitle (recipeMetadata recipe) `shouldBe` Just "Carrot Risotto With Chile Crisp"
|
||||
metaTotalTime (recipeMetadata recipe) `shouldBe` Just (Duration 30 (Just "minutes"))
|
||||
length (recipeSections recipe) `shouldSatisfy` (> 0)
|
||||
|
||||
-- | Check if a Maybe value is Just.
|
||||
isJust :: Maybe a -> Bool
|
||||
isJust (Just _) = True
|
||||
|
||||
Reference in New Issue
Block a user