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

[RFC] Pattern expanders #21

Closed
norberttech opened this issue Jun 22, 2014 · 3 comments
Closed

[RFC] Pattern expanders #21

norberttech opened this issue Jun 22, 2014 · 3 comments

Comments

@norberttech
Copy link
Member

In most cases patterns are enough to create our expectations against value but sometimes there is a need to check something more. For example if we want to check if integer is lower than X or if array contain specific key/value.
Of course there is a expression pattern which is very elastic but it also make our patterns big, less readable and sometimes hard to understand.
I believe it would be nice to expand patterns with some extra critierias.
Few examples:

Following patterns will match ['foo' => 'bar'] value
@array@.contains('foo':'bar')
@array@.keyExists('foo')
@array@.valueExists('bar')

Following patterns will match "25" value:
@integer@.lowerThan(23)
@integer@.greaterThan(20)
@integer@.between(10, 100)

Following patterns will match "Hello world" value:
@string@.startWith('Hello')
@string@.endWith('World')
@string@.contains('llo Wo')

I think there might be a need to use more than one expander for a pattern.

@string@.startWith('Hello').contains(' ').endWith('World')

First matcher will check if pattern match value and after that value is going to be check against every single expander. The result will be positive only if every single expander return "true".

Maybe there are some more expanders we can add?

@defrag
Copy link
Member

defrag commented Jun 23, 2014

Yes this is interesting. I am thinking how to implement the repeat format with was mentioned in other issue like:

[
    {
        "id": @integer@,
        "name": @string@
    }.repeat(1..Inf)
]

Something similar to chancancode/json_expressions#18

@norberttech
Copy link
Member Author

Oh I forgot about repeat expander. But above implementation require custom JSON parser. I think that using following syntax would be much easier:

{
    "deccription": "Users collection", 
    @array@.repeat({'id': @integer@, 'name': @string@}, 1, INF)
}

Exapnder definition:
repeat(pattenr, offset = 0, limit = null)

@norberttech
Copy link
Member Author

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

No branches or pull requests

2 participants