mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
tests: Add regression test for Debug impl of raw pointers
This commit is contained in:
@@ -79,6 +79,7 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"rand_xorshift",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -297,6 +298,31 @@ dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||
dependencies = [
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.24"
|
||||
|
||||
@@ -25,3 +25,4 @@ test = true
|
||||
[dev-dependencies]
|
||||
rand = { version = "0.9.0", default-features = false }
|
||||
rand_xorshift = { version = "0.4.0", default-features = false }
|
||||
regex = { version = "1.11.1", default-features = false }
|
||||
|
||||
@@ -19,6 +19,37 @@ fn test_pointer_formats_data_pointer() {
|
||||
assert_eq!(format!("{b:p}"), format!("{:p}", b as *const _));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fmt_debug_of_raw_pointers() {
|
||||
use core::fmt::Debug;
|
||||
|
||||
fn check_fmt<T: Debug>(t: T, expected: &str) {
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
static ADDR_REGEX: LazyLock<Regex> =
|
||||
LazyLock::new(|| Regex::new(r"0x[0-9a-fA-F]+").unwrap());
|
||||
|
||||
let formatted = format!("{:?}", t);
|
||||
let normalized = ADDR_REGEX.replace_all(&formatted, "$$HEX");
|
||||
|
||||
assert_eq!(normalized, expected);
|
||||
}
|
||||
|
||||
let plain = &mut 100;
|
||||
check_fmt(plain as *mut i32, "$HEX");
|
||||
check_fmt(plain as *const i32, "$HEX");
|
||||
|
||||
let slice = &mut [200, 300, 400][..];
|
||||
check_fmt(slice as *mut [i32], "$HEX");
|
||||
check_fmt(slice as *const [i32], "$HEX");
|
||||
|
||||
let vtable = &mut 500 as &mut dyn Debug;
|
||||
check_fmt(vtable as *mut dyn Debug, "$HEX");
|
||||
check_fmt(vtable as *const dyn Debug, "$HEX");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_estimated_capacity() {
|
||||
assert_eq!(format_args!("").estimated_capacity(), 0);
|
||||
|
||||
Reference in New Issue
Block a user