Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate and add new tests of internally tagged enums #2788

Merged
merged 22 commits into from
Aug 15, 2024

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented Aug 6, 2024

The goal of this PR is to improve test coverage by testing corner cases that could be break during refactorings and implementing optimizations.

This PR moves all tests for internally tagged enums (those which is defined using #[serde(tag = "tag")] attribute) into a dedicated file, removes duplicated tests and organize tests in a logical manner.

This PR does not add tests which is failed without changes in serde_text or in serde (they are left in #2569). So only refactoring of existing tests and a new tests that already passes.

Mingun and others added 22 commits August 15, 2024 23:33
(review this commit with "ignore whitespace changes" option on)
…ed module

Moved:
- test_internally_tagged_enum_with_untagged_variant             => untagged_variant
- test_internally_tagged_bytes                                  => string_and_bytes mod
- test_internally_tagged_struct_variant_containing_unit_variant => struct_variant_containing_unit_variant
- test_internally_tagged_borrow                                 => borrow
- test_enum_in_internally_tagged_enum                           => newtype_variant_containing_externally_tagged_enum
- test_internally_tagged_newtype_variant_containing_unit_struct => newtype_variant_containing_unit_struct

(review this commit with "ignore whitespace changes" option on)
Moved all except flattened tests:
- test_internally_tagged_enum_with_skipped_conflict    => with_skipped_conflict
- test_internally_tagged_enum_new_type_with_unit       => newtype_variant_containing_unit
- test_internally_tagged_unit_enum_with_unknown_fields => unit_variant_with_unknown_fields
- test_expecting_message_internally_tagged_enum        => expecting_message
- flatten::enum_::internally_tagged::straightforward   => containing_flatten
- newtype_variant_containing_unit                   -> newtype_unit
- newtype_variant_containing_unit_struct            -> newtype_unit_struct
- newtype_variant_containing_externally_tagged_enum -> newtype_enum
- struct_variant_containing_unit_variant            -> struct_enum
Separate testing each variant kind of enum (unit, newtype, tuple, struct) results
in more specific information if that checks fail

(review this commit with "ignore whitespace changes" option on)
Special case is the tag field first (so the enum variant are known after reading the first entry from map).
General case is the tag field not the first (so we need to buffer entries until we found an entry with tag)
- check that unit variant can be deserialized from a map
- check that newtype variant with unit can be deserialized from a struct
@Mingun Mingun force-pushed the internally-tagged-enum-tests branch from 543feb0 to 2adb0e9 Compare August 15, 2024 18:42
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thank you!

@dtolnay dtolnay merged commit 1a9ffdb into serde-rs:master Aug 15, 2024
15 checks passed
@Mingun Mingun deleted the internally-tagged-enum-tests branch August 16, 2024 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants