From 9a918414c0c16c8f329c848e92cbbd7e464d7107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Haudebourg?= Date: Mon, 8 Jul 2024 12:24:33 +0200 Subject: [PATCH] Add a few JSON-LD expansion tests. --- crates/json-ld/src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/crates/json-ld/src/lib.rs b/crates/json-ld/src/lib.rs index ddf556ff5..0e3ffd438 100644 --- a/crates/json-ld/src/lib.rs +++ b/crates/json-ld/src/lib.rs @@ -231,3 +231,46 @@ impl WithContext { } } } + +#[cfg(test)] +mod tests { + use crate::{CompactJsonLd, ContextLoader, Expandable}; + + #[async_std::test] + async fn accept_defined_type() { + let input = CompactJsonLd(json_syntax::json!({ + "@context": { "Defined": "http://example.org/#Defined" }, + "@type": ["Defined"] + })); + + assert!(input.expand(&ContextLoader::default()).await.is_ok()); + } + + #[async_std::test] + async fn reject_undefined_type() { + let input = CompactJsonLd(json_syntax::json!({ + "@type": ["Undefined"] + })); + + assert!(input.expand(&ContextLoader::default()).await.is_err()); + } + + #[async_std::test] + async fn accept_defined_property() { + let input = CompactJsonLd(json_syntax::json!({ + "@context": { "defined": "http://example.org/#defined" }, + "defined": "foo" + })); + + assert!(input.expand(&ContextLoader::default()).await.is_ok()); + } + + #[async_std::test] + async fn reject_undefined_property() { + let input = CompactJsonLd(json_syntax::json!({ + "undefined": "foo" + })); + + assert!(input.expand(&ContextLoader::default()).await.is_err()); + } +}