How to use startwith class of io.kotest.matchers.collections package

Best Kotest code snippet using io.kotest.matchers.collections.startwith

ExpressionTest.kt

Source:ExpressionTest.kt Github

copy

Full Screen

1/*2* The MIT License (MIT)3*4* Product: Kotlin Expression Builder (DSL)5* Description: A decent expression (Regex) builder written in Kotlin.6*7* Copyright (c) 2017-2022 Steven Agyekum <agyekum@posteo.de>8*9* Permission is hereby granted, free of charge, to any person obtaining a copy of this software10* and associated documentation files (the "Software"), to deal in the Software without restriction,11* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 12* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,13* subject to the following conditions:14*15* The above copyright notice and this permission notice shall be included in all copies16* or substantial portions of the Software.17*18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED19* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,21* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.22*23*/24package com.github.burnett01.expression25import io.kotest.core.spec.style.StringSpec26import io.kotest.matchers.collections.beEmpty27import io.kotest.matchers.should28import io.kotest.matchers.string.endWith29import io.kotest.matchers.string.include30import io.kotest.matchers.string.startWith31import io.kotest.matchers.types.beOfType32import java.lang.StringBuilder33class ExpressionTest : StringSpec({34 val expression = Expression()35 /* INTEGRITY TESTS */36 37 "expression.op should be empty" {38 expression.op should beEmpty()39 }40 "expression.result should be of type <StringBuilder>" {41 expression.result should beOfType(StringBuilder::class)42 }43 "expression.markStart should mark start position" {44 expression.markStart()45 expression.result.toString() should startWith("^")46 }47 "expression.quantity should add quantifier 1 = '?'" {48 expression.quantity(Q.ZERO_OR_ONE)49 expression.result.toString() should endWith("?")50 }51 52 "expression.quantity should add quantifier 3 = '+'" {53 expression.quantity(Q.ONE_OR_MORE)54 expression.result.toString() should endWith("+")55 }56 "expression.markOr should mark 'or' position" {57 expression.markOr()58 expression.result.toString() should endWith("|")59 }60 "expression.range should add range from 0 to 9 | delim = '-'" {61 expression.range(0, 9)62 expression.result.toString() should endWith("[0-9]")63 }64 "expression.setChar should add a character (Char) = 'A'" {65 expression.setChar('A')66 expression.result.toString() should endWith("A")67 }68 "expression.exact should add exact 9" {69 expression.exact(9)70 expression.result.toString() should endWith("{9,9}")71 }72 "expression.setString should add a string (setString) = TestString" {73 expression.setString("TestString")74 expression.result.toString() should endWith("TestString")75 }76 "expression.range should add range from 0 to 9 | delim = ','" {77 expression.range(0, 9, ',')78 expression.result.toString() should endWith("{0,9}")79 }80 81 "expression.setLiteral should add a literal (Char) = '\\%'" {82 expression.setLiteral('%')83 expression.result.toString() should endWith("\\%")84 }85 86 "expression.startMatch should start match class = '['" {87 expression.startMatch()88 expression.result.toString() should endWith("[")89 }90 "expression.range should add range from A to z | delim = '-'" {91 expression.range('A', 'z')92 expression.result.toString() should endWith("A-z")93 }94 "expression.setDigit should add digit class = '\\d'" {95 expression.setDigit()96 expression.result.toString() should endWith("\\d")97 }98 "expression.setWord should add word class = '\\w'" {99 expression.setWord()100 expression.result.toString() should endWith("\\w")101 }102 103 "expression.endMatch should end match class = ']'" {104 expression.endMatch()105 expression.result.toString() should endWith("]")106 }107 "expression.quantity should add quantifier 2 = '*'" {108 expression.quantity(Q.ZERO_OR_MORE)109 expression.result.toString() should endWith("*")110 }111 "expression.startGroup should start capture group (0) = '('" {112 expression.startGroup(0)113 expression.result.toString() should endWith("(")114 }115 116 "expression.endGroup should end capture group (0) = ')'" {117 expression.endGroup()118 expression.result.toString() should endWith(")")119 }120 "expression.startGroup should start non-capture group (1) = '(?:'" {121 expression.startGroup(1)122 expression.result.toString() should endWith("(?:")123 }124 "expression.endGroup should end non-capture group (1) = ')'" {125 expression.endGroup()126 expression.result.toString() should endWith(")")127 }128 "expression.markEnd should mark end position" {129 expression.markEnd()130 expression.result.toString() should endWith("$")131 }132 "expression.compile should be of type <Regex>" {133 expression.compile() should beOfType(Regex::class)134 }135 /* RUNTIME TESTS */136 val date = "20.05.2017"137 val origPatternA = "(\\d{2,2}.\\d{2,2}.\\d{4,4})"138 val origValA = Regex(origPatternA).find(date)!!.value139 140 val runtimeExprA = Expression()141 runtimeExprA.startGroup(0)142 runtimeExprA.setDigit()143 runtimeExprA.exact(2)144 runtimeExprA.setChar('.')145 runtimeExprA.setDigit()146 runtimeExprA.exact(2)147 runtimeExprA.setChar('.')148 runtimeExprA.setDigit()149 runtimeExprA.exact(4)150 runtimeExprA.endGroup()151 "runtimeExprA.compile should compile and return pattern = '$origPatternA'" {152 runtimeExprA.compile()153 .pattern should include(origPatternA)154 }155 "runtimeExprA.compile.matchEntire().value should return origValA = '$date'" {156 runtimeExprA.compile()157 .matchEntire(date)?.value.toString() should include(origValA)158 }159 /* RegexOption TESTS (IGNORE_CASE) */160 val opts: Set<RegexOption> = setOf( RegexOption.IGNORE_CASE )161 val text = "CAtCh Me!"162 val origPatternB = "(Catch me\\!)"163 val origValB = Regex(origPatternB, opts).find(text)!!.value164 165 val runtimeExprB = Expression(opts)166 runtimeExprB.startGroup(0)167 runtimeExprB.setString("Catch me")168 runtimeExprB.setLiteral('!')169 runtimeExprB.endGroup()170 "runtimeExprB.compile should compile and return pattern = '$origPatternB'" {171 runtimeExprB.compile()172 .pattern should include(origPatternB)173 }174 "runtimeExprB.compile.matchEntire().value should return origValB = '$text'" {175 runtimeExprB.compile()176 .matchEntire(text)?.value.toString() should include(origValB)177 }178})...

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

