aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-04-06 01:09:42 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2025-04-06 01:09:42 +0200
commit9b9e713ebaa9e934d291c4e220872433b5fcc9f6 (patch)
tree4d000a9ae5148a029187d778df5352056e7f2ac6 /src
parentd0f582b98712d967b2f95d0405886d063bd89468 (diff)
Use gets all across
Diffstat (limited to 'src')
-rw-r--r--src/command/add.rs8
-rw-r--r--src/command/update.rs6
-rw-r--r--src/post.rs41
3 files changed, 30 insertions, 25 deletions
diff --git a/src/command/add.rs b/src/command/add.rs
index 7079707..ea574da 100644
--- a/src/command/add.rs
+++ b/src/command/add.rs
@@ -115,7 +115,7 @@ mod tests {
let dependencies = add.before_dependencies();
assert_eq!(dependencies.len(), 1);
- assert_eq!(dependencies[0].command(), "sync-down");
+ assert_eq!(dependencies.first().unwrap().command(), "sync-down");
}
#[test]
@@ -124,9 +124,9 @@ mod tests {
let dependencies = add.after_dependencies();
assert_eq!(dependencies.len(), 3);
- assert_eq!(dependencies[0].command(), "update");
- assert_eq!(dependencies[1].command(), "generate");
- assert_eq!(dependencies[2].command(), "sync-up");
+ assert_eq!(dependencies.first().unwrap().command(), "update");
+ assert_eq!(dependencies.get(1).unwrap().command(), "generate");
+ assert_eq!(dependencies.get(2).unwrap().command(), "sync-up");
}
// These two tests feel pointless but I'm doing it for the coverage :p
diff --git a/src/command/update.rs b/src/command/update.rs
index 1da6198..1f7a744 100644
--- a/src/command/update.rs
+++ b/src/command/update.rs
@@ -314,7 +314,7 @@ mod tests {
let dependencies = update.before_dependencies();
assert_eq!(dependencies.len(), 1);
- assert_eq!(dependencies[0].command(), "sync-down");
+ assert_eq!(dependencies.first().unwrap().command(), "sync-down");
}
#[test]
@@ -323,8 +323,8 @@ mod tests {
let dependencies = update.after_dependencies();
assert_eq!(dependencies.len(), 2);
- assert_eq!(dependencies[0].command(), "generate");
- assert_eq!(dependencies[1].command(), "sync-up");
+ assert_eq!(dependencies.first().unwrap().command(), "generate");
+ assert_eq!(dependencies.get(1).unwrap().command(), "sync-up");
}
// These two tests feel pointless but I'm doing it for the coverage :p
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()
- )
+ ))
);
}
}