about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Poveda <christian.poveda@ferrous-systems.com>2025-09-12 11:22:07 -0500
committerChristian Poveda <christian.poveda@ferrous-systems.com>2025-09-12 11:22:07 -0500
commit51e3b6238d66fb9f70f2750fed3a6ee2f610ce9d (patch)
treedfc412e130db8b8062debfa993feb7336880fa9e
parent408eacfb95ea19e248c0fe5e377980bc00682c1b (diff)
downloadrust-51e3b6238d66fb9f70f2750fed3a6ee2f610ce9d.tar.gz
rust-51e3b6238d66fb9f70f2750fed3a6ee2f610ce9d.zip
Improve `core::char` coverage
-rw-r--r--library/coretests/tests/char.rs43
-rw-r--r--library/coretests/tests/lib.rs1
2 files changed, 44 insertions, 0 deletions
diff --git a/library/coretests/tests/char.rs b/library/coretests/tests/char.rs
index 852f073bae1..6f94065b2d9 100644
--- a/library/coretests/tests/char.rs
+++ b/library/coretests/tests/char.rs
@@ -220,6 +220,7 @@ fn test_escape_default() {
     }
     assert_eq!(string('\n'), "\\n");
     assert_eq!(string('\r'), "\\r");
+    assert_eq!(string('\t'), "\\t");
     assert_eq!(string('\''), "\\'");
     assert_eq!(string('"'), "\\\"");
     assert_eq!(string(' '), " ");
@@ -417,3 +418,45 @@ fn eu_iterator_specializations() {
     check('\u{12340}');
     check('\u{10FFFF}');
 }
+
+#[test]
+#[should_panic]
+fn test_from_digit_radix_too_high() {
+    let _ = char::from_digit(0, 37);
+}
+
+#[test]
+fn test_from_digit_invalid_radix() {
+    assert!(char::from_digit(10, 9).is_none());
+}
+
+#[test]
+#[should_panic]
+fn test_to_digit_radix_too_low() {
+    let _ = 'a'.to_digit(1);
+}
+
+#[test]
+#[should_panic]
+fn test_to_digit_radix_too_high() {
+    let _ = 'a'.to_digit(37);
+}
+
+#[test]
+fn test_as_ascii_invalid() {
+    assert!('❤'.as_ascii().is_none());
+}
+
+#[test]
+#[should_panic]
+fn test_encode_utf8_raw_buffer_too_small() {
+    let mut buf = [0u8; 1];
+    let _ = char::encode_utf8_raw('ß'.into(), &mut buf);
+}
+
+#[test]
+#[should_panic]
+fn test_encode_utf16_raw_buffer_too_small() {
+    let mut buf = [0u16; 1];
+    let _ = char::encode_utf16_raw('𐐷'.into(), &mut buf);
+}
diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs
index 1bdaa6965f6..3b5334391ac 100644
--- a/library/coretests/tests/lib.rs
+++ b/library/coretests/tests/lib.rs
@@ -13,6 +13,7 @@
 #![feature(bool_to_result)]
 #![feature(bstr)]
 #![feature(cfg_target_has_reliable_f16_f128)]
+#![feature(char_internals)]
 #![feature(char_max_len)]
 #![feature(clone_to_uninit)]
 #![feature(const_convert)]