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()); + } +}