Skip to content

Commit f13a1d7

Browse files
authored
Unrolled build for #146477
Rollup merge of #146477 - ferrocene:pvdrz/improve-char-coverage, r=Noratrieb Improve `core::char` coverage This PR improves the `core::char` coverage by adding new tests to `coretests` r? ``@workingjubilee``
2 parents 4ba1cf9 + 51e3b62 commit f13a1d7

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

library/coretests/tests/char.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ fn test_escape_default() {
220220
}
221221
assert_eq!(string('\n'), "\\n");
222222
assert_eq!(string('\r'), "\\r");
223+
assert_eq!(string('\t'), "\\t");
223224
assert_eq!(string('\''), "\\'");
224225
assert_eq!(string('"'), "\\\"");
225226
assert_eq!(string(' '), " ");
@@ -417,3 +418,45 @@ fn eu_iterator_specializations() {
417418
check('\u{12340}');
418419
check('\u{10FFFF}');
419420
}
421+
422+
#[test]
423+
#[should_panic]
424+
fn test_from_digit_radix_too_high() {
425+
let _ = char::from_digit(0, 37);
426+
}
427+
428+
#[test]
429+
fn test_from_digit_invalid_radix() {
430+
assert!(char::from_digit(10, 9).is_none());
431+
}
432+
433+
#[test]
434+
#[should_panic]
435+
fn test_to_digit_radix_too_low() {
436+
let _ = 'a'.to_digit(1);
437+
}
438+
439+
#[test]
440+
#[should_panic]
441+
fn test_to_digit_radix_too_high() {
442+
let _ = 'a'.to_digit(37);
443+
}
444+
445+
#[test]
446+
fn test_as_ascii_invalid() {
447+
assert!('❤'.as_ascii().is_none());
448+
}
449+
450+
#[test]
451+
#[should_panic]
452+
fn test_encode_utf8_raw_buffer_too_small() {
453+
let mut buf = [0u8; 1];
454+
let _ = char::encode_utf8_raw('ß'.into(), &mut buf);
455+
}
456+
457+
#[test]
458+
#[should_panic]
459+
fn test_encode_utf16_raw_buffer_too_small() {
460+
let mut buf = [0u16; 1];
461+
let _ = char::encode_utf16_raw('𐐷'.into(), &mut buf);
462+
}

library/coretests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(bool_to_result)]
1414
#![feature(bstr)]
1515
#![feature(cfg_target_has_reliable_f16_f128)]
16+
#![feature(char_internals)]
1617
#![feature(char_max_len)]
1718
#![feature(clone_to_uninit)]
1819
#![feature(const_cmp)]

0 commit comments

Comments
 (0)