pub trait PropertyAssertions<'a> {
// Required methods
fn has_property(&'a mut self, name: &str) -> &'a mut Self;
fn has_properties<I, S>(&'a mut self, names: I) -> &'a mut Self
where I: IntoIterator<Item = S>,
S: AsRef<str>;
fn has_property_count(&'a mut self, expected: usize) -> &'a mut Self;
fn has_property_count_matching<F>(
&'a mut self,
predicate: F,
expected: usize,
) -> &'a mut Self
where F: Fn(&str) -> bool;
fn has_property_value(
&'a mut self,
name: &str,
expected: Value,
) -> &'a mut Self;
fn has_property_matching<F>(
&'a mut self,
name: &str,
predicate: F,
) -> &'a mut Self
where F: Fn(&Value) -> bool;
fn properties_matching<F>(&'a mut self, predicate: F) -> PropertyMatcher<'a>
where F: Fn(&str) -> bool;
}
Expand description
Trait providing property testing capabilities for JSON objects.
Required Methods§
Sourcefn has_property(&'a mut self, name: &str) -> &'a mut Self
fn has_property(&'a mut self, name: &str) -> &'a mut Self
Sourcefn has_properties<I, S>(&'a mut self, names: I) -> &'a mut Self
fn has_properties<I, S>(&'a mut self, names: I) -> &'a mut Self
Sourcefn has_property_count(&'a mut self, expected: usize) -> &'a mut Self
fn has_property_count(&'a mut self, expected: usize) -> &'a mut Self
Asserts that the object has exactly the expected number of properties.
§Examples
test.assert_path("$.user")
.has_property_count(2);
§Panics
- Panics if the value is not an object
- Panics if the number of properties doesn’t match the expected countfn has_property_count(&’a mut self, expected: usize) -> &’a mut Self;
Sourcefn has_property_count_matching<F>(
&'a mut self,
predicate: F,
expected: usize,
) -> &'a mut Self
fn has_property_count_matching<F>( &'a mut self, predicate: F, expected: usize, ) -> &'a mut Self
Asserts that the object has the expected number of properties matching a predicate.
§Examples
test.assert_path("$.user")
.has_property_count_matching(|key| key.starts_with("meta_"), 2);
§Panics
- Panics if the value is not an object
- Panics if the number of matching properties doesn’t equal the expected count
Sourcefn has_property_value(&'a mut self, name: &str, expected: Value) -> &'a mut Self
fn has_property_value(&'a mut self, name: &str, expected: Value) -> &'a mut Self
Sourcefn has_property_matching<F>(
&'a mut self,
name: &str,
predicate: F,
) -> &'a mut Self
fn has_property_matching<F>( &'a mut self, name: &str, predicate: F, ) -> &'a mut Self
Sourcefn properties_matching<F>(&'a mut self, predicate: F) -> PropertyMatcher<'a>
fn properties_matching<F>(&'a mut self, predicate: F) -> PropertyMatcher<'a>
Creates a PropertyMatcher for testing properties that match a predicate.
§Examples
test.assert_path("$.user")
.properties_matching(|key| key.starts_with("meta_"))
.count(2)
.and()
.has_property_count(2);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.