Implements isList predicate.

This commit is contained in:
Jean-Christophe Amiel 2025-11-04 18:11:49 +01:00
parent be0b93cf44
commit a02339b121
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
16 changed files with 143 additions and 126 deletions

View File

@ -459,9 +459,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
49 | jsonpath "$.not-exist" isDate
49 | jsonpath "$.not-exist" isList
| actual: none
| expected: date
| expected: list
|
error: Assert failure
@ -469,9 +469,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
50 | jsonpath "$.not-exist" exists
50 | jsonpath "$.not-exist" isDate
| actual: none
| expected: something
| expected: date
|
error: Assert failure
@ -479,9 +479,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
51 | jsonpath "$.not-exist" isEmpty
51 | jsonpath "$.not-exist" exists
| actual: none
| expected: empty
| expected: something
|
error: Assert failure
@ -489,9 +489,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
52 | jsonpath "$.not-exist" isIpv4
52 | jsonpath "$.not-exist" isEmpty
| actual: none
| expected: ipv4
| expected: empty
|
error: Assert failure
@ -499,9 +499,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
53 | jsonpath "$.not-exist" isIpv6
53 | jsonpath "$.not-exist" isIpv4
| actual: none
| expected: ipv6
| expected: ipv4
|
error: Assert failure
@ -509,9 +509,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
54 | jsonpath "$.not-exist" isUuid
54 | jsonpath "$.not-exist" isIpv6
| actual: none
| expected: uuid
| expected: ipv6
|
error: Assert failure
@ -519,9 +519,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
55 | jsonpath "$.not_a_date" isIsoDate
| actual: 2018
| expected: string with format YYYY-MM-DDTHH:mm:ss.sssZ
55 | jsonpath "$.not-exist" isUuid
| actual: none
| expected: uuid
|
error: Assert failure
@ -529,9 +529,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
56 | jsonpath "$.is_a_date" not isIsoDate
| actual: 2018-12-10T13:45:00.000Z
| expected: not string with format YYYY-MM-DDTHH:mm:ss.sssZ
56 | jsonpath "$.not_a_date" isIsoDate
| actual: 2018
| expected: string with format YYYY-MM-DDTHH:mm:ss.sssZ
|
error: Assert failure
@ -539,9 +539,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
57 | jsonpath "$.not_a_date" isNumber
| actual: string <2018>
| expected: number
57 | jsonpath "$.is_a_date" not isIsoDate
| actual: 2018-12-10T13:45:00.000Z
| expected: not string with format YYYY-MM-DDTHH:mm:ss.sssZ
|
error: Assert failure
@ -549,9 +549,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
58 | jsonpath "$.is_a_date" isIpv4
| actual: 2018-12-10T13:45:00.000Z
| expected: string in IPv4 format
58 | jsonpath "$.not_a_date" isNumber
| actual: string <2018>
| expected: number
|
error: Assert failure
@ -559,9 +559,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
59 | jsonpath "$.is_a_date" isIpv6
59 | jsonpath "$.is_a_date" isIpv4
| actual: 2018-12-10T13:45:00.000Z
| expected: string in IPv6 format
| expected: string in IPv4 format
|
error: Assert failure
@ -569,8 +569,8 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
60 | jsonpath "$.ipv4" isIpv6
| actual: 127.0.0.1
60 | jsonpath "$.is_a_date" isIpv6
| actual: 2018-12-10T13:45:00.000Z
| expected: string in IPv6 format
|
@ -579,9 +579,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
61 | jsonpath "$.ipv4" not isIpv4
61 | jsonpath "$.ipv4" isIpv6
| actual: 127.0.0.1
| expected: not string in IPv4 format
| expected: string in IPv6 format
|
error: Assert failure
@ -589,9 +589,9 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
62 | jsonpath "$.ipv6" isIpv4
| actual: 2001:db8::1
| expected: string in IPv4 format
62 | jsonpath "$.ipv4" not isIpv4
| actual: 127.0.0.1
| expected: not string in IPv4 format
|
error: Assert failure
@ -599,7 +599,17 @@ error: Assert failure
|
| GET http://localhost:8000/predicate/error/type
| ...
63 | jsonpath "$.ipv6" not isIpv6
63 | jsonpath "$.ipv6" isIpv4
| actual: 2001:db8::1
| expected: string in IPv4 format
|
error: Assert failure
--> tests_failed/predicate/predicate.hurl:64:0
|
| GET http://localhost:8000/predicate/error/type
| ...
64 | jsonpath "$.ipv6" not isIpv6
| actual: 2001:db8::1
| expected: not string in IPv6 format
|

View File

@ -46,6 +46,7 @@ jsonpath "$.not-exist" isFloat
jsonpath "$.not-exist" isBoolean
jsonpath "$.not-exist" isString
jsonpath "$.not-exist" isCollection
jsonpath "$.not-exist" isList
jsonpath "$.not-exist" isDate
jsonpath "$.not-exist" exists
jsonpath "$.not-exist" isEmpty

View File

@ -16,6 +16,7 @@ header "Set-Cookie" exists
header "Set-Cookie" count == 3
header "Set-Cookie" contains "cookie1=value1; Path=/"
header "Set-Cookie" not contains "cookie4=value4; Path=/"
header "X-Fruit" isList
header "X-Fruit" isCollection
header "x-fruit" count == 4
header "X-Fruit" nth 0 == "Banana"
@ -33,7 +34,9 @@ HTTP 200
[Captures]
fruits: header "X-fruit"
[Asserts]
header "X-Fruit" isList
header "X-Fruit" isCollection
variable "fruits" isList
variable "fruits" isCollection
variable "fruits" count == 4
variable "fruits" nth 0 == "Banana"

File diff suppressed because one or more lines are too long

View File

@ -27,8 +27,10 @@ jsonpath "$.success" != null
jsonpath "$.success" exists
jsonpath "$.success" isBoolean
jsonpath "$.errors" count == 2
jsonpath "$.errors" isList
jsonpath "$.errors" isCollection
jsonpath "$.failures" count == 1
jsonpath "$.failures" isList
jsonpath "$.failures" isCollection
jsonpath "$.warnings" count == 0
jsonpath "$.warnings" isEmpty
@ -38,6 +40,7 @@ jsonpath "$.toto" not exists
jsonpath "$.failures" exists
jsonpath "$.warnings" exists
jsonpath "$.errors[0]" exists
jsonpath "$.errors[0]" not isList
jsonpath "$.errors[0]" isCollection
jsonpath "$.errors[0].id" == "error1"
jsonpath "$.errors[0].id" isString

View File

@ -16,6 +16,7 @@
<span class="query-type">jsonpath</span> <span class="string">"$.nooks"</span> <span class="predicate-type">includes</span> <span class="string">"Dune"</span> <span class="comment"># includes</span>
<span class="query-type">jsonpath</span> <span class="string">"$.nooks"</span> <span class="predicate-type">contains</span> <span class="string">"Dune"</span> <span class="comment"># contains</span>
<span class="query-type">jsonpath</span> <span class="string">"$.succeeded"</span> <span class="predicate-type">isBoolean</span> <span class="comment"># isBoolean</span>
<span class="query-type">jsonpath</span> <span class="string">"$.books"</span> <span class="predicate-type">isList</span> <span class="comment"># isList</span>
<span class="query-type">jsonpath</span> <span class="string">"$.books"</span> <span class="predicate-type">isCollection</span> <span class="comment"># isCollection</span>
<span class="query-type">certificate</span> <span class="string">"Expire-Date"</span> <span class="predicate-type">isDate</span> <span class="comment"># isDate</span>
<span class="query-type">jsonpath</span> <span class="string">"$.publication_date"</span> <span class="predicate-type">isIsoDate</span> <span class="comment"># isIsoDate</span>

View File

@ -16,6 +16,7 @@ jsonpath "$.book" exists # exists
jsonpath "$.nooks" includes "Dune" # includes
jsonpath "$.nooks" contains "Dune" # contains
jsonpath "$.succeeded" isBoolean # isBoolean
jsonpath "$.books" isList # isList
jsonpath "$.books" isCollection # isCollection
certificate "Expire-Date" isDate # isDate
jsonpath "$.publication_date" isIsoDate # isIsoDate

View File

