-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
let mut tree = PathTree::new(); | ||
|
||
tree.insert("/users/:id", 0); | ||
tree.insert("/users/:user_id", 1); |
There was a problem hiding this comment.
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
tests/tree.rs
Outdated
let path = r.unwrap(); | ||
match (path.value, path.params()) { | ||
(0, params) => { | ||
assert_eq!(params, vec![("id", "gordon")]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After being overwritten, this is no longer valid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not trying to establish behavior with respect to overriding, what it is saying is that if the matched value is 0
then the param name should be id
and if the value is 1
the param name should be user_id
. It is currently failing because the returned value is 1
but the param name is id
which is wrong. In other words, the only reason I included this branch is to avoid specifying the behavior of overriding. If you already decided that the last parameter is preserved then the test can be simplified to:
fn repeated_single_named_param() {
// Pattern: /users/:id
//
// /users/gordon match
// /users/you match
// /users/gordon/profile no match
// /users/ no match
let mut tree = PathTree::new();
tree.insert("/users/:id", 0);
tree.insert("/users/:user_id", 1);
let r = tree.find("/users/gordon");
let path = r.unwrap();
assert_eq!(path.value, 1);
assert_eq!(path.params, vec![("user_id", "gordon")]);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this can only be reserved for one case
a1f13c5
to
1fc018c
Compare
@@ -3,7 +3,9 @@ use rand::seq::SliceRandom; | |||
|
|||
#[test] | |||
fn statics() { | |||
const ROUTES: [&str; 11] = [ | |||
const ROUTES: [&str; 13] = [ | |||
"", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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());
No description provided.