BoardServiceFunSpecSemSpringTest.kt

Source:BoardServiceFunSpecSemSpringTest.kt Github

copy

Full Screen

1package nitrox.org.ktboard.application.service2import com.ninjasquad.springmockk.MockkBean3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.FunSpec5import io.kotest.core.test.TestCase6import io.kotest.extensions.spring.SpringExtension7import io.kotest.matchers.collections.shouldBeIn8import io.kotest.matchers.longs.shouldBeExactly9import io.kotest.matchers.should10import io.kotest.matchers.shouldBe11import io.kotest.matchers.string.startWith12import io.mockk.clearMocks13import io.mockk.every14import io.mockk.junit5.MockKExtension15import io.mockk.verify16import nitrox.org.ktboard.domain.board.Board17import nitrox.org.ktboard.domain.board.Column18import nitrox.org.ktboard.domain.board.Task19import nitrox.org.ktboard.extensions.KBoardFunSpec20import nitrox.org.ktboard.infrastructure.bd.BoardRepositoryJPA21import org.junit.jupiter.api.extension.ExtendWith22import org.springframework.boot.test.context.SpringBootTest23import org.springframework.test.context.junit.jupiter.SpringExtension24import java.time.LocalDateTime25@ExtendWith(MockKExtension::class)26@SpringBootTest27internal class BoardServiceFunSpecSemSpringTest(boardService: BoardService) : FunSpec() {28 override fun extensions() = listOf(SpringExtension)29 @MockkBean30 private lateinit var boardRepository: BoardRepositoryJPA31 override fun beforeTest(testCase: TestCase) {32 clearMocks(boardRepository)33 }34 init {35 test("Arquivar quadros sem colunas").config(invocations = 3) {36 val board = Board(1L, "Projeto X", "Projeto do produto X", LocalDateTime.now())37 every { boardRepository.save(board)} returns board38 every { boardRepository.findByIdOrNull(1L)} returns board39 val resultBoad = boardService.finishBoard(1L)40 verify { boardRepository.save(board) }41 resultBoad!!.id shouldBeExactly board.id42 resultBoad!!.name shouldBe board.name43 }44 test("Arquivar quadros com colunas e sem tarefas") {45 val board = Board(1L, "Projeto X", "Projeto do produto X", LocalDateTime.now())46 val column = Column(1L, "Backlog", LocalDateTime.now())47 board.columns = listOf<Column>(column)48 every { boardRepository.save(board)} returns board49 every { boardRepository.findByIdOrNull(1L)} returns board50 val resultBoad = boardService.finishBoard(1L)51 resultBoad!!.id shouldBeExactly board.id52 resultBoad!!.name shouldBe board.name53 }54 test("Arquivar quadros sem colunas e com tarefas finalizadas").config(invocations = 3) {55 val board = Board(1L, "Projeto X", "Projeto do produto X", LocalDateTime.now())56 val column = Column(1L, "Backlog", LocalDateTime.now())57 board.columns = listOf<Column>(column)58 val finalizedTask = Task(1L, "Contruir serviço x", "contruir serviço necessário",59 LocalDateTime.now(), LocalDateTime.now().plusMonths(1)).apply {60 this.finalized = true61 }62 column.tasks = listOf<Task>(finalizedTask)63 every { boardRepository.save(board)} returns board64 every { boardRepository.findByIdOrNull(1L)} returns board65 val resultBoad = boardService.finishBoard(1L)66 resultBoad!!.id shouldBeExactly board.id67 resultBoad!!.name shouldBe board.name68 finalizedTask shouldBeIn resultBoad.allTasks()69 }70 test("Arquivar quadros sem colunas e com tarefas ativas") {71 val board = Board(1L, "Projeto X", "Projeto do produto X", LocalDateTime.now())72 val column = Column(1L, "Backlog", LocalDateTime.now())73 val activeTask = Task(1L, "Contruir serviço x", "contruir serviço necessário",74 LocalDateTime.now(), LocalDateTime.now().plusMonths(1))75 column.tasks = listOf<Task>(activeTask)76 board.columns = listOf<Column>(column)77 every { boardRepository.findByIdOrNull(1L)} returns board78 val exception = shouldThrow<RuntimeException> {79 boardService.finishBoard(1L)80 }81 verify(exactly = 0) { boardRepository.save(board) }82 exception.message should startWith("Não é possivel arquivar")83 }84 }85}...