@ -1 +1 @@
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/dummy"},"response":{"status":200,"asserts":[{"query":{"type":"jsonpath","expr":"$.book"},"predicate":{"not":true,"type":"==","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.book"},"predicate":{"type":"==","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.color"},"predicate":{"type":"!=","value":"red"}},{"query":{"type":"jsonpath","expr":"$.year"},"predicate":{"type":">","value":1978}},{"query":{"type":"jsonpath","expr":"$.year"},"predicate":{"type":">=","value":1978}},{"query":{"type":"jsonpath","expr":"$.year"},"predicate":{"type":"<","value":1978}},{"query":{"type":"jsonpath","expr":"$.year"},"predicate":{"type":"<=","value":1978}},{"query":{"type":"jsonpath","expr":"$.movie"},"predicate":{"type":"contains","value":"Empire"}},{"query":{"type":"bytes"},"predicate":{"type":"contains","value":"vu8=","encoding":"base64"}},{"query":{"type":"jsonpath","expr":"$.movie"},"predicate":{"type":"endsWith","value":"Back"}},{"query":{"type":"bytes"},"predicate":{"type":"endsWith","value":"qxI0Vg==","encoding":"base64"}},{"query":{"type":"jsonpath","expr":"$.book"},"predicate":{"type":"exists"}},{"query":{"type":"jsonpath","expr":"$.nooks"},"predicate":{"type":"includes","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.nooks"},"predicate":{"type":"contains","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.succeeded"},"predicate":{"type":"isBoolean"}},{"query":{"type":"jsonpath","expr":"$.books"},"predicate":{"type":"isCollection"}},{"query":{"type":"certificate","expr":"Expire-Date"},"predicate":{"type":"isDate"}},{"query":{"type":"jsonpath","expr":"$.publication_date"},"predicate":{"type":"isIsoDate"}},{"query":{"type":"jsonpath","expr":"$.movies"},"predicate":{"type":"isEmpty"}},{"query":{"type":"jsonpath","expr":"$.height"},"predicate":{"type":"isFloat"}},{"query":{"type":"jsonpath","expr":"$.count"},"predicate":{"type":"isInteger"}},{"query":{"type":"jsonpath","expr":"$.name"},"predicate":{"type":"isString"}},{"query":{"type":"jsonpath","expr":"$.release"},"predicate":{"type":"matches","value":"\\d{4}"}},{"query":{"type":"jsonpath","expr":"$.release"},"predicate":{"type":"matches","value":"\\d{4}","encoding":"regex"}},{"query":{"type":"jsonpath","expr":"$.movie"},"predicate":{"type":"startsWith","value":"The"}},{"query":{"type":"bytes"},"predicate":{"type":"startsWith","value":"77u/","encoding":"base64"}},{"query":{"type":"jsonpath","expr":"$.count"},"predicate":{"type":"isNumber"}},{"query":{"type":"ip"},"predicate":{"type":"isIpv6"}},{"query":{"type":"ip"},"predicate":{"type":"isIpv4"}},{"query":{"type":"jsonpath","expr":"$.uuid"},"predicate":{"type":"isUuid"}}]}}]}
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/dummy"},"response":{"status":200,"asserts":[{"query":{"type":"jsonpath","expr":"$.book"},"predicate":{"not":true,"type":"==","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.book"},"predicate":{"type":"==","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.color"},"predicate":{"type":"!=","value":"red"}},{"query":{"type":"jsonpath","expr":"$.year"},"predicate":{"type":">","value":1978}},{"query":{"type":"jsonpath","expr":"$.year"},"predicate":{"type":">=","value":1978}},{"query":{"type":"jsonpath","expr":"$.year"},"predicate":{"type":"<","value":1978}},{"query":{"type":"jsonpath","expr":"$.year"},"predicate":{"type":"<=","value":1978}},{"query":{"type":"jsonpath","expr":"$.movie"},"predicate":{"type":"contains","value":"Empire"}},{"query":{"type":"bytes"},"predicate":{"type":"contains","value":"vu8=","encoding":"base64"}},{"query":{"type":"jsonpath","expr":"$.movie"},"predicate":{"type":"endsWith","value":"Back"}},{"query":{"type":"bytes"},"predicate":{"type":"endsWith","value":"qxI0Vg==","encoding":"base64"}},{"query":{"type":"jsonpath","expr":"$.book"},"predicate":{"type":"exists"}},{"query":{"type":"jsonpath","expr":"$.nooks"},"predicate":{"type":"includes","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.nooks"},"predicate":{"type":"contains","value":"Dune"}},{"query":{"type":"jsonpath","expr":"$.succeeded"},"predicate":{"type":"isBoolean"}},{"query":{"type":"jsonpath","expr":"$.books"},"predicate":{"type":"isList"}},{"query":{"type":"jsonpath","expr":"$.books"},"predicate":{"type":"isCollection"}},{"query":{"type":"certificate","expr":"Expire-Date"},"predicate":{"type":"isDate"}},{"query":{"type":"jsonpath","expr":"$.publication_date"},"predicate":{"type":"isIsoDate"}},{"query":{"type":"jsonpath","expr":"$.movies"},"predicate":{"type":"isEmpty"}},{"query":{"type":"jsonpath","expr":"$.height"},"predicate":{"type":"isFloat"}},{"query":{"type":"jsonpath","expr":"$.count"},"predicate":{"type":"isInteger"}},{"query":{"type":"jsonpath","expr":"$.name"},"predicate":{"type":"isString"}},{"query":{"type":"jsonpath","expr":"$.release"},"predicate":{"type":"matches","value":"\\d{4}"}},{"query":{"type":"jsonpath","expr":"$.release"},"predicate":{"type":"matches","value":"\\d{4}","encoding":"regex"}},{"query":{"type":"jsonpath","expr":"$.movie"},"predicate":{"type":"startsWith","value":"The"}},{"query":{"type":"bytes"},"predicate":{"type":"startsWith","value":"77u/","encoding":"base64"}},{"query":{"type":"jsonpath","expr":"$.count"},"predicate":{"type":"isNumber"}},{"query":{"type":"ip"},"predicate":{"type":"isIpv6"}},{"query":{"type":"ip"},"predicate":{"type":"isIpv4"}},{"query":{"type":"jsonpath","expr":"$.uuid"},"predicate":{"type":"isUuid"}}]}}]}

