How to use containIgnoringCase method of io.kotest.matchers.string.matchers class

Best Kotest code snippet using io.kotest.matchers.string.matchers.containIgnoringCase

StringMatchersTest.kt

Source:StringMatchersTest.kt Github

copy

Full Screen

...9import io.kotest.matchers.string.beBlank10import io.kotest.matchers.string.beEmpty11import io.kotest.matchers.string.contain12import io.kotest.matchers.string.containADigit13import io.kotest.matchers.string.containIgnoringCase14import io.kotest.matchers.string.containOnlyDigits15import io.kotest.matchers.string.containOnlyOnce16import io.kotest.matchers.string.containOnlyWhitespace17import io.kotest.matchers.string.endWith18import io.kotest.matchers.string.haveSameLengthAs19import io.kotest.matchers.string.match20import io.kotest.matchers.string.shouldBeBlank21import io.kotest.matchers.string.shouldBeEmpty22import io.kotest.matchers.string.shouldBeEqualIgnoringCase23import io.kotest.matchers.string.shouldBeInteger24import io.kotest.matchers.string.shouldBeSingleLine25import io.kotest.matchers.string.shouldContain26import io.kotest.matchers.string.shouldContainADigit27import io.kotest.matchers.string.shouldContainIgnoringCase28import io.kotest.matchers.string.shouldContainOnlyDigits29import io.kotest.matchers.string.shouldContainOnlyOnce30import io.kotest.matchers.string.shouldEndWith31import io.kotest.matchers.string.shouldHaveLengthBetween32import io.kotest.matchers.string.shouldHaveLengthIn33import io.kotest.matchers.string.shouldHaveSameLengthAs34import io.kotest.matchers.string.shouldMatch35import io.kotest.matchers.string.shouldNotBeBlank36import io.kotest.matchers.string.shouldNotBeEmpty37import io.kotest.matchers.string.shouldNotBeEqualIgnoringCase38import io.kotest.matchers.string.shouldNotBeSingleLine39import io.kotest.matchers.string.shouldNotContain40import io.kotest.matchers.string.shouldNotContainADigit41import io.kotest.matchers.string.shouldNotContainIgnoringCase42import io.kotest.matchers.string.shouldNotContainOnlyDigits43import io.kotest.matchers.string.shouldNotContainOnlyOnce44import io.kotest.matchers.string.shouldNotEndWith45import io.kotest.matchers.string.shouldNotHaveLengthBetween46import io.kotest.matchers.string.shouldNotHaveLengthIn47import io.kotest.matchers.string.shouldNotHaveSameLengthAs48import io.kotest.matchers.string.shouldNotMatch49class StringMatchersTest : FreeSpec() {50 init {51 "string shouldBe other" - {52 "should support null arguments" {53 val a: String? = "a"54 val b: String? = "a"55 a shouldBe b56 }57 "should report when only line endings differ" {58 forAll(59 row("a\nb", "a\r\nb"),60 row("a\nb\nc", "a\nb\r\nc"),61 row("a\r\nb", "a\nb"),62 row("a\nb", "a\rb"),63 row("a\rb", "a\r\nb")64 ) { expected, actual ->65 shouldThrow<AssertionError> {66 actual shouldBe expected67 }.let {68 it.message shouldContain "contents match, but line-breaks differ"69 }70 }71 }72 "should show diff when newline count differs" {73 shouldThrow<AssertionError> {74 "a\nb" shouldBe "a\n\nb"75 }.message shouldBe """76 |(contents match, but line-breaks differ; output has been escaped to show line-breaks)77 |expected:<a\n\nb> but was:<a\nb>78 """.trimMargin()79 }80 }81 "contain only once" {82 "la tour" should containOnlyOnce("tour")83 "la tour tour" shouldNot containOnlyOnce("tour")84 "la tour tour" shouldNotContainOnlyOnce "tour"85 shouldThrow<AssertionError> {86 "la" should containOnlyOnce("tour")87 }.message shouldBe """"la" should contain the substring "tour" exactly once"""88 shouldThrow<AssertionError> {89 null shouldNot containOnlyOnce("tour")90 }.message shouldBe "Expecting actual not to be null"91 shouldThrow<AssertionError> {92 null shouldNotContainOnlyOnce "tour"93 }.message shouldBe "Expecting actual not to be null"94 shouldThrow<AssertionError> {95 null should containOnlyOnce("tour")96 }.message shouldBe "Expecting actual not to be null"97 shouldThrow<AssertionError> {98 null shouldContainOnlyOnce "tour"99 }.message shouldBe "Expecting actual not to be null"100 }101 "contain(regex)" {102 "la tour" should contain("^.*?tour$".toRegex())103 "la tour" shouldNot contain(".*?abc.*?".toRegex())104 "la tour" shouldContain "^.*?tour$".toRegex()105 "la tour" shouldNotContain ".*?abc.*?".toRegex()106 shouldThrow<AssertionError> {107 "la tour" shouldContain ".*?abc.*?".toRegex()108 }.message shouldBe "\"la tour\" should contain regex .*?abc.*?"109 shouldThrow<AssertionError> {110 "la tour" shouldNotContain "^.*?tour$".toRegex()111 }.message shouldBe "\"la tour\" should not contain regex ^.*?tour\$"112 shouldThrow<AssertionError> {113 null shouldNot contain("^.*?tour$".toRegex())114 }.message shouldBe "Expecting actual not to be null"115 shouldThrow<AssertionError> {116 null shouldNotContain "^.*?tour$".toRegex()117 }.message shouldBe "Expecting actual not to be null"118 shouldThrow<AssertionError> {119 null should contain("^.*?tour$".toRegex())120 }.message shouldBe "Expecting actual not to be null"121 shouldThrow<AssertionError> {122 null shouldContain "^.*?tour$".toRegex()123 }.message shouldBe "Expecting actual not to be null"124 }125 "string should beEmpty()" - {126 "should test that a string has length 0" {127 "" should beEmpty()128 "hello" shouldNot beEmpty()129 "hello".shouldNotBeEmpty()130 "".shouldBeEmpty()131 shouldThrow<AssertionError> {132 "hello".shouldBeEmpty()133 }.message shouldBe "\"hello\" should be empty"134 shouldThrow<AssertionError> {135 "".shouldNotBeEmpty()136 }.message shouldBe "<empty string> should not be empty"137 }138 "should fail if value is null" {139 shouldThrow<AssertionError> {140 null shouldNot beEmpty()141 }.message shouldBe "Expecting actual not to be null"142 shouldThrow<AssertionError> {143 null.shouldNotBeEmpty()144 }.message shouldBe "Expecting actual not to be null"145 shouldThrow<AssertionError> {146 null should beEmpty()147 }.message shouldBe "Expecting actual not to be null"148 shouldThrow<AssertionError> {149 null.shouldBeEmpty()150 }.message shouldBe "Expecting actual not to be null"151 }152 }153 "string should containADigit()" - {154 "should test that a string has at least one number" {155 "" shouldNot containADigit()156 "1" should containADigit()157 "a1".shouldContainADigit()158 "a1b" should containADigit()159 "hello" shouldNot containADigit()160 "hello".shouldNotContainADigit()161 shouldThrow<AssertionError> {162 "hello" should containADigit()163 }.message shouldBe "\"hello\" should contain at least one digit"164 }165 "should fail if value is null" {166 shouldThrow<AssertionError> {167 null shouldNot containADigit()168 }.message shouldBe "Expecting actual not to be null"169 shouldThrow<AssertionError> {170 null.shouldNotContainADigit()171 }.message shouldBe "Expecting actual not to be null"172 shouldThrow<AssertionError> {173 null should containADigit()174 }.message shouldBe "Expecting actual not to be null"175 shouldThrow<AssertionError> {176 null.shouldContainADigit()177 }.message shouldBe "Expecting actual not to be null"178 }179 }180 "string should beBlank()" - {181 "should test that a string has only whitespace" {182 "" should beBlank()183 "" should containOnlyWhitespace()184 " \t " should beBlank()185 "hello" shouldNot beBlank()186 "hello".shouldNotBeBlank()187 " ".shouldBeBlank()188 }189 "should fail if value is null" {190 shouldThrow<AssertionError> {191 null shouldNot beBlank()192 }.message shouldBe "Expecting actual not to be null"193 shouldThrow<AssertionError> {194 null.shouldNotBeBlank()195 }.message shouldBe "Expecting actual not to be null"196 shouldThrow<AssertionError> {197 null should beBlank()198 }.message shouldBe "Expecting actual not to be null"199 shouldThrow<AssertionError> {200 null.shouldBeBlank()201 }.message shouldBe "Expecting actual not to be null"202 }203 }204 "string should haveSameLengthAs(other)" - {205 "should test that a string has the same length as another string" {206 "hello" should haveSameLengthAs("world")207 "hello" shouldNot haveSameLengthAs("o")208 "" should haveSameLengthAs("")209 "" shouldNot haveSameLengthAs("o")210 "5" shouldNot haveSameLengthAs("")211 "" shouldHaveSameLengthAs ""212 "qwe" shouldHaveSameLengthAs "sdf"213 "" shouldNotHaveSameLengthAs "qweqweqe"214 "qe" shouldNotHaveSameLengthAs ""215 "qe" shouldNotHaveSameLengthAs "fffff"216 }217 "should fail if value is null" {218 shouldThrow<AssertionError> {219 null shouldNot haveSameLengthAs("")220 }.message shouldBe "Expecting actual not to be null"221 shouldThrow<AssertionError> {222 null shouldNotHaveSameLengthAs ""223 }.message shouldBe "Expecting actual not to be null"224 shouldThrow<AssertionError> {225 null should haveSameLengthAs("o")226 }.message shouldBe "Expecting actual not to be null"227 shouldThrow<AssertionError> {228 null shouldHaveSameLengthAs "o"229 }.message shouldBe "Expecting actual not to be null"230 }231 }232 "string should containIgnoringCase(other)" - {233 "should test that a string contains another string ignoring case" {234 "hello" should containIgnoringCase("HELLO")235 "hello" shouldNot containIgnoringCase("hella")236 "hello" shouldContainIgnoringCase "HEllO"237 "hello" shouldNotContainIgnoringCase "hella"238 }239 "should fail if value is null" {240 shouldThrow<AssertionError> {241 null shouldNot containIgnoringCase("")242 }.message shouldBe "Expecting actual not to be null"243 shouldThrow<AssertionError> {244 null shouldNotContainIgnoringCase ""245 }.message shouldBe "Expecting actual not to be null"246 shouldThrow<AssertionError> {247 null should containIgnoringCase("o")248 }.message shouldBe "Expecting actual not to be null"249 shouldThrow<AssertionError> {250 null shouldContainIgnoringCase "o"251 }.message shouldBe "Expecting actual not to be null"252 }253 }254 "should containOnlyDigits()" - {255 "should test that a string only contains 0-9" {256 "hello" shouldNot containOnlyDigits()257 "123123" should containOnlyDigits()258 "" should containOnlyDigits()259 "aa123" shouldNot containOnlyDigits()260 "123".shouldContainOnlyDigits()261 "qweqwe123".shouldNotContainOnlyDigits()...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...94 { "${value.show().value} should contain only whitespace" },95 { "${value.show().value} should not contain only whitespace" }96 )97}98infix fun String?.shouldContainIgnoringCase(substr: String) = this should containIgnoringCase(99 substr)100infix fun String?.shouldNotContainIgnoringCase(substr: String) = this shouldNot containIgnoringCase(101 substr)102fun containIgnoringCase(substr: String) = neverNullMatcher<String> { value ->103 MatcherResult(104 value.toLowerCase().indexOf(substr.toLowerCase()) >= 0,105 { "${value.show().value} should contain the substring ${substr.show().value} (case insensitive)" },106 { "${value.show().value} should not contain the substring ${substr.show().value} (case insensitive)" }107 )108}109infix fun String?.shouldContain(regex: Regex) = this should contain(regex)110infix fun String?.shouldNotContain(regex: Regex) = this shouldNot contain(regex)111fun contain(regex: Regex) = neverNullMatcher<String> { value ->112 MatcherResult(113 value.contains(regex),114 { "${value.show().value} should contain regex $regex" },115 { "${value.show().value} should not contain regex $regex" })116}...

Full Screen

Full Screen

LibdocRobotConfigurationTest.kt

Source:LibdocRobotConfigurationTest.kt Github

copy

Full Screen

...7import io.kotest.matchers.nulls.beNull8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNot11import io.kotest.matchers.string.containIgnoringCase12import org.gradle.api.Project13import org.gradle.testfixtures.ProjectBuilder14import org.junit.jupiter.api.DisplayName15import org.junit.jupiter.api.Test16import org.junit.jupiter.api.assertAll17import org.junit.jupiter.api.assertThrows18import org.junit.jupiter.api.fail19import java.io.File20internal class LibdocRobotConfigurationTest : ConfigurationTestBase() {21 private val project: Project = ProjectBuilder.builder().build().also {22 listOf("ALibraryFile.robot", "AResourceFile.resource").forEach { res ->23 this.javaClass.getResource("/$res").openStream().use { iS ->24 var fl = File(it.projectDir, "/src/test/resources")25 fl.mkdirs()26 fl = File(fl, res)27 fl.createNewFile()28 fl.outputStream().use { os ->29 iS.copyTo(os)30 }31 }32 }33 it.pluginManager.apply(PLUGIN_ID)34 }35 private val rfExtension: RobotFrameworkExtension = project.robotframework()36 @Test37 fun `generating default run arguments`() {38 val result = applyConfig { }.generateRunArguments()39 result.size shouldBe 040 }41 @Test42 fun `generate with single relative resource file`() {43 val result = applyConfig {44 it.libraryOrResourceFile = "./src/test/resources/ALibraryFile.robot"45 }.generateRunArguments()46 assertAll(47 { result shouldNot beNull() },48 { result shouldNot beEmpty() },49 { result.first().toArray().toList() should haveElementContains("ALibraryFile.robot") }50 )51 }52 @Test53 fun `generate with single resource file`() {54 val result = applyConfig {55 it.libraryOrResourceFile = "src/test/resources/ALibraryFile.robot"56 }.generateRunArguments()57 assertAll(58 { result shouldNot beNull() },59 { result shouldNot beEmpty() },60 { result.first().toArray().toList() should haveElementContains("ALibraryFile.robot") }61 )62 }63 @Test64 fun `generate with wildcard for lib or resource file`() {65 val result = applyConfig {66 it.libraryOrResourceFile = "src/test/resources/*.robot"67 }.generateRunArguments()68 assertAll(69 { result shouldNot beNull() },70 { result shouldNot beEmpty() },71 { result.first().toArray().toList() should haveElementContains("ALibraryFile.robot") }72 )73 }74 @Test75 fun `generate with folder wildcard for lib or resource file`() {76 val result = applyConfig {77 it.libraryOrResourceFile = "**/resources/*.robot"78 }.generateRunArguments()79 assertAll(80 { result shouldNot beNull() },81 { result shouldNot beEmpty() },82 { result.first().toArray().toList() should haveElementContains("ALibraryFile.robot") }83 )84 }85 @Test86 fun `generate with folder and pattern for lib or resource file`() {87 val result = applyConfig {88 it.libraryOrResourceFile = "src/test/**"89 }.generateRunArguments()90 assertAll(91 { result shouldNot beNull() },92 { result shouldNot beEmpty() },93 { result should haveSize(2) },94 { result[0].toArray().union(result[1].toArray().toList()) should haveElementContains("ALibraryFile.robot") },95 { result[1].toArray().union(result[0].toArray().toList()) should haveElementContains("AResourceFile.resource") }96 )97 }98 @Test99 fun `generate with empty folder for path lib or resource file`() {100 val path = "src/test/empty/"101 val emptyDir = File(project.projectDir.absoluteFile, path)102 if (!emptyDir.mkdirs()) {103 fail("Unable to create directories $emptyDir!")104 }105 val result = applyConfig {106 it.libraryOrResourceFile = path107 }.generateRunArguments()108 assertAll(109 { result shouldNot beNull() },110 { result should beEmpty() }111 )112 }113 @Test114 fun `generate with with nonexisting folder for path lib or resource file should throw exception`() {115 val path = "src/test/notexisting/"116 val ex = assertThrows<IllegalArgumentException> {117 applyConfig {118 it.libraryOrResourceFile = path119 }.generateRunArguments()120 }121 ex.message should containIgnoringCase(path)122 }123 @Test124 fun `generate with class name for library or resource file`() {125 val result = applyConfig {126 it.libraryOrResourceFile = "de.qualersoft.robotframework.gradleplugin.tasks.LibdocTask"127 }.generateRunArguments()128 assertAll(129 { result shouldNot beNull() },130 { result shouldNot beEmpty() },131 { result.first().toArray().toList() should haveElementContains("") }132 )133 }134 @Test135 fun `When libraryOrResourceFile is some strange pattern, an exception is thrown`() {...

Full Screen

Full Screen

containIgnoringCase

Using AI Code Generation

copy

Full Screen

1str should containIgnoringCase("hello")2str should startWithIgnoringCase("hello")3str should endWithIgnoringCase("world")4str should containOnlyDigits()5str should containOnlyLetters()6str should containOnlyLettersOrDigits()7str should containOnlyWhitespace()8str should containOnlyOnce("Hello")9str should containNone("xyz")10str should containAny("xyz")11str should containAll("xyz")12str should containAtLeast(2,"xyz")13str should containAtMost(2,"xyz")14str should containAtLeastOneOf("xyz")

Full Screen

Full Screen

containIgnoringCase

Using AI Code Generation

copy

Full Screen

1message should containIgnoringCase("hello")2message should startWithIgnoringCase("hello")3message should endWithIgnoringCase("hello")4message should matchIgnoringCase("hello")5message should containOnlyDigits()6message should containOnlyLetters()7message should containOnlyLettersOrDigits()8message should containOnlyWhitespace()9message should containNoneOf("world")10message should containAnyOf("world")11message should containAllOf("world")12message should containAtLeastOneOf("world")13message should containAtLeast(1, "world")14message should containExactly(1, "world")15message should containAtMost(1,

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