Update docs/integration test with regex syntax / flags.
This commit is contained in:
parent
d568b13180
commit
877bf98320
|
|
@ -387,14 +387,14 @@ Predicates consist of a predicate function and a predicate value. Predicate func
|
|||
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
|
||||
| __`==`__ | Query and predicate value are equal | `jsonpath "$.book" == "Dune"` |
|
||||
| __`!=`__ | Query and predicate value are different | `jsonpath "$.color" != "red"` |
|
||||
| __`>`__ | Query number or date is greater than predicate value | `jsonpath "$.year" > 1978`<br><br>`jsonpath "$.createdAt" toDate "%+" > {{ a_date }}` |
|
||||
| __`>=`__ | Query number or date is greater than or equal to the predicate value | `jsonpath "$.year" >= 1978` |
|
||||
| __`<`__ | Query number or date is less than that predicate value | `jsonpath "$.year" < 1978` |
|
||||
| __`<=`__ | Query number or date is less than or equal to the predicate value | `jsonpath "$.year" <= 1978` |
|
||||
| __`>`__ | Query number or date is greater than predicate value | `jsonpath "$.year" > 1978`<br><br>`jsonpath "$.createdAt" toDate "%+" > {{ a_date }}` |
|
||||
| __`>=`__ | Query number or date is greater than or equal to the predicate value | `jsonpath "$.year" >= 1978` |
|
||||
| __`<`__ | Query number or date is less than that predicate value | `jsonpath "$.year" < 1978` |
|
||||
| __`<=`__ | Query number or date is less than or equal to the predicate value | `jsonpath "$.year" <= 1978` |
|
||||
| __`startsWith`__ | Query starts with the predicate value<br>Value is string or a binary content | `jsonpath "$.movie" startsWith "The"`<br><br>`bytes startsWith hex,efbbbf;` |
|
||||
| __`endsWith`__ | Query ends with the predicate value<br>Value is string or a binary content | `jsonpath "$.movie" endsWith "Back"`<br><br>`bytes endsWith hex,ab23456;` |
|
||||
| __`contains`__ | If query returns a collection of string or numbers, query collection includes the predicate value (string or number)<br>If query returns a string or a binary content, query contains the predicate value (string or bytes) | `jsonpath "$.movie" contains "Empire"`<br><br>`bytes contains hex,beef;`<br><br>`jsonpath "$.numbers" contains 42` |
|
||||
| __`matches`__ | Part of the query string matches the regex pattern described by the predicate value | `jsonpath "$.release" matches "\\d{4}"`<br><br>`jsonpath "$.release" matches /\d{4}/` |
|
||||
| __`matches`__ | Part of the query string matches the regex pattern described by the predicate value (see [regex syntax](https://docs.rs/regex/latest/regex/#syntax)) | `jsonpath "$.release" matches "\\d{4}"`<br><br>`jsonpath "$.release" matches /\d{4}/` |
|
||||
| __`exists`__ | Query returns a value | `jsonpath "$.book" exists` |
|
||||
| __`isBoolean`__ | Query returns a boolean | `jsonpath "$.succeeded" isBoolean` |
|
||||
| __`isCollection`__ | Query returns a collection | `jsonpath "$.books" isCollection` |
|
||||
|
|
@ -827,6 +827,16 @@ captured group value. When the regex pattern is a double-quoted string, metachar
|
|||
pattern (like `\d`, `\s`) must be escaped; literal pattern enclosed by `/` can also be used to avoid metacharacters
|
||||
escaping.
|
||||
|
||||
The regex syntax is documented at <https://docs.rs/regex/latest/regex/#syntax>. For instance, once can use [flags](https://docs.rs/regex/latest/regex/#grouping-and-flags)
|
||||
to enable case-insensitive match:
|
||||
|
||||
```hurl
|
||||
GET https://example.org/hello
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
regex /(?i)hello (\w+)!/ == "World"
|
||||
```
|
||||
|
||||
### SHA-256 assert
|
||||
|
||||
Check response body [SHA-256] hash.
|
||||
|
|
|
|||
|
|
@ -284,7 +284,17 @@ name: regex "Hello ([a-zA-Z]+)"
|
|||
|
||||
The regex pattern must have at least one capture group, otherwise the
|
||||
capture will fail. When the pattern is a double-quoted string, metacharacters beginning with a backslash in the pattern
|
||||
(like `\d`, `\s`) must be escaped; literal pattern enclosed by `/` can also be used to avoid metacharacters escaping.
|
||||
(like `\d`, `\s`) must be escaped; literal pattern enclosed by `/` can also be used to avoid metacharacters escaping.
|
||||
|
||||
The regex syntax is documented at <https://docs.rs/regex/latest/regex/#syntax>. For instance, one can use [flags](https://docs.rs/regex/latest/regex/#grouping-and-flags)
|
||||
to enable case-insensitive match:
|
||||
|
||||
```hurl
|
||||
GET https://example.org/hello
|
||||
HTTP 200
|
||||
[Captures]
|
||||
word: regex /(?i)hello (\w+)!/
|
||||
```
|
||||
|
||||
### SHA-256 capture
|
||||
|
||||
|
|
|
|||
|
|
@ -273,8 +273,11 @@ HTTP 200
|
|||
param1: header "header1"
|
||||
param2: header "header2" regex "Hello (.*)!"
|
||||
param3: header "header2" regex /Hello (.*)!/
|
||||
param3: header "header2" regex /(?i)Hello (.*)!/
|
||||
```
|
||||
|
||||
The regex syntax is documented at <https://docs.rs/regex/latest/regex/#syntax>.
|
||||
|
||||
### replace
|
||||
|
||||
Replaces all occurrences of old string with new string.
|
||||
|
|
|
|||
|
|
@ -442,7 +442,8 @@ jsonpath "$.hasDevice" == false
|
|||
jsonpath "$.links" count == 12
|
||||
jsonpath "$.state" != null
|
||||
jsonpath "$.order" matches "^order-\\d{8}$"
|
||||
jsonpath "$.order" matches /^order-\d{8}$/ # Alternative syntax with regex literal
|
||||
jsonpath "$.order" matches /^order-\d{8}$/ # Alternative syntax with regex literal
|
||||
jsonpath "$.id" matches /(?i)[a-z]*/ # See syntax for flags <https://docs.rs/regex/latest/regex/#grouping-and-flags>
|
||||
jsonpath "$.created" isIsoDate
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# matches predicate use the regex syntax from <https://docs.rs/regex/latest/regex/#syntax>
|
||||
GET http://localhost:8000/assert-match
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
|
|
@ -8,3 +9,5 @@ jsonpath "$.date1" matches /^\d{4}-\d{2}-\d{2}$/
|
|||
jsonpath "$.date2" not matches /^\d{4}-\d{2}-\d{2}$/
|
||||
jsonpath "$.path1" matches /aa\/bb/
|
||||
jsonpath "$.path2" matches /aa\\bb/
|
||||
# Flags are supported (see <https://docs.rs/regex/latest/regex/#grouping-and-flags>).
|
||||
jsonpath "$.path3" matches /(?i)hello \w+!/
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@
|
|||
"date1": "2014-01-01",
|
||||
"date2": "x2014-01-01",
|
||||
"path1": "aa/bb",
|
||||
"path2": "aa\\bb"
|
||||
"path2": "aa\\bb",
|
||||
"path3": "Hello World!"
|
||||
}
|
||||
|
|
@ -9,7 +9,8 @@ def assert_match():
|
|||
"date1": "2014-01-01",
|
||||
"date2": "x2014-01-01",
|
||||
"path1": "aa/bb",
|
||||
"path2": "aa\\\\bb"
|
||||
"path2": "aa\\\\bb",
|
||||
"path3": "Hello World!"
|
||||
}""",
|
||||
mimetype="application/json",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# regex query uses syntax from <https://docs.rs/regex/latest/regex/#syntax>
|
||||
GET http://localhost:8000/assert-regex
|
||||
HTTP 200
|
||||
[Asserts]
|
||||
|
|
@ -6,3 +7,6 @@ regex /Hello ([0-9]+)!/ not exists
|
|||
body regex /Hello ([0-9]+)!/ not exists
|
||||
regex "Hello ([a-zA-Z]+)!" == "World"
|
||||
regex /Hello ([a-zA-Z]+)!/ == "World"
|
||||
# Flags are supported (see <https://docs.rs/regex/latest/regex/#grouping-and-flags>).
|
||||
# For instance, if you want to capture in a case-insensitive way:
|
||||
regex /(?i)hello (\w+)!/ == "World"
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ jsonpath "$.ips" split ", " last == "10.0.0.10"
|
|||
jsonpath "$.ips" replace ", " "|" == "192.168.2.1|10.0.0.20|10.0.0.10"
|
||||
jsonpath "$.id" replaceRegex /\d/ "x" == "xxx"
|
||||
jsonpath "$.message" replaceRegex "B[a-z]b" "dude" == "Hello dude!"
|
||||
jsonpath "$.message" replaceRegex /(?i)b[a-z]b/ "dude" == "Hello dude!"
|
||||
# First args of replace filter _is not_ a regex
|
||||
jsonpath "$.id" replace "\\d" "x" == "123"
|
||||
jsonpath "$.json" jsonpath "$.message" == "Hello"
|
||||
|
|
|
|||
Loading…
Reference in New Issue