Skip to content

Commit

Permalink
fix tests and whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
va-an committed May 30, 2024
1 parent a355e3a commit 1c1af5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 3 additions & 1 deletion examples/templating/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use rocket_dyn_templates::Template;
#[get("/")]
fn index() -> RawHtml<&'static str> {
RawHtml(
r#"See <a href="tera">Tera</a>, <a href="hbs">Handlebars</a>, or <a href="minijinja">MiniJinja</a>."#,
r#"See <a href="tera">Tera</a>,
<a href="hbs">Handlebars</a>,
or <a href="minijinja">MiniJinja</a>."#,
)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/templating/src/minijinja.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn about() -> Template {
#[catch(404)]
pub fn not_found(req: &Request<'_>) -> Template {
println!("Handling 404 for URI: {}", req.uri());

Template::render(
"minijinja/error/404",
context! {
Expand Down
18 changes: 8 additions & 10 deletions examples/templating/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,23 @@ fn test_name(base: &str) {
assert!(response.into_string().unwrap().contains("Hi Jack Daniels!"));
}


fn test_404(base: &str) {
// Check that the error catcher works.
let client = Client::tracked(rocket()).unwrap();
for bad_path in &["/hello", "/foo/bar", "/404"] {
let path = format!("/{}{}", base, bad_path);

let escaped_path_upper = RawStr::new(&path).html_escape();
let escaped_path_lower = escaped_path_upper.to_lowercase();
let escaped_path = RawStr::new(&path).html_escape().to_lowercase();

let response = client.get(&path).dispatch();
assert_eq!(response.status(), Status::NotFound);
let response = response.into_string().unwrap();
let response = response.into_string().unwrap().to_lowercase();

assert!(response.contains(base));
assert!(
response.contains(&format!("{} does not exist", path)) ||
response.contains(&format!("{} does not exist", escaped_path_upper)) ||
response.contains(&format!("{} does not exist", escaped_path_lower))
);
assert!(response.contains(base));
assert! {
response.contains(&format!("{} does not exist", path))
|| response.contains(&format!("{} does not exist", escaped_path))
};
}
}

Expand Down

0 comments on commit 1c1af5d

Please sign in to comment.