Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifies PartialEq for Violation #208

Merged
merged 8 commits into from
Mar 11, 2024
Merged

Modifies PartialEq for Violation #208

merged 8 commits into from
Mar 11, 2024

Conversation

desaikd
Copy link
Contributor

@desaikd desaikd commented Feb 21, 2024

Issue #206:

Description of changes:

This PR works on fixing PartialEq for Violation and modifies flattened_violations return sorted violations which can be used for comparison.

List of changes:

  • Changes PartialEq for Violation to defer to flattened violations
    for equivalence rather then Violations tree
  • Modified flattened_violations to return sorted vector absed on
    constraint
  • Modified flattened_violations to not return the violation itself
    when there are no children
  • adds clippy and rustfmt changes

Test:

Adds test for violations equivalence.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

* Changes `PartialEq` for `Violation` to defer to flattened violations
for equivalence rather then `Violation`s tree
* Modified `flattened_violations` to return sorted vector absed on
constraint
* Modified `flattened_violations` to not return the violation itself
when there are no children
),
],
);
assert_ne!(violation1.violations(), violation2.violations());
Copy link
Contributor

Choose a reason for hiding this comment

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

question—why are we asserting that this are not equal? This seems like it's not relevant to the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Err: this was part of debugging. I will remove this.

use crate::violation::{Violation, ViolationCode};

#[test]
fn violation_equivalence() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add another test case with multiple levels of nesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I will add that.

Copy link
Contributor

@popematt popematt Feb 21, 2024

Choose a reason for hiding this comment

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

Also, if we're writing tests for eq, we should also include cases where things are not equal and other edge cases.

  • constraint not equal
  • code not equal
  • message not equal
  • ion_path not equal
  • flattened_violations() not equal
  • violations not equal, but flattened_violations() equal
  • violations empty for both
  • violations with two child violations with the same constraint name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PartialEq had missing ion_path equivalence check. Added a condition check for that along with more tests.

ion-schema/src/violation.rs Show resolved Hide resolved
ion-schema/src/violation.rs Outdated Show resolved Hide resolved
ion-schema/src/violation.rs Outdated Show resolved Hide resolved
ion-schema/src/violation.rs Outdated Show resolved Hide resolved
* Adds macros for asserting violation equivalence
* Changes `violations` back to a vector instead of `HashSet`
@desaikd desaikd requested a review from popematt March 7, 2024 21:16
Copy link
Contributor

@popematt popematt left a comment

Choose a reason for hiding this comment

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

Two minor comments. Otherwise it looks good.

wasm-schema-sandbox/src/lib.rs Outdated Show resolved Hide resolved
ion-schema/src/violation.rs Show resolved Hide resolved
@desaikd desaikd merged commit 2735dab into main Mar 11, 2024
5 checks passed
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