Make use of raw strings in core::fmt::builders
There are quite a few uses of escaped quotes. Turn these into raw strings within documentation and tests to make things easier to read.
This commit is contained in:
parent
5affbb1715
commit
68fb25e2eb
@ -78,7 +78,7 @@ fn write_char(&mut self, c: char) -> fmt::Result {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() }),
|
/// format!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() }),
|
||||||
/// "Foo { bar: 10, baz: \"Hello World\" }",
|
/// r#"Foo { bar: 10, baz: "Hello World" }"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "must eventually call `finish()` on Debug builders"]
|
#[must_use = "must eventually call `finish()` on Debug builders"]
|
||||||
@ -125,7 +125,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Bar { bar: 10, another: "Hello World".to_string() }),
|
/// format!("{:?}", Bar { bar: 10, another: "Hello World".to_string() }),
|
||||||
/// "Bar { bar: 10, another: \"Hello World\", nonexistent_field: 1 }",
|
/// r#"Bar { bar: 10, another: "Hello World", nonexistent_field: 1 }"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||||
@ -237,7 +237,7 @@ pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Bar { bar: 10, baz: "Hello World".to_string() }),
|
/// format!("{:?}", Bar { bar: 10, baz: "Hello World".to_string() }),
|
||||||
/// "Bar { bar: 10, baz: \"Hello World\" }",
|
/// r#"Bar { bar: 10, baz: "Hello World" }"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||||
@ -280,7 +280,7 @@ fn is_pretty(&self) -> bool {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(10, "Hello World".to_string())),
|
/// format!("{:?}", Foo(10, "Hello World".to_string())),
|
||||||
/// "Foo(10, \"Hello World\")",
|
/// r#"Foo(10, "Hello World")"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "must eventually call `finish()` on Debug builders"]
|
#[must_use = "must eventually call `finish()` on Debug builders"]
|
||||||
@ -322,7 +322,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(10, "Hello World".to_string())),
|
/// format!("{:?}", Foo(10, "Hello World".to_string())),
|
||||||
/// "Foo(10, \"Hello World\")",
|
/// r#"Foo(10, "Hello World")"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||||
@ -381,7 +381,7 @@ pub fn field_with<F>(&mut self, value_fmt: F) -> &mut Self
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(10, "Hello World".to_string())),
|
/// format!("{:?}", Foo(10, "Hello World".to_string())),
|
||||||
/// "Foo(10, \"Hello World\")",
|
/// r#"Foo(10, "Hello World")"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||||
@ -747,7 +747,7 @@ pub fn finish(&mut self) -> fmt::Result {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
||||||
/// "{\"A\": 10, \"B\": 11}",
|
/// r#"{"A": 10, "B": 11}"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "must eventually call `finish()` on Debug builders"]
|
#[must_use = "must eventually call `finish()` on Debug builders"]
|
||||||
@ -787,7 +787,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
||||||
/// "{\"whole\": [(\"A\", 10), (\"B\", 11)]}",
|
/// r#"{"whole": [("A", 10), ("B", 11)]}"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||||
@ -823,7 +823,7 @@ pub fn entry(&mut self, key: &dyn fmt::Debug, value: &dyn fmt::Debug) -> &mut Se
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
||||||
/// "{\"whole\": [(\"A\", 10), (\"B\", 11)]}",
|
/// r#"{"whole": [("A", 10), ("B", 11)]}"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_map_key_value", since = "1.42.0")]
|
#[stable(feature = "debug_map_key_value", since = "1.42.0")]
|
||||||
@ -899,7 +899,7 @@ pub fn key_with<F>(&mut self, key_fmt: F) -> &mut Self
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
||||||
/// "{\"whole\": [(\"A\", 10), (\"B\", 11)]}",
|
/// r#"{"whole": [("A", 10), ("B", 11)]}"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_map_key_value", since = "1.42.0")]
|
#[stable(feature = "debug_map_key_value", since = "1.42.0")]
|
||||||
@ -957,7 +957,7 @@ pub fn value_with<F>(&mut self, value_fmt: F) -> &mut Self
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
||||||
/// "{\"A\": 10, \"B\": 11}",
|
/// r#"{"A": 10, "B": 11}"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||||
@ -997,7 +997,7 @@ pub fn entries<K, V, I>(&mut self, entries: I) -> &mut Self
|
|||||||
///
|
///
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
|
||||||
/// "{\"A\": 10, \"B\": 11}",
|
/// r#"{"A": 10, "B": 11}"#,
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||||
|
@ -79,23 +79,23 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"Bar { foo: Foo { bar: true, baz: 10/20 }, hello: \"world\" }",
|
r#"Bar { foo: Foo { bar: true, baz: 10/20 }, hello: "world" }"#,
|
||||||
format!("{Bar:?}")
|
format!("{Bar:?}")
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"Bar {
|
r#"Bar {
|
||||||
foo: Foo {
|
foo: Foo {
|
||||||
bar: true,
|
bar: true,
|
||||||
baz: 10/20,
|
baz: 10/20,
|
||||||
},
|
},
|
||||||
hello: \"world\",
|
hello: "world",
|
||||||
}",
|
}"#,
|
||||||
format!("{Bar:#?}")
|
format!("{Bar:#?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_only_non_exhaustive() {
|
fn test_empty_non_exhaustive() {
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
||||||
impl fmt::Debug for Foo {
|
impl fmt::Debug for Foo {
|
||||||
@ -157,19 +157,19 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"Bar { foo: Foo { bar: true, baz: 10/20, .. }, hello: \"world\", .. }",
|
r#"Bar { foo: Foo { bar: true, baz: 10/20, .. }, hello: "world", .. }"#,
|
||||||
format!("{Bar:?}")
|
format!("{Bar:?}")
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"Bar {
|
r#"Bar {
|
||||||
foo: Foo {
|
foo: Foo {
|
||||||
bar: true,
|
bar: true,
|
||||||
baz: 10/20,
|
baz: 10/20,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
hello: \"world\",
|
hello: "world",
|
||||||
..
|
..
|
||||||
}",
|
}"#,
|
||||||
format!("{Bar:#?}")
|
format!("{Bar:#?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -249,15 +249,15 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!("Bar(Foo(true, 10/20), \"world\")", format!("{Bar:?}"));
|
assert_eq!(r#"Bar(Foo(true, 10/20), "world")"#, format!("{Bar:?}"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"Bar(
|
r#"Bar(
|
||||||
Foo(
|
Foo(
|
||||||
true,
|
true,
|
||||||
10/20,
|
10/20,
|
||||||
),
|
),
|
||||||
\"world\",
|
"world",
|
||||||
)",
|
)"#,
|
||||||
format!("{Bar:#?}")
|
format!("{Bar:#?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -301,11 +301,11 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
assert_eq!(format!("{Entry:?}"), format!("{KeyValue:?}"));
|
assert_eq!(format!("{Entry:?}"), format!("{KeyValue:?}"));
|
||||||
assert_eq!(format!("{Entry:#?}"), format!("{KeyValue:#?}"));
|
assert_eq!(format!("{Entry:#?}"), format!("{KeyValue:#?}"));
|
||||||
|
|
||||||
assert_eq!("{\"bar\": true}", format!("{Entry:?}"));
|
assert_eq!(r#"{"bar": true}"#, format!("{Entry:?}"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"{
|
r#"{
|
||||||
\"bar\": true,
|
"bar": true,
|
||||||
}",
|
}"#,
|
||||||
format!("{Entry:#?}")
|
format!("{Entry:#?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -339,12 +339,12 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
assert_eq!(format!("{Entry:?}"), format!("{KeyValue:?}"));
|
assert_eq!(format!("{Entry:?}"), format!("{KeyValue:?}"));
|
||||||
assert_eq!(format!("{Entry:#?}"), format!("{KeyValue:#?}"));
|
assert_eq!(format!("{Entry:#?}"), format!("{KeyValue:#?}"));
|
||||||
|
|
||||||
assert_eq!("{\"bar\": true, 10: 10/20}", format!("{Entry:?}"));
|
assert_eq!(r#"{"bar": true, 10: 10/20}"#, format!("{Entry:?}"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"{
|
r#"{
|
||||||
\"bar\": true,
|
"bar": true,
|
||||||
10: 10/20,
|
10: 10/20,
|
||||||
}",
|
}"#,
|
||||||
format!("{Entry:#?}")
|
format!("{Entry:#?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -371,21 +371,21 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"{\"foo\": {\"bar\": true, 10: 10/20}, \
|
r#"{"foo": {"bar": true, 10: 10/20}, \
|
||||||
{\"bar\": true, 10: 10/20}: \"world\"}",
|
{"bar": true, 10: 10/20}: "world"}"#,
|
||||||
format!("{Bar:?}")
|
format!("{Bar:?}")
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"{
|
r#"{
|
||||||
\"foo\": {
|
"foo": {
|
||||||
\"bar\": true,
|
"bar": true,
|
||||||
10: 10/20,
|
10: 10/20,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
\"bar\": true,
|
"bar": true,
|
||||||
10: 10/20,
|
10: 10/20,
|
||||||
}: \"world\",
|
}: "world",
|
||||||
}",
|
}"#,
|
||||||
format!("{Bar:#?}")
|
format!("{Bar:#?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -547,15 +547,15 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!("{{true, 10/20}, \"world\"}", format!("{Bar:?}"));
|
assert_eq!(r#"{{true, 10/20}, "world"}"#, format!("{Bar:?}"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"{
|
r#"{
|
||||||
{
|
{
|
||||||
true,
|
true,
|
||||||
10/20,
|
10/20,
|
||||||
},
|
},
|
||||||
\"world\",
|
"world",
|
||||||
}",
|
}"#,
|
||||||
format!("{Bar:#?}")
|
format!("{Bar:#?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -635,15 +635,15 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!("[[true, 10/20], \"world\"]", format!("{Bar:?}"));
|
assert_eq!(r#"[[true, 10/20], "world"]"#, format!("{Bar:?}"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"[
|
r#"[
|
||||||
[
|
[
|
||||||
true,
|
true,
|
||||||
10/20,
|
10/20,
|
||||||
],
|
],
|
||||||
\"world\",
|
"world",
|
||||||
]",
|
]"#,
|
||||||
format!("{Bar:#?}")
|
format!("{Bar:#?}")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user