Overview
googletest-json-serde adds focused matcher macros for JSON so your Rust tests read like intent, not plumbing. It handles heterogeneous arrays, deep object patterns, path checks, and produces readable failure messages with path context.
Installation
Add as a dev-dependency:
Usage
use *;
use json;
use json as j;
let actual = j!;
assert_that!;
Features
- Object patterns:
json::matches_pattern!/json::pat!(strict or relaxed)
- Arrays:
- Ordered:
json::elements_are! - Unordered:
json::unordered_elements_are! - Contains-each:
json::contains_each! - Contained-in:
json::is_contained_in! - Length:
json::len! - Apply to all elements:
json::each! - Type guard:
json::each_is_string()/number/boolean/null/array/object
- Ordered:
- Primitives and kinds:
json::primitive!,json::is_number/integer/fractional_number/whole_number/string/boolean,json::is_true/false,json::is_null,json::is_not_null,json::is_empty_string/non_empty_string,json::is_empty_array/object,json::is_non_empty_array/object
- Paths and shape:
json::has_paths,json::has_only_paths,json::has_path_with!
- Optional fields:
json::optional!
- Clear diagnostics that point to the failing path or element.
More Examples
Primitives
use *;
use json;
use json as j;
assert_that!;
assert_that!;
assert_that!;
assert_that!;
assert_that!;
assert_that!;
assert_that!;
Path value matching
use *;
use json;
use json as j;
let value = j!;
assert_that!;
assert_that!;
assert_that!;
Predicates
use *;
use json;
use json as j;
assert_that!;
assert_that!;
Objects
use *;
use json;
use json as j;
assert_that!;
Arrays
use *;
use json;
use json as j;
assert_that!;
assert_that!;
assert_that!;
assert_that!;
Combined Example
use *;
use json;
use json as j;
assert_that!;
Documentation
- API reference: https://docs.rs/googletest-json-serde
- Crate: https://crates.io/crates/googletest-json-serde
- More usage patterns live in
tests/andsanity/tests/sanity_test.rs.
Contributing
- Issues: https://github.com/chege/googletest-json-serde/issues
- Contributions welcome! See CONTRIBUTING.md.
License
Dual-licensed under MIT or Apache-2.0.