Skip to content

Commit

Permalink
Add a few JSON-LD expansion tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothee-haudebourg committed Jul 8, 2024
1 parent 02b8dbe commit 9a91841
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions crates/json-ld/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,46 @@ impl<T> WithContext<T> {
}
}
}

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

0 comments on commit 9a91841

Please sign in to comment.