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

Exhaustive internally tagged tests + support of internally tagged enums in non self-describing formats #2569

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from

Commits on Aug 7, 2023

  1. Use correct tokens in test to represent an enum variant

    Unit variant of externally tagged enum cannot be deserialized from the string
    token by itself. It is ContentDeserializer + serde_test::Deserializer that makes
    this possible, because serde_test::Deserializer produces Content::Str() from
    Token::BorrowedStr() and ContentDeserializer produces unit variant from Content::Str().
    
    The following tokens all produces Content::String(variant):
    - Token::String(variant)
    - Token::Str(variant)
    - Token::UnitVariant { variant, .. }
    
    Token::BorrowedStr(variant) produces Content::Str(variant) that was the real purpose to
    use it in test in serde-rs#933. This actually makes this test testing `Content` rather than type itself.
    
    Correct way to represent enum one of:
    - [xxxVariant { .. }]
    - [Enum { .. }, xxxVariant { variant, .. }]
    - [Enum { .. }, String(variant), <variant content>]
    - [Enum { .. }, Str(variant), <variant content>]
    - [Enum { .. }, BorrowedStr(variant), <variant content>]
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    84d1c53 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6a097ec View commit details
    Browse the repository at this point in the history
  3. Convert test_internally_tagged_enum into module

    (review this commit with "ignore whitespace changes" option on)
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    4437833 View commit details
    Browse the repository at this point in the history
  4. Move all internally tagged enum tests into a dedicated module

    Moved:
    - 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)
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    6fadf4d View commit details
    Browse the repository at this point in the history
  5. Remove excess test

    We already have two tests where inner types serialized
    as a Struct container and as a Map container. No need yet
    another test for a Map container
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    269be57 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    55c0bfb View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    b1af745 View commit details
    Browse the repository at this point in the history
  8. Move internally tagged enum tests into a dedicated file

    Ctrl+X, Ctrl+V
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    23323b6 View commit details
    Browse the repository at this point in the history
  9. Move all other internally tagged enum tests into a dedicated file

    Moved all except flattened tests:
    - test_internally_tagged_enum_with_skipped_conflict    => with_skipped_conflict
    - test_internally_tagged_enum_containing_flatten       => containing_flatten
    - 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
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    310e00a View commit details
    Browse the repository at this point in the history
  10. Use the same order of derives

    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    4e12f39 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    45512d6 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    2be1112 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    541d76e View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    b01f5bd View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    047e7a5 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    4770a7e View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    dfc8527 View commit details
    Browse the repository at this point in the history
  18. Share externally tagged enum Enum between all tests and reuse in stru…

    …ct_variant_containing_unit_variant
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    23f3e22 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    5af0e8e View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    b2cca0d View commit details
    Browse the repository at this point in the history
  21. Move and rename tests:

    - 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
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    43ab6d6 View commit details
    Browse the repository at this point in the history
  22. Convert newtype_enum and struct_enum tests into modules

    (review this commit with "ignore whitespace changes" option on)
    Mingun committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    9b4cb8b View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    437cf03 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    5a18a4d View commit details
    Browse the repository at this point in the history

Commits on Aug 12, 2023

  1. Add missing tests for enum variants as a values of struct variant of …

    …internally tagged enum
    
    failures (3) - until serde-rs/test#31 is merged:
        struct_enum::newtype
        struct_enum::struct_
        struct_enum::tuple
    Mingun committed Aug 12, 2023
    Configuration menu
    Copy the full SHA
    de4c2de View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    426b3a5 View commit details
    Browse the repository at this point in the history
  3. Add test for sequence in newtype_variant_containing_unit

    failures(1):
        newtype_unit
    Mingun committed Aug 12, 2023
    Configuration menu
    Copy the full SHA
    f869500 View commit details
    Browse the repository at this point in the history
  4. Unify handling of unit and unit structs in ContentDeserializer

    In theory, ContentRefDeserializer should have matching implementation,
    but handling empty maps and sequences as units breaks some cases with
    untagged enums:
    - test_untagged_newtype_variant_containing_unit_struct_not_map
    Mingun committed Aug 12, 2023
    Configuration menu
    Copy the full SHA
    b4e73e2 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    b9a4860 View commit details
    Browse the repository at this point in the history
  6. Deserializer should not check correctness of data, this is the respon…

    …sibility of the Visitor
    Mingun committed Aug 12, 2023
    Configuration menu
    Copy the full SHA
    1006028 View commit details
    Browse the repository at this point in the history
  7. Add support for internally tagged enums in non self-describing formats

    Deserializer methods are only hints which deserializer is not obliged to follow.
    Both TaggedContentVisitor and InternallyTaggedUnitVisitor accepts only
    visit_map and visit_seq and that is what derived implementation of Deserialize
    does for structs. Therefore it is fine to call deserialize_map here, as that
    already did in derived deserialize implementation
    Mingun committed Aug 12, 2023
    Configuration menu
    Copy the full SHA
    dafede9 View commit details
    Browse the repository at this point in the history
  8. Add support for struct variants in untagged and adjacently tagged enu…

    …ms in non self-describing formats
    
    Visitor that passed th the deserialize_any supports only visit_map method,
    so we can always requests deserialize_map
    Mingun committed Aug 12, 2023
    Configuration menu
    Copy the full SHA
    a08c600 View commit details
    Browse the repository at this point in the history