Skip to content

Commit

Permalink
Make use of raw strings in core::fmt::builders
Browse files Browse the repository at this point in the history
There are quite a few uses of escaped quotes. Turn these into raw
strings within documentation and tests to make things easier to read.
  • Loading branch information
tgross35 committed Jul 21, 2024
1 parent d1d9893 commit b405024
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
24 changes: 12 additions & 12 deletions core/src/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl fmt::Write for PadAdapter<'_, '_> {
///
/// assert_eq!(
/// 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"]
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
///
/// assert_eq!(
/// 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")]
Expand Down Expand Up @@ -237,7 +237,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
///
/// assert_eq!(
/// 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")]
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
///
/// assert_eq!(
/// 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"]
Expand Down Expand Up @@ -322,7 +322,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
///
/// assert_eq!(
/// format!("{:?}", Foo(10, "Hello World".to_string())),
/// "Foo(10, \"Hello World\")",
/// r#"Foo(10, "Hello World")"#,
/// );
/// ```
#[stable(feature = "debug_builders", since = "1.2.0")]
Expand Down Expand Up @@ -381,7 +381,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
///
/// assert_eq!(
/// format!("{:?}", Foo(10, "Hello World".to_string())),
/// "Foo(10, \"Hello World\")",
/// r#"Foo(10, "Hello World")"#,
/// );
/// ```
#[stable(feature = "debug_builders", since = "1.2.0")]
Expand Down Expand Up @@ -747,7 +747,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {
///
/// assert_eq!(
/// 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"]
Expand Down Expand Up @@ -787,7 +787,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
///
/// assert_eq!(
/// 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")]
Expand Down Expand Up @@ -823,7 +823,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
///
/// assert_eq!(
/// 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")]
Expand Down Expand Up @@ -899,7 +899,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
///
/// assert_eq!(
/// 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")]
Expand Down Expand Up @@ -957,7 +957,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
///
/// assert_eq!(
/// 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")]
Expand Down Expand Up @@ -997,7 +997,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
///
/// assert_eq!(
/// 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")]
Expand Down
74 changes: 37 additions & 37 deletions core/tests/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,23 @@ mod debug_struct {
}

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:?}")
);
assert_eq!(
"Bar {
r#"Bar {
foo: Foo {
bar: true,
baz: 10/20,
},
hello: \"world\",
}",
hello: "world",
}"#,
format!("{Bar:#?}")
);
}

#[test]
fn test_only_non_exhaustive() {
fn test_empty_non_exhaustive() {
struct Foo;

impl fmt::Debug for Foo {
Expand Down Expand Up @@ -157,19 +157,19 @@ mod debug_struct {
}

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:?}")
);
assert_eq!(
"Bar {
r#"Bar {
foo: Foo {
bar: true,
baz: 10/20,
..
},
hello: \"world\",
hello: "world",
..
}",
}"#,
format!("{Bar:#?}")
);
}
Expand Down Expand Up @@ -249,15 +249,15 @@ mod debug_tuple {
}
}

assert_eq!("Bar(Foo(true, 10/20), \"world\")", format!("{Bar:?}"));
assert_eq!(r#"Bar(Foo(true, 10/20), "world")"#, format!("{Bar:?}"));
assert_eq!(
"Bar(
r#"Bar(
Foo(
true,
10/20,
),
\"world\",
)",
"world",
)"#,
format!("{Bar:#?}")
);
}
Expand Down Expand Up @@ -301,11 +301,11 @@ mod debug_map {
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!(
"{
\"bar\": true,
}",
r#"{
"bar": true,
}"#,
format!("{Entry:#?}")
);
}
Expand Down Expand Up @@ -339,12 +339,12 @@ mod debug_map {
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!(
"{
\"bar\": true,
r#"{
"bar": true,
10: 10/20,
}",
}"#,
format!("{Entry:#?}")
);
}
Expand All @@ -371,21 +371,21 @@ mod debug_map {
}

assert_eq!(
"{\"foo\": {\"bar\": true, 10: 10/20}, \
{\"bar\": true, 10: 10/20}: \"world\"}",
r#"{"foo": {"bar": true, 10: 10/20}, \
{"bar": true, 10: 10/20}: "world"}"#,
format!("{Bar:?}")
);
assert_eq!(
"{
\"foo\": {
\"bar\": true,
r#"{
"foo": {
"bar": true,
10: 10/20,
},
{
\"bar\": true,
"bar": true,
10: 10/20,
}: \"world\",
}",
}: "world",
}"#,
format!("{Bar:#?}")
);
}
Expand Down Expand Up @@ -547,15 +547,15 @@ mod debug_set {
}
}

assert_eq!("{{true, 10/20}, \"world\"}", format!("{Bar:?}"));
assert_eq!(r#"{{true, 10/20}, "world"}"#, format!("{Bar:?}"));
assert_eq!(
"{
r#"{
{
true,
10/20,
},
\"world\",
}",
"world",
}"#,
format!("{Bar:#?}")
);
}
Expand Down Expand Up @@ -635,15 +635,15 @@ mod debug_list {
}
}

assert_eq!("[[true, 10/20], \"world\"]", format!("{Bar:?}"));
assert_eq!(r#"[[true, 10/20], "world"]"#, format!("{Bar:?}"));
assert_eq!(
"[
r#"[
[
true,
10/20,
],
\"world\",
]",
"world",
]"#,
format!("{Bar:#?}")
);
}
Expand Down

0 comments on commit b405024

Please sign in to comment.