Skip to content

Commit

Permalink
Showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron authored and JelteF committed Jul 20, 2024
1 parent e307908 commit b6ef1a3
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 32 deletions.
67 changes: 65 additions & 2 deletions tests/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod structs {
assert_eq!(format!("{:03?}", UpperHex), "00B");
assert_eq!(format!("{:07?}", LowerExp), "03.15e0");
assert_eq!(format!("{:07?}", UpperExp), "03.15E0");
assert_eq!(format!("{:018?}", Pointer).len(), 18);
assert_eq!(format!("{:018?}", Pointer), format!("{POINTER:018p}"));
}

mod omitted {
Expand Down Expand Up @@ -246,6 +246,35 @@ mod structs {
"Struct {\n field: 0.0,\n}",
);
}

mod pointer {
#[cfg(not(feature = "std"))]
use alloc::format;

use derive_more::Debug;

#[derive(Debug)]
struct Tuple<'a>(#[debug("{_0:p}.{:p}", self.0)] &'a i32);

#[derive(Debug)]
struct Struct<'a> {
#[debug("{field:p}.{:p}", self.field)]
field: &'a i32,
}

#[test]
fn assert() {
let a = 42;
assert_eq!(
format!("{:?}", Tuple(&a)),
format!("Tuple({0:p}.{0:p})", &a),
);
assert_eq!(
format!("{:?}", Struct { field: &a }),
format!("Struct {{ field: {0:p}.{0:p} }}", &a),
);
}
}
}

mod ignore {
Expand Down Expand Up @@ -527,6 +556,37 @@ mod structs {
assert_eq!(format!("{:?}", Tuple(10, true)), "10 * true");
assert_eq!(format!("{:?}", Struct { a: 10, b: true }), "10 * true");
}

mod pointer {
#[cfg(not(feature = "std"))]
use alloc::format;

use derive_more::Debug;

#[derive(Debug)]
#[debug("{_0:p} * {_1:p}", _0 = self.0)]
struct Tuple<'a, 'b>(&'a u8, &'b bool);

#[derive(Debug)]
#[debug("{a:p} * {b:p}", a = self.a)]
struct Struct<'a, 'b> {
a: &'a u8,
b: &'b bool,
}

#[test]
fn assert() {
let (a, b) = (10, true);
assert_eq!(
format!("{:?}", Tuple(&a, &b)),
format!("{:p} * {:p}", &a, &b),
);
assert_eq!(
format!("{:?}", Struct { a: &a, b: &b }),
format!("{:p} * {:p}", &a, &b),
);
}
}
}

mod ignore {
Expand Down Expand Up @@ -677,7 +737,10 @@ mod enums {
assert_eq!(format!("{:03?}", Unit::UpperHex), "00B");
assert_eq!(format!("{:07?}", Unit::LowerExp), "03.15e0");
assert_eq!(format!("{:07?}", Unit::UpperExp), "03.15E0");
assert_eq!(format!("{:018?}", Unit::Pointer).len(), 18);
assert_eq!(
format!("{:018?}", Unit::Pointer),
format!("{POINTER:018p}"),
);
}

mod omitted {
Expand Down
103 changes: 73 additions & 30 deletions tests/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod structs {
assert_eq!(format!("{:03}", UpperHex), "00B");
assert_eq!(format!("{:07}", LowerExp), "03.15e0");
assert_eq!(format!("{:07}", UpperExp), "03.15E0");
assert_eq!(format!("{:018}", Pointer).len(), 18);
assert_eq!(format!("{:018}", Pointer), format!("{POINTER:018p}"));
}
}

Expand Down Expand Up @@ -318,9 +318,10 @@ mod structs {
format!("{:07E}", StructUpperExp { field: 42.0 }),
"004.2E1",
);
let a = 42;
assert_eq!(
format!("{:018p}", StructPointer { field: &42 }).len(),
18,
format!("{:018p}", StructPointer { field: &a }),
format!("{:018p}", &a),
);
}
}
Expand Down Expand Up @@ -390,9 +391,10 @@ mod structs {
format!("{:07}", StructUpperExp { field: 42.0 }),
"004.2E1",
);
let a = 42;
assert_eq!(
format!("{:018}", StructPointer { field: &42 }).len(),
18,
format!("{:018}", StructPointer { field: &a }),
format!("{:018p}", &a),
);
}
}
Expand Down Expand Up @@ -462,9 +464,10 @@ mod structs {
format!("{:07}", StructUpperExp { field: 42.0 }),
"4.2E1",
);
assert_ne!(
format!("{:018}", StructPointer { field: &42 }).len(),
18,
let a = 42;
assert_eq!(
format!("{:018}", StructPointer { field: &a }),
format!("{:p}", &a),
);
}
}
Expand Down Expand Up @@ -667,9 +670,10 @@ mod structs {
format!("{:07}", StructUpperExp { a: 41.0, b: 42.0 }),
"004.2E1",
);
let (a, b) = (42, 43);
assert_eq!(
format!("{:018}", StructPointer { a: &42, b: &43 }).len(),
18,
format!("{:018}", StructPointer { a: &a, b: &b }),
format!("{:018p}", &b),
);
}
}
Expand Down Expand Up @@ -758,7 +762,10 @@ mod enums {
assert_eq!(format!("{:03}", Unit::UpperHex), "00B");
assert_eq!(format!("{:07}", Unit::LowerExp), "03.15e0");
assert_eq!(format!("{:07}", Unit::UpperExp), "03.15E0");
assert_eq!(format!("{:018}", Unit::Pointer).len(), 18);
assert_eq!(
format!("{:018}", Unit::Pointer),
format!("{POINTER:018p}"),
);
}
}

