Skip to content

Commit cfd83c0

Browse files
committed
review
1 parent 6f58228 commit cfd83c0

File tree

1 file changed

+10
-50
lines changed

1 file changed

+10
-50
lines changed

library/core/tests/ascii_char.rs

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,15 @@ fn test_display() {
1414

1515
/// Tests Debug implementation for ascii::Char.
1616
#[test]
17-
fn test_debug() {
18-
for (chr, want) in [
19-
// Control characters
20-
(Char::Null, r#"'\0'"#),
21-
(Char::StartOfHeading, r#"'\x01'"#),
22-
(Char::StartOfText, r#"'\x02'"#),
23-
(Char::EndOfText, r#"'\x03'"#),
24-
(Char::EndOfTransmission, r#"'\x04'"#),
25-
(Char::Enquiry, r#"'\x05'"#),
26-
(Char::Acknowledge, r#"'\x06'"#),
27-
(Char::Bell, r#"'\x07'"#),
28-
(Char::Backspace, r#"'\x08'"#),
29-
(Char::CharacterTabulation, r#"'\t'"#),
30-
(Char::LineFeed, r#"'\n'"#),
31-
(Char::LineTabulation, r#"'\x0b'"#),
32-
(Char::FormFeed, r#"'\x0c'"#),
33-
(Char::CarriageReturn, r#"'\r'"#),
34-
(Char::ShiftOut, r#"'\x0e'"#),
35-
(Char::ShiftIn, r#"'\x0f'"#),
36-
(Char::DataLinkEscape, r#"'\x10'"#),
37-
(Char::DeviceControlOne, r#"'\x11'"#),
38-
(Char::DeviceControlTwo, r#"'\x12'"#),
39-
(Char::DeviceControlThree, r#"'\x13'"#),
40-
(Char::DeviceControlFour, r#"'\x14'"#),
41-
(Char::NegativeAcknowledge, r#"'\x15'"#),
42-
(Char::SynchronousIdle, r#"'\x16'"#),
43-
(Char::EndOfTransmissionBlock, r#"'\x17'"#),
44-
(Char::Cancel, r#"'\x18'"#),
45-
(Char::EndOfMedium, r#"'\x19'"#),
46-
(Char::Substitute, r#"'\x1a'"#),
47-
(Char::Escape, r#"'\x1b'"#),
48-
(Char::InformationSeparatorFour, r#"'\x1c'"#),
49-
(Char::InformationSeparatorThree, r#"'\x1d'"#),
50-
(Char::InformationSeparatorTwo, r#"'\x1e'"#),
51-
(Char::InformationSeparatorOne, r#"'\x1f'"#),
52-
// U+007F is also a control character
53-
(Char::Delete, r#"'\x7f'"#),
54-
55-
// Characters which need escaping.
56-
(Char::ReverseSolidus, r#"'\\'"#),
57-
(Char::Apostrophe, r#"'\''"#),
58-
59-
// Regular, non-control characters, which don’t need any special
60-
// handling.
61-
(Char::Space, r#"' '"#),
62-
(Char::QuotationMark, r#"'"'"#),
63-
(Char::CapitalM, r#"'M'"#),
64-
(Char::Tilde, r#"'~'"#),
65-
] {
66-
assert_eq!(want, format!("{chr:?}"), "chr: {}", chr as u8);
17+
fn test_debug_control() {
18+
for byte in 0..128u8 {
19+
let mut want = format!("{:?}", byte as char);
20+
// `char` uses `'\u{#}'` representation where ascii::char uses `'\x##'`.
21+
// Transform former into the latter.
22+
if let Some(rest) = want.strip_prefix("'\\u{") {
23+
want = format!("'\\x{:0>2}'", rest.strip_suffix("}'").unwrap());
24+
}
25+
let chr = core::ascii::Char::from_u8(byte).unwrap();
26+
assert_eq!(want, format!("{chr:?}"), "byte: {byte}");
6727
}
6828
}

0 commit comments

Comments
 (0)