Skip to content

Commit

Permalink
Add Validate::validate_and_return_fiurst_error
Browse files Browse the repository at this point in the history
This method is completely redundant with `Validate::validate` right now,
but it will become useful in a moment, when I change `validate` to emit
an arbitrary number of errors.
  • Loading branch information
hannobraun committed Jan 12, 2023
1 parent 84a9bed commit 6a17480
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/validate/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ mod tests {
Cycle::new(half_edges)
};

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand Down
16 changes: 8 additions & 8 deletions crates/fj-kernel/src/validate/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ mod tests {
HalfEdge::new(vertices, valid.global_form().clone())
};

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand All @@ -301,8 +301,8 @@ mod tests {
tmp.build(&mut services.objects)
});

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand Down Expand Up @@ -333,8 +333,8 @@ mod tests {
tmp.build(&mut services.objects)
});

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand Down Expand Up @@ -370,8 +370,8 @@ mod tests {
valid.global_form().clone(),
);

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/validate/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ mod tests {
Face::new(valid.exterior().clone(), interiors, valid.color())
};

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand Down Expand Up @@ -188,8 +188,8 @@ mod tests {
Face::new(valid.exterior().clone(), interiors, valid.color())
};

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand Down
5 changes: 5 additions & 0 deletions crates/fj-kernel/src/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ use fj_math::Scalar;
///
/// This trait is used automatically when inserting an object into a store.
pub trait Validate: Sized {
/// Validate the object using default config and return on first error
fn validate_and_return_first_error(&self) -> Result<(), ValidationError> {
self.validate()
}

/// Validate the object using default configuration
fn validate(&self) -> Result<(), ValidationError> {
self.validate_with_config(&ValidationConfig::default())
Expand Down
12 changes: 6 additions & 6 deletions crates/fj-kernel/src/validate/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ mod tests {
Vertex::new(valid.position(), valid.curve().clone(), surface_form)
};

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand Down Expand Up @@ -271,8 +271,8 @@ mod tests {
Vertex::new(valid.position(), valid.curve().clone(), surface_form)
};

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand All @@ -293,8 +293,8 @@ mod tests {
GlobalVertex::new([1., 0., 0.]).insert(&mut services.objects),
);

valid.validate()?;
assert!(invalid.validate().is_err());
valid.validate_and_return_first_error()?;
assert!(invalid.validate_and_return_first_error().is_err());

Ok(())
}
Expand Down

0 comments on commit 6a17480

Please sign in to comment.