Expand Down Expand Up @@ -916,8 +923,15 @@ mod enums {
format!("{:07E}", UpperExp::B { field: 43.0 }),
"004.3E1",
);
assert_eq!(format!("{:018p}", Pointer::A(&7)).len(), 18);
assert_eq!(format!("{:018p}", Pointer::B { field: &42 }).len(), 18);
let (a, b) = (7, 42);
assert_eq!(
format!("{:018p}", Pointer::A(&a)),
format!("{:018p}", &a),
);
assert_eq!(
format!("{:018p}", Pointer::B { field: &b }),
format!("{:018p}", &b),
);
}
}

Expand Down Expand Up @@ -1020,8 +1034,15 @@ mod enums {
format!("{:07}", UpperExp::B { field: 43.0 }),
"004.3E1",
);
assert_eq!(format!("{:018}", Pointer::A(&7)).len(), 18);
assert_eq!(format!("{:018}", Pointer::B { field: &42 }).len(), 18);
let (a, b) = (7, 42);
assert_eq!(
format!("{:018}", Pointer::A(&a)),
format!("{:018p}", &a),
);
assert_eq!(
format!("{:018}", Pointer::B { field: &b }),
format!("{:018p}", &b),
);
}
}

Expand Down Expand Up @@ -1118,8 +1139,12 @@ mod enums {
assert_eq!(format!("{:07}", LowerExp::B { field: 43.0 }), "4.3e1");
assert_eq!(format!("{:07}", UpperExp::A(42.0)), "4.2E1");
assert_eq!(format!("{:07}", UpperExp::B { field: 43.0 }), "4.3E1");
assert_ne!(format!("{:018}", Pointer::A(&7)).len(), 18);
assert_ne!(format!("{:018}", Pointer::B { field: &42 }).len(), 18);
let (a, b) = (7, 42);
assert_eq!(format!("{:018}", Pointer::A(&a)), format!("{:0p}", &a));
assert_eq!(
format!("{:018}", Pointer::B { field: &b }),
format!("{:p}", &b),
);
}
}
}
Expand Down Expand Up @@ -1270,10 +1295,14 @@ mod enums {
format!("{:07}", UpperExp::B { a: 43.0, b: 52.0 }),
"004.3E1",
);
assert_eq!(format!("{:018}", Pointer::A(&7.0, &8.3)).len(), 18);
let (a, b) = (8.3, 42.1);
assert_eq!(
format!("{:018}", Pointer::A(&7.0, &a)),
format!("{:018p}", &a),
);
assert_eq!(
format!("{:018}", Pointer::B { a: &42.1, b: &43.3 }).len(),
18,
format!("{:018}", Pointer::B { a: &b, b: &43.3 }),
format!("{:018p}", &b),
);
}
}
Expand Down Expand Up @@ -1989,12 +2018,19 @@ mod generic {
format!("{:07E}", Enum::<i8, _>::B { field: 43.0 }),
"004.3E1",
);
assert_eq!(format!("{:018p}", Tuple(&42)).len(), 18);
assert_eq!(format!("{:018p}", Struct { field: &42 }).len(), 18);
assert_eq!(format!("{:018p}", Enum::<_, &i8>::A(&7)).len(), 18);
let (a, b) = (42, 7);
assert_eq!(format!("{:018p}", Tuple(&a)), format!("{:018p}", &a));
assert_eq!(
format!("{:018p}", Enum::<&i8, _>::B { field: &42 }).len(),
18,
format!("{:018p}", Struct { field: &a }),
format!("{:018p}", &a),
);
assert_eq!(
format!("{:018p}", Enum::<_, &i8>::A(&b)),
format!("{:018p}", &b),
);
assert_eq!(
format!("{:018p}", Enum::<&i8, _>::B { field: &a }),
format!("{:018p}", &a),
);
}
}
Expand Down Expand Up @@ -2210,12 +2246,19 @@ mod generic {
format!("{:07}", EnumUpperExp::<i8, _>::B { field: 43.0 }),
"004.3E1",
);
assert_eq!(format!("{:018}", TuplePointer(&42)).len(), 18);
assert_eq!(format!("{:018}", StructPointer { field: &42 }).len(), 18);
assert_eq!(format!("{:018}", EnumPointer::<_, &i8>::A(&7)).len(), 18);
let (a, b) = (42, 7);
assert_eq!(format!("{:018}", TuplePointer(&a)), format!("{:018p}", &a));
assert_eq!(
format!("{:018}", StructPointer { field: &a }),
format!("{:018p}", &a),
);
assert_eq!(
format!("{:018}", EnumPointer::<_, &i8>::A(&b)),
format!("{:018p}", &b),
);
assert_eq!(
format!("{:018}", EnumPointer::<&i8, _>::B { field: &42 }).len(),
18,
format!("{:018}", EnumPointer::<&i8, _>::B { field: &a }),
format!("{:018p}", &a),
);
}
}
Expand Down

0 comments on commit b6ef1a3

Please sign in to comment.