diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index d128d30b..0686ad80 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -1021,4 +1021,16 @@ final class Expectation return $this; } + + /** + * Asserts that the value is kebab-case. + * + * @return self + */ + public function toBeKebabCase(string $message = ''): self + { + Assert::assertTrue((bool) preg_match('/^[\p{Ll}-]+$/u', (string) $this->value), $message); + + return $this; + } } diff --git a/tests/Features/Expect/toBeKebabCase.php b/tests/Features/Expect/toBeKebabCase.php new file mode 100644 index 00000000..1ca54ddc --- /dev/null +++ b/tests/Features/Expect/toBeKebabCase.php @@ -0,0 +1,23 @@ +toBeKebabCase(); + expect('abc-def')->toBeKebabCase(); + expect('abc_def')->not->toBeKebabCase(); + expect('abcDef')->not->toBeKebabCase(); + expect('AbcDef')->not->toBeKebabCase(); +}); + +test('failures', function () { + expect('Abc')->toBeKebabCase(); +})->throws(ExpectationFailedException::class); + +test('failures with custom message', function () { + expect('Abc')->toBeKebabCase('oh no!'); +})->throws(ExpectationFailedException::class, 'oh no!'); + +test('not failures', function () { + expect('abc-def')->not->toBeKebabCase(); +})->throws(ExpectationFailedException::class);