diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-04-06 01:09:42 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-04-06 01:09:42 +0200 |
| commit | 9b9e713ebaa9e934d291c4e220872433b5fcc9f6 (patch) | |
| tree | 4d000a9ae5148a029187d778df5352056e7f2ac6 /src/post.rs | |
| parent | d0f582b98712d967b2f95d0405886d063bd89468 (diff) | |
Use gets all across
Diffstat (limited to 'src/post.rs')
| -rw-r--r-- | src/post.rs | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/post.rs b/src/post.rs index 20322b4..2e2b0e6 100644 --- a/src/post.rs +++ b/src/post.rs @@ -84,9 +84,9 @@ mod tests { fn test_creates_context_with_empty_posts() { let context = Post::to_template_context(&[]); - assert_eq!(context["has_posts"], Value::Bool(false)); - assert_eq!(context["posts_length"], Value::Unsigned(0)); - if let Value::Collection(posts) = &context["posts"] { + assert_eq!(context.get("has_posts"), Some(&Value::Bool(false))); + assert_eq!(context.get("posts_length"), Some(&Value::Unsigned(0))); + if let Some(Value::Collection(posts)) = &context.get("posts") { assert!(posts.is_empty()); } else { panic!("The posts context was not the right type."); @@ -107,9 +107,9 @@ mod tests { let context = Post::to_template_context(&[post]); - assert_eq!(context["has_posts"], Value::Bool(true)); - assert_eq!(context["posts_length"], Value::Unsigned(1)); - if let Value::Collection(posts) = &context["posts"] { + assert_eq!(context.get("has_posts"), Some(&Value::Bool(true))); + assert_eq!(context.get("posts_length"), Some(&Value::Unsigned(1))); + if let Some(Value::Collection(posts)) = &context.get("posts") { if let Some(post) = posts.first() { assert_eq!(post["id"], Value::String("cool".to_string())); } else { @@ -137,29 +137,34 @@ beep boop" let context = post.to_template_value(); - assert_eq!(context["id"], Value::String("cool".to_string())); - assert_eq!(context["created_on"], Value::Unsigned(1_736_035_200_000)); + assert_eq!(context.get("id"), Some(&Value::String("cool".to_string()))); assert_eq!( - context["created_on_utc"], - Value::String("Sun, 05 Jan 2025 00:00:00 +0000".to_string()) + context.get("created_on"), + Some(&Value::Unsigned(1_736_035_200_000)) ); assert_eq!( - context["title"], - Value::String("Hello everybody".to_string()) + context.get("created_on_utc"), + Some(&Value::String( + "Sun, 05 Jan 2025 00:00:00 +0000".to_string() + )) ); - assert_eq!(context["index"], Value::Unsigned(28)); assert_eq!( - context["html"], - Value::String("<p>beep boop</p>".to_string()) + context.get("title"), + Some(&Value::String("Hello everybody".to_string())) ); + assert_eq!(context.get("index"), Some(&Value::Unsigned(28))); assert_eq!( - context["raw"], - Value::String( + context.get("html"), + Some(&Value::String("<p>beep boop</p>".to_string())) + ); + assert_eq!( + context.get("raw"), + Some(&Value::String( "\ # Hello everybody beep boop" .to_string() - ) + )) ); } } |