How to use String.isNilUUID method of io.kotest.matchers.string.matchers class

Best Kotest code snippet using io.kotest.matchers.string.matchers.String.isNilUUID

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package io.kotest.matchers.string2import io.kotest.assertions.failure3import io.kotest.assertions.print.print4import io.kotest.matchers.*5import io.kotest.matchers.neverNullMatcher6import io.kotest.matchers.string.UUIDVersion.ANY7import kotlin.contracts.contract8import kotlin.text.RegexOption.IGNORE_CASE9fun String?.shouldContainOnlyDigits(): String? {10 this should containOnlyDigits()11 return this12}13fun String?.shouldNotContainOnlyDigits(): String? {14 this shouldNot containOnlyDigits()15 return this16}17fun containOnlyDigits() = neverNullMatcher<String> { value ->18 MatcherResult(19 value.toCharArray().all { it in '0'..'9' },20 { "${value.print().value} should contain only digits" },21 { "${value.print().value} should not contain only digits" })22}23fun String?.shouldContainADigit(): String? {24 this should containADigit()25 return this26}27fun String?.shouldNotContainADigit(): String? {28 this shouldNot containADigit()29 return this30}31fun containADigit() = neverNullMatcher<String> { value ->32 MatcherResult(33 value.toCharArray().any { it in '0'..'9' },34 { "${value.print().value} should contain at least one digit" },35 { "${value.print().value} should not contain any digits" })36}37infix fun String?.shouldContainOnlyOnce(substr: String): String? {38 this should containOnlyOnce(substr)39 return this40}41infix fun String?.shouldNotContainOnlyOnce(substr: String): String? {42 this shouldNot containOnlyOnce(substr)43 return this44}45fun containOnlyOnce(substring: String) = neverNullMatcher<String> { value ->46 MatcherResult(47 value.indexOf(substring) >= 0 && value.indexOf(substring) == value.lastIndexOf(substring),48 { "${value.print().value} should contain the substring ${substring.print().value} exactly once" },49 { "${value.print().value} should not contain the substring ${substring.print().value} exactly once" })50}51fun String?.shouldBeEmpty(): String? {52 this should beEmpty()53 return this54}55fun String?.shouldNotBeEmpty(): String? {56 this shouldNot beEmpty()57 return this58}59fun beEmpty() = neverNullMatcher<String> { value ->60 MatcherResult(61 value.isEmpty(),62 { "${value.print().value} should be empty" },63 { "${value.print().value} should not be empty" })64}65fun String?.shouldBeBlank(): String? {66 this should beBlank()67 return this68}69fun String?.shouldNotBeBlank(): String? {70 this shouldNot beBlank()71 return this72}73fun containOnlyWhitespace() = beBlank()74fun beBlank() = neverNullMatcher<String> { value ->75 MatcherResult(76 value.isBlank(),77 { "${value.print().value} should contain only whitespace" },78 { "${value.print().value} should not contain only whitespace" }79 )80}81infix fun String?.shouldContainIgnoringCase(substr: String): String? {82 this should containIgnoringCase(substr)83 return this84}85infix fun String?.shouldNotContainIgnoringCase(substr: String): String? {86 this shouldNot containIgnoringCase(substr)87 return this88}89fun containIgnoringCase(substr: String) = neverNullMatcher<String> { value ->90 MatcherResult(91 value.lowercase().indexOf(substr.lowercase()) >= 0,92 { "${value.print().value} should contain the substring ${substr.print().value} (case insensitive)" },93 { "${value.print().value} should not contain the substring ${substr.print().value} (case insensitive)" }94 )95}96infix fun String?.shouldContain(regex: Regex): String? {97 this should contain(regex)98 return this99}100infix fun String?.shouldNotContain(regex: Regex): String? {101 this shouldNot contain(regex)102 return this103}104fun contain(regex: Regex) = neverNullMatcher<String> { value ->105 MatcherResult(106 value.contains(regex),107 { "${value.print().value} should contain regex $regex" },108 { "${value.print().value} should not contain regex $regex" })109}110fun String?.shouldContainInOrder(vararg substrings: String): String? {111 this should containInOrder(*substrings)112 return this113}114fun String?.shouldNotContainInOrder(vararg substrings: String): String? {115 this shouldNot containInOrder(*substrings)116 return this117}118fun containInOrder(vararg substrings: String) = neverNullMatcher<String> { value ->119 fun recTest(str: String, subs: List<String>): Boolean =120 subs.isEmpty() || str.indexOf(subs.first()).let { it > -1 && recTest(str.substring(it + 1), subs.drop(1)) }121 MatcherResult(122 recTest(value, substrings.filter { it.isNotEmpty() }),123 { "${value.print().value} should include substrings ${substrings.print().value} in order" },124 { "${value.print().value} should not include substrings ${substrings.print().value} in order" })125}126infix fun String?.shouldContain(substr: String): String? {127 this should contain(substr)128 return this129}130infix fun String?.shouldNotContain(substr: String): String? {131 this shouldNot contain(substr)132 return this133}134fun contain(substr: String) = include(substr)135infix fun String?.shouldInclude(substr: String): String? {136 this should include(substr)137 return this138}139infix fun String?.shouldNotInclude(substr: String): String? {140 this shouldNot include(substr)141 return this142}143fun include(substr: String) = neverNullMatcher<String> { value ->144 MatcherResult(145 value.contains(substr),146 { "${value.print().value} should include substring ${substr.print().value}" },147 { "${value.print().value} should not include substring ${substr.print().value}" })148}149/**150 * Asserts that [this] is equal to [other] (ignoring case)151 *152 * Verifies that this string is equal to [other], ignoring case.153 * Opposite of [shouldNotBeEqualIgnoringCase]154 *155 * ```156 * "foo" shouldBeEqualIgnoringCase "FoO" // Assertion passes157 *158 * "foo" shouldBeEqualIgnoringCase "BaR" // Assertion fails159 * ```160 *161 * @see [shouldNotBeEqualIgnoringCase]162 * @see [beEqualIgnoringCase]163 */164infix fun String?.shouldBeEqualIgnoringCase(other: String): String? {165 this should beEqualIgnoringCase(other)166 return this167}168/**169 * Asserts that [this] is NOT equal to [other] (ignoring case)170 *171 * Verifies that this string is NOT equal to [other], ignoring case.172 * Opposite of [shouldBeEqualIgnoringCase]173 *174 * ```175 * "foo" shouldNotBeEqualIgnoringCase "FoO" // Assertion fails176 * "foo" shouldNotBeEqualIgnoringCase "foo" // Assertion fails177 *178 * "foo" shouldNotBeEqualIgnoringCase "bar" // Assertion passes179 *180 * ```181 *182 * @see [shouldBeEqualIgnoringCase]183 * @see [beEqualIgnoringCase]184 */185infix fun String?.shouldNotBeEqualIgnoringCase(other: String): String? {186 this shouldNot beEqualIgnoringCase(other)187 return this188}189/**190 * Matcher that matches strings that are equal when case is not considered191 *192 * Verifies that a specific String is equal to another String when case is not considered.193 *194 * ```195 * "foo" should beEqualIgnoringCase("FoO") // Assertion passes196 *197 * "bar shouldNot beEqualIgnoringCase("BoB") // Assertion passes198 *199 * ```200 *201 */202fun beEqualIgnoringCase(other: String) = neverNullMatcher<String> { value ->203 MatcherResult(204 value.equals(other, ignoreCase = true),205 { "${value.print().value} should be equal ignoring case ${other.print().value}" },206 {207 "${value.print().value} should not be equal ignoring case ${other.print().value}"208 })209}210enum class UUIDVersion(211 val uuidRegex: Regex212) {213 ANY("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}".toRegex(IGNORE_CASE)),214 V1("[0-9a-f]{8}-[0-9a-f]{4}-[1][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}".toRegex(IGNORE_CASE)),215 V2("[0-9a-f]{8}-[0-9a-f]{4}-[2][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}".toRegex(IGNORE_CASE)),216 V3("[0-9a-f]{8}-[0-9a-f]{4}-[3][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}".toRegex(IGNORE_CASE)),217 V4("[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}".toRegex(IGNORE_CASE)),218 V5("[0-9a-f]{8}-[0-9a-f]{4}-[5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}".toRegex(IGNORE_CASE));219}220/**221 * Asserts that this String is a valid UUID222 *223 * Opposite of [shouldNotBeUUID]224 *225 * Verifies that this string is a valid UUID as per RFC4122. Version depends on [version]. By default, all versions226 * (v1 through v5) are matched. A special attention is necessary for the NIL UUID (an UUID with all zeros),227 * which is considered a valid UUID. By default, it's matched as valid.228 *229 * ```230 * "123e4567-e89b-12d3-a456-426655440000".shouldBeUUID(version = ANY) // Assertion passes231 * "123e4567-e89b-12d3-a456-426655440000".shouldBeUUID(version = V4) // Assertion Fails (is V1 UUID)232 * "123e4567e89b12d3a456426655440000".shouldBeUUID() // Assertion fails233 * "00000000-0000-0000-0000-000000000000".shouldBeUUID(considerNilValid = true) // Assertion passes234 *235 * ```236 *237 * @see RFC4122 https://tools.ietf.org/html/rfc4122238 */239fun String.shouldBeUUID(240 version: UUIDVersion = ANY,241 considerNilValid: Boolean = true242): String {243 this should beUUID(version, considerNilValid)244 return this245}246/**247 * Asserts that this String is NOT a valid UUID248 *249 * Opposite of [shouldBeUUID]250 *251 * Verifies that this string is a NOT valid UUID as per RFC4122. Version depends on [version]. By default, all versions252 * (v1 through v5) are matched. A special attention is necessary for the NIL UUID (an UUID with all zeros),253 * which is considered a valid UUID. By default it's matched as valid.254 *255 * ```256 * "123e4567-e89b-12d3-a456-426655440000".shouldNotBeUUID(version = ANY) // Assertion fails257 * "123e4567e89b12d3a456426655440000".shouldNotBeUUID() // Assertion passes258 * "00000000-0000-0000-0000-000000000000".shouldNotBeUUID(considerNilValid = true) // Assertion fails259 *260 * ```261 *262 * @see [RFC4122] https://tools.ietf.org/html/rfc4122263 */264fun String.shouldNotBeUUID(265 version: UUIDVersion = ANY,266 considerNilValid: Boolean = true267): String {268 this shouldNot beUUID(version, considerNilValid)269 return this270}271/**272 * Matcher that verifies if a String is an UUID273 *274 *275 * Verifies that a string is a valid UUID as per RFC4122. Version depends on [version]. By default, all versions276 * (v1 through v5) are matched. A special attention is necessary for the NIL UUID (an UUID with all zeros),277 * which is considered a valid UUID. By default it's matched as valid.278 *279 *280 * @see [RFC4122] https://tools.ietf.org/html/rfc4122281 * @see shouldBeUUID282 * @see shouldNotBeUUID283 */284fun beUUID(285 version: UUIDVersion = ANY,286 considerNilValid: Boolean = true287) = object : Matcher<String> {288 override fun test(value: String) = MatcherResult(289 value.matches(version.uuidRegex) || (considerNilValid && value.isNilUUID()),290 { "String $value is not an UUID ($version), but should be" },291 { "String $value is an UUID ($version), but shouldn't be" })292 private fun String.isNilUUID() = this == "00000000-0000-0000-0000-000000000000"293}294fun String?.shouldBeInteger(radix: Int = 10): Int {295 contract {296 returns() implies (this@shouldBeInteger != null)297 }298 return when (this) {299 null -> throw failure("String is null, but it should be integer.")300 else -> when (val integer = this.toIntOrNull(radix)) {301 null -> throw failure("String '$this' is not integer, but it should be.")302 else -> integer303 }304 }305}...

