Skip to content

JSON comparison system parity#415

Merged
timkimadobe merged 7 commits intodevfrom
feature/json-comparison-parity
Oct 12, 2023
Merged

JSON comparison system parity#415
timkimadobe merged 7 commits intodevfrom
feature/json-comparison-parity

Conversation

@timkimadobe
Copy link
Copy Markdown
Contributor

@timkimadobe timkimadobe commented Sep 29, 2023

Description

This PR:

  1. Brings the iOS JSON comparison system to parity with the Android version AND
  2. Refactors the allowed wildcard index array format and validation logic

The changes are covered in detail in the following feature branch PRs:
1.
Utility updates: #401
Test cases updates: #402
2.
Wildcard index refactor: #416

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.

* 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
* 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
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 29, 2023

Codecov Report

Merging #415 (55ff0ee) into dev (196d390) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##              dev     #415   +/-   ##
=======================================
  Coverage   96.77%   96.77%           
=======================================
  Files          27       27           
  Lines        1672     1672           
=======================================
  Hits         1618     1618           
  Misses         54       54           

# Conflicts:
#	AEPEdge.xcodeproj/project.pbxproj
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.

Thank you for the review @emdobrin! Updated based on feedback, with new PR from fork for the changes

// 1. Mark the path end (where the value is a `String`), or
// 2. Contain the asterisk (*) character.
let pathEndKeys = pathTree?.filter { key, value in
value is String || key.contains("*")
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.

This might not work as expected if the key has * in it eg: awesome*key. Should we check startsWith and EndsWith '*'? applies to Android code as well.

Copy link
Copy Markdown
Contributor Author

@timkimadobe timkimadobe Oct 4, 2023

Choose a reason for hiding this comment

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

These pathEndKeys are only used in the context of array index path end keys. It's ok at this stage if keys like awesome*key are captured in this list since the else block handles:

  1. filtering out all keys that dont strictly have array access style notation via the arrayIndexValueRegex: "[123]" (awesome*key would be filtered out here)
  2. sanitization of invalid non integer values: "[awesome*key]" -> "awesomekey" -> cannot be converted to Int and is filtered out

Hopefully this addresses the case mentioned, or were you thinking of something else?

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.

Yes, I saw that we will drop it while after casting, but I was thinking if we could set a preferred way to do this. Like it has to start with * or end with *. So we don't do not necessary casting and also keep it standardized.

How about "1*2" for the above test?

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.

I think standardization could definitely be helpful for users of the method; what do you think of emitting information/test errors based on non-standard formats, since we have this information at parse time?

For example, if the * is only allowed at the start or end, then [1*2] would emit a test failure as a setup issue. I feel like standardization without this kind of correction/warning could be less useful? Although I do also see the benefit of format consistency for writers and maintainers of test cases as well

In the current implementation, [1*2] will be interpreted as: wildcard index 12

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.

Update: #416 (comment)

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.

Update: The wildcard array format and related logic has been refactored in #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 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
@timkimadobe timkimadobe merged commit 2aed8e9 into dev Oct 12, 2023
@timkimadobe timkimadobe deleted the feature/json-comparison-parity branch October 12, 2023 20:36
@emdobrin emdobrin added this to the v4.3.0 milestone Oct 31, 2023
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.

3 participants