Skip to content

Commit 09b39c1

Browse files
committed
Fix wrong error message
If you compared two values like this: ``` assert_json_include!( actual: json!({}); expected: json!({ "c": 4 }) ); ``` It would say that "c" is missing from expected, when in fact it is missing from actual. Thanks to alexheretic on reddit for pointing out this silly mistake.
1 parent 67e8df3 commit 09b39c1

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ N/A
2020

2121
### Fixed
2222

23-
N/A
23+
- Fix wrong error message when a JSON atom was missing from actual.
2424

2525
## [0.2.0] - 2018-11-16
2626

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn main() {
133133
That will print
134134

135135
```
136-
json atom at path ".a.b" is missing from expected
136+
json atom at path ".a.b" is missing from actual
137137
```
138138

139139
### Exact matching

src/lib.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
//! That will print
130130
//!
131131
//! ```text
132-
//! json atom at path ".a.b" is missing from expected
132+
//! json atom at path ".a.b" is missing from actual
133133
//! ```
134134
//!
135135
//! ## Exact matching
@@ -153,7 +153,7 @@
153153
//! This will panic with the error message:
154154
//!
155155
//! ```text
156-
//! json atom at path ".a.b" is missing from rhs
156+
//! json atom at path ".a.b" is missing from lhs
157157
//! ```
158158
159159
#![deny(
@@ -633,7 +633,7 @@ impl MatchErrors {
633633
.indent(8),
634634
),
635635
ErrorType::MissingPath(Either::Left(path)) => {
636-
format!(r#"json atom at path "{}" is missing from expected"#, path)
636+
format!(r#"json atom at path "{}" is missing from actual"#, path)
637637
}
638638
ErrorType::MissingPath(Either::Right((path, SideWithoutPath::Lhs))) => {
639639
format!(r#"json atom at path "{}" is missing from lhs"#, path)
@@ -811,7 +811,13 @@ mod tests {
811811
);
812812
assert_output_eq(
813813
result,
814-
Err(r#"json atom at path ".a.b" is missing from expected"#),
814+
Err(r#"json atom at path ".a.b" is missing from actual"#),
815+
);
816+
817+
let result = test_partial_match(Actual(json!({})), Expected(json!({ "a": true })));
818+
assert_output_eq(
819+
result,
820+
Err(r#"json atom at path ".a" is missing from actual"#),
815821
);
816822

817823
let result = test_partial_match(
@@ -880,7 +886,7 @@ mod tests {
880886
);
881887
assert_output_eq(
882888
result,
883-
Err(r#"json atom at path ".a[2]" is missing from expected"#),
889+
Err(r#"json atom at path ".a[2]" is missing from actual"#),
884890
);
885891
}
886892

@@ -902,12 +908,6 @@ mod tests {
902908
"b""#),
903909
);
904910

905-
let result = test_exact_match(json!({ "a": {} }), json!({ "a": { "b": true }}));
906-
assert_output_eq(
907-
result,
908-
Err(r#"json atom at path ".a.b" is missing from lhs"#),
909-
);
910-
911911
let result = test_exact_match(
912912
json!({ "a": [1, { "b": 2 }] }),
913913
json!({ "a": [1, { "b": 3 }] }),
@@ -930,7 +930,7 @@ mod tests {
930930
Err(r#"json atom at path ".a.b" is missing from rhs"#),
931931
);
932932

933-
let result = test_exact_match(json!({ "a": {} }), json!({ "a": { "b": 1} }));
933+
let result = test_exact_match(json!({ "a": {} }), json!({ "a": { "b": 1 } }));
934934
assert_output_eq(
935935
result,
936936
Err(r#"json atom at path ".a.b" is missing from lhs"#),
@@ -958,10 +958,10 @@ mod tests {
958958
return;
959959
} else {
960960
println!("Errors didn't match");
961-
println!("Actual:");
962-
println!("{}", actual_error);
963961
println!("Expected:");
964962
println!("{}", expected_error);
963+
println!("Got:");
964+
println!("{}", actual_error);
965965
}
966966
}
967967
}

0 commit comments

Comments
 (0)