diff options
| author | Volpeon <github@volpeon.ink> | 2023-05-28 08:13:08 +0200 |
|---|---|---|
| committer | Volpeon <github@volpeon.ink> | 2023-05-28 08:13:08 +0200 |
| commit | 8c49a30faa431b8b56a4b4926e7dae56b1311fea (patch) | |
| tree | 6a103b49cdfe6df38fadad1f9d59521dd92ebf74 /test/Test/Flattening.hs | |
| parent | Added Node Map Merging algorithm (diff) | |
| download | hs-jsonld-8c49a30faa431b8b56a4b4926e7dae56b1311fea.tar.gz hs-jsonld-8c49a30faa431b8b56a4b4926e7dae56b1311fea.tar.bz2 hs-jsonld-8c49a30faa431b8b56a4b4926e7dae56b1311fea.zip | |
Completed untested Flattening implementation
Diffstat (limited to 'test/Test/Flattening.hs')
| -rw-r--r-- | test/Test/Flattening.hs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/Test/Flattening.hs b/test/Test/Flattening.hs new file mode 100644 index 0000000..bc64b88 --- /dev/null +++ b/test/Test/Flattening.hs | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | module Test.Flattening (flatteningTests) where | ||
| 2 | |||
| 3 | import Data.JLD.Prelude | ||
| 4 | |||
| 5 | import Test.Tasty | ||
| 6 | import Test.Tasty.ExpectedFailure (ignoreTestBecause) | ||
| 7 | import Test.Tasty.HUnit | ||
| 8 | |||
| 9 | import Data.JLD (expand, flatten, toJldErrorCode) | ||
| 10 | import Data.Maybe (fromJust) | ||
| 11 | import Test.Common (W3CTest (..), W3CTestList (..), W3CTestOption (..), fetchTest, parseExpansionOptions) | ||
| 12 | import Text.URI (mkURI, relativeTo) | ||
| 13 | |||
| 14 | flatteningTests :: W3CTestList -> TestTree | ||
| 15 | flatteningTests testList = testGroup "Flattening" <| uncurry flatteningTest <$> zip (w3cSequence testList) [1 ..] | ||
| 16 | |||
| 17 | flatteningTest :: W3CTest -> Int -> TestTree | ||
| 18 | flatteningTest W3CTest{..} (show .> (<> ". " <> toString w3cTestName) -> testName) | ||
| 19 | | Just "json-ld-1.0" <- w3cTestOptionSpecVersion =<< w3cTestOption = | ||
| 20 | ignoreTestBecause "specVersion json-ld-1.0 is not supported" | ||
| 21 | <| testCase testName do pure () | ||
| 22 | -- | ||
| 23 | | Just expectUrlRaw <- w3cTestExpect = | ||
| 24 | testCase testName do | ||
| 25 | baseUrl <- mkURI "https://w3c.github.io/json-ld-api/tests/" | ||
| 26 | inputUrl <- fromJust <. (`relativeTo` baseUrl) <$> mkURI w3cTestInput | ||
| 27 | expectUrl <- fromJust <. (`relativeTo` baseUrl) <$> mkURI expectUrlRaw | ||
| 28 | |||
| 29 | inputJld <- fetchTest inputUrl | ||
| 30 | expectJld <- fetchTest expectUrl | ||
| 31 | |||
| 32 | (expandBaseUrl, params) <- parseExpansionOptions baseUrl inputUrl w3cTestOption | ||
| 33 | (result, _) <- flatten inputJld expandBaseUrl params | ||
| 34 | |||
| 35 | result @?= Right expectJld | ||
| 36 | -- | ||
| 37 | | Just expectErrorRaw <- w3cTestExpectErrorCode = | ||
| 38 | testCase testName do | ||
| 39 | baseUrl <- mkURI "https://w3c.github.io/json-ld-api/tests/" | ||
| 40 | inputUrl <- fromJust <. (`relativeTo` baseUrl) <$> mkURI w3cTestInput | ||
| 41 | |||
| 42 | inputJld <- fetchTest inputUrl | ||
| 43 | |||
| 44 | (expandBaseUrl, params) <- parseExpansionOptions baseUrl inputUrl w3cTestOption | ||
| 45 | (result, _) <- flatten inputJld expandBaseUrl params | ||
| 46 | |||
| 47 | (result |> first toJldErrorCode) @?= Left expectErrorRaw | ||
| 48 | -- | ||
| 49 | | otherwise = | ||
| 50 | testCase testName do | ||
| 51 | assertFailure <| "Unhandled test type" | ||
