mirror of
https://github.com/serde-rs/json.git
synced 2025-10-05 08:45:34 +00:00

warning: variables can be used directly in the `format!` string --> src/ser.rs:448:15 | 448 | match write!(adapter, "{}", value) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: `-W clippy::uninlined-format-args` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::uninlined_format_args)]` help: change this to | 448 - match write!(adapter, "{}", value) { 448 + match write!(adapter, "{value}") { | warning: variables can be used directly in the `format!` string --> src/value/mod.rs:182:37 | 182 | Value::Bool(boolean) => write!(formatter, "Bool({})", boolean), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 182 - Value::Bool(boolean) => write!(formatter, "Bool({})", boolean), 182 + Value::Bool(boolean) => write!(formatter, "Bool({boolean})"), | warning: variables can be used directly in the `format!` string --> src/value/mod.rs:184:38 | 184 | Value::String(string) => write!(formatter, "String({:?})", string), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 184 - Value::String(string) => write!(formatter, "String({:?})", string), 184 + Value::String(string) => write!(formatter, "String({string:?})"), | warning: variables can be used directly in the `format!` string --> src/number.rs:365:9 | 365 | write!(formatter, "Number({})", self) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args help: change this to | 365 - write!(formatter, "Number({})", self) 365 + write!(formatter, "Number({self})") |
84 lines
2.0 KiB
Rust
84 lines
2.0 KiB
Rust
#![allow(clippy::uninlined_format_args)]
|
|
|
|
use indoc::indoc;
|
|
use serde_json::{json, Number, Value};
|
|
|
|
#[test]
|
|
fn number() {
|
|
assert_eq!(format!("{:?}", Number::from(1)), "Number(1)");
|
|
assert_eq!(format!("{:?}", Number::from(-1)), "Number(-1)");
|
|
assert_eq!(
|
|
format!("{:?}", Number::from_f64(1.0).unwrap()),
|
|
"Number(1.0)"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn value_null() {
|
|
assert_eq!(format!("{:?}", json!(null)), "Null");
|
|
}
|
|
|
|
#[test]
|
|
fn value_bool() {
|
|
assert_eq!(format!("{:?}", json!(true)), "Bool(true)");
|
|
assert_eq!(format!("{:?}", json!(false)), "Bool(false)");
|
|
}
|
|
|
|
#[test]
|
|
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]
|
|
fn value_string() {
|
|
assert_eq!(format!("{:?}", json!("s")), "String(\"s\")");
|
|
}
|
|
|
|
#[test]
|
|
fn value_array() {
|
|
assert_eq!(format!("{:?}", json!([])), "Array []");
|
|
}
|
|
|
|
#[test]
|
|
fn value_object() {
|
|
assert_eq!(format!("{:?}", json!({})), "Object {}");
|
|
}
|
|
|
|
#[test]
|
|
fn error() {
|
|
let err = serde_json::from_str::<Value>("{0}").unwrap_err();
|
|
let expected = "Error(\"key must be a string\", line: 1, column: 2)";
|
|
assert_eq!(format!("{:?}", err), expected);
|
|
}
|
|
|
|
#[test]
|
|
fn indented() {
|
|
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);
|
|
}
|