use crate::matchers::{Should, ShouldNot};
use crate::matchers::equal::be_equal_ignoring_case;
pub trait IgnoreCaseEqualityAssertion {
fn should_be_equal_ignoring_case(&self, other: &str) -> &Self;
fn should_not_be_equal_ignoring_case(&self, other: &str) -> &Self;
}
impl<T> IgnoreCaseEqualityAssertion for T
where T: AsRef<str> {
fn should_be_equal_ignoring_case(&self, other: &str) -> &Self {
self.should(&be_equal_ignoring_case(other));
self
}
fn should_not_be_equal_ignoring_case(&self, other: &str) -> &Self {
self.should_not(&be_equal_ignoring_case(other));
self
}
}
#[cfg(test)]
mod tests {
use crate::assertions::string::equal::IgnoreCaseEqualityAssertion;
#[test]
fn should_be_equal() {
let name = "john";
name.should_be_equal_ignoring_case("JOHN");
}
#[test]
#[should_panic]
fn should_be_equal_but_was_not() {
let name = "johnR";
name.should_be_equal_ignoring_case("JOHN");
}
#[test]
fn should_not_be_equal() {
let name = "john";
name.should_not_be_equal_ignoring_case("JOHN-R");
}
#[test]
#[should_panic]
fn should_not_be_equal_but_was() {
let name = "john";
name.should_not_be_equal_ignoring_case("JOHN");
}
}
#[cfg(test)]
mod string_tests {
use crate::assertions::string::equal::IgnoreCaseEqualityAssertion;
#[test]
fn should_be_equal() {
let name = String::from("john");
name.should_be_equal_ignoring_case("JOHN");
}
#[test]
#[should_panic]
fn should_be_equal_but_was_not() {
let name = String::from("johnR");
name.should_be_equal_ignoring_case("JOHN");
}
#[test]
fn should_not_be_equal() {
let name = String::from("john");
name.should_not_be_equal_ignoring_case("JOHN-R");
}
#[test]
#[should_panic]
fn should_not_be_equal_but_was() {
let name = String::from("john");
name.should_not_be_equal_ignoring_case("JOHN");
}
}