Skip to content

Commit

Permalink
Removed PartialEq for Violation and added `assert_equivalent_viol…
Browse files Browse the repository at this point in the history
…ations!` for equivalence (#208)

* Removed `PartialEq` for `Violation`
* Adds macros for asserting violation equivalence and non equivalence
  • Loading branch information
desaikd authored Mar 11, 2024
1 parent 34eec9e commit 2735dab
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ion-schema-tests-runner/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ fn generate_test_cases_for_file(ctx: Context) -> TokenStream {
// get the schema content from given schema file path
let ion_content = fs::read(ctx.current_dir.as_path())
.unwrap_or_else(|e| panic!("Unable to read {path_string} – {e}"));
let schema_content = Element::read_all(&ion_content)
.unwrap_or_else(|e| panic!("Error in {path_string} – {e:?}"));
let schema_content =
Element::read_all(ion_content).unwrap_or_else(|e| panic!("Error in {path_string} – {e:?}"));

let isl_version = find_isl_version(&schema_content);

Expand Down
2 changes: 1 addition & 1 deletion ion-schema/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn validate(command_args: &ArgMatches) -> IonSchemaResult<()> {
// Extract Ion value provided by user
let input_file = command_args.value_of("input").unwrap();
let value = fs::read(input_file).expect("Can not load given ion file");
let owned_elements = Element::read_all(&value).expect("parsing failed unexpectedly");
let owned_elements = Element::read_all(value).expect("parsing failed unexpectedly");

// Set up authorities vector
let mut document_authorities: Vec<Box<dyn DocumentAuthority>> = vec![];
Expand Down
8 changes: 6 additions & 2 deletions ion-schema/src/ion_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;
use std::fmt::{Debug, Formatter};

/// Represents a single element in Ion Path which is either an index value or a field name depending on its parent container type
#[derive(Clone, PartialEq, PartialOrd)]
#[derive(Clone, PartialEq, PartialOrd, Eq, Hash)]
pub enum IonPathElement {
Index(usize),
Field(String),
Expand Down Expand Up @@ -57,7 +57,7 @@ impl fmt::Display for IonPathElement {
/// ```ion
/// ( greetings 1 ) // here 1 represents the index of "hi" in the Ion list value
/// ```
#[derive(Default, Clone, PartialEq, PartialOrd)]
#[derive(Default, Clone, PartialEq, PartialOrd, Eq, Hash)]
pub struct IonPath {
ion_path_elements: Vec<IonPathElement>,
}
Expand All @@ -70,6 +70,10 @@ impl IonPath {
pub fn pop(&mut self) -> Option<IonPathElement> {
self.ion_path_elements.pop()
}

pub(crate) fn new(ion_path_elements: Vec<IonPathElement>) -> Self {
Self { ion_path_elements }
}
}

impl From<IonPath> for Element {
Expand Down
4 changes: 2 additions & 2 deletions ion-schema/src/isl/isl_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub mod v_1_0 {
{
IslConstraint::new(
IslVersion::V1_0,
IslConstraintValue::Fields(fields.map(|(s, t)| (s, t)).collect(), false),
IslConstraintValue::Fields(fields.collect(), false),
)
}

Expand Down Expand Up @@ -278,7 +278,7 @@ pub mod v_2_0 {
{
IslConstraint::new(
IslVersion::V2_0,
IslConstraintValue::Fields(fields.map(|(s, t)| (s, t)).collect(), false),
IslConstraintValue::Fields(fields.collect(), false),
)
}

Expand Down
Loading

0 comments on commit 2735dab

Please sign in to comment.