Skip to content

Commit

Permalink
feat: Add support for atLeast and atMost with matching rule definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jan 20, 2024
1 parent 5579e58 commit 1cf8809
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
22 changes: 22 additions & 0 deletions docs/matching-rule-definition-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ Configures a matching rule to be applied to each value in a map or list.

For example: `eachValue(matching(type, 100))`

### atLeast(SIZE)

Configures a type matching rule to be applied to a map or list (if another rule is not applied),
and asserts the length is at least the given size.

For example: `atLeast(2)`

### atMost(SIZE)

Configures a type matching rule to be applied to a map or list (if another rule is not applied), and asserts the
length is at most the given size.
If an expression is provided, that will be used instead of the type matching rule.

For example: `atMost(2)`

## Composing expressions

Expressions can be composed by separating them with a comma. For example
`atLeast(2), atMost(10), eachValue(matching(regex, '\d+', '1234'))`. This will configure an
array to have at least 2 items, at most 10, and each item in the array must match the
given regex.

## Grammar

There is a grammar for the definitions in [ANTLR4 format](https://github.com/pact-foundation/pact-plugins/blob/main/docs/matching-rule-definition.g4).
2 changes: 2 additions & 0 deletions docs/matching-rule-definition.g4
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ matchingDefinitionExp :
| 'notEmpty' LEFT_BRACKET primitiveValue RIGHT_BRACKET
| 'eachKey' LEFT_BRACKET matchingDefinitionExp RIGHT_BRACKET
| 'eachValue' LEFT_BRACKET matchingDefinitionExp RIGHT_BRACKET
| 'atLeast' LEFT_BRACKET DIGIT+ RIGHT_BRACKET
| 'atMost' LEFT_BRACKET DIGIT+ RIGHT_BRACKET
)
;

Expand Down
4 changes: 2 additions & 2 deletions drivers/rust/driver/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion drivers/rust/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ log = "0.4.20"
maplit = "1.0.2"
md5 = "0.7.0"
os_info = "3.7.0"
pact_models = { version = "~1.1.16", default-features = false }
pact_models = { version = "~1.1.17", default-features = false }
prost = "0.11.9"
prost-types = "0.11.9"
regex = "1.10.3"
Expand Down

0 comments on commit 1cf8809

Please sign in to comment.