Skip to content

Commit

Permalink
refactor!: rename string assertions to make them more idiomatic
Browse files Browse the repository at this point in the history
BREAKING CHANGE: changing public api
  • Loading branch information
open-schnick committed Dec 15, 2024
1 parent aca5151 commit 2529179
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/assertions/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ where
/// # use regex::Regex;
/// #
/// assert_that("I categorically deny having triskaidekaphobia.")
/// .is_matching(&Regex::new(r"\b\w{13}\b").unwrap());
/// .matches(&Regex::new(r"\b\w{13}\b").unwrap());
/// ```
///
/// # Panics
/// When the value does not match the regex
#[track_caller]
#[allow(clippy::wrong_self_convention)]
fn is_matching(self, regex: &Regex) -> AssertionConnector<StringLike>;
fn matches(self, regex: &Regex) -> AssertionConnector<StringLike>;

/// Asserts that the value starts with the pattern
///
/// # Examples
/// ```
/// # use smoothy::prelude::*;
/// #
/// assert_that("Hello World").starts_with_string("Hello");
/// assert_that("Hello World").starts_with("Hello");
/// ```
///
/// # Panics
/// When the value does not start with the pattern
#[track_caller]
fn starts_with_string(self, string: impl AsRef<str>) -> AssertionConnector<StringLike>;
fn starts_with(self, string: impl AsRef<str>) -> AssertionConnector<StringLike>;
}

impl<StringLike> StringAssertion<StringLike> for BasicAsserter<StringLike>
Expand All @@ -71,7 +71,7 @@ where
AssertionConnector { value: self.value }
}

fn is_matching(self, regex: &Regex) -> AssertionConnector<StringLike> {
fn matches(self, regex: &Regex) -> AssertionConnector<StringLike> {
let asserted_value = self.value.as_ref();

implementation::assert(
Expand All @@ -83,7 +83,7 @@ where
AssertionConnector { value: self.value }
}

fn starts_with_string(self, string: impl AsRef<str>) -> AssertionConnector<StringLike> {
fn starts_with(self, string: impl AsRef<str>) -> AssertionConnector<StringLike> {
let asserted_value = self.value.as_ref();

implementation::assert(
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@
//!
//! ```
//! # use smoothy::prelude::*;
//! assert_that("Hello World").starts_with_string("Hello");
//! assert_that("Hello World").starts_with("Hello");
//! ```
//!
//! ```
//! # use smoothy::prelude::*;
//! # use regex::Regex;
//! assert_that("Hello World").is_matching(&Regex::new(r"\bHello\b").unwrap());
//! assert_that("Hello World").matches(&Regex::new(r"\bHello\b").unwrap());
//! ```
//!
//! ## Result
Expand Down
6 changes: 3 additions & 3 deletions tests/is_matching.rs → tests/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ use smoothy::{assert_that, AssertionConnector, StringAssertion};
fn succeeds() {
let _connector: AssertionConnector<&str> =
assert_that("I categorically deny having triskaidekaphobia.")
.is_matching(&Regex::new(r"\b\w{13}\b").unwrap());
.matches(&Regex::new(r"\b\w{13}\b").unwrap());
}

#[allow(clippy::unnecessary_to_owned)]
#[test]
fn succeeds_with_string() {
let _connector: AssertionConnector<String> =
assert_that("I categorically deny having triskaidekaphobia.".to_string())
.is_matching(&Regex::new(r"\b\w{13}\b").unwrap());
.matches(&Regex::new(r"\b\w{13}\b").unwrap());
}

#[test]
#[should_panic = "assertion failed: `(Value is matching regex)`\n found: \"I deny having fun.\""]
fn fails() {
assert_that("I deny having fun.".to_string()).is_matching(&Regex::new(r"\b\w{13}\b").unwrap());
assert_that("I deny having fun.".to_string()).matches(&Regex::new(r"\b\w{13}\b").unwrap());
}
10 changes: 5 additions & 5 deletions tests/starts_with_string.rs → tests/starts_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ use smoothy::{assert_that, StringAssertion};
#[test]
fn succeeds_with_str() {
assert_that("Hello World")
.starts_with_string("Hello")
.starts_with("Hello")
.and()
.starts_with_string("Hello".to_string());
.starts_with("Hello".to_string());
}

#[allow(clippy::unnecessary_to_owned)]
#[test]
fn succeeds_with_string() {
assert_that("Hello World".to_string())
.starts_with_string("Hello")
.starts_with("Hello")
.and()
.starts_with_string("Hello".to_string());
.starts_with("Hello".to_string());
}

#[test]
#[should_panic = "assertion failed: `(Value starts with 'BlaFasel')`\n found: \"Hello World\""]
fn fails() {
assert_that("Hello World").starts_with_string("BlaFasel");
assert_that("Hello World").starts_with("BlaFasel");
}

0 comments on commit 2529179

Please sign in to comment.