View File

@ -16,6 +16,7 @@ jsonpath "$.book" exists # exists
jsonpath "$.nooks" includes "Dune" # includes
jsonpath "$.nooks" contains "Dune" # contains
jsonpath "$.succeeded" isBoolean # isBoolean
jsonpath "$.books" isList # isList
jsonpath "$.books" isCollection # isCollection
certificate "Expire-Date" isDate # isDate
jsonpath "$.publication_date" isIsoDate # isIsoDate

View File

@ -190,18 +190,19 @@ fn expected_no_value(
let expected = eval_predicate_value_template(expected, variables)?;
Ok(format!("matches regex <{expected}>"))
}
PredicateFuncValue::IsInteger => Ok("integer".to_string()),
PredicateFuncValue::IsFloat => Ok("float".to_string()),
PredicateFuncValue::Exist => Ok("something".to_string()),
PredicateFuncValue::IsBoolean => Ok("boolean".to_string()),
PredicateFuncValue::IsString => Ok("string".to_string()),
PredicateFuncValue::IsCollection => Ok("collection".to_string()),
PredicateFuncValue::IsDate => Ok("date".to_string()),
PredicateFuncValue::IsIsoDate => Ok("date".to_string()),
PredicateFuncValue::Exist => Ok("something".to_string()),
PredicateFuncValue::IsEmpty => Ok("empty".to_string()),
PredicateFuncValue::IsNumber => Ok("number".to_string()),
PredicateFuncValue::IsFloat => Ok("float".to_string()),
PredicateFuncValue::IsInteger => Ok("integer".to_string()),
PredicateFuncValue::IsIpv4 => Ok("ipv4".to_string()),
PredicateFuncValue::IsIpv6 => Ok("ipv6".to_string()),
PredicateFuncValue::IsIsoDate => Ok("date".to_string()),
PredicateFuncValue::IsNumber => Ok("number".to_string()),
PredicateFuncValue::IsList => Ok("list".to_string()),
PredicateFuncValue::IsString => Ok("string".to_string()),
PredicateFuncValue::IsUuid => Ok("uuid".to_string()),
}
}
@ -268,18 +269,19 @@ fn eval_predicate_func(
value,
context_dir,
),
PredicateFuncValue::IsInteger => eval_is_integer(value),
PredicateFuncValue::IsFloat => eval_is_float(value),
PredicateFuncValue::Exist => eval_exist(value),
PredicateFuncValue::IsBoolean => eval_is_boolean(value),
PredicateFuncValue::IsString => eval_is_string(value),
PredicateFuncValue::IsCollection => eval_is_collection(value),
PredicateFuncValue::IsDate => eval_is_date(value),
PredicateFuncValue::IsIsoDate => eval_is_iso_date(value),
PredicateFuncValue::Exist => eval_exist(value),
PredicateFuncValue::IsEmpty => eval_is_empty(value),
PredicateFuncValue::IsNumber => eval_is_number(value),
PredicateFuncValue::IsFloat => eval_is_float(value),
PredicateFuncValue::IsInteger => eval_is_integer(value),
PredicateFuncValue::IsIpv4 => eval_is_ipv4(value),
PredicateFuncValue::IsIpv6 => eval_is_ipv6(value),
PredicateFuncValue::IsIsoDate => eval_is_iso_date(value),
PredicateFuncValue::IsList => eval_is_list(value),
PredicateFuncValue::IsNumber => eval_is_number(value),
PredicateFuncValue::IsString => eval_is_string(value),
PredicateFuncValue::IsUuid => eval_is_uuid(value),
}
}
@ -525,6 +527,16 @@ fn eval_is_collection(actual: &Value) -> Result<PredicateResult, RunnerError> {
})
}
/// Evaluates if an `actual` value is a list.
fn eval_is_list(actual: &Value) -> Result<PredicateResult, RunnerError> {
Ok(PredicateResult {
success: actual.is_list(),
actual: actual.repr(),
expected: "list".to_string(),
type_mismatch: false,
})
}
/// Evaluates if an `actual` value is a date.
fn eval_is_date(actual: &Value) -> Result<PredicateResult, RunnerError> {
Ok(PredicateResult {

View File

@ -35,9 +35,7 @@ impl Value {
}
}
/// Returns `true` if the value starts with the given prefix.
///
/// Returns `false` if it does not.
/// Returns `true` if the value starts with the given prefix; otherwise `false`.
///
/// Returns a [`EvalError::Type`] if the given value types are not supported.
pub fn starts_with(&self, other: &Value) -> Result<bool, EvalError> {
@ -48,9 +46,7 @@ impl Value {
}
}
/// Returns `true` if the value ends with the given suffix.
///
/// Returns `false` if it does not.
/// Returns `true` if the value ends with the given suffix, otherwise `false`.
///
/// Returns a [`EvalError::Type`] if the given value types are not supported.
pub fn ends_with(&self, other: &Value) -> Result<bool, EvalError> {
@ -61,10 +57,8 @@ impl Value {
}
}
/// Returns `true` if the value contains another value.
/// Returns `true` if the value contains another value, otherwise `false`.
///
/// Returns `false` if it does not.
///
/// Returns a [`EvalError::Type`] if the given value types are not supported.
pub fn contains(&self, other: &Value) -> Result<bool, EvalError> {
match (self, other) {
@ -87,10 +81,8 @@ impl Value {
}
}
/// Returns `true` if the list value includes another value.
/// Returns `true` if the list value includes another value, otherwise `false`.
///
/// Returns `false` if it does not.
///
/// Returns a [`EvalError::Type`] if the given value types are not supported.
///
/// TODO: deprecate method in favor of contains.
@ -110,16 +102,17 @@ impl Value {
}
}
/// Returns `true` the value is a boolean.
///
/// Returns `false` if it is not.
/// Returns `true` the value is a boolean, otherwise `false`.
pub fn is_boolean(&self) -> bool {
self.kind() == ValueKind::Bool
}
/// Returns `true` the value is a collection.
///
/// Returns `false` if it is not.
/// Returns `true` the value is a list, otherwise `false`.
pub fn is_list(&self) -> bool {
self.kind() == ValueKind::Bytes || self.kind() == ValueKind::List
}
/// Returns `true` the value is a collection, otherwise `false`.
pub fn is_collection(&self) -> bool {
self.kind() == ValueKind::Bytes
|| self.kind() == ValueKind::List
@ -127,44 +120,32 @@ impl Value {
|| self.kind() == ValueKind::Object
}
/// Returns `true` the value is a date.
///
/// Returns `false` if it is not.
/// Returns `true` the value is a date, otherwise `false`.
pub fn is_date(&self) -> bool {
self.kind() == ValueKind::Date
}
/// Returns `true` the value is a float.
///
/// Returns `false` if it is not.
/// Returns `true` the value is a float, otherwise `false`.
pub fn is_float(&self) -> bool {
self.kind() == ValueKind::Float
}
/// Returns `true` the value is an integer.
///
/// Returns `false` if it is not.
/// Returns `true` the value is an integer, otherwise `false`.
pub fn is_integer(&self) -> bool {
self.kind() == ValueKind::Integer
}
/// Returns `true` the value is a number.
///
/// Returns `false` if it is not.
/// Returns `true` the value is a number, otherwise `false`.
pub fn is_number(&self) -> bool {
self.kind() == ValueKind::Integer || self.kind() == ValueKind::Float
}
/// Returns `true` the value is a String.
///
/// Returns `false` if it is not.
/// Returns `true` the value is a string, otherwise `false`.
pub fn is_string(&self) -> bool {
self.kind() == ValueKind::String || self.kind() == ValueKind::Secret
}
/// Returns `true` the value is an IPv4 address.
///
/// Returns `false` if it is not.
/// Returns `true` the value is an IPv4 address, otherwise `false`.
///
/// Returns a [`EvalError::Type`] if the given value is not a String.
pub fn is_ipv4(&self) -> Result<bool, EvalError> {
@ -177,9 +158,7 @@ impl Value {
}
}
/// Returns `true` the value is a IPv6 address.
///
/// Returns `false` if it is not.
/// Returns `true` the value is a IPv6 address, otherwise `false`.
///
/// Returns a [`EvalError::Type`] if the given value is not a String.
pub fn is_ipv6(&self) -> Result<bool, EvalError> {
@ -192,9 +171,7 @@ impl Value {
}
}
/// Returns `true` the value is a UUID.
///
/// Returns `false` if it is not.
/// Returns `true` the value is a UUID, otherwise `false`.
///
/// Returns a [`EvalError::Type`] if the given value is not a String.
pub fn is_uuid(&self) -> Result<bool, EvalError> {
@ -207,9 +184,8 @@ impl Value {
}
}
/// Returns `true` the string value represents a RFC339 date (format YYYY-MM-DDTHH:mm:ss.sssZ).
///
/// Returns `false` if it does not.
/// Returns `true` the string value represents a RFC339 date (format YYYY-MM-DDTHH:mm:ss.sssZ),
/// otherwise `false`.
///
/// Returns a [`EvalError::Type`] if the given value is not a String.
pub fn is_iso_date(&self) -> Result<bool, EvalError> {
@ -233,9 +209,7 @@ impl Value {
}
}
/// Returns `true` if and only if there is a match for the regex anywhere in the value.
///
/// Returns `false` otherwise.
/// Returns `true` if and only if there is a match for the regex anywhere in the value, otherwise `false`.
///
/// Returns a [`EvalError::Type`] if the type of the value is not supported.
///

View File

@ -402,18 +402,19 @@ pub enum PredicateFuncValue {
space0: Whitespace,
value: PredicateValue,
},
IsInteger,
IsFloat,
Exist,
IsBoolean,
IsString,
IsCollection,
IsDate,
IsIsoDate,
Exist,
IsEmpty,
IsNumber,
IsFloat,
IsInteger,
IsIpv4,
IsIpv6,
IsIsoDate,
IsList,
IsNumber,
IsString,
IsUuid,
}
@ -432,18 +433,19 @@ impl PredicateFuncValue {
PredicateFuncValue::Contain { .. } => "contains",
PredicateFuncValue::Include { .. } => "includes",
PredicateFuncValue::Match { .. } => "matches",
PredicateFuncValue::IsInteger => "isInteger",
PredicateFuncValue::IsFloat => "isFloat",
PredicateFuncValue::Exist => "exists",
PredicateFuncValue::IsBoolean => "isBoolean",
PredicateFuncValue::IsString => "isString",
PredicateFuncValue::IsCollection => "isCollection",
PredicateFuncValue::IsDate => "isDate",
PredicateFuncValue::IsIsoDate => "isIsoDate",
PredicateFuncValue::Exist => "exists",
PredicateFuncValue::IsEmpty => "isEmpty",
PredicateFuncValue::IsNumber => "isNumber",
PredicateFuncValue::IsFloat => "isFloat",
PredicateFuncValue::IsInteger => "isInteger",
PredicateFuncValue::IsIpv4 => "isIpv4",
PredicateFuncValue::IsIpv6 => "isIpv6",
PredicateFuncValue::IsIsoDate => "isIsoDate",
PredicateFuncValue::IsList => "isList",
PredicateFuncValue::IsNumber => "isNumber",
PredicateFuncValue::IsString => "isString",
PredicateFuncValue::IsUuid => "isUuid",
}
}

View File

@ -683,18 +683,19 @@ pub fn walk_predicate<V: Visitor>(visitor: &mut V, pred: &Predicate) {
visitor.visit_whitespace(space0);
visitor.visit_predicate_value(value);
}
PredicateFuncValue::IsInteger
| PredicateFuncValue::IsFloat
PredicateFuncValue::Exist
| PredicateFuncValue::IsBoolean
| PredicateFuncValue::IsString
| PredicateFuncValue::IsCollection
| PredicateFuncValue::IsDate
| PredicateFuncValue::IsIsoDate
| PredicateFuncValue::Exist
| PredicateFuncValue::IsEmpty
| PredicateFuncValue::IsNumber
| PredicateFuncValue::IsFloat
| PredicateFuncValue::IsInteger
| PredicateFuncValue::IsIpv4
| PredicateFuncValue::IsIpv6
| PredicateFuncValue::IsIsoDate
| PredicateFuncValue::IsList
| PredicateFuncValue::IsNumber
| PredicateFuncValue::IsString
| PredicateFuncValue::IsUuid => {}
}
}

