ppx/test: cover encode behavior for @drop_default variants#84
Open
Khady wants to merge 2 commits intomelange-community:mainfrom
Open
ppx/test: cover encode behavior for @drop_default variants#84Khady wants to merge 2 commits intomelange-community:mainfrom
Khady wants to merge 2 commits intomelange-community:mainfrom
Conversation
Existing e2e tests only exercised the [@option] + [@json.drop_default] combination. Add runtime coverage for the three remaining shapes so the encode behavior (drop when value matches default vs include otherwise) is visible in the cram output: - [@json.default E] [@json.drop_default] (flag form, non-option default) - [@json.default E] [@json.drop_default expr] (custom comparator) - [@json.default E] [@json.drop_default_if_json_equal] Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds an outer record whose default for a record-typed field is a let-bound value, where the inner record's own field uses [@option] [@json.drop_default]. Exercises three cases: - inner foo=None present: round-trips via {"inner":{}} (foo dropped) - inner foo=Some 5 present: round-trips via {"inner":{"foo":5}} - outer field missing: default kicks in and decodes to the empty inner record Previously [@json.default] was only tested with scalar literal payloads. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Existing e2e runtime tests only exercised the
[@option] + [@json.drop_default]combination viadrop_default_option. The other three drop-default shapes had only PPX-generation coverage inppx_deriving_json_js.t/ppx_deriving_json_native.t, but no runtime assertion that the encoder actually drops the field.This PR adds runtime cases for the three remaining shapes so the encode behavior (drop when value matches default vs. include otherwise) is visible in the cram output:
[@json.default E] [@json.drop_default](flag form, non-option default; usesequal_<type>in scope)[@json.default E] [@json.drop_default expr](custom comparator form)[@json.default E] [@json.drop_default_if_json_equal]Each new type contributes two cases: value matching the default (field dropped) and value differing (field included). Behavior is identical between native and JS backends.
This PR was motivated by a bug in ppx_deriving_jsonschema, which was struggling to handle an absent value marked with
[@option] [@drop_default], as such values are serialized toundefinedby melange json. It seems like a useful information to capture in the tests. Unfortunately it is not very explicit.