Refactor JSON comparison options handling#9
Merged
timkimadobe merged 7 commits intomainfrom Dec 13, 2023
Merged
Conversation
Refactor AnyCodable assert methods to use new NodeConfig class
…by the new node system
Update method docs Rename helper method to more generic validateJSON
This was referenced Nov 30, 2023
This was referenced Dec 12, 2023
Closed
cdhoffmann
approved these changes
Dec 13, 2023
Contributor
cdhoffmann
left a comment
There was a problem hiding this comment.
This is really good stuff. Great job Tim.
This was referenced Apr 26, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR overhauls the comparison option system to create a powerful modular design that allows for easy customizability. Previously, the design relied on a brittle nested dictionary that only allowed for:
The new design specifically addresses these two points:
MultiPathConfigprotocol that provides for the base configuration optionsIt also improves maintainability:
NodeConfighandles all the options setup and resolution, AnyCodableAsserts methods can just use the options as neededassertEquals(expected:actual:file:line:)) could be removed because the underlying comparison system can now entirely handle this case, because it is not as brittle as beforeThe tree is minimally constructed; that is, it only builds the tree out to the paths that are specified and relies on last set defaults for the given portion of the subtree for unspecified nodes.
Note
The methods related to path extraction have been transferred to NodeConfig, pretty much unchanged:
extractValidWildcardIndexextractRegexCaptureGroupsgetCapturedRegexGroupsgetKeyPathComponentsextractArrayFormattedComponentsStandard usage
Remains unchanged! (see unchanged unit test coverage)
Advanced usage
The usage has been refined so that for a given option configuration, multiple paths can easily be constructed with minimal syntax
Paths
This is possible using overloaded constructors that allow for passing path values as:
Active or not toggle
Each comparison option has a toggle which controls if it is "active" or not for the given node being evaluated
Scope
Scope allows the user to control the granularity of how the option applies to the rest of the JSON structure. Two options are currently allowed:
Related Issue
Motivation and Context
The primary motivation for this change was to accommodate the new option for
CollectionEqualCount, allowing users to specify if they want collections (dictionary or array) to strictly validate the expected number of elements instead of the default permissive extensible object/array.How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: