Refactor wildcard index logic#416
Refactor wildcard index logic#416timkimadobe merged 5 commits intoadobe:feature/json-comparison-parityfrom
Conversation
…tion and replacement groups are not needed
Codecov Report
@@ Coverage Diff @@
## feature/json-comparison-parity #416 +/- ##
===============================================================
Coverage 96.77% 96.77%
===============================================================
Files 27 27
Lines 1671 1671
===============================================================
Hits 1617 1617
Misses 54 54 |
| // Discard wildcard indexes that are out of bounds of the available expected indexes | ||
| let intersection = expectedIndexes.intersection(result) | ||
| wildcardIndexes = intersection | ||
| // Remove all wildcard indexes from the valid expected indexes, so validation is not performed twice |
There was a problem hiding this comment.
Looks good. Just a small comment, some of these comments may be too verbose and it might be difficult to read through code. Can you extract this else block in a function with description and/or consolidate the comments in a single block?
There was a problem hiding this comment.
Thank you! I tried consolidating into a single block at the start of the logic, what do you think?
| .filter { $0.contains("*") } | ||
| .compactMap { Int($0.replacingOccurrences(of: "*", with: "")) }) | ||
|
|
||
| let intersection = expectedIndexes.intersection(result) |
There was a problem hiding this comment.
nit: Update variable names with more context and add comments to make the code easy to read. Something on these lines:
// Filters all the entries with wildcard character `*` and returns the index marked with wildcard.
var listOfIndexes = Set(indexValues
.filter { $0.contains("*") }
.compactMap { Int($0.replacingOccurrences(of: "*", with: "")) })
// result of regex matching with list of wildcard indexes
let wildcardIndexes = expectedIndexes.intersection(result)
There was a problem hiding this comment.
Updated variable names! As for the inline comments, they were inline before but updated to be collected together before the else block logic based on the discussion: #416 (comment)
@emdobrin would inline be clearer in terms of explaining the intent of each step?
| // Discard wildcard indexes that are out of bounds of the available expected indexes | ||
| // Then remove all wildcard indexes from the valid expected indexes, so validation is not performed twice | ||
|
|
||
| let arrayIndexValueRegex = #"^\[(.*?)\]$"# |
There was a problem hiding this comment.
nit: add comment
// regex to extract indexes with wildcard matching identifier '*'
|
Based on offline discussion with @emdobrin and @addb, aligned on the following updates:
With the consequences of
|
Extract wildcard array index extraction logic into separate function Update usages, test cases, and method documentation
| var result: Set<Int> = [] | ||
| for potentialWildcardIndex in potentialWildcardIndexes { | ||
| if potentialWildcardIndex.first != "*" { | ||
| XCTFail("TEST ERROR: wildcard indexes must have a single `*` character to the left of the index.", file: file, line: line) |
There was a problem hiding this comment.
nit: let's include a simple example for the implementor: ... to the left of the index, ie [*0].
There was a problem hiding this comment.
That's a great idea! Thank you, updated to include example
* 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
Description
This PR:
[*123]. If the wildcard candidate fails validation, it causes a test failure to help test writers and maintainers enforce consistency across usagesRelated Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: