From 1bb6f74645e39bb45e33a7413771ea7f971628c9 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 27 May 2023 12:10:51 +0200 Subject: Structural improvements --- test/Test/Expansion.hs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/Test/Expansion.hs b/test/Test/Expansion.hs index 33397f4..89024c6 100644 --- a/test/Test/Expansion.hs +++ b/test/Test/Expansion.hs @@ -2,9 +2,8 @@ module Test.Expansion (W3CExpansionTestList, expansionTests) where import Data.JLD.Prelude -import Data.JLD (DocumentLoader (..), JLDExpandParams (..), JLDVersion (..), expand, mimeType, toJldErrorCode) +import Data.JLD (DocumentLoader (..), JLDExpansionParams (..), JLDVersion (..), expand, mimeType, toJldErrorCode) import Data.JLD.Model.URI (parseUri) -import Data.JLD.Monad (JLDEnv (..), newEnv) import Test.Tasty import Test.Tasty.ExpectedFailure (ignoreTestBecause) @@ -31,7 +30,7 @@ instance FromJSON W3CExpansionTestOption where <*> (v .:? "processingMode") <*> (v .:? "base") <*> (v .:? "expandContext") - parseJSON invalid = prependFailure "parsing Coord failed, " (typeMismatch "Object" invalid) + parseJSON invalid = prependFailure "parsing W3CExpansionTestOption failed, " (typeMismatch "Object" invalid) data W3CExpansionTest = W3CExpansionTest { w3cExpansionTestName :: Text @@ -50,7 +49,7 @@ instance FromJSON W3CExpansionTest where <*> (v .:? "expect") <*> (v .:? "expectErrorCode") <*> (v .:? "option") - parseJSON invalid = prependFailure "parsing Coord failed, " (typeMismatch "Object" invalid) + parseJSON invalid = prependFailure "parsing W3CExpansionTest failed, " (typeMismatch "Object" invalid) newtype W3CExpansionTestList = W3CExpansionTestList { w3cExpansionSequence :: [W3CExpansionTest] @@ -59,7 +58,7 @@ newtype W3CExpansionTestList = W3CExpansionTestList instance FromJSON W3CExpansionTestList where parseJSON (Object v) = W3CExpansionTestList <$> (v .: "sequence") - parseJSON invalid = prependFailure "parsing Coord failed, " (typeMismatch "Object" invalid) + parseJSON invalid = prependFailure "parsing W3CExpansionTestList failed, " (typeMismatch "Object" invalid) documentLoader :: MonadIO m => DocumentLoader Text m documentLoader = DocumentLoader \uri -> @@ -75,7 +74,7 @@ fetchTest url = do res <- req GET reqUrl NoReqBody jsonResponse (reqOptions <> header "Accept" mimeType) pure <| responseBody res -parseOptions :: URI -> URI -> Maybe W3CExpansionTestOption -> IO (URI, JLDExpandParams () IO -> JLDExpandParams Text IO) +parseOptions :: URI -> URI -> Maybe W3CExpansionTestOption -> IO (URI, JLDExpansionParams () IO -> JLDExpansionParams Text IO) parseOptions baseUrl inputUrl maybeOptions = do expandContext <- case maybeOptions >>= w3cExpansionTestOptionExpandContext of Just rawUrl -> do @@ -85,20 +84,18 @@ parseOptions baseUrl inputUrl maybeOptions = do let params p = p - { jldExpandParamsEnv = env' - , jldExpandParamsExpandContext = expandContext <|> jldExpandParamsExpandContext p + { jldExpansionParamsDocumentLoader = documentLoader + , jldExpansionParamsProcessingMode = case maybeOptions >>= w3cExpansionTestOptionProcessingMode of + Just "json-ld-1.0" -> JLD1_0 + Just "json-ld-1.1" -> JLD1_1 + _ -> jldExpansionParamsProcessingMode p + , jldExpansionParamsExpandContext = expandContext <|> jldExpansionParamsExpandContext p } pure (expandBaseUrl, params) where expandBaseUrl = fromMaybe inputUrl (parseUri =<< w3cExpansionTestOptionBase =<< maybeOptions) - env = newEnv \e -> e{jldEnvDocumentLoader = documentLoader} - env' = case maybeOptions >>= w3cExpansionTestOptionProcessingMode of - Just "json-ld-1.0" -> env{jldEnvProcessingMode = JLD1_0} - Just "json-ld-1.1" -> env{jldEnvProcessingMode = JLD1_1} - _ -> env - expansionTests :: W3CExpansionTestList -> TestTree expansionTests testList = testGroup "Expansion" <| uncurry expansionTest <$> (take 999 <. drop 0 <| zip (w3cExpansionSequence testList) [1 ..]) -- cgit v1.2.3-70-g09d2