Full Screen

Full Screen

startwith.kt

Source:startwith.kt Github

copy

Full Screen

1package io.kotest.matchers.collections2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.should5import io.kotest.matchers.shouldNot6infix fun <T> Iterable<T>.shouldStartWith(element: T) = toList().shouldStartWith(listOf(element))7infix fun <T> Iterable<T>.shouldStartWith(slice: Iterable<T>) = toList().shouldStartWith(slice.toList())8infix fun <T> Iterable<T>.shouldStartWith(slice: Array<T>) = toList().shouldStartWith(slice.asList())9infix fun <T> Array<T>.shouldStartWith(element: T) = asList().shouldStartWith(listOf(element))10infix fun <T> Array<T>.shouldStartWith(slice: Collection<T>) = asList().shouldStartWith(slice)11infix fun <T> Array<T>.shouldStartWith(slice: Array<T>) = asList().shouldStartWith(slice.asList())12infix fun <T> List<T>.shouldStartWith(element: T) = this should startWith(listOf(element))13infix fun <T> List<T>.shouldStartWith(slice: Collection<T>) = this should startWith(slice)14infix fun <T> Iterable<T>.shouldNotStartWith(element: T) = toList().shouldNotStartWith(listOf(element))15infix fun <T> Iterable<T>.shouldNotStartWith(slice: Iterable<T>) = toList().shouldNotStartWith(slice.toList())16infix fun <T> Iterable<T>.shouldNotStartWith(slice: Array<T>) = toList().shouldNotStartWith(slice.asList())17infix fun <T> Array<T>.shouldNotStartWith(element: T) = asList().shouldNotStartWith(listOf(element))18infix fun <T> Array<T>.shouldNotStartWith(slice: Collection<T>) = asList().shouldNotStartWith(slice)19infix fun <T> Array<T>.shouldNotStartWith(slice: Array<T>) = asList().shouldNotStartWith(slice.asList())20infix fun <T> List<T>.shouldNotStartWith(element: T) = this shouldNot startWith(listOf(element))21infix fun <T> List<T>.shouldNotStartWith(slice: Collection<T>) = this shouldNot startWith(slice)22fun <T> startWith(slice: Collection<T>) = object : Matcher<List<T>> {23 override fun test(value: List<T>) =24 MatcherResult(25 value.subList(0, slice.size) == slice,26 { "List should start with ${slice.printed().value} but was ${value.take(slice.size).printed().value}" },27 { "List should not start with ${slice.printed().value}" }28 )29}30infix fun <T> Iterable<T>.shouldEndWith(element: T) = toList().shouldEndWith(listOf(element))31infix fun <T> Iterable<T>.shouldEndWith(slice: Iterable<T>) = toList().shouldEndWith(slice.toList())32infix fun <T> Iterable<T>.shouldEndWith(slice: Array<T>) = toList().shouldEndWith(slice.asList())33infix fun <T> Array<T>.shouldEndWith(element: T) = asList().shouldEndWith(listOf(element))34infix fun <T> Array<T>.shouldEndWith(slice: Collection<T>) = asList().shouldEndWith(slice)35infix fun <T> Array<T>.shouldEndWith(slice: Array<T>) = asList().shouldEndWith(slice.asList())36infix fun <T> List<T>.shouldEndWith(element: T) = this.shouldEndWith(listOf(element))37infix fun <T> List<T>.shouldEndWith(slice: Collection<T>) = this should endWith(slice)38infix fun <T> List<T>.shouldEndWith(slice: Array<T>) = this.shouldEndWith(slice.toList())39infix fun <T> Iterable<T>.shouldNotEndWith(element: T) = toList().shouldNotEndWith(listOf(element))40infix fun <T> Iterable<T>.shouldNotEndWith(slice: Iterable<T>) = toList().shouldNotEndWith(slice.toList())41infix fun <T> Iterable<T>.shouldNotEndWith(slice: Array<T>) = toList().shouldNotEndWith(slice.asList())42infix fun <T> Array<T>.shouldNotEndWith(element: T) = asList().shouldNotEndWith(listOf(element))43infix fun <T> Array<T>.shouldNotEndWith(slice: Collection<T>) = asList().shouldNotEndWith(slice)44infix fun <T> Array<T>.shouldNotEndWith(slice: Array<T>) = asList().shouldNotEndWith(slice.asList())45infix fun <T> List<T>.shouldNotEndWith(element: T) = this shouldNot endWith(listOf(element))46infix fun <T> List<T>.shouldNotEndWith(slice: Collection<T>) = this shouldNot endWith(slice)47fun <T> endWith(slice: Collection<T>) = object : Matcher<List<T>> {48 override fun test(value: List<T>) =49 MatcherResult(50 value.subList(value.size - slice.size, value.size) == slice,51 { "List should end with ${slice.printed().value} but was ${value.take(slice.size).printed().value}" },52 { "List should not end with ${slice.printed().value}" }53 )54}...