Full Screen

Full Screen

String.isNilUUID

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.string.matchers.isNilUUID2 import io.kotest.matchers.string.matchers.isUUID3 import io.kotest.matchers.string.matchers.shouldBeBlank4 import io.kotest.matchers.string.matchers.shouldBeEmpty5 import io.kotest.matchers.string.matchers.shouldBeLowerCase6 import io.kotest.matchers.string.matchers.shouldBeUpperCase7 import io.kotest.matchers.string.matchers.shouldBeUUID8 import io.kotest.matchers.string.matchers.shouldContainAll9 import io.kotest.matchers.string.matchers.shouldContainAny10 import io.kotest.matchers.string.matchers.shouldContainAnyOf11 import io.kotest.matchers.string.matchers.shouldContainNone12 import io.kotest.matchers.string.matchers.shouldContainOnlyDigits13 import io.kotest.matchers.string.matchers.shouldContainOnlyLetters14 import io.kotest.matchers.string.matchers.should

Full Screen

Full Screen

String.isNilUUID

Using AI Code Generation

copy

Full Screen

1import io.kotest.assertions.throwables.shouldThrow2import io.kotest.matchers.string.matchers.shouldNotBeNilUUID3import io.kotest.matchers.string.matchers.shouldBeNilUUID4import io.kotest.matchers.string.matchers.isNilUUID5import io.kotest.assertions.throwables.shouldThrow6import io.kotest.matchers.string.matchers.shouldNotBeUUID7import io.kotest.matchers.string.matchers.shouldBeUUID8import io.kotest.matchers.string.matchers.isUUID9import io.kotest.assertions.throwables.shouldThrow10import io.kotest.matchers.string.matchers.shouldNotBeEmail11import io.kotest.matchers.string.matchers.shouldBeEmail12import io.kotest.matchers.string.matchers.isEmail13import io.kotest.assertions.throwables.shouldThrow14import io.kotest.matchers.string.matchers.shouldNotBeUrl15import io.kotest.matchers.string.matchers.shouldBeUrl16import io.kotest.matchers.string.matchers.isUrl17import io.kotest.assertions.throwables.shouldThrow18import io.kotest.matchers.string.matchers.shouldNotBeBase6419import io.kotest.matchers.string.matchers.shouldBeBase6420import io.kotest.matchers.string.matchers.isBase6421import io.kotest.assertions.throwables.shouldThrow22import io.kotest.matchers.string.matchers.shouldNotBeBase6423import io.kotest.matchers.string.matchers.shouldBeBase6424import io.kotest.matchers.string.matchers.isBase6425import io.kotest.assertions.throwables.shouldThrow26import io.kotest.matchers.string.matchers.shouldNotBeBase6427import io.kotest.matchers.string.matchers.shouldBeBase64