View File

@ -87,6 +87,7 @@ fn predicate_func_value(reader: &mut Reader) -> ParseResult<PredicateFuncValue>
boolean_predicate,
string_predicate,
collection_predicate,
is_list_predicate,
date_predicate,
iso_date_predicate,
exist_predicate,
@ -324,6 +325,11 @@ fn is_uuid_predicate(reader: &mut Reader) -> ParseResult<PredicateFuncValue> {
Ok(PredicateFuncValue::IsUuid)
}
fn is_list_predicate(reader: &mut Reader) -> ParseResult<PredicateFuncValue> {
try_literal("isList", reader)?;
Ok(PredicateFuncValue::IsList)
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -559,18 +559,19 @@ impl ToJson for Predicate {
PredicateFuncValue::Match { value, .. } => {
add_predicate_value(&mut attributes, value);
}
PredicateFuncValue::IsInteger
| PredicateFuncValue::IsFloat
PredicateFuncValue::Exist
| PredicateFuncValue::IsBoolean
| PredicateFuncValue::IsString
| PredicateFuncValue::IsCollection
| PredicateFuncValue::IsDate
| PredicateFuncValue::IsIsoDate
| PredicateFuncValue::Exist
| PredicateFuncValue::IsEmpty
| PredicateFuncValue::IsNumber
| PredicateFuncValue::IsFloat
| PredicateFuncValue::IsInteger
| PredicateFuncValue::IsIpv4
| PredicateFuncValue::IsIpv6
| PredicateFuncValue::IsIsoDate
| PredicateFuncValue::IsList
| PredicateFuncValue::IsNumber
| PredicateFuncValue::IsString
| PredicateFuncValue::IsUuid => {}
}
JValue::Object(attributes)

View File

@ -620,18 +620,19 @@ impl Lint for PredicateFuncValue {
s.push(' ');
s.push_str(&value.lint());
}
PredicateFuncValue::IsInteger
| PredicateFuncValue::IsFloat
PredicateFuncValue::Exist
| PredicateFuncValue::IsBoolean
| PredicateFuncValue::IsString
| PredicateFuncValue::IsCollection
| PredicateFuncValue::IsDate
| PredicateFuncValue::IsIsoDate
| PredicateFuncValue::Exist
| PredicateFuncValue::IsEmpty
| PredicateFuncValue::IsNumber
| PredicateFuncValue::IsFloat
| PredicateFuncValue::IsInteger
| PredicateFuncValue::IsIpv4
| PredicateFuncValue::IsIpv6
| PredicateFuncValue::IsIsoDate
| PredicateFuncValue::IsList
| PredicateFuncValue::IsNumber
| PredicateFuncValue::IsString
| PredicateFuncValue::IsUuid => {}
}
s