Skip to content

Commit

Permalink
test: update tests for accessing to reason
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Dec 31, 2023
1 parent 9c14b32 commit b7fabb4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/helpers/string_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mod tests {
define_case_helpers_test_cases!("trainCase", test_train_case, ("train case", "Train-Case"),);

#[test]
fn test_invlaid_input() {
fn test_invalid_input() {
use crate::error::RenderErrorReason;
use std::error::Error;

Expand All @@ -126,10 +126,7 @@ mod tests {
.render_template("{{snakeCase 1}}", &json!({}))
.unwrap_err();
assert!(matches!(
err.source()
.unwrap()
.downcast_ref::<RenderErrorReason>()
.unwrap(),
err.reason().unwrap(),
RenderErrorReason::ParamTypeMismatchForName(_, _, _)
));
}
Expand Down
7 changes: 2 additions & 5 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,6 @@ mod test {
use crate::render::{Helper, RenderContext, Renderable};
use crate::support::str::StringWriter;
use crate::template::Template;
use std::error::Error;
use std::fs::File;
use std::io::Write;
use tempfile::tempdir;
Expand Down Expand Up @@ -1161,8 +1160,7 @@ mod test {
assert_eq!(render_error.column_no.unwrap(), 26);
assert_eq!(
render_error
.source()
.and_then(|e| e.downcast_ref::<RenderErrorReason>())
.reason()
.and_then(|e| match e {
RenderErrorReason::MissingVariable(path) => path.to_owned(),
_ => unreachable!(),
Expand All @@ -1184,8 +1182,7 @@ mod test {
assert_eq!(render_error2.column_no.unwrap(), 31);
assert_eq!(
render_error2
.source()
.and_then(|e| e.downcast_ref::<RenderErrorReason>())
.reason()
.and_then(|e| match e {
RenderErrorReason::MissingVariable(path) => path.to_owned(),
_ => unreachable!(),
Expand Down
7 changes: 1 addition & 6 deletions tests/subexpression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ extern crate handlebars;
#[macro_use]
extern crate serde_json;

use std::error::Error;
use std::sync::atomic::{AtomicU16, Ordering};
use std::sync::Arc;

Expand Down Expand Up @@ -82,11 +81,7 @@ fn invalid_json_path() {
let hbs = Handlebars::new();

let error = hbs.render_template("{{x[]@this}}", &data).unwrap_err();
let cause = error
.source()
.unwrap()
.downcast_ref::<RenderErrorReason>()
.unwrap();
let cause = error.reason().unwrap();

assert!(matches!(cause, RenderErrorReason::HelperNotFound(_)));
}
Expand Down

0 comments on commit b7fabb4

Please sign in to comment.