From e7d16580f5856ecb0c515c7cdcabd2c10ba91547 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Sun, 26 Jun 2016 15:11:48 +0200 Subject: Escape fewer Unicode codepoints in `Debug` impl of `str` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/ --- src/libcoretest/char.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/libcoretest') 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] -- cgit 1.4.1-3-g733a5