Full Screen

Full Screen

BoardServiceAnnotationSpecSpringTest.kt

Source:BoardServiceAnnotationSpecSpringTest.kt Github

copy

Full Screen

1package nitrox.org.ktboard.application.service2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.AnnotationSpec4import io.kotest.matchers.collections.shouldBeIn5import io.kotest.matchers.longs.shouldBeExactly6import io.kotest.matchers.should7import io.kotest.matchers.shouldBe8import io.kotest.matchers.string.startWith9import io.mockk.clearMocks10import io.mockk.every11import io.mockk.mockk12import io.mockk.verify13import nitrox.org.ktboard.domain.board.Board14import nitrox.org.ktboard.domain.board.Column15import nitrox.org.ktboard.domain.board.Task16import nitrox.org.ktboard.infrastructure.bd.BoardRepositoryJPA17import java.time.LocalDateTime18internal class BoardServiceAnnotationSpecSpringTest : AnnotationSpec() {19 private lateinit var boardService: BoardService20 private val boardRepository: BoardRepositoryJPA = mockk<BoardRepositoryJPA>()21 @BeforeEach22 fun beforeTest() {23 clearMocks(boardRepository)24 boardService = BoardService(boardRepository)25 }26 @Test27 fun finishBoardWithNoColumns() {28 val board = Board(1L, "Projeto X", "Projeto do produto X", LocalDateTime.now())29 every { boardRepository.save(board)} returns board30 every { boardRepository.findByIdOrNull(1L)} returns board31 val resultBoad = boardService.finishBoard(1L)32 verify { boardRepository.save(board) }33 resultBoad!!.id shouldBeExactly board.id34 resultBoad.name shouldBe board.name35 }36 @Test37 fun finishBoardWithColumnsAndNoTasks() {38 val board = Board(1L, "Projeto X", "Projeto do produto X", LocalDateTime.now())39 val column = Column(1L, "Backlog", LocalDateTime.now())40 board.columns = listOf<Column>(column)41 every { boardRepository.save(board)} returns board42 every { boardRepository.findByIdOrNull(1L)} returns board43 val resultBoad = boardService.finishBoard(1L)44 resultBoad!!.id shouldBeExactly board.id45 resultBoad.name shouldBe board.name46 }47 @Test48 fun finishBoardWithColumnsAndNoActiveTasks() {49 val board = Board(1L, "Projeto X", "Projeto do produto X", LocalDateTime.now())50 val column = Column(1L, "Backlog", LocalDateTime.now())51 val finalizedTask = Task(1L, "Contruir serviço x", "contruir serviço necessário",52 LocalDateTime.now(), LocalDateTime.now().plusMonths(1)).apply {53 this.finalized = true54 }55 column.tasks = listOf<Task>(finalizedTask)56 board.columns = listOf<Column>(column)57 every { boardRepository.save(board)} returns board58 every { boardRepository.findByIdOrNull(1L)} returns board59 val resultBoad = boardService.finishBoard(1L)60 resultBoad!!.id shouldBeExactly board.id61 resultBoad.name shouldBe board.name62 finalizedTask shouldBeIn resultBoad.allTasks()63 }64 @Test65 fun finishBoardWithColumnsAndActiveTasks() {66 val board = Board(1L, "Projeto X", "Projeto do produto X", LocalDateTime.now())67 val column = Column(1L, "Backlog", LocalDateTime.now())68 val activeTask = Task(1L, "Contruir serviço x", "contruir serviço necessário",69 LocalDateTime.now(), LocalDateTime.now().plusMonths(1))70 val finalizedTask = Task(2L, "Contruir serviço y", "contruir serviço necessário",71 LocalDateTime.now(), LocalDateTime.now().plusMonths(1)).apply {72 this.finalized = true73 }74 column.tasks = listOf<Task>(activeTask, finalizedTask)75 board.columns = listOf<Column>(column)76 every { boardRepository.findByIdOrNull(1L)} returns board77 val exception = shouldThrow<RuntimeException> {78 boardService.finishBoard(1L)79 }80 verify(exactly = 0) { boardRepository.save(board) }81 exception.message should startWith("Não é possivel arquivar")82 }83}...

