Skip to content

Commit

Permalink
Add a test to check that LabelledGeneric works with keyword fields (#238
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 authored Nov 9, 2024
1 parent f413e1d commit ffba8cf
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);
}

1 comment on commit ffba8cf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Frunk Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: ffba8cf Previous: f413e1d Ratio
hlist_into_hlist_pat_match 1.55 ns/iter (± 0.01) 0.77 ns/iter (± 0.00) 2.01
hlist_into_tuple2_match 1.55 ns/iter (± 0.01) 0.77 ns/iter (± 0.00) 2.01

This comment was automatically generated by workflow using github-action-benchmark.

CC: @lloydmeta

Please sign in to comment.