aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/debug.rs43
-rw-r--r--tests/macros/mod.rs2
-rw-r--r--tests/regression/issue795.rs2
-rw-r--r--tests/regression/issue845.rs2
-rw-r--r--tests/regression/issue953.rs9
-rw-r--r--tests/stream.rs1
-rw-r--r--tests/test.rs11
-rw-r--r--tests/ui/missing_colon.stderr7
-rw-r--r--tests/ui/missing_comma.stderr6
-rw-r--r--tests/ui/missing_value.stderr7
-rw-r--r--tests/ui/parse_expr.stderr6
-rw-r--r--tests/ui/unexpected_after_array_element.stderr2
-rw-r--r--tests/ui/unexpected_after_map_entry.stderr2
-rw-r--r--tests/ui/unexpected_colon.stderr2
-rw-r--r--tests/ui/unexpected_comma.stderr2
15 files changed, 82 insertions, 22 deletions
diff --git a/tests/debug.rs b/tests/debug.rs
index d2d8448..8ddcf5a 100644
--- a/tests/debug.rs
+++ b/tests/debug.rs
@@ -1,3 +1,4 @@
+use indoc::indoc;
use serde_json::{json, Number, Value};
#[test]
@@ -26,6 +27,8 @@ fn value_number() {
assert_eq!(format!("{:?}", json!(1)), "Number(1)");
assert_eq!(format!("{:?}", json!(-1)), "Number(-1)");
assert_eq!(format!("{:?}", json!(1.0)), "Number(1.0)");
+ assert_eq!(Number::from_f64(1.0).unwrap().to_string(), "1.0"); // not just "1"
+ assert_eq!(Number::from_f64(12e40).unwrap().to_string(), "1.2e41");
}
#[test]
@@ -35,12 +38,12 @@ fn value_string() {
#[test]
fn value_array() {
- assert_eq!(format!("{:?}", json!([])), "Array([])");
+ assert_eq!(format!("{:?}", json!([])), "Array []");
}
#[test]
fn value_object() {
- assert_eq!(format!("{:?}", json!({})), "Object({})");
+ assert_eq!(format!("{:?}", json!({})), "Object {}");
}
#[test]
@@ -50,19 +53,29 @@ fn error() {
assert_eq!(format!("{:?}", err), expected);
}
-const INDENTED_EXPECTED: &str = r#"Object({
- "array": Array([
- Number(
- 0,
- ),
- Number(
- 1,
- ),
- ]),
-})"#;
-
#[test]
fn indented() {
- let j = json!({ "array": [0, 1] });
- assert_eq!(format!("{:#?}", j), INDENTED_EXPECTED);
+ let j = json!({
+ "Array": [true],
+ "Bool": true,
+ "EmptyArray": [],
+ "EmptyObject": {},
+ "Null": null,
+ "Number": 1,
+ "String": "...",
+ });
+ let expected = indoc! {r#"
+ Object {
+ "Array": Array [
+ Bool(true),
+ ],
+ "Bool": Bool(true),
+ "EmptyArray": Array [],
+ "EmptyObject": Object {},
+ "Null": Null,
+ "Number": Number(1),
+ "String": String("..."),
+ }"#
+ };
+ assert_eq!(format!("{:#?}", j), expected);
}
diff --git a/tests/macros/mod.rs b/tests/macros/mod.rs
index 8ac4619..aaf820f 100644
--- a/tests/macros/mod.rs
+++ b/tests/macros/mod.rs
@@ -1,3 +1,5 @@
+#![allow(unused_macro_rules)]
+
macro_rules! json_str {
([]) => {
"[]"
diff --git a/tests/regression/issue795.rs b/tests/regression/issue795.rs
index 06b6872..bb82852 100644
--- a/tests/regression/issue795.rs
+++ b/tests/regression/issue795.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::assertions_on_result_states)]
+
use serde::de::{
Deserialize, Deserializer, EnumAccess, IgnoredAny, MapAccess, VariantAccess, Visitor,
};
diff --git a/tests/regression/issue845.rs b/tests/regression/issue845.rs
index dcca556..56037ae 100644
--- a/tests/regression/issue845.rs
+++ b/tests/regression/issue845.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::trait_duplication_in_bounds)] // https://github.com/rust-lang/rust-clippy/issues/8757
+
use serde::{Deserialize, Deserializer};
use std::convert::TryFrom;
use std::fmt::{self, Display};
diff --git a/tests/regression/issue953.rs b/tests/regression/issue953.rs
new file mode 100644
index 0000000..771aa52
--- /dev/null
+++ b/tests/regression/issue953.rs
@@ -0,0 +1,9 @@
+use serde_json::Value;
+
+#[test]
+fn test() {
+ let x1 = serde_json::from_str::<Value>("18446744073709551615.");
+ assert!(x1.is_err());
+ let x2 = serde_json::from_str::<Value>("18446744073709551616.");
+ assert!(x2.is_err());
+}
diff --git a/tests/stream.rs b/tests/stream.rs
index ca54e9a..ec6b9e3 100644
--- a/tests/stream.rs
+++ b/tests/stream.rs
@@ -1,4 +1,5 @@
#![cfg(not(feature = "preserve_order"))]
+#![allow(clippy::assertions_on_result_states)]
use serde_json::{json, Deserializer, Value};
diff --git a/tests/test.rs b/tests/test.rs
index b11635e..c205072 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -1,10 +1,11 @@
#![cfg(not(feature = "preserve_order"))]
#![allow(
+ clippy::assertions_on_result_states,
clippy::cast_precision_loss,
+ clippy::derive_partial_eq_without_eq,
clippy::excessive_precision,
clippy::float_cmp,
clippy::items_after_statements,
- clippy::let_underscore_drop,
clippy::shadow_unrelated,
clippy::too_many_lines,
clippy::unreadable_literal,
@@ -93,7 +94,7 @@ where
let s = to_string(value).unwrap();
assert_eq!(s, out);
- let v = to_value(&value).unwrap();
+ let v = to_value(value).unwrap();
let s = to_string(&v).unwrap();
assert_eq!(s, out);
}
@@ -109,7 +110,7 @@ where
let s = to_string_pretty(value).unwrap();
assert_eq!(s, out);
- let v = to_value(&value).unwrap();
+ let v = to_value(value).unwrap();
let s = to_string_pretty(&v).unwrap();
assert_eq!(s, out);
}
@@ -1105,7 +1106,7 @@ fn test_parse_string() {
]);
test_parse_ok(vec![
- ("\"\"", "".to_string()),
+ ("\"\"", String::new()),
("\"foo\"", "foo".to_string()),
(" \"foo\" ", "foo".to_string()),
("\"\\\"\"", "\"".to_string()),
@@ -1926,7 +1927,7 @@ fn test_deny_float_key() {
// map with float key
let map = treemap!(Float => "x");
- assert!(serde_json::to_value(&map).is_err());
+ assert!(serde_json::to_value(map).is_err());
}
#[test]
diff --git a/tests/ui/missing_colon.stderr b/tests/ui/missing_colon.stderr
index 9b83c17..1515211 100644
--- a/tests/ui/missing_colon.stderr
+++ b/tests/ui/missing_colon.stderr
@@ -4,4 +4,9 @@ error: unexpected end of macro invocation
4 | json!({ "a" });
| ^^^^^^^^^^^^^^ missing tokens in macro arguments
|
- = note: this error originates in the macro `json_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
+note: while trying to match `@`
+ --> src/macros.rs
+ |
+ | (@array [$($elems:expr,)*]) => {
+ | ^
+ = note: this error originates in the macro `json_internal` which comes from the expansion of the macro `json` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui/missing_comma.stderr b/tests/ui/missing_comma.stderr
index bd911d0..bafa0f8 100644
--- a/tests/ui/missing_comma.stderr
+++ b/tests/ui/missing_comma.stderr
@@ -5,3 +5,9 @@ error: no rules expected the token `"2"`
| -^^^ no rules expected this token in macro call
| |
| help: missing comma here
+ |
+note: while trying to match `,`
+ --> src/macros.rs
+ |
+ | ($e:expr , $($tt:tt)*) => {};
+ | ^
diff --git a/tests/ui/missing_value.stderr b/tests/ui/missing_value.stderr
index d538d96..9c9de99 100644
--- a/tests/ui/missing_value.stderr
+++ b/tests/ui/missing_value.stderr
@@ -4,4 +4,9 @@ error: unexpected end of macro invocation
4 | json!({ "a" : });
| ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
- = note: this error originates in the macro `json_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
+note: while trying to match `@`
+ --> src/macros.rs
+ |
+ | (@array [$($elems:expr,)*]) => {
+ | ^
+ = note: this error originates in the macro `json_internal` which comes from the expansion of the macro `json` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/tests/ui/parse_expr.stderr b/tests/ui/parse_expr.stderr
index 6959673..cd3e1c9 100644
--- a/tests/ui/parse_expr.stderr
+++ b/tests/ui/parse_expr.stderr
@@ -3,3 +3,9 @@ error: no rules expected the token `~`
|
4 | json!({ "a" : ~ });
| ^ no rules expected this token in macro call
+ |
+note: while trying to match meta-variable `$e:expr`
+ --> src/macros.rs
+ |
+ | ($e:expr , $($tt:tt)*) => {};
+ | ^^^^^^^
diff --git a/tests/ui/unexpected_after_array_element.stderr b/tests/ui/unexpected_after_array_element.stderr
index f745a21..ef449f7 100644
--- a/tests/ui/unexpected_after_array_element.stderr
+++ b/tests/ui/unexpected_after_array_element.stderr
@@ -3,3 +3,5 @@ error: no rules expected the token `=>`
|
4 | json!([ true => ]);
| ^^ no rules expected this token in macro call
+ |
+ = note: while trying to match end of macro
diff --git a/tests/ui/unexpected_after_map_entry.stderr b/tests/ui/unexpected_after_map_entry.stderr
index a18c9b4..c62d90b 100644
--- a/tests/ui/unexpected_after_map_entry.stderr
+++ b/tests/ui/unexpected_after_map_entry.stderr
@@ -3,3 +3,5 @@ error: no rules expected the token `=>`
|
4 | json!({ "k": true => });
| ^^ no rules expected this token in macro call
+ |
+ = note: while trying to match end of macro
diff --git a/tests/ui/unexpected_colon.stderr b/tests/ui/unexpected_colon.stderr
index ed038f6..7e47726 100644
--- a/tests/ui/unexpected_colon.stderr
+++ b/tests/ui/unexpected_colon.stderr
@@ -3,3 +3,5 @@ error: no rules expected the token `:`
|
4 | json!({ : true });
| ^ no rules expected this token in macro call
+ |
+ = note: while trying to match end of macro
diff --git a/tests/ui/unexpected_comma.stderr b/tests/ui/unexpected_comma.stderr
index a4309c4..552f399 100644
--- a/tests/ui/unexpected_comma.stderr
+++ b/tests/ui/unexpected_comma.stderr
@@ -3,3 +3,5 @@ error: no rules expected the token `,`
|
4 | json!({ "a" , "b": true });
| ^ no rules expected this token in macro call
+ |
+ = note: while trying to match end of macro