Full Screen

Full Screen

StartWithEndWithTest.kt

Source:StartWithEndWithTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.collections2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.WordSpec4import io.kotest.matchers.collections.endWith5import io.kotest.matchers.collections.shouldEndWith6import io.kotest.matchers.collections.shouldNotEndWith7import io.kotest.matchers.collections.shouldNotStartWith8import io.kotest.matchers.collections.shouldStartWith9import io.kotest.matchers.collections.startWith10import io.kotest.matchers.should11import io.kotest.matchers.throwable.shouldHaveMessage12class StartWithEndWithTest : WordSpec() {13 init {14 "startWith" should {15 "test that a list starts with the given collection" {16 val col = listOf(1, 2, 3, 4, 5)17 col.shouldStartWith(listOf(1))18 col.shouldStartWith(listOf(1, 2))19 col.shouldNotStartWith(listOf(2, 3))20 col.shouldNotStartWith(listOf(4, 5))21 col.shouldNotStartWith(listOf(1, 3))22 }23 "print errors unambiguously" {24 shouldThrow<AssertionError> {25 listOf(1L, 2L) should startWith(listOf(1L, 3L))26 }.shouldHaveMessage("List should start with [1L, 3L] but was [1L, 2L]")27 }28 "print errors unambiguously when the actual value is empty" {29 shouldThrow<AssertionError> {30 emptyList<Long>() should startWith(listOf(1L, 3L))31 }.shouldHaveMessage("List should start with [1L, 3L] but was []")32 }33 }34 "endWith" should {35 "test that a list ends with the given collection" {36 val col = listOf(1, 2, 3, 4, 5)37 col.shouldEndWith(listOf(5))38 col.shouldEndWith(listOf(4, 5))39 col.shouldNotEndWith(listOf(2, 3))40 col.shouldNotEndWith(listOf(3, 5))41 col.shouldNotEndWith(listOf(1, 2))42 }43 "print errors unambiguously" {44 shouldThrow<AssertionError> {45 listOf(1L, 2L, 3L, 4L) should endWith(listOf(1L, 3L))46 }.shouldHaveMessage("List should end with [1L, 3L] but was [3L, 4L]")47 }48 "print errors unambiguously when the actual value is empty" {49 shouldThrow<AssertionError> {50 emptyList<Long>() should endWith(listOf(1L, 3L))51 }.shouldHaveMessage("List should end with [1L, 3L] but was []")52 }53 }54 }55}...

