diff options
Diffstat (limited to 'test/Test/Expansion.hs')
-rw-r--r-- | test/Test/Expansion.hs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/test/Test/Expansion.hs b/test/Test/Expansion.hs index b5b1e07..0d553a7 100644 --- a/test/Test/Expansion.hs +++ b/test/Test/Expansion.hs | |||
@@ -6,10 +6,33 @@ import Test.Tasty | |||
6 | import Test.Tasty.ExpectedFailure (ignoreTestBecause) | 6 | import Test.Tasty.ExpectedFailure (ignoreTestBecause) |
7 | import Test.Tasty.HUnit | 7 | import Test.Tasty.HUnit |
8 | 8 | ||
9 | import Data.JLD (expand, toJldErrorCode) | 9 | import Data.JLD (JLDExpansionParams (..), JLDVersion (..), expand, toJldErrorCode) |
10 | import Data.JLD.Model.URI (parseUri) | ||
10 | import Data.Maybe (fromJust) | 11 | import Data.Maybe (fromJust) |
11 | import Test.Common (W3CTest (..), W3CTestList (..), W3CTestOption (..), fetchTest, parseExpansionOptions) | 12 | import Test.Common (W3CTest (..), W3CTestList (..), W3CTestOption (..), documentLoader, fetchTest) |
12 | import Text.URI (mkURI, relativeTo) | 13 | import Text.URI (URI, mkURI, relativeTo) |
14 | |||
15 | parseExpansionOptions :: URI -> URI -> Maybe W3CTestOption -> IO (URI, JLDExpansionParams () IO -> JLDExpansionParams Text IO) | ||
16 | parseExpansionOptions baseUrl inputUrl maybeOptions = do | ||
17 | expandContext <- case maybeOptions >>= w3cTestOptionExpandContext of | ||
18 | Just rawUrl -> do | ||
19 | url <- fromJust <. (`relativeTo` baseUrl) <$> mkURI rawUrl | ||
20 | Just <$> fetchTest url | ||
21 | Nothing -> pure Nothing | ||
22 | |||
23 | let params p = | ||
24 | p | ||
25 | { jldExpansionParamsDocumentLoader = documentLoader | ||
26 | , jldExpansionParamsProcessingMode = case maybeOptions >>= w3cTestOptionProcessingMode of | ||
27 | Just "json-ld-1.0" -> JLD1_0 | ||
28 | Just "json-ld-1.1" -> JLD1_1 | ||
29 | _ -> jldExpansionParamsProcessingMode p | ||
30 | , jldExpansionParamsExpandContext = expandContext <|> jldExpansionParamsExpandContext p | ||
31 | } | ||
32 | |||
33 | pure (expandBaseUrl, params) | ||
34 | where | ||
35 | expandBaseUrl = fromMaybe inputUrl (parseUri =<< w3cTestOptionBase =<< maybeOptions) | ||
13 | 36 | ||
14 | expansionTests :: W3CTestList -> TestTree | 37 | expansionTests :: W3CTestList -> TestTree |
15 | expansionTests testList = testGroup "Expansion" <| uncurry expansionTest <$> zip (w3cSequence testList) [1 ..] | 38 | expansionTests testList = testGroup "Expansion" <| uncurry expansionTest <$> zip (w3cSequence testList) [1 ..] |