2
2
3
3
# assert-json-diff
4
4
5
- This crate includes macros for comparing two JSON values. It is designed to give much
6
- more helpful error messages than the standard [ ` assert_eq! ` ] . It basically does a diff of the
7
- two objects and tells you the exact differences. This is useful when asserting that two large
8
- JSON objects are the same.
5
+ This crate includes macros for comparing two serializable values by diffing their JSON
6
+ representations. It is designed to give much more helpful error messages than the standard
7
+ [ ` assert_eq! ` ] . It basically does a diff of the two objects and tells you the exact
8
+ differences. This is useful when asserting that two large JSON objects are the same.
9
9
10
- It uses the [ ` serde_json::Value ` ] type to represent JSON .
10
+ It uses the [ serde ] and [ serde_json ] to perform the serialization .
11
11
12
- [ `serde_json::Value` ] : https://docs.serde.rs/serde_json/value/enum.Value.html
12
+ [ serde ] : https://crates.io/crates/serde
13
+ [ serde_json ] : https://crates.io/crates/serde_json
13
14
[ `assert_eq!` ] : https://doc.rust-lang.org/std/macro.assert_eq.html
14
15
15
16
### Partial matching
@@ -18,10 +19,8 @@ If you want to assert that one JSON value is "included" in another use
18
19
[ ` assert_json_include ` ] ( macro.assert_json_include.html ) :
19
20
20
21
``` rust
21
- #[macro_use]
22
- extern crate assert_json_diff;
23
- #[macro_use]
24
- extern crate serde_json;
22
+ use assert_json_diff :: assert_json_include;
23
+ use serde_json :: json;
25
24
26
25
fn main () {
27
26
let a = json! ({
@@ -86,10 +85,8 @@ json atoms at path ".data.users[1].id" are not equal:
86
85
of the JSON without having to specify the whole thing. For example this test passes:
87
86
88
87
``` rust
89
- #[macro_use]
90
- extern crate assert_json_diff;
91
- #[macro_use]
92
- extern crate serde_json;
88
+ use assert_json_diff :: assert_json_include;
89
+ use serde_json :: json;
93
90
94
91
fn main () {
95
92
assert_json_include! (
@@ -106,10 +103,8 @@ fn main() {
106
103
However ` expected ` cannot contain additional data so this test fails:
107
104
108
105
``` rust
109
- #[macro_use]
110
- extern crate assert_json_diff;
111
- #[macro_use]
112
- extern crate serde_json;
106
+ use assert_json_diff :: assert_json_include;
107
+ use serde_json :: json;
113
108
114
109
fn main () {
115
110
assert_json_include! (
@@ -134,10 +129,8 @@ json atom at path ".a.b" is missing from actual
134
129
If you want to ensure two JSON values are * exactly* the same, use [ ` assert_json_eq ` ] ( macro.assert_json_eq.html ) .
135
130
136
131
``` rust
137
- #[macro_use]
138
- extern crate assert_json_diff;
139
- #[macro_use]
140
- extern crate serde_json;
132
+ use assert_json_diff :: assert_json_eq;
133
+ use serde_json :: json;
141
134
142
135
fn main () {
143
136
assert_json_eq! (
0 commit comments