Full Screen

Full Screen

ParserTest.kt

Source:ParserTest.kt Github

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2import io.kotest.matchers.be3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.comparables.shouldBeEqualComparingTo5import io.kotest.matchers.maps.shouldContain6import io.kotest.matchers.maps.shouldNotContainKey7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldNot10import io.kotest.matchers.string.endWith11import io.kotest.matchers.string.shouldNotContain12import io.kotest.matchers.string.startWith13import io.kotest.property.Arb14import io.kotest.property.arbitrary.next15import io.kotest.property.arbitrary.string16import io.kotest.property.checkAll17import org.jsoup.Jsoup18import org.jsoup.select.Elements19//TODO("")20class SanitzeHtmlSpec : StringSpec({21 "No soft hypen in replaced characters" {22 val arb = Arb.string()23 arb.checkAll(99000) {24 a ->25 val result = sanitizeHtml(a)26 result shouldNotContain "\u00AD"27 }28 }29 "Specifically trigger soft hypen in previous result" {30 val result = sanitizeHtml("&nbsptestword")31 result shouldNotContain "\u00AD"32 result shouldBe "testword"33 }34 "Strong should be filtered from software" {35 var arb = Arb.string()36 arb.checkAll { a ->37 val word = a + "<strong>" + arb.next()38 val result = sanitizeHtml(word)39 result shouldNotContain "<strong>"40 }41 }42 "Trigger the test in another way" {43 val result = sanitizeHtml("<strong>")44 result shouldNot be("\u00AD")45 result shouldBe ""46 }47})48class ParserTest : StringSpec({49 "C" {50 Model.items["in"] = 1751 Model.filter()52 for(banWord in Model.bansWord) {53 Model.items shouldNotContainKey banWord54 }55 }56})...

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

startwith

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.collections.shouldStartWith2 import io.kotest.matchers.collections.shouldEndWith3 import io.kotest.matchers.collections.shouldContain4 import io.kotest.matchers.collections.shouldContainInOrder5 import io.kotest.matchers.collections.shouldContainAll6 import io.kotest.matchers.collections.shouldContainExactly7 import io.kotest.matchers.collections.shouldContainInAnyOrder8 import io.kotest.matchers.collections.shouldContainInAnyOrder9 import io.kotest.matchers.collections.shouldContainNone10 import io.kotest.matchers.collections.shouldBeEmpty11 import io.kotest.matchers.collections.shouldBeEmpty12 import io.kotest.matchers.collections.shouldHaveSize13 import io.kotest.matchers.collections.shouldBeEmpty14 import io.kotest.matchers.collections.shouldBeEmpty15 import io.kotest.matchers.collections.shouldHaveSize16 import io.kotest.matchers.collections.shouldBeEmpty

Full Screen

Full Screen

