diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2016-06-26 15:11:48 +0200 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2016-07-23 00:18:44 +0200 |
| commit | e7d16580f5856ecb0c515c7cdcabd2c10ba91547 (patch) | |
| tree | 68359f4a107dc3d3c2fbc21d17e4ad006688f4c5 /src/libcoretest | |
| parent | ad264f7f39b6113fb87a489d72d31abbc03ab148 (diff) | |
| download | rust-e7d16580f5856ecb0c515c7cdcabd2c10ba91547.tar.gz rust-e7d16580f5856ecb0c515c7cdcabd2c10ba91547.zip | |
Escape fewer Unicode codepoints in `Debug` impl of `str`
Use the same procedure as Python to determine whether a character is
printable, described in [PEP 3138]. In particular, this means that the
following character classes are escaped:
- Cc (Other, Control)
- Cf (Other, Format)
- Cs (Other, Surrogate), even though they can't appear in Rust strings
- Co (Other, Private Use)
- Cn (Other, Not Assigned)
- Zl (Separator, Line)
- Zp (Separator, Paragraph)
- Zs (Separator, Space), except for the ASCII space `' '` (`0x20`)
This allows for user-friendly inspection of strings that are not
English (e.g. compare `"\u{e9}\u{e8}\u{ea}"` to `"éèê"`).
Fixes #34318.
[PEP 3138]: https://www.python.org/dev/peps/pep-3138/
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/char.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index c8906fed3d2..e01f83ed70a 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -142,18 +142,28 @@ fn test_escape_default() { assert_eq!(s, "a"); let s = string('~'); assert_eq!(s, "~"); + let s = string('é'); + assert_eq!(s, "é"); let s = string('\x00'); assert_eq!(s, "\\u{0}"); let s = string('\x1f'); assert_eq!(s, "\\u{1f}"); let s = string('\x7f'); assert_eq!(s, "\\u{7f}"); + let s = string('\u{80}'); + assert_eq!(s, "\\u{80}"); let s = string('\u{ff}'); - assert_eq!(s, "\\u{ff}"); + assert_eq!(s, "\u{ff}"); let s = string('\u{11b}'); - assert_eq!(s, "\\u{11b}"); + assert_eq!(s, "\u{11b}"); let s = string('\u{1d4b6}'); - assert_eq!(s, "\\u{1d4b6}"); + assert_eq!(s, "\u{1d4b6}"); + let s = string('\u{200b}'); // zero width space + assert_eq!(s, "\\u{200b}"); + let s = string('\u{e000}'); // private use 1 + assert_eq!(s, "\\u{e000}"); + let s = string('\u{100000}'); // private use 2 + assert_eq!(s, "\\u{100000}"); } #[test] |
