Skip to content

Commit

Permalink
Add similar-asserts for nicer test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
CathalMullan committed Sep 10, 2024
1 parent cd64023 commit aec7f2c
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 17 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ categories.workspace = true
workspace = true

[dev-dependencies]
# Snapshots
# Testing
# NOTE: Keep in sync with `cargo-insta` Nix package.
insta = "=1.40.0"
similar-asserts = "1.6"

# Encoding
percent-encoding = "2.3"
Expand Down
1 change: 1 addition & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ impl<'a> IntoIterator for &'a ParsedRoute<'a> {
#[cfg(test)]
mod tests {
use super::*;
use similar_asserts::assert_eq;

#[test]
fn test_parts_static() {
Expand Down
4 changes: 2 additions & 2 deletions tests/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::error::Error;
use wayfind::{Constraint, Router};

#[path = "./common.rs"]
mod common;
#[path = "./utils.rs"]
mod utils;

struct LengthBetween3And10;
impl Constraint for LengthBetween3And10 {
Expand Down
4 changes: 2 additions & 2 deletions tests/edge_cases.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::error::Error;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
#[path = "./utils.rs"]
mod utils;

#[test]
fn test_depth_matching_simple() -> Result<(), Box<dyn Error>> {
Expand Down
4 changes: 2 additions & 2 deletions tests/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::error::Error;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
#[path = "./utils.rs"]
mod utils;

#[test]
fn percent_encoding() -> Result<(), Box<dyn Error>> {
Expand Down
1 change: 1 addition & 0 deletions tests/matchit_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![allow(clippy::too_many_lines, clippy::cognitive_complexity)]

use similar_asserts::assert_eq;
use std::error::Error;
use wayfind::Router;

Expand Down
4 changes: 2 additions & 2 deletions tests/matchit_matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use std::error::Error;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
#[path = "./utils.rs"]
mod utils;

// https://github.com/ibraheemdev/matchit/issues/22
#[test]
Expand Down
5 changes: 3 additions & 2 deletions tests/path_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#![allow(clippy::too_many_lines)]

use similar_asserts::assert_eq;
use std::error::Error;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
#[path = "./utils.rs"]
mod utils;

#[test]
fn statics() -> Result<(), Box<dyn Error>> {
Expand Down
4 changes: 2 additions & 2 deletions tests/poem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use std::error::Error;
use wayfind::{Constraint, Router};

#[path = "./common.rs"]
mod common;
#[path = "./utils.rs"]
mod utils;

struct DigitString;
impl Constraint for DigitString {
Expand Down
4 changes: 2 additions & 2 deletions tests/uncommon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::error::Error;
use wayfind::Router;

#[path = "./common.rs"]
mod common;
#[path = "./utils.rs"]
mod utils;

#[test]
fn uncommon() -> Result<(), Box<dyn Error>> {
Expand Down
5 changes: 3 additions & 2 deletions tests/common.rs → tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use similar_asserts::assert_eq;
use std::{fmt::Debug, sync::Arc};
use wayfind::{Match, Parameter, Path, Router};

Expand All @@ -8,7 +9,7 @@ macro_rules! assert_router_matches {
}) => {
$({
let expected = assert_router_matches!(@parse_expected $expected);
$crate::common::assert_router_match(&$router, $input, expected);
$crate::utils::assert_router_match(&$router, $input, expected);
})+
};

Expand All @@ -19,7 +20,7 @@ macro_rules! assert_router_matches {
$($param_key:expr => $param_value:expr),+
})?
}) => {
Some($crate::common::ExpectedMatch {
Some($crate::utils::ExpectedMatch {
route: std::sync::Arc::from($route),
data: $data,
params: vec![
Expand Down

0 comments on commit aec7f2c

Please sign in to comment.