startwith

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)2list should startWith(1, 2, 3)3list should startWith(1, 2, 3, 4, 5, 6)4list should startWith(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)5val list = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)6list should endWith(9, 10)7list should endWith(5, 6, 7, 8, 9, 10)8list should endWith(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)9val list = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)10list should containInOrder(1, 2, 3)11list should containInOrder(1, 2, 3, 4, 5, 6)12list should containInOrder(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)13val list = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)14list should containInOrderOnly(1, 2, 3)15list should containInOrderOnly(1, 2, 3, 4, 5, 6)16list should containInOrderOnly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)17val list = listOf(

Full Screen

Full Screen

startwith

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.collections.shouldStartWith2fun main() {3val list = listOf(1, 2, 3, 4)4list shouldStartWith listOf(1, 2)5}6import io.kotest.matchers.collections.shouldEndWith7fun main() {8val list = listOf(1, 2, 3, 4)9list shouldEndWith listOf(3, 4)10}11import io.kotest.matchers.collections.shouldContainInOrder12fun main() {13val list = listOf(1, 2, 3, 4)14list shouldContainInOrder listOf(1, 2, 3)15}16import io.kotest.matchers.collections.shouldContainInOrderOnly17fun main() {18val list = listOf(1, 2, 3, 4)19list shouldContainInOrderOnly listOf(1, 2, 3, 4)20}21import io.kotest.matchers.collections.shouldContainInOrderOnlyNulls22fun main() {23val list = listOf(null, null, null)24list shouldContainInOrderOnlyNulls listOf(null, null, null)25}26import io.kotest.matchers.collections.shouldContainInOrderOnlyElementsOf27fun main() {28val list = listOf(1, 2, 3, 4)29list shouldContainInOrderOnlyElementsOf listOf(1, 2, 3, 4)30}31import io.kotest.matchers.collections.shouldContainInOrderElementsOf32fun main() {33val list = listOf(1, 2, 3, 4)34list shouldContainInOrderElementsOf listOf(1, 2, 3)35}36import

Full Screen

Full Screen

startwith

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, 4, 5)2list should startWith(1, 2, 3)3val list = listOf(1, 2, 3, 4, 5)4list should endWith(4, 5)5val list = listOf(1, 2, 3, 4, 5)6list should containAll(1, 2, 3)7val list = listOf(1, 2, 3, 4, 5)8list should containNone(6, 7, 8)9val list = listOf(1, 2, 3, 4, 5)10list should containExactly(1, 2, 3, 4, 5)11val list = listOf(1, 2, 3, 4, 5)12list should containInOrder(1, 2, 3, 4, 5)13val list = listOf(1, 2, 3, 4, 5)14list should containInOrderOnly(1, 2, 3, 4, 5)15val list = listOf(1, 2, 3, 4, 5)16list should containExactlyInAnyOrder(5, 4, 3, 2,

Full Screen

Full Screen

startwith

Using AI Code Generation

copy

Full Screen

1import io.kotest.assertions.throwables.shouldThrow2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.collections.shouldStartWith4import io.kotest.matchers.collections.startWith5class StartWithTest : StringSpec({6 "should start with" {7 val list = listOf(1, 2, 3)8 list shouldStartWith listOf(1, 2)9 }10 "should start with" {11 val list = listOf(1, 2, 3)12 list should startWith(listOf(1, 2))13 }14 "should throw exception"{15 val list = listOf(1, 2, 3)16 shouldThrow<AssertionError> {17 list shouldStartWith listOf(2, 3, 4)18 }19 }20})21import io.kotest.assertions.throwables.shouldThrow22import io.kotest.core.spec.style.StringSpec23import io.kotest.matchers.collections.shouldEndWith24import io.kotest.matchers.collections.endWith25class EndWithTest : StringSpec({26 "should end with" {27 val list = listOf(1, 2, 3)28 list shouldEndWith listOf(2, 3)29 }30 "should end with" {31 val list = listOf(1, 2, 3)32 list should endWith(listOf(2, 3))33 }34 "should throw exception"{35 val list = listOf(1, 2, 3)36 shouldThrow<AssertionError> {37 list shouldEndWith listOf(2, 3, 4)38 }39 }40})41The endWith() function returns true if the given collection ends with the elements of

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 methods in startwith

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful