Skip to content

JSON comparison parity (utility only)#401

Merged
timkimadobe merged 8 commits intoadobe:feature/json-comparison-parityfrom
timkimadobe:json-comparison-parity-utility-only
Sep 19, 2023
Merged

JSON comparison parity (utility only)#401
timkimadobe merged 8 commits intoadobe:feature/json-comparison-parityfrom
timkimadobe:json-comparison-parity-utility-only

Conversation

@timkimadobe
Copy link
Copy Markdown
Contributor

@timkimadobe timkimadobe commented Sep 18, 2023

Description

This PR updates the JSON comparison system to be in line with the Android implementation, taking the following improvements:

  1. Streamlined flexible array comparison logic
    • General wildcard [*] overrides all other alternate paths
    • Precedence: general wildcard [*] > specific index [0] > unspecified index (no alternate path) > wildcard index [*0]
  2. Ability to escape array style access in key names (ex: key name -> "key1[0]", alternate path -> "key1[0]"
  3. Reducing reliance on brittle regex by implementing string manipulation logic
  4. Removal of the test helper method getAnyCodableAndPayload in favor of using AnyCodable's dictionary representation directly
  5. Removal of defunct AssertMode and PayloadType enums

For reference, please see the Android implementation: adobe/aepsdk-edge-android#79

Note that the unit and parameterized tests are not implemented in this PR to facilitate easier review process and will be implemented in followup PRs

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 18, 2023

Codecov Report

Merging #401 (04d1708) into feature/json-comparison-parity (c3ce8a6) will not change coverage.
The diff coverage is n/a.

@@                       Coverage Diff                       @@
##           feature/json-comparison-parity     #401   +/-   ##
===============================================================
  Coverage                           96.77%   96.77%           
===============================================================
  Files                                  27       27           
  Lines                                1671     1671           
===============================================================
  Hits                                 1617     1617           
  Misses                                 54       54           

@timkimadobe timkimadobe changed the title JSON comparison parity utility only JSON comparison parity (utility only) Sep 18, 2023
Copy link
Copy Markdown
Contributor

@emdobrin emdobrin left a comment

Choose a reason for hiding this comment

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

thanks for porting these changes over

/// 3. The general wildcard: [*] (must be in exactly this format) - Every element not explicitly specified by 1 or 2 will use the alternate mode and apply wildcard matching logic. This option is mututally exclusive with default behavior.
/// - The default behavior is that elements from the expected JSON side are compared in order, up to the last element of the expected array.
/// For wildcard array matching, where position doesn't matter:
/// 1. Specific index with wildcard: `[*<INT>]` or `[<INT>*]` (ex: `[*1]`, `[28*]`). The element
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

will you add new tests for the wildcard index matches similar to Android in the next PRs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, they will be included in a followup PR!

Update param name of extractArrayStyleComponents to be more intuitively descriptive
Copy link
Copy Markdown
Contributor Author

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

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

Thanks so much for the review @emdobrin! Updated based on feedback and will open the corresponding test updates PR as a followup to this one

/// 3. The general wildcard: [*] (must be in exactly this format) - Every element not explicitly specified by 1 or 2 will use the alternate mode and apply wildcard matching logic. This option is mututally exclusive with default behavior.
/// - The default behavior is that elements from the expected JSON side are compared in order, up to the last element of the expected array.
/// For wildcard array matching, where position doesn't matter:
/// 1. Specific index with wildcard: `[*<INT>]` or `[<INT>*]` (ex: `[*1]`, `[28*]`). The element
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, they will be included in a followup PR!

@timkimadobe timkimadobe merged commit d7e511e into adobe:feature/json-comparison-parity Sep 19, 2023
@timkimadobe timkimadobe deleted the json-comparison-parity-utility-only branch September 29, 2023 22:43
@timkimadobe timkimadobe mentioned this pull request Sep 29, 2023
10 tasks
timkimadobe added a commit that referenced this pull request Oct 12, 2023
* JSON comparison parity (utility only) (#401)

* Remove custom helper enums and refactor usages

Update documentation and code logic to match Android implementation

* Apply lint autocorrect

* Revert "Apply lint autocorrect"

This reverts commit 7f38d19.

* Apply lint autocorrect

* Reduce wordiness of file and line param descriptions

* Update documentation null to nil

* Update file and line param descriptions

* Add method documentation to all helper methods

Update param name of extractArrayStyleComponents to be more intuitively descriptive

* JSON comparison parity - test cases (#402)

* Achieves parity with the Android Edge test setup for JSON comparison

Splits coverage into parameterized and special case tests, and update provides more comprehensive systematic coverage

* Add additional test cases to validate type mismatch detection and all boolean cases

Update index helper comments based on changed values

* Update failure cases to check for unintended type casting

* Fix comment typo

* Extract inline actual AnyCodable creation to separate line for clarity

* Refactor wildcard index logic (#416)

* Refactor wildcard index access to flatten logic since different condition and replacement groups are not needed

* Reformat method documentation to bring them all together

* Rename variables to better reflect what each one stores

* Refactor wildcard array index extraction to strictly validate format

Extract wildcard array index extraction logic into separate function
Update usages, test cases, and method documentation

* Update test failure message to include example format

* Rename `extractArrayStyleComponents` and update method docs (#418)

* Rename the extractArrayStyleComponents -> extractArrayFormattedComponents to better reflect actual behavior

Update method documentation to reflect the rename and to better explain the logic

* Update parameter description

* Update method description

* Include information about removing escape character
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants