Skip to content

Add failing tests #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 26, 2022
17 changes: 16 additions & 1 deletion tests/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use rand::seq::SliceRandom;

#[test]
fn statics() {
const ROUTES: [&str; 11] = [
const ROUTES: [&str; 13] = [
"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate this line out, it will be overwritten by / and left here they will be randomly broken up and have different values, causing the test to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand. Are you saying that having "" and "/" is supported but not at the same time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lines of operations below that will shuffle the array.
routes.shuffle(&mut rand::thread_rng());

"/",
"/hi",
"/contact",
"/co",
Expand Down Expand Up @@ -128,6 +130,19 @@ fn single_named_parameter() {
}
}

#[test]
fn repeated_single_named_param() {
let mut tree = PathTree::new();

tree.insert("/users/:id", 0);
tree.insert("/users/:user_id", 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adriangb Both the name and the value should be overwritten


let r = tree.find("/users/gordon");
let path = r.unwrap();
assert_eq!(*path.value, 1);
assert_eq!(path.params(), vec![("user_id", "gordon")]);
}

#[test]
fn static_and_named_parameter() {
// Pattern: /a/b/c
Expand Down