Full Screen

Full Screen

String.isNilUUID

Using AI Code Generation

copy

Full Screen

1assertThat(uuid).isNilUUID()2assertThat(uuid).isNotNilUUID()3assertThat(uuid).isUUID()4assertThat(uuid).isNotUUID()5assertThat(uuid).isUUIDv3()6assertThat(uuid).isNotUUIDv3()7assertThat(uuid).isUUIDv4()8assertThat(uuid).isNotUUIDv4()9assertThat(uuid).isUUIDv5()10assertThat(uuid).isNotUUIDv5()11assertThat(uuid).isUUIDv3()12assertThat(uuid).isNotUUIDv3()13assertThat(uuid).isUUIDv4()14assertThat(uuid).isNotUUIDv4()15assertThat(uuid).isUUIDv5()16assertThat(uuid).isNotUUIDv5()

Full Screen

Full Screen

String.isNilUUID

Using AI Code Generation

copy

Full Screen

1 val uuid = UUID.randomUUID()2 uuid.toString().shouldNotBeNilUUID()3 val uuid = UUID.randomUUID()4 uuid.toString().shouldNotBeNilUUID()5 val uuid = UUID.randomUUID()6 uuid.toString().shouldNotBeNilUUID()7 val uuid = UUID.randomUUID()8 uuid.toString().shouldNotBeNilUUID()9 val uuid = UUID.randomUUID()10 uuid.toString().shouldNotBeNilUUID()11 val uuid = UUID.randomUUID()12 uuid.toString().shouldNotBeNilUUID()13 val uuid = UUID.randomUUID()14 uuid.toString().shouldNotBeNilUUID()15 val uuid = UUID.randomUUID()16 uuid.toString().shouldNotBeNilUUID()17 val uuid = UUID.randomUUID()18 uuid.toString().shouldNotBeNilUUID()19 val uuid = UUID.randomUUID()20 uuid.toString().shouldNotBeNilUUID()21 val uuid = UUID.randomUUID()22 uuid.toString().shouldNotBeNilUUID()23 val uuid = UUID.randomUUID()24 uuid.toString().shouldNotBeNilUUID()25 val uuid = UUID.randomUUID()26 uuid.toString().shouldNotBeNilUUID()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful