1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! Declarative JSON value matching for testing.
//!
//! This library provides a flexible way to assert that JSON values match expected patterns,
//! supporting both exact matching and flexible matchers for common types like UUIDs, dates,
//! and arbitrary values.
//!
//! # Basic Usage
//!
//! Use the [`assert_jm!`] macro to match JSON values against expected patterns:
//!
//! ```
//! use serde_json::json;
//! use json_matcher::assert_jm;
//!
//! let response = json!({
//! "status": "success",
//! "count": 42
//! });
//!
//! // Exact match using inline JSON syntax
//! assert_jm!(response, {
//! "status": "success",
//! "count": 42
//! });
//! ```
//!
//! # Using Matchers
//!
//! For flexible matching, use matcher types like [`AnyMatcher`], [`UuidMatcher`], or [`U16Matcher`]:
//!
//! ```
//! use serde_json::json;
//! use json_matcher::{assert_jm, AnyMatcher, UuidMatcher};
//!
//! let response = json!({
//! "id": "550e8400-e29b-41d4-a716-446655440000",
//! "timestamp": "2024-01-15T10:30:00Z",
//! "value": 123
//! });
//!
//! assert_jm!(response, {
//! "id": UuidMatcher::new(),
//! "timestamp": AnyMatcher::not_null(),
//! "value": 123
//! });
//! ```
//!
//! # Error Reporting
//!
//! When assertions fail, [`assert_jm!`] reports all errors found (not just the first) and displays
//! the actual JSON value for debugging:
//!
//! ```should_panic
//! use serde_json::json;
//! use json_matcher::{assert_jm, UuidMatcher};
//!
//! let response = json!({
//! "id": "not-a-uuid",
//! "name": "Alice",
//! "age": 25
//! });
//!
//! // This will panic with a detailed error message showing:
//! // - All validation errors ($.id and $.name mismatches)
//! // - The full actual JSON value
//! assert_jm!(response, {
//! "id": UuidMatcher::new(),
//! "name": "Bob",
//! "age": 25
//! });
//! // Output:
//! // Json matcher failed:
//! // - $.id: Expected valid UUID format
//! // - $.name: Expected string "Bob" but got "Alice"
//! //
//! // Actual:
//! // {
//! // "id": "not-a-uuid",
//! // "name": "Alice",
//! // "age": 25
//! // }
//! ```
//!
//! # Custom Matchers
//!
//! Create custom matchers by implementing the [`JsonMatcher`] trait:
//!
//! ```
//! use serde_json::{json, Value};
//! use json_matcher::{assert_jm, JsonMatcher, JsonMatcherError};
//!
//! struct OnlyVowels;
//!
//! impl JsonMatcher for OnlyVowels {
//! fn json_matches(&self, value: &Value) -> Vec<JsonMatcherError> {
//! match value.as_str() {
//! Some(s) if s.chars().all(|c| "aeiouAEIOU".contains(c)) => vec![],
//! Some(_) => vec![JsonMatcherError::at_root("String contains non-vowel characters")],
//! None => vec![JsonMatcherError::at_root("Expected string")],
//! }
//! }
//! }
//!
//! let data = json!({
//! "sound": "aeiou",
//! "count": 5
//! });
//!
//! assert_jm!(data, {
//! "sound": OnlyVowels,
//! "count": 5
//! });
//! ```
//!
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;