aboutsummaryrefslogtreecommitdiffstats
path: root/test/Test/Flattening.hs
diff options
context:
space:
mode:
authorVolpeon <github@volpeon.ink>2023-05-28 08:13:08 +0200
committerVolpeon <github@volpeon.ink>2023-05-28 08:13:08 +0200
commit8c49a30faa431b8b56a4b4926e7dae56b1311fea (patch)
tree6a103b49cdfe6df38fadad1f9d59521dd92ebf74 /test/Test/Flattening.hs
parentAdded Node Map Merging algorithm (diff)
downloadhs-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.hs51
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 @@
1module Test.Flattening (flatteningTests) where
2
3import Data.JLD.Prelude
4
5import Test.Tasty
6import Test.Tasty.ExpectedFailure (ignoreTestBecause)
7import Test.Tasty.HUnit
8
9import Data.JLD (expand, flatten, toJldErrorCode)
10import Data.Maybe (fromJust)
11import Test.Common (W3CTest (..), W3CTestList (..), W3CTestOption (..), fetchTest, parseExpansionOptions)
12import Text.URI (mkURI, relativeTo)
13
14flatteningTests :: W3CTestList -> TestTree
15flatteningTests testList = testGroup "Flattening" <| uncurry flatteningTest <$> zip (w3cSequence testList) [1 ..]
16
17flatteningTest :: W3CTest -> Int -> TestTree
18flatteningTest 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"