How to use Values class of io.kotest.matchers.string package

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

FakerServiceTest.kt

Source:FakerServiceTest.kt Github

copy

Full Screen

...171 context("secondary key is empty String") {172 val category = fakerService.fetchCategory(CategoryName.ADDRESS)173 val countryByCode = fakerService.getRawValue(category, "postcode_by_state", "")174 it("random value is returned") {175 val rawValues = listOf(176 "350##", "995##", "967##", "850##", "717##", "900##", "800##", "061##", "204##", "198##",177 "322##", "301##", "967##", "832##", "600##", "463##", "510##", "666##", "404##", "701##",178 "042##", "210##", "026##", "480##", "555##", "387##", "650##", "590##", "688##", "898##",179 "036##", "076##", "880##", "122##", "288##", "586##", "444##", "730##", "979##", "186##",180 "029##", "299##", "577##", "383##", "798##", "847##", "050##", "222##", "990##", "247##",181 "549##", "831##"182 )183 rawValues shouldContain countryByCode.value184 }185 }186 context("value type !is Map") {187 val category = fakerService.fetchCategory(CategoryName.ADDRESS)188 it("exception is thrown") {189 shouldThrow<UnsupportedOperationException> {190 fakerService.getRawValue(category, "country", "country")191 }192 }193 it("exception contains message") {194 val exception = shouldThrow<UnsupportedOperationException> {195 fakerService.getRawValue(category, "country", "country")196 }197 exception.message shouldContain "Unsupported type of raw value"...

Full Screen

Full Screen

MainTest.kt

Source:MainTest.kt Github

copy

Full Screen

1import io.kotest.core.spec.style.AnnotationSpec2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.comparables.shouldBeEqualComparingTo5import io.kotest.matchers.maps.shouldContain6import io.kotest.matchers.should7import io.kotest.matchers.shouldBe8import io.kotest.matchers.shouldNot9import io.kotest.matchers.string.endWith10import io.kotest.matchers.string.shouldNotContain11import io.kotest.matchers.string.startWith12import io.kotest.property.Arb13import io.kotest.property.arbitrary.string14import io.kotest.property.checkAll15import org.jsoup.Jsoup16import org.jsoup.select.Elements17class GetListWordsSpec : StringSpec({18 "list should be found" {19 val html : String = """20 <html>21 <div>22 <ul>23 <li>Coffee</li>24 <li>Tea</li>25 <li>IceTea</li>26 </ul>27 </div>28 </html>29 """.trimIndent()30 val elements = Jsoup.parse(html).allElements31 val values = getListWords(elements)32 values shouldContain "Coffee"33 values shouldContain "Tea"34 values shouldContain "IceTea"35 println(values)36 values.size shouldBe 337 }38 "No list within html should return zero words" {39 val html : String = """40 <html>41 <div>42 <ul>43 <blah>Coffee</blah>44 <blah>Tea</blah>45 <blah>IceTea</blah>46 </ul>47 </div>48 </html>49 """.trimIndent()50 val elements = Jsoup.parse(html).allElements51 val values = getListWords(elements)52 values.size shouldBe 053 }54 "empty hmtl string should return zero words" {55 val html : String = ""56 val elements = Jsoup.parse(html).allElements57 val values = getListWords(elements)58 println(values)59 values.size shouldBe 060 }61 "serve no correct element by Jsoup" {62 val html : String = ""63 val elements = Jsoup.parse(html).getElementsByClass("beautiful")64 val values = getListWords(elements)65 println(values)66 values.size shouldBe 067 }68})69class WordFilterSpec : StringSpec({70 "<li> at the beginning should be removed" {71 val filteredWord = filterWord("<li>hello")72 filteredWord shouldNot startWith("<li>")73 }74 "</li> at the end should be remove" {75 val filteredWord = filterWord("hello</li>")76 filteredWord shouldNot endWith("</li>")77 }78 "- should be removed at every position" {79 val filteredWord = filterWord("a-t-a-t")80 filteredWord shouldBe "atat"81 }82 "soft hypen should be removed from word" {83 val filteredWord = filterWord("test\u00ADword")84 filteredWord shouldNotContain "\u00AD"85 filteredWord shouldBe "testword"86 }87 "< should be removed at every position" {88 val filteredWord = filterWord("<abp")89 filteredWord shouldBe "abp"90 }91 "> should be removed at every position" {92 val filteredWord = filterWord("abp>")93 filteredWord shouldBe "abp"94 }95 "<strong> should be removed at the beginning" {96 val filteredWord = filterWord("<strong>Eigenschaften")97 filteredWord shouldNot startWith("<strong>")98 filteredWord shouldBe "eigenschaften"99 }100 "Words should be parsed lowercase" {101 val filterWord = filterWord("AaAaAaAaBbBbBZz")102 filterWord shouldNotContain "A"103 filterWord shouldNotContain "B"104 filterWord shouldNotContain "Z"105 }106 "Should parse all letters lowercase" {107 val arb = Arb.string()108 arb.checkAll { a ->109 val filterWord = filterWord(a)110 for (c in 'A'..'Z') {111 filterWord shouldNotContain c.toString()112 }113 }114 }115})116class AddToModelSpec : AnnotationSpec() {117 fun `Word should be sucessfully added to model`() {118 addWordToModel("test")119 Model.items.keys shouldContain "test"120 }121 fun `Increment should work`() {122 addWordToModel("increment")123 addWordToModel("increment")124 Model.items.keys shouldContain "increment"125 Model.items["increment"] shouldBe 2126 }127 fun `Many Increment should work`() {128 val number = 20129 repeat(number) {130 addWordToModel("many")131 }132 Model.items.keys shouldContain "many"133 Model.items["many"] shouldBe number134 }135 suspend fun `randomized insertion test should work`() {136 val number = 20137 val arb = Arb.string()138 arb.checkAll { a ->139 repeat(number) {140 addWordToModel(a)141 }142 Model.items.keys shouldContain filterWord(a)143 Model.items[filterWord(a)] shouldBe number144 }145 }146 @BeforeEach147 fun clearModel() {148 Model.items = HashMap<String, Int>()149 }150}...

Full Screen

Full Screen

RandomServiceTest.kt

Source:RandomServiceTest.kt Github

copy

Full Screen

1package io.github.serpro69.kfaker2import io.kotest.assertions.assertSoftly3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.DescribeSpec5import io.kotest.matchers.collections.shouldContain6import io.kotest.matchers.shouldBe7import io.kotest.matchers.string.shouldContain8import java.util.*9internal class RandomServiceTest : DescribeSpec({10 describe("RandomService instance") {11 val randomService = RandomService(Random())12 context("calling nextInt(min, max)") {13 val values = List(100) { randomService.nextInt(6..8) }14 it("return value should be within specified range") {15 values.all { it in 6..8 } shouldBe true16 }17 }18 context("calling nextInt(intRange)") {19 val values = List(100) { randomService.nextInt(3..9) }20 it("return value should be within specified range") {21 values.all { it in 3..9 } shouldBe true22 }23 }24 context("calling randomValue<T>(list)") {25 context("list is not empty") {26 val values = List(100) { randomService.nextInt(3..9) }27 val value = randomService.randomValue(values)28 it("return value should be in the list") {29 values shouldContain value30 }31 }32 context("list is empty") {33 val values = listOf<String>()34 it("exception is thrown") {35 shouldThrow<IllegalArgumentException> {36 randomService.randomValue(values)37 }38 }39 }40 context("list contains nulls") {41 val values = listOf(1, 2, 3, null).filter { it == null }42 val value = randomService.randomValue(values)43 it("return value should be in the list") {44 assertSoftly {45 values shouldContain value46 value shouldBe null47 }48 }49 }50 }51 context("calling randomValue<T>(array)") {52 context("array is not empty") {53 val values = Array(100) { randomService.nextInt(3..9) }54 val value = randomService.randomValue(values)55 it("return value should be in the array") {56 values shouldContain value57 }58 }59 context("array is empty") {60 val values = arrayOf<String>()61 it("exception is thrown") {62 shouldThrow<IllegalArgumentException> {63 randomService.randomValue(values)64 }65 }66 }67 context("array contains nulls") {68 val values = arrayOf(1, 2, 3, null).filter { it == null }69 val value = randomService.randomValue(values)70 it("return value should be in the array") {71 assertSoftly {72 values shouldContain value73 value shouldBe null74 }75 }76 }77 }78 context("calling nextChar()") {79 val source = "qwertyuiopasdfghjklzxcvbnm"80 context("upperCase is true") {81 it("random upper-case letter is generated") {82 val letter = randomService.nextLetter(true).toString()83 source.toUpperCase() shouldContain letter84 }85 }86 context("upperCase is false") {87 it("random lower-case letter is generated") {88 val letter = randomService.nextLetter(false).toString()89 source shouldContain letter90 }91 }92 }93 }94})...

Full Screen

Full Screen

MultimapTests.kt

Source:MultimapTests.kt Github

copy

Full Screen

1package com.adidas.mvi2import io.kotest.assertions.assertSoftly3import io.kotest.core.spec.IsolationMode4import io.kotest.core.spec.style.BehaviorSpec5import io.kotest.matchers.collections.shouldBeEmpty6import io.kotest.matchers.collections.shouldContain7import io.kotest.matchers.collections.shouldHaveSize8import io.kotest.matchers.collections.shouldNotContain9import io.kotest.matchers.shouldBe10internal class MultimapTests : BehaviorSpec({11 isolationMode = IsolationMode.InstancePerLeaf12 given("An empty multimap") {13 val multimap = Multimap<String, Int>()14 `when`("I put a value") {15 val entry = multimap.put("Test", 1)16 then("The value should be returned") {17 entry shouldBe MultimapEntry("Test", 1)18 }19 then("The value should be in the map") {20 assertSoftly(multimap["Test"]) {21 shouldHaveSize(1)22 shouldContain(MultimapEntry("Test", 1))23 }24 }25 then("A key should be returned") {26 assertSoftly(multimap.keys) {27 shouldHaveSize(1)28 shouldContain("Test")29 }30 }31 }32 `when`("I try to get a key which has no values") {33 val entries = multimap["NotAdded"]34 then("The entries should be empty") {35 entries.shouldBeEmpty()36 }37 }38 }39 given("A multimap with an already added value") {40 val multimap = Multimap<String, Int>()41 multimap.put("Test", 1)42 `when`("I put another value on the same key") {43 multimap.put("Test", 2)44 then("The other value should be added also") {45 assertSoftly(multimap["Test"]) {46 shouldHaveSize(2)47 shouldContain(MultimapEntry("Test", 2))48 }49 }50 }51 }52 given("A multimap with 2 values added on the same key") {53 val multimap = Multimap<String, Int>()54 multimap.put("Test", 1)55 multimap.put("Test", 2)56 `when`("I remove an entry") {57 multimap.remove(MultimapEntry("Test", 1))58 then("The value should not be returned anymore") {59 assertSoftly(multimap["Test"]) {60 shouldHaveSize(1)61 shouldNotContain(MultimapEntry("Test", 1))62 }63 }64 }65 `when`("I remove all entries") {66 multimap.remove(MultimapEntry("Test", 1))67 multimap.remove(MultimapEntry("Test", 2))68 then("The key should be removed") {69 multimap.keys shouldNotContain "Test"70 }71 }72 }73 given("A filled multimap") {74 val original = Multimap<String, Int>()75 original.put("Test", 1)76 `when`("I copy it and add a value on the original") {77 val copied = original.copy()78 original.put("Test", 2)79 then("The copied should not contain the added value") {80 assertSoftly(copied["Test"]) {81 shouldHaveSize(1)82 shouldNotContain(MultimapEntry("Test", 2))83 }84 }85 }86 `when`("I copy it and remove a value on the original") {87 val copied = original.copy()88 original.remove(MultimapEntry("Test", 1))89 then("The copied should still contain the removed entry") {90 assertSoftly(copied["Test"]) {91 shouldHaveSize(1)92 shouldContain(MultimapEntry("Test", 1))93 }94 }95 }96 }97})...

Full Screen

Full Screen

helloSpec.kt

Source:helloSpec.kt Github

copy

Full Screen

1package playground2import io.kotest.assertions.print.print3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.assertions.withClue5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.matchers.Matcher7import io.kotest.matchers.MatcherResult8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldNot10import io.kotest.matchers.throwable.shouldHaveMessage11import java.time.LocalDate12class HelloSpec : DescribeSpec({13 describe("hello") {14 it("should compare strings") {15 // given:16 val name = "planet"17 // when/then:18 "hello, $name!".shouldBe("hello, world!")19 }20 it("should have a clue and compare strings") {21 withClue("should be string '1'") {22 1.shouldBe("1")23 }24 }25 it("should have exception assertion") {26 shouldThrow<IllegalStateException> {27 error("error message")28 }.shouldHaveMessage("error message")29 }30 it("should format values for assertion error messages") {31 println(1.print())32 println("1".print())33 println(true.print())34 println(null.print())35 println("".print())36 println(listOf(1, 2, 3).print())37 println(listOf(1, 2, listOf(3, 4, listOf(5, 6))).print())38 println(LocalDate.parse("2020-01-02").print())39 data class AvroProduct(val name: String)40 data class Product(val name: String)41 listOf(1, 2).shouldBe(arrayOf(1, 2))42 Product("foo").shouldBe(AvroProduct("foo"))43 }44 it("should use custom matcher") {45 fun containFoo() = object : Matcher<String> {46 override fun test(value: String) = MatcherResult(47 value.contains("foo"),48 { "String '$value' should include 'foo'" },49 { "String '$value' should not include 'foo'" }50 )51 }52 "hello foo".shouldNot(containFoo())53 "hello bar".shouldNot(containFoo())54 }55 }56})57/*58use soft assertions to group assertions.59```60assertSoftly(foo) {61 shouldNotEndWith("b")62 length.shouldBe(3)63}64custom matchers65```66interface Matcher<in T> {67 fun test(value: T): MatcherResult68}69```70*/...

Full Screen

Full Screen

EnvKegListTest.kt

Source:EnvKegListTest.kt Github

copy

Full Screen

...35 val result: List<Int> = parseListFromEnv(envVarName)36 result shouldHaveSize 037 }38 @Test39 fun multipleValuesInList() {40 val values = (0..4).map { Random.nextInt() }41 val envVarName = "multipleIntListVar"42 mockEnvVariable(envVarName, values.joinToString())43 val result: List<Int> = parseListFromEnv(envVarName)44 result shouldHaveSize values.size45 result shouldContainInOrder values46 }47 @Test48 fun brokenValuesInList() {49 val values = listOf(1, 2, 4)50 val envVarName = "brokenIntListVar"51 mockEnvVariable(envVarName, "1,2,whatsup,4")52 val result: List<Int> = parseListFromEnv(envVarName)53 result shouldHaveSize values.size54 result shouldContainInOrder values55 }56 @Test57 fun emptyValuesInList() {58 val values = listOf(1, 2, 4)59 val envVarName = "emptyItemsInIntListVar"60 mockEnvVariable(envVarName, "1,2,,4")61 val result: List<Int> = parseListFromEnv(envVarName)62 result shouldHaveSize values.size63 result shouldContainInOrder values64 }65}...

Full Screen

Full Screen

MyTests.kt

Source:MyTests.kt Github

copy

Full Screen

1import io.kotest.assertions.throwables.shouldThrow2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.collections.shouldBeIn4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.string.startWith7class MyTests : StringSpec({8 "length should return size of string" {9 "hello".length shouldBe 510 }11 "startsWith should test for a prefix" {12 "world" should startWith("wor")13 }14 "check config sizes" {15 val config = GameConfig(2, 1, 1, 5)16 val players = config.create()17 players.size shouldBe config.size18 }19 fun zeroTypeMsgs() = PlayerType.values().map { "No $it" }20 fun wrongNumber() = PlayerType.values().map { "Wrong number of $it" }21 "invalid mafia config sizes" {22 val exception =23 shouldThrow<IllegalStateException> {24 GameConfig(0, 1, 1, 5).create()25 }26 exception.message shouldBeIn zeroTypeMsgs()27 }28 "invalid villager config sizes" {29 val exception =30 shouldThrow<IllegalStateException> {31 GameConfig(2, 1, 1, 0).create()32 }33 exception.message shouldBeIn zeroTypeMsgs()34 }35 "invalid angel config sizes" {36 val exception =37 shouldThrow<IllegalStateException> {38 GameConfig(2, 0, 1, 5).create()39 }40 exception.message shouldBeIn wrongNumber()41 }42 "invalid detective config sizes" {43 val exception =44 shouldThrow<IllegalStateException> {45 GameConfig(2, 1, 0, 5).create()46 }47 exception.message shouldBeIn wrongNumber()48 }49})...

Full Screen

Full Screen

RecordedRequestMatchers.kt

Source:RecordedRequestMatchers.kt Github

copy

Full Screen

...5import io.kotest.matchers.nulls.shouldNotBeNull6import io.kotest.matchers.shouldBe7import okhttp3.mockwebserver.RecordedRequest8internal fun RecordedRequest.shouldHaveQueryParam(key: String, expectedValue: String) {9 requestUrl?.queryParameterValues(key)10 .shouldNotBeNull()11 .shouldHaveSize(1)12 .shouldContain(expectedValue)13}14internal fun RecordedRequest.shouldContainHeaders(headers: Map<String, String>) {15 headers.forEach { (name, expectedValue) ->16 this.getHeader(name).shouldBe(expectedValue)17 }18}19enum class HttpRequestMethod {20 GET, HEAD, PUT, POST, PATCH, DELETE, CONNECT, OPTIONS, TRACE21}22internal fun RecordedRequest.shouldBeHttpMethod(httpMethod: HttpRequestMethod) =23 method.shouldBe(httpMethod.name)...

Full Screen

Full Screen

Values

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.string.Values2 import io.kotest.matchers.string.shouldContain3 import io.kotest.matchers.string.shouldNotContain4 import io.kotest.matchers.string.Values5 import io.kotest.matchers.string.shouldContain6 import io.kotest.matchers.string.shouldNotContain7 import io.kotest.matchers.string.Values8 import io.kotest.matchers.string.shouldContain9 import io.kotest.matchers.string.shouldNotContain10 import io.kotest.matchers.string.Values11 import io.kotest.matchers.string.shouldContain12 import io.kotest.matchers.string.shouldNotContain13 import io.kotest.matchers.string.Values14 import io.kotest.matchers.string.shouldContain15 import io.kotest.matchers.string.shouldNotContain16 import io.kotest.matchers.string.Values17 import io.kotest.matchers.string.shouldContain18 import io.kotest.matchers.string.shouldNotContain19 import io.kotest.matchers.string.Values20 import io.kotest.matchers.string.shouldContain21 import io.kotest.matchers.string.shouldNotContain22 import io.kotest.matchers.string.Values23 import io.kotest.matchers.string.shouldContain24 import io.kotest.matchers.string.shouldNotContain25 import io.kotest.matchers.string.Values26 import io.kotest.matchers.string.shouldContain27 import io.kotest.matchers.string.shouldNotContain28 import io.kotest.matchers.string.Values29 import io.kotest.matchers.string.should

Full Screen

Full Screen

Values

Using AI Code Generation

copy

Full Screen

1str should startWith("Kot")2str should endWith("lin")3str should contain("lin")4str should match("Kot.*")5str should haveLength(6)6str should haveLineCount(1)7str should startWith("Kot")8str should endWith("lin")9str should contain("lin")10str should match("Kot.*")11str should haveLength(6)12str should haveLineCount(1)13str should startWith("Kot")14str should endWith("lin")15str should contain("lin")16str should match("Kot.*")17str should haveLength(6)18str should haveLineCount(1)19str should startWith("Kot")20str should endWith("lin")21str should contain("lin")22str should match("Kot.*")23str should haveLength(6)24str should haveLineCount(1)25str should startWith("Kot")26str should endWith("lin")27str should contain("lin")28str should match("Kot.*")29str should haveLength(6)30str should haveLineCount(1)31str should startWith("Kot")32str should endWith("lin")33str should contain("lin")34str should match("Kot.*")35str should haveLength(6)36str should haveLineCount(1)37str should startWith("Kot")38str should endWith("lin")39str should contain("lin")40str should match("Kot.*")41str should haveLength(6)42str should haveLineCount(1)43str should startWith("Kot")44str should endWith("lin")45str should contain("lin")

Full Screen

Full Screen

Values

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.string.Values2val values = Values("a", "b", "c", "d")3values.shouldContain("a", "d", "c")4import io.kotest.matchers.collections.Values5val values = Values(1, 2, 3, 4)6values.shouldContain(1, 4, 3)7import io.kotest.matchers.booleans.Values8val values = Values(true, false)9values.shouldBeTrue()10values.shouldBeFalse()11import io.kotest.matchers.longs.Values12val values = Values(1L, 2L, 3L, 4L)13values.shouldBeInRange(1L..4L)14values.shouldBeInRange(1L until 4L)15import io.kotest.matchers.ints.Values16val values = Values(1, 2, 3, 4)17values.shouldBeInRange(1..4)18values.shouldBeInRange(1 until 4)19import io.kotest.matchers.floats.Values20val values = Values(1f, 2f, 3f, 4f)21values.shouldBeInRange(1f..4f)22values.shouldBeInRange(1f until 4f)23import io.kotest.matchers.doubles.Values24val values = Values(1.0, 2.0, 3.0, 4.0)25values.shouldBeInRange(1.0..4.0)26values.shouldBeInRange(1.0 until 4.0)27import io.kotest.matchers.bytes.Values28val values = Values(1.toByte(), 2.toByte(), 3.toByte(), 4.toByte())29values.shouldBeInRange(1.toByte()..4.toByte())30values.shouldBeInRange(1.toByte() until 4

Full Screen

Full Screen

Values

Using AI Code Generation

copy

Full Screen

1val values = Values("a", "b", "c")2val result = values.find { it == "d" }3val values = Values("a", "b", "c")4val result = values.find { it == "b" }5val values = Values("a", "b", "c")6val result = values.find { it == "d" }7val values = Values("a", "b", "c")8val result = values.find { it == "b" }9val values = Values("a", "b", "c")10val result = values.find { it == "d" }11val values = Values("a", "b", "c")12val result = values.find { it == "b" }13val values = Values("a", "b", "c")14val result = values.find { it == "d" }15val values = Values("a", "b", "c")16val result = values.find { it == "b" }17val values = Values("a", "b", "c")18val result = values.find { it == "d" }19val values = Values("a", "b", "c")20val result = values.find { it == "b" }21val values = Values("a", "b", "c")22val result = values.find { it == "d" }23println(result)

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful