How to use String.removeAllExtraWhitespaces method of io.kotest.core.names.TestName class

Best Kotest code snippet using io.kotest.core.names.TestName.String.removeAllExtraWhitespaces

names.kt

Source:names.kt Github

copy

Full Screen

1package io.kotest.core.names2/**3 * Models the name of a [io.kotest.core.test.TestCase] as entered by a user.4 *5 * A test case can sometimes have a prefix and/or suffix set by the spec style,6 * eg when using BehaviorSpec or WordSpec. Note that the prefix or suffix should include7 * any whitespace required.8 *9 * Test names can be prefixed with ! or f: to indicate bang or focus respectively.10 *11 * @param testName the name exactly as the user entered it but with focus or bang stripped12 * @param focus if the test name was specified with f: prefix13 * @param bang if the test name was specified with ! prefix14 * @param prefix if the test style includes a test name prefix, such as "should"15 * @param suffix if the test style includes a test name suffix, such as "when"16 * @param defaultAffixes if the test style recommends test affixes by default, such as BehaviorSpec17 */18data class TestName(19 val testName: String,20 val focus: Boolean,21 val bang: Boolean,22 val prefix: String?,23 val suffix: String?,24 val defaultAffixes: Boolean,25) {26 companion object {27 operator fun invoke(name: String): TestName = TestName(null, name, null, false)28 operator fun invoke(prefix: String?, name: String, defaultAffixes: Boolean): TestName =29 TestName(prefix, name, null, defaultAffixes)30 operator fun invoke(31 prefix: String?,32 name: String,33 suffix: String?,34 defaultAffixes: Boolean,35 ): TestName {36 val trimmed = name.removeAllExtraWhitespaces()37 val (focus, bang, parsedName) = when {38 trimmed.startsWith("!") -> Triple(first = false, second = true, third = trimmed.drop(1).trim())39 trimmed.startsWith("f:") -> Triple(first = true, second = false, third = trimmed.drop(2).trim())40 else -> Triple(first = false, second = false, third = trimmed)41 }42 return TestName(parsedName, focus, bang, prefix, suffix, defaultAffixes)43 }44 }45 init {46 require(testName.isNotBlank() && testName.isNotEmpty()) { "Cannot create test with blank or empty name" }47 require(!focus || !bang) { "Bang and focus cannot both be true" }48 }49}50private fun String.removeAllExtraWhitespaces() = this.split(Regex("\\s")).filterNot { it == "" }.joinToString(" ")...

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.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in TestName

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful