Skip to content
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

Added unbounded array patterns #17

Merged
merged 1 commit into from
Jun 19, 2014

Conversation

K-Phoen
Copy link
Contributor

@K-Phoen K-Phoen commented May 30, 2014

Can be useful when you want to test the structure of an array without knowing its size.

@norberttech
Copy link
Member

Hi @K-Phoen feature looks cool. It would be nice if you could you provide some real use case for it, you know maybe some kind of scenario.
I'm just not sure about the @...@ pattern. I think its not enought descriptive and might be a bit confusing. Any other suggestions?

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Jun 1, 2014

I'm writing (behat) tests for an API and this feature allows me to "strictly" check the first N results that are returned and just check the structure of the rest.
I'd like to write things like this in my features:

Then the response should match json:
'''
{
    "results": [
        {
            "id": @string@,
            "foo": "bar",
            "bar": 42
        },
        {
            "id": @string@,
            "foo": @string@,
            "bar": @integer@
        },
        @...@
    ]
}
'''

Concerning the pattern, I haven't a lot of other ideas. Would you prefer @rest@ instead of @...@?

@norberttech
Copy link
Member

Oh yest, it might be useful for api testing. But I'm still not convinced about the pattern. I think the name should point out that this pattern can be used only for arrays. Maybe @array_wildcard@, or @array_rest@? @defrag what do you think about it?

@defrag
Copy link
Member

defrag commented Jun 2, 2014

Hmm well i guess it makes sense for some scenarios, but i have a feeling with this implementation its confusing how to use it. Maybe we should introduce some repeatable array pattern?

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Jun 2, 2014

Can you be more explicit?

@defrag
Copy link
Member

defrag commented Jun 2, 2014

Im thinking something like:

Then the response should match json:
'''
{
    "results": [       
        {
            "id": @string@,
            "foo": @string@,
            "bar": @integer@
        }
    ].repeat(0...1|Inf)
}
'''

or something similar. I honestly dont see the point of matching two first values and then the rest pattern.

@norberttech
Copy link
Member

Looks like @defrag solution solves @K-Phoen problem, right? To be honest I like it more, its more desriptive.

@defrag
Copy link
Member

defrag commented Jun 2, 2014

But i guess this would be much more work to achieve that :P

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Jun 2, 2014

Yep, I also prefer this solution :)
I don't know when I'll be able to work on an implementation though.

@jakzal
Copy link
Contributor

jakzal commented Jun 2, 2014

I honestly dont see the point of matching two first values and then the rest pattern.

Here's a case: verify if a new entry was added to the response and ignore the rest.

@defrag
Copy link
Member

defrag commented Jun 2, 2014

@jakzal but in scenario described here we can verify only if its on one of the first position. We cant check if it was addes as last one.

@norberttech
Copy link
Member

To solve @jakzal use case I can think about two possible solutions

Then the response should match json pattern:
'''
{
    "results": @[email protected](["id": "@integer@", "name": "New"])
}
'''
Then the response should match json pattern:
'''
{
    "results": [
      @...@,
      {
        "id": @integer@
        "name": "Norbert" 
      },
      @...@
    ]
}
'''

@norberttech
Copy link
Member

btw. @K-Phoen I belive you can achieve your goal with Expression expr() matcher.

@norberttech
Copy link
Member

@K-Phoen could you please rebase this PR against master? It should be enough before 2.0 release where we plan to add pattern expanders.

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Jun 19, 2014

Done :)

norberttech added a commit that referenced this pull request Jun 19, 2014
@norberttech norberttech merged commit f8d46c8 into coduo:master Jun 19, 2014
@norberttech
Copy link
Member

Thanks!

@K-Phoen K-Phoen deleted the dev-unbounded-arrays branch June 19, 2014 13:06
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.

4 participants