Repository: willowtreeapps/assertk (kotlin)

Issue:
Add `Assert<CharSequence>.doesNotContainMatch(regex: Regex)`
Like https://github.com/google/truth/blob/213a1569fe9ed49c4f3b87d923e7e29733f232e7/core/src/main/java/com/google/common/truth/StringSubject.java#L198-L213

Pull request description:
Closes #515.

Patch:
diff --git a/assertk/src/commonMain/kotlin/assertk/assertions/charsequence.kt b/assertk/src/commonMain/kotlin/assertk/assertions/charsequence.kt
index ab0115fd..8d527586 100644
--- a/assertk/src/commonMain/kotlin/assertk/assertions/charsequence.kt
+++ b/assertk/src/commonMain/kotlin/assertk/assertions/charsequence.kt
@@ -117,6 +117,14 @@ fun Assert<CharSequence>.doesNotContain(expected: Iterable<CharSequence>, ignore
     expected("to not contain:${show(expected)} but was:${show(actual)}")
 }
 
+/**
+ * Asserts the char sequence does not contain the expected regular expression.
+ */
+fun Assert<CharSequence>.doesNotContainMatch(regex: Regex) = given { actual ->
+    if (!regex.containsMatchIn(actual)) return
+    expected("to not contain match:${show(regex)} but was:${show(actual)}")
+}
+
 /**
  * Asserts the char sequence starts with the expected char sequence.
  * @param ignoreCase true to compare ignoring case, the default if false.


Test patch:
diff --git a/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt b/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt
index 8eb64c0b..baaf942a 100644
--- a/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt
+++ b/assertk/src/commonTest/kotlin/test/assertk/assertions/CharSequenceTest.kt
@@ -223,6 +223,22 @@ class CharSequenceTest {
     }
     //endregion
 
+    //region doesNotContainMatch
+    @Test
+    fun doesNotContainMatch_non_matching_value_passes() {
+        assertThat("abcd").doesNotContainMatch(Regex("\\d\\d\\d\\d"))
+    }
+
+    @Test
+    fun doesNotContainMatch_matching_value_fails() {
+        val regex = Regex("\\d\\d\\d\\d")
+        val error = assertFailsWith<AssertionError> {
+            assertThat("1234").doesNotContainMatch(regex)
+        }
+        assertEquals("expected to not contain match:${show(regex)} but was:<\"1234\">", error.message)
+    }
+    //endregion
+
     //region startsWith
     @Test
     fun startsWith_value_prefix_passes() {