Skip to content

Commit

Permalink
Add a test to check that LabelledGeneric works with keyword fields
Browse files Browse the repository at this point in the history
Checks that derives works and transmogrifying works.

Signed-off-by: lloydmeta <[email protected]>
  • Loading branch information
lloydmeta committed Nov 9, 2024
1 parent f413e1d commit 68397c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ pub struct SuperLongField {
pub abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789: i32,
}

#[derive(LabelledGeneric)]
pub struct HasKeyword1 {
pub r#type: i32,
}

#[derive(LabelledGeneric)]
pub struct HasKeyword2 {
pub r#type: i32,
}

#[derive(LabelledGeneric)]
pub struct HasKeyword1Embedder {
pub r#true: HasKeyword1,
}

#[derive(LabelledGeneric)]
pub struct HasKeyword2Embedder {
pub r#true: HasKeyword2,
}

#[derive(Generic, Debug, PartialEq, Eq)]
pub struct TupleStruct<'a>(pub &'a str, pub i32);

Expand Down
17 changes: 17 additions & 0 deletions tests/labelled_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,20 @@ fn test_sculpt_enum() {
}
);
}

#[test]
fn test_transmogrify_keyword_field_structs() {
let value = HasKeyword1 { r#type: 3 };
let result: HasKeyword2 = value.transmogrify();
assert_eq!(3, result.r#type);
}

#[test]
fn test_transmogrify_keyword_field_embedder_structs() {
let value = {
let embedded = HasKeyword1 { r#type: 3 };
HasKeyword1Embedder { r#true: embedded }
};
let result: HasKeyword2Embedder = value.transmogrify();
assert_eq!(3, result.r#true.r#type);
}

0 comments on commit 68397c7

Please sign in to comment.