Skip to content

Commit

Permalink
Add tests with keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Jan 15, 2025
1 parent f1d3c92 commit d279435
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 2 deletions.
63 changes: 61 additions & 2 deletions tests/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,20 +1831,38 @@ mod generic {
r#thing: T,
}

#[derive(Debug)]
struct StructOneKeyword<T> {
r#struct: T,
}

#[derive(Debug)]
enum Enum<T> {
One { r#thing: T },
}

#[derive(Debug)]
enum EnumKeyword<T> {
One { r#struct: T },
}

#[test]
fn assert() {
assert_eq!(
format!("{:?}", StructOne::<u8> { r#thing: 8 }),
"StructOne { thing: 8 }"
"StructOne { thing: 8 }",
);
assert_eq!(
format!("{:?}", StructOneKeyword::<u8> { r#struct: 8 }),
"StructOneKeyword { struct: 8 }",
);
assert_eq!(
format!("{:?}", Enum::<u8>::One { r#thing: 8 }),
"One { thing: 8 }"
"One { thing: 8 }",
);
assert_eq!(
format!("{:?}", EnumKeyword::<u8>::One { r#struct: 8 }),
"One { struct: 8 }",
);
}

Expand All @@ -1860,37 +1878,78 @@ mod generic {
r#thing: T,
}

#[derive(Debug)]
#[debug("{struct}")]
struct StructOneKeyword<T> {
r#struct: T,
}

#[derive(Debug)]
enum Enum1<T> {
#[debug("{thing}")]
One { r#thing: T },
}

#[derive(Debug)]
enum Enum1Keyword<T> {
#[debug("{struct}")]
One { r#struct: T },
}

#[derive(Debug)]
#[debug("{a}:{b}")]
struct StructTwo<A, B> {
r#a: A,
b: B,
}

#[derive(Debug)]
#[debug("{pub}:{b}")]
struct StructTwoKeyword<A, B> {
r#pub: A,
b: B,
}

#[derive(Debug)]
enum Enum2<A, B> {
#[debug("{a}:{b}")]
Two { r#a: A, b: B },
}

#[derive(Debug)]
enum Enum2Keyword<A, B> {
#[debug("{pub}:{b}")]
Two { r#pub: A, b: B },
}

#[test]
fn assert() {
assert_eq!(format!("{:?}", StructOne::<u8> { r#thing: 8 }), "8");
assert_eq!(
format!("{:?}", StructOneKeyword::<u8> { r#struct: 8 }),
"8",
);
assert_eq!(format!("{:?}", Enum1::<u8>::One { r#thing: 8 }), "8");
assert_eq!(
format!("{:?}", Enum1Keyword::<u8>::One { r#struct: 8 }),
"8",
);
assert_eq!(
format!("{:?}", StructTwo::<u8, u16> { r#a: 8, b: 16 }),
"8:16",
);
assert_eq!(
format!("{:?}", StructTwoKeyword::<u8, u16> { r#pub: 8, b: 16 }),
"8:16",
);
assert_eq!(
format!("{:?}", Enum2::<u8, u16>::Two { r#a: 8, b: 16 }),
"8:16",
);
assert_eq!(
format!("{:?}", Enum2Keyword::<u8, u16>::Two { r#pub: 8, b: 16 }),
"8:16",
);
}
}
}
Expand Down
58 changes: 58 additions & 0 deletions tests/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,11 @@ mod generic {
r#thing: T,
}

#[derive(Display)]
struct StructOneKeyword<T> {
r#struct: T,
}

#[derive(Display)]
enum Enum<T> {
One { r#thing: T },
Expand All @@ -2033,6 +2038,7 @@ mod generic {
#[test]
fn assert() {
assert_eq!(StructOne::<u8> { r#thing: 8 }.to_string(), "8");
assert_eq!(StructOneKeyword::<u8> { r#struct: 8 }.to_string(), "8");
assert_eq!(Enum::<u8>::One { r#thing: 8 }.to_string(), "8");
}

Expand All @@ -2045,48 +2051,100 @@ mod generic {
r#thing: T,
}

#[derive(Display)]
#[display("{struct}")]
struct StructOneKeyword<T> {
r#struct: T,
}

#[derive(Display)]
enum Enum1<T> {
#[display("{thing}")]
One { r#thing: T },
}

#[derive(Display)]
enum Enum1Keyword<T> {
#[display("{struct}")]
One { r#struct: T },
}

#[derive(Display)]
#[display("{thing}")]
enum Enum1Top<T> {
One { r#thing: T },
}

#[derive(Display)]
#[display("{struct}")]
enum Enum1TopKeyword<T> {
One { r#struct: T },
}

#[derive(Display)]
#[display("{a}:{b}")]
struct StructTwo<A, B> {
r#a: A,
b: B,
}

#[derive(Display)]
#[display("{pub}:{b}")]
struct StructTwoKeyword<A, B> {
r#pub: A,
b: B,
}

#[derive(Display)]
enum Enum2<A, B> {
#[display("{a}:{b}")]
Two { r#a: A, b: B },
}

#[derive(Display)]
enum Enum2Keyword<A, B> {
#[display("{pub}:{b}")]
Two { r#pub: A, b: B },
}

#[derive(Display)]
#[display("{a}:{b}")]
enum Enum2Shared<A, B> {
Two { r#a: A, b: B },
}

#[derive(Display)]
#[display("{pub}:{b}")]
enum Enum2SharedKeyword<A, B> {
Two { r#pub: A, b: B },
}

#[test]
fn assert() {
assert_eq!(StructOne::<u8> { r#thing: 8 }.to_string(), "8");
assert_eq!(StructOneKeyword::<u8> { r#struct: 8 }.to_string(), "8");
assert_eq!(Enum1::<u8>::One { r#thing: 8 }.to_string(), "8");
assert_eq!(Enum1Keyword::<u8>::One { r#struct: 8 }.to_string(), "8");
assert_eq!(Enum1Top::<u8>::One { r#thing: 8 }.to_string(), "8");
assert_eq!(Enum1TopKeyword::<u8>::One { r#struct: 8 }.to_string(), "8");
assert_eq!(StructTwo::<u8, u16> { r#a: 8, b: 16 }.to_string(), "8:16");
assert_eq!(
StructTwoKeyword::<u8, u16> { r#pub: 8, b: 16 }.to_string(),
"8:16",
);
assert_eq!(Enum2::<u8, u16>::Two { r#a: 8, b: 16 }.to_string(), "8:16");
assert_eq!(
Enum2Keyword::<u8, u16>::Two { r#pub: 8, b: 16 }.to_string(),
"8:16",
);
assert_eq!(
Enum2Shared::<u8, u16>::Two { r#a: 8, b: 16 }.to_string(),
"8:16",
);
assert_eq!(
Enum2SharedKeyword::<u8, u16>::Two { r#pub: 8, b: 16 }.to_string(),
"8:16",
);
}
}
}
Expand Down

0 comments on commit d279435

Please sign in to comment.