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
Merged

Add failing tests #26

merged 11 commits into from
Sep 26, 2022

Conversation

adriangb
Copy link
Contributor

No description provided.

@adriangb adriangb mentioned this pull request Sep 24, 2022
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

tests/tree.rs Outdated
let path = r.unwrap();
match (path.value, path.params()) {
(0, params) => {
assert_eq!(params, vec![("id", "gordon")])
Copy link
Member

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

Copy link
Contributor Author

@adriangb adriangb Sep 24, 2022

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")]);
}

Copy link
Member

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

@fundon fundon deleted the branch viz-rs:main September 26, 2022 01:34
@fundon fundon closed this Sep 26, 2022
@fundon fundon reopened this Sep 26, 2022
@@ -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());

@adriangb adriangb changed the base branch from allow_empty_str to main September 26, 2022 02:02
@fundon fundon merged commit cac52f7 into viz-rs:main Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants