feat: add parseISODuration for ISO 8601 duration parsing

This commit is contained in:
2026-05-19 22:46:57 -04:00
parent 9586afcb46
commit 1addddd8fc
2 changed files with 57 additions and 2 deletions
+14
View File
@@ -1,6 +1,7 @@
module Roux.SchemaOrgSpec (spec) where
import qualified Data.Aeson as A
import Data.CookLang (Duration (..))
import Data.Maybe (fromJust, isJust)
import Data.Text (Text)
import qualified Data.Text as T
@@ -49,3 +50,16 @@ spec = describe "SchemaOrg" $ do
case recipe of
Nothing -> expectationFailure "expected Just SchemaOrgRecipe, got Nothing"
Just r -> soName r `shouldBe` "Carrot Risotto With Chile Crisp"
describe "parseISODuration" $ do
let chk :: Text -> Maybe Duration -> IO ()
chk input expected = parseISODuration input `shouldBe` expected
it "PT20M -> 20 minutes" $ chk "PT20M" (Just (Duration 20 (Just "minutes")))
it "PT1H -> 60 minutes" $ chk "PT1H" (Just (Duration 60 (Just "minutes")))
it "PT1H30M -> 90 minutes" $ chk "PT1H30M" (Just (Duration 90 (Just "minutes")))
it "P1D -> 1440 minutes" $ chk "P1D" (Just (Duration 1440 (Just "minutes")))
it "P1DT2H -> 1560 minutes" $ chk "P1DT2H" (Just (Duration 1560 (Just "minutes")))
it "PT30M -> 30 minutes" $ chk "PT30M" (Just (Duration 30 (Just "minutes")))
it "empty string -> Nothing" $ chk "" Nothing
it "human-readable -> Nothing" $ chk "20 minutes" Nothing