How to use Arb.Companion.file method of io.kotest.property.arbitrary.file class

Best Kotest code snippet using io.kotest.property.arbitrary.file.Arb.Companion.file

ParseProperty.kt

Source:ParseProperty.kt Github

copy

Full Screen

1package net.torommo.logspy2import io.kotest.core.spec.style.StringSpec3import io.kotest.property.Arb4import io.kotest.property.arbitrary.Codepoint5import io.kotest.property.arbitrary.arbitrary6import io.kotest.property.arbitrary.bind7import io.kotest.property.arbitrary.element8import io.kotest.property.arbitrary.filter9import io.kotest.property.arbitrary.int10import io.kotest.property.arbitrary.map11import io.kotest.property.arbitrary.merge12import io.kotest.property.arbitrary.single13import io.kotest.property.arbitrary.string14import io.kotest.property.checkAll15import kotlin.random.Random16import kotlin.random.nextInt17import kotlin.streams.asSequence18import kotlin.text.CharCategory.DECIMAL_DIGIT_NUMBER19import kotlin.text.CharCategory.LETTER_NUMBER20import kotlin.text.CharCategory.LOWERCASE_LETTER21import kotlin.text.CharCategory.MODIFIER_LETTER22import kotlin.text.CharCategory.OTHER_LETTER23import kotlin.text.CharCategory.TITLECASE_LETTER24import kotlin.text.CharCategory.UPPERCASE_LETTER25import net.torommo.logspy.ExceptionCreationAction.ADD_SUPPRESSED_TO_ROOT_EXCEPTION26import net.torommo.logspy.ExceptionCreationAction.RANDOM_ACTION_ON_RANDOM_SUPPRESSED_IN_ROOT_EXCEPTION27import net.torommo.logspy.ExceptionCreationAction.SET_NEW_ROOT_EXCEPTION28import org.junit.jupiter.api.Assertions.assertDoesNotThrow29import org.slf4j.Logger30import org.slf4j.LoggerFactory31class ParseProperty :32    StringSpec(33        {34            "logger name parsability" {35                checkAll(36                    arbitrary(PositionIndenpendentStringShrinker(1)) { rs ->37                        arbJavaIdentifier.merge(arbKotlinIdentifier).single(rs)38                    }39                ) { loggerName ->40                    val logger = LoggerFactory.getLogger(loggerName)41                    LogstashStdoutSpyProvider().createFor(loggerName)42                        .use {43                            logger.error("Test")44                            assertDoesNotThrow(it::events);45                        }46                }47            }48            "log level parsability" {49                checkAll(arbLevel) { logAction ->50                    val logger = LoggerFactory.getLogger("test")51                    LogstashStdoutSpyProvider().createFor("test")52                        .use {53                            logAction(logger, "Test")54                            assertDoesNotThrow(it::events);55                        }56                }57            }58            "log message parsability" {59                checkAll(60                    arbitrary(PositionIndenpendentStringShrinker()) { rs -> arbMessage.single(rs) }61                ) { message ->62                    val logger = LoggerFactory.getLogger("test")63                    LogstashStdoutSpyProvider().createFor("test")64                        .use {65                            logger.error(message)66                            assertDoesNotThrow(it::events);67                        }68                }69            }70            "exception message parsability" {71                val logger = LoggerFactory.getLogger("test")72                checkAll(73                    arbitrary(PositionIndenpendentStringShrinker()) { rs -> arbMessage.single(rs) }74                ) { message ->75                    LogstashStdoutSpyProvider().createFor("test")76                        .use {77                            val exception = RuntimeException(message)78                            exception.stackTrace = emptyArray()79                            logger.error("test", exception)80                            assertDoesNotThrow(it::events);81                        }82                }83            }84            "stack trace parsability" {85                val logger = LoggerFactory.getLogger("test")86                checkAll(87                    arbitrary(ArrayShrinker()) { rs ->88                        arbKotlinStackTraceElements.merge(arbJavaStackTraceElements).single(rs)89                    }90                ) { element: Array<StackTraceElement> ->91                    LogstashStdoutSpyProvider().createFor("test")92                        .use {93                            val exception = RuntimeException("test message")94                            exception.stackTrace = element95                            logger.error("test", exception)96                            assertDoesNotThrow(it::events);97                        }98                }99            }100            "exception tree parsability" {101                val logger = LoggerFactory.getLogger("test")102                checkAll(arbExceptionTree) { exception: Throwable ->103                    LogstashStdoutSpyProvider().createFor("test")104                        .use {105                            logger.error("test", exception)106                            assertDoesNotThrow(it::events);107                        }108                }109            }110        }111    )112fun Arb.Companion.printableAscii(): Arb<Codepoint> =113    arbitrary(listOf(Codepoint('a'.code))) { rs ->114        val printableChars = (' '.code..'~'.code).asSequence()115        val codepoints = printableChars.map { Codepoint(it) }.toList()116        val ints = Arb.int(codepoints.indices)117        codepoints[ints.sample(rs).value]118    }119fun Arb.Companion.printableMultilinesIndentedAscii(): Arb<Codepoint> =120    arbitrary(listOf(Codepoint('a'.code))) { rs ->121        val indentings = sequenceOf(0xB)122        val endOfLines = sequenceOf(0xA, 0xD)123        val printableChars = (' '.code..'~'.code).asSequence()124        val codepoints = (indentings + endOfLines + printableChars).map { Codepoint(it) }.toList()125        val ints = Arb.int(codepoints.indices)126        codepoints[ints.sample(rs).value]127    }128fun Arb.Companion.unicode(): Arb<Codepoint> =129    arbitrary(listOf(Codepoint('a'.code))) { rs ->130        val ints = Arb.int(Character.MIN_CODE_POINT..Character.MAX_CODE_POINT)131        Codepoint(ints.sample(rs).value)132    }133val arbLevel =134    Arb.element(135        listOf<(Logger, String) -> Unit>(136            Logger::error,137            Logger::warn,138            Logger::info,139            Logger::debug,140            Logger::trace141        )142    )143val arbMessage =144    Arb.string(0, 1024, Arb.printableMultilinesIndentedAscii())145        .merge(Arb.string(0, 1024, Arb.unicode()))146val arbJavaIdentifier =147    Arb.string(minSize = 1, codepoints = Arb.printableAscii())148        .merge(Arb.string(minSize = 1, codepoints = Arb.unicode()))149        .filter { Character.isJavaIdentifierStart(it.codePoints().asSequence().first()) }150        .filter {151            it.codePoints()152                .asSequence()153                .all { codePoint -> Character.isJavaIdentifierPart(codePoint) }154        }155val arbJavaFileName = arbJavaIdentifier.map { "${it}.java" }156val arbJavaStackTraceElement =157    Arb.bind(arbJavaIdentifier, arbJavaIdentifier, arbJavaFileName, Arb.int(-65536, 65535))158        { className, methodName, fileName, lineNumber ->159            StackTraceElement(className, methodName, fileName, lineNumber)160        }161val arbJavaStackTraceElements = Arb.array(arbJavaStackTraceElement, 0..7)162val arbKotlinIdentifier =163    Arb.string(minSize = 1, codepoints = Arb.printableAscii())164        .merge(Arb.string(minSize = 1, codepoints = Arb.unicode()))165        .filter { isUnescapedIdentifier(it) || isEscapedIdentifier(it) }166val arbKotlinFileName = arbKotlinIdentifier.map { "${it}.kt" };167val arbKotlinStackTraceElement =168    Arb.bind(arbKotlinIdentifier, arbKotlinIdentifier, arbKotlinFileName, Arb.int(-65536, 65535))169        { className, methodName, fileName, lineNumber ->170            StackTraceElement(className, methodName, fileName, lineNumber)171        }172val arbKotlinStackTraceElements = Arb.array(arbKotlinStackTraceElement, 0..7)173val arbExceptionTree: Arb<Throwable> =174    arbitrary { rs ->175        val throwableGenerator = arbFlatException.generate(rs).iterator()176        val result = throwableGenerator.next().value177        repeat(rs.random.nextInt(1..7)) {178            val exceptionToPlace = throwableGenerator.next().value179            addExceptionToRandomPlace(rs.random, result, exceptionToPlace)180        }181        result182    }183private fun addExceptionToRandomPlace(random: Random, aggregator: Throwable, addition: Throwable) {184    when (ExceptionCreationAction.values()[random.nextInt(ExceptionCreationAction.values().size)]) {185        SET_NEW_ROOT_EXCEPTION -> {186            rootCauseOf(aggregator).initCause(addition)187        }188        ADD_SUPPRESSED_TO_ROOT_EXCEPTION -> {189            rootCauseOf(aggregator).addSuppressed(addition)190        }191        RANDOM_ACTION_ON_RANDOM_SUPPRESSED_IN_ROOT_EXCEPTION -> {192            val rootCause = rootCauseOf(aggregator)193            if (rootCause.suppressed.isNotEmpty()) {194                addExceptionToRandomPlace(195                    random,196                    rootCause.suppressed[random.nextInt(rootCause.suppressed.size)],197                    addition198                )199            }200        }201    }202}203private tailrec fun rootCauseOf(candidate: Throwable): Throwable {204    return if (candidate.cause == null) {205        candidate206    } else {207        rootCauseOf(candidate.cause!!)208    }209}210private enum class ExceptionCreationAction {211    SET_NEW_ROOT_EXCEPTION,212    ADD_SUPPRESSED_TO_ROOT_EXCEPTION,213    RANDOM_ACTION_ON_RANDOM_SUPPRESSED_IN_ROOT_EXCEPTION214}215val arbFlatException =216    Arb.bind(217        Arb.string(0, 255, Arb.printableMultilinesIndentedAscii()),218        arbKotlinStackTraceElements.merge(arbJavaStackTraceElements)219    ) { message, stackTrace ->220        val result: Exception = RuntimeException(message)221        result.stackTrace = stackTrace222        result223    }224private fun isUnescapedIdentifier(string: String): Boolean {225    return isLetterOrUnderscore(string.first()) &&226        string.toCharArray().all { char -> isLetterOrUnderscore(char) || isUnicodeDigit(char) }227}228private fun isLetterOrUnderscore(char: Char): Boolean {229    return LOWERCASE_LETTER.contains(char) || UPPERCASE_LETTER.contains(char) ||230        TITLECASE_LETTER.contains(char) || LETTER_NUMBER.contains(char) ||231        MODIFIER_LETTER.contains(char) || OTHER_LETTER.contains(char) || char == '_'232}233private fun isUnicodeDigit(char: Char): Boolean {234    return DECIMAL_DIGIT_NUMBER.contains(char)235}236private fun isEscapedIdentifier(string: String): Boolean {237    return string.all { it != '\r' && it != '\n' && it != '`' }238}...

Full Screen

Full Screen

GenHelper.kt

Source:GenHelper.kt Github

copy

Full Screen

1/*2 * Copyright (c) 2020 sparetimedevs and respective authors and developers.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 *     http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.sparetimedevs.pofpaf.test.generator17import arrow.core.Either18import arrow.core.left19import arrow.core.right20import com.microsoft.azure.functions.HttpMethod21import com.sparetimedevs.pofpaf.test.implementation.general.log.Level22import io.kotest.property.Arb23import io.kotest.property.Exhaustive24import io.kotest.property.arbitrary.bool25import io.kotest.property.arbitrary.byte26import io.kotest.property.arbitrary.choice27import io.kotest.property.arbitrary.create28import io.kotest.property.arbitrary.double29import io.kotest.property.arbitrary.element30import io.kotest.property.arbitrary.file31import io.kotest.property.arbitrary.float32import io.kotest.property.arbitrary.int33import io.kotest.property.arbitrary.localDate34import io.kotest.property.arbitrary.localDateTime35import io.kotest.property.arbitrary.localTime36import io.kotest.property.arbitrary.long37import io.kotest.property.arbitrary.map38import io.kotest.property.arbitrary.next39import io.kotest.property.arbitrary.period40import io.kotest.property.arbitrary.short41import io.kotest.property.arbitrary.string42import io.kotest.property.arbitrary.uuid43import io.kotest.property.exhaustive.exhaustive44import java.net.URI45fun Arb.Companion.suspendFunThatReturnsEitherAnyOrAnyOrThrows(): Arb<suspend () -> Either<Any, Any>> =46    choice(47        suspendFunThatReturnsAnyRight(),48        suspendFunThatReturnsAnyLeft(),49        suspendFunThatThrows()50    )51fun Arb.Companion.suspendFunThatReturnsEitherAnyOrUnitOrThrows(): Arb<suspend () -> Either<Any, Unit>> =52    choice(53        suspendFunThatReturnsUnitRight() as Arb<suspend () -> Either<Any, Unit>>,54        suspendFunThatReturnsAnyLeft() as Arb<suspend () -> Either<Any, Unit>>,55        suspendFunThatThrows() as Arb<suspend () -> Either<Any, Unit>>56    )57fun Arb.Companion.suspendFunThatReturnsUnitRight(): Arb<suspend () -> Either<Any, Unit>> =58    unit().map { suspend { it.right() } }59fun Arb.Companion.suspendFunThatReturnsAnyRight(): Arb<suspend () -> Either<Any, Any>> =60    any().map { suspend { it.right() } }61fun Arb.Companion.suspendFunThatReturnsAnyLeft(): Arb<suspend () -> Either<Any, Any>> =62    any().map { suspend { it.left() } }63fun Arb.Companion.suspendFunThatThrows(): Arb<suspend () -> Either<Any, Any>> =64    throwable().map { suspend { throw it } } as Arb<suspend () -> Either<Any, Any>>65fun Arb.Companion.suspendFunThatThrowsFatalThrowable(): Arb<suspend () -> Either<Any, Any>> =66    fatalThrowable().map { suspend { throw it } } as Arb<suspend () -> Either<Any, Any>>67fun Arb.Companion.throwable(): Arb<Throwable> =68    element(69        Exception(),70        RuntimeException(),71        IllegalArgumentException(),72        IllegalStateException(),73        IndexOutOfBoundsException(),74        UnsupportedOperationException(),75        ArithmeticException(),76        NumberFormatException(),77        NullPointerException(),78        ClassCastException(),79        AssertionError(),80        NoSuchElementException(),81        ConcurrentModificationException()82    )83fun Arb.Companion.fatalThrowable(): Arb<Throwable> =84    element(85        MyVirtualMachineError(),86        ThreadDeath(),87        InterruptedException(),88        LinkageError()89    )90class MyVirtualMachineError : VirtualMachineError()91fun Arb.Companion.any(): Arb<Any> =92    choice(93        string() as Arb<Any>,94        int() as Arb<Any>,95        short() as Arb<Any>,96        long() as Arb<Any>,97        float() as Arb<Any>,98        double() as Arb<Any>,99        bool() as Arb<Any>,100        byte() as Arb<Any>,101        uuid() as Arb<Any>,102        file() as Arb<Any>,103        localDate() as Arb<Any>,104        localTime() as Arb<Any>,105        localDateTime() as Arb<Any>,106        period() as Arb<Any>,107        throwable() as Arb<Any>,108        fatalThrowable() as Arb<Any>,109        mapOfStringAndStringGenerator() as Arb<Any>,110        uri() as Arb<Any>,111        httpMethod() as Arb<Any>,112        unit() as Arb<Any>113    )114fun Arb.Companion.unit(): Arb<Unit> =115    create { Unit }116fun Arb.Companion.mapOfStringAndStringGenerator(): Arb<Map<String, String>> =117    element(118        listOf(119            emptyMap(),120            mapOf(121                string().next() to string().next()122            ),123            mapOf(124                string().next() to string().next(),125                string().next() to string().next()126            ),127            mapOf(128                string().next() to string().next(),129                string().next() to string().next(),130                string().next() to string().next()131            ),132            mapOf(133                string().next() to string().next(),134                string().next() to string().next(),135                string().next() to string().next(),136                string().next() to string().next(),137                string().next() to string().next(),138                string().next() to string().next()139            ),140            mapOf(141                string().next() to string().next(),142                string().next() to string().next(),143                string().next() to string().next(),144                string().next() to string().next(),145                string().next() to string().next(),146                string().next() to string().next(),147                string().next() to string().next(),148                string().next() to string().next(),149                string().next() to string().next(),150                string().next() to string().next(),151                string().next() to string().next(),152                string().next() to string().next()153            ),154            mapOf(155                string().next() to string().next(),156                string().next() to string().next(),157                string().next() to string().next(),158                string().next() to string().next(),159                string().next() to string().next(),160                string().next() to string().next(),161                string().next() to string().next(),162                string().next() to string().next(),163                string().next() to string().next(),164                string().next() to string().next(),165                string().next() to string().next(),166                string().next() to string().next(),167                string().next() to string().next(),168                string().next() to string().next(),169                string().next() to string().next(),170                string().next() to string().next(),171                string().next() to string().next(),172                string().next() to string().next(),173                string().next() to string().next(),174                string().next() to string().next(),175                string().next() to string().next(),176                string().next() to string().next(),177                string().next() to string().next(),178                string().next() to string().next()179            )180        )181    )182fun Arb.Companion.uri(): Arb<URI> =183    element(184        listOf(185            URI.create("https://sparetimedevs.com"),186            URI.create("https://www.sparetimedevs.com"),187            URI.create("https://something.sparetimedevs.com"),188            URI.create("https://something.sparetimedevs.com/another/thing"),189            URI.create("https://something.sparetimedevs.com/another/thing?query=param")190        )191    )192fun Arb.Companion.httpMethod(): Arb<HttpMethod> =193    element(194        listOf(195            HttpMethod.GET,196            HttpMethod.HEAD,197            HttpMethod.POST,198            HttpMethod.PUT,199            HttpMethod.DELETE,200            HttpMethod.CONNECT,201            HttpMethod.OPTIONS,202            HttpMethod.TRACE203        )204    )205fun Exhaustive.Companion.logLevel(): Exhaustive<Level> =206    listOf(207        Level.INFO,208        Level.DEBUG,209        Level.WARN,210        Level.ERROR211    ).exhaustive()212fun Arb.Companion.stringOrNull(): Arb<String?> =213    choice(214        string() as Arb<String?>,215        create { null } as Arb<String?>216    )...

Full Screen

Full Screen

EmailTests.kt

Source:EmailTests.kt Github

copy

Full Screen

1/*2 * Copyright 2022 the original author or authors.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 *      https://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.github.hwolf.kvalidation.common17import io.github.hwolf.kvalidation.ConstraintViolation18import io.github.hwolf.kvalidation.PropertyName19import io.github.hwolf.kvalidation.PropertyType20import io.github.hwolf.kvalidation.validate21import io.github.hwolf.kvalidation.validator22import io.kotest.core.spec.style.FunSpec23import io.kotest.datatest.withData24import io.kotest.property.Arb25import io.kotest.property.arbitrary.domain26import io.kotest.property.arbitrary.email27import io.kotest.property.arbitrary.emailLocalPart28import io.kotest.property.arbitrary.map29import io.kotest.property.checkAll30import strikt.api.expectThat31class EmailTests : FunSpec({32    data class EmailBean(val email: String)33    val normalMail = "max.mustermann@muster.de"34    val localMail = "max.mustermann@localhost"35    context("Validate mail") {36        val validator = validator<EmailBean> { EmailBean::email { email() } }37        context("is valid mail") {38            withData(listOf(normalMail)) { mail ->39                val actual = validator.validate(EmailBean(mail))40                expectThat(actual).isValid()41            }42        }43        context("is invalid mail") {44            withData(localMail, "max.mustermann@", "muster.xy") { mail ->45                val actual = validator.validate(EmailBean(mail))46                expectThat(actual).hasViolations(ConstraintViolation(47                    propertyPath = listOf(PropertyName("email")),48                    propertyType = PropertyType("String"),49                    propertyValue = mail,50                    constraint = Email(emptySet())))51            }52        }53        context("random mail is valid") {54            checkAll(Arb.email()) { mail ->55                val actual = validator.validate(EmailBean(mail))56                expectThat(actual).isValid()57            }58        }59        context("random local mail is invalid") {60            checkAll(Arb.emailLocalPart()) { mail ->61                val actual = validator.validate(EmailBean(mail))62                expectThat(actual).not().isValid()63            }64        }65    }66    context("validate local mails") {67        val validator = validator<EmailBean> { EmailBean::email { email(Email.Option.AllowLocal) } }68        context("is valid local mail") {69            withData(normalMail, localMail) { mail ->70                val actual = validator.validate(EmailBean(mail))71                expectThat(actual).isValid()72            }73        }74        context("is invalid local mail") {75            withData("max.mustermann@", "muster.xy") { mail ->76                val actual = validator.validate(EmailBean(mail))77                expectThat(actual).hasViolations(ConstraintViolation(78                    propertyPath = listOf(PropertyName("email")),79                    propertyType = PropertyType("String"),80                    propertyValue = mail,81                    constraint = Email(setOf(Email.Option.AllowLocal))))82            }83        }84        context("random mail is valid") {85            checkAll(Arb.email()) { mail ->86                val actual = validator.validate(EmailBean(mail))87                expectThat(actual).isValid()88            }89        }90        context("random local mail is valid") {91            checkAll(Arb.email(domainGen = Arb.serverName())) { mail ->92                val actual = validator.validate(EmailBean(mail))93                expectThat(actual).isValid()94            }95        }96    }97})98private fun Arb.Companion.serverName() = domain().map { it.substring(0, it.indexOf('.')) }...

Full Screen

Full Screen

InputStreamDecompressingBodyHandlerIntegrationTest.kt

Source:InputStreamDecompressingBodyHandlerIntegrationTest.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2022 Edgar Asatryan3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 *     http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16@file:Suppress("ArrayInDataClass")17package io.github.nstdio.http.ext18import io.kotest.matchers.shouldBe19import io.kotest.property.Arb20import io.kotest.property.arbitrary.map21import io.kotest.property.arbitrary.next22import io.kotest.property.arbitrary.string23import mockwebserver3.MockResponse24import mockwebserver3.MockWebServer25import mockwebserver3.junit5.internal.MockWebServerExtension26import org.junit.jupiter.api.extension.ExtendWith27import org.junit.jupiter.params.ParameterizedTest28import org.junit.jupiter.params.provider.MethodSource29import java.net.http.HttpClient30import java.net.http.HttpRequest31import java.nio.charset.StandardCharsets32@ExtendWith(MockWebServerExtension::class)33internal class InputStreamDecompressingBodyHandlerIntegrationTest(private val mockWebServer: MockWebServer) {34  private val httpClient = HttpClient.newHttpClient()35  @ParameterizedTest36  @MethodSource("compressedData")37  fun shouldCreate(compressedString: CompressedString) {38    //given39    val uri = mockWebServer.url("/data").toUri()40    mockWebServer.enqueue(41      MockResponse()42        .setResponseCode(200)43        .addHeader("Content-Encoding", compressedString.compression)44        .setBody(compressedString.compressed)45    )46    val request = HttpRequest.newBuilder(uri)47      .build()48    //when49    val body = httpClient.send(request, BodyHandlers.ofDecompressing()).body()50    val actual = body.readAllBytes().toString(StandardCharsets.UTF_8)51    //then52    actual shouldBe compressedString.original53  }54  companion object {55    @JvmStatic56    fun compressedData(): List<CompressedString> {57      val stringArb = Arb.string(32..64)58      return listOf(59        stringArb.map { CompressedString(it, "gzip", Compression.gzip(it)) }.next(),60        stringArb.map { CompressedString(it, "deflate", Compression.deflate(it)) }.next()61      )62    }63  }64  internal data class CompressedString(val original: String, val compression: String, val compressed: ByteArray)65}...

Full Screen

Full Screen

identifierGenerator.kt

Source:identifierGenerator.kt Github

copy

Full Screen

1/*2 * Copyright 2021 Oliver Berg3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 *        http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package net.ormr.semver4k17import io.kotest.property.Arb18import io.kotest.property.RandomSource19import io.kotest.property.Sample20import io.kotest.property.arbitrary.Codepoint21import io.kotest.property.arbitrary.element22import io.kotest.property.arbitrary.map23import io.kotest.property.arbitrary.string24import kotlinx.collections.immutable.PersistentList25import kotlinx.collections.immutable.toPersistentList26internal fun Arb.Companion.semVerIdentifier(minParts: Int = 1, maxParts: Int): Arb<Pair<PersistentList<Identifier>, String>> =27    object : Arb<Pair<PersistentList<Identifier>, String>>() {28        override fun edgecase(rs: RandomSource): Pair<PersistentList<Identifier>, String>? = null29        override fun sample(rs: RandomSource): Sample<Pair<PersistentList<Identifier>, String>> {30            // I don't really know what a sensible maxSize would be, even 100 feels a bit large for a semver identifier31            // the system should be able to handle identifiers of any size (as long as the final string isn't larger32            // than what is supported by the JVM)33            val stringArb = Arb.string(minSize = 1, maxSize = 100, codepoints = Codepoint.semVerIdentifier())34            val sequenceSize = rs.random.nextInt(minParts, maxParts + 1)35            val identifiers = stringArb.samples(rs)36                .take(sequenceSize)37                .map { it.value }38                .map { Identifier.of(it) }39                .toPersistentList()40            val identifierTextSequence = identifiers.joinToString(separator = ".")41            return Sample(identifiers to identifierTextSequence)42        }43    }44internal fun Codepoint.Companion.semVerIdentifier(): Arb<Codepoint> =45    Arb.element((('a'..'z') + ('A'..'Z') + ('0'..'9') + '-').toList()).map { Codepoint(it.code) }...

Full Screen

Full Screen

ExecutionContextGenerator.kt

Source:ExecutionContextGenerator.kt Github

copy

Full Screen

1/*2 * Copyright (c) 2020 sparetimedevs and respective authors and developers.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 *     http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.sparetimedevs.pofpaf.test.generator17import com.microsoft.azure.functions.ExecutionContext18import com.microsoft.azure.functions.TraceContext19import io.kotest.property.Arb20import io.kotest.property.arbitrary.bind21import io.kotest.property.arbitrary.create22import io.kotest.property.arbitrary.string23import java.util.logging.Logger24private fun Arb.Companion.traceContextArb(): Arb<TraceContext> =25    bind(26        string(), string(), mapOfStringAndStringGenerator()27    ) { traceParent, traceState, attributes ->28        ExecutionTraceContextTestImpl(traceParent, traceState, attributes)29    }30fun Arb.Companion.executionContextArb(): Arb<ExecutionContext> =31    bind(32        string(), traceContextArb(), create { Logger.getGlobal() }, string()33    ) { invocationId, traceContext, logger, functionName ->34        ExecutionContextTestImpl(invocationId, traceContext, logger, functionName)35    }...

Full Screen

Full Screen

Arb.kt

Source:Arb.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2022 Edgar Asatryan3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 *     http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.github.nstdio.http.ext17import io.kotest.property.Arb18import io.kotest.property.Gen19import io.kotest.property.arbitrary.byte20import io.kotest.property.arbitrary.byteArray21import io.kotest.property.arbitrary.int22import io.kotest.property.arbitrary.map23import java.nio.ByteBuffer24fun Arb.Companion.byteArray(length: Gen<Int>): Arb<ByteArray> = Arb.byteArray(length, Arb.byte())25fun Arb.Companion.byteArray(length: Int): Arb<ByteArray> = Arb.byteArray(Arb.int(length, length))26fun Arb.Companion.byteBuffer(length: Gen<Int>): Arb<ByteBuffer> =27  Arb.byteArray(length).map { ByteBuffer.wrap(it) }28fun Arb.Companion.byteBuffer(length: Int): Arb<ByteBuffer> =29  Arb.byteArray(Arb.int(length, length)).map { ByteBuffer.wrap(it) }...

Full Screen

Full Screen

gen.kt

Source:gen.kt Github

copy

Full Screen

1package com.github.durun.nitron.inout.model2import io.kotest.property.Arb3import io.kotest.property.arbitrary.*4import java.io.File5fun Arb.Companion.code(software: String? = null): Arb<Code> = arbitrary { rs ->6	Code(7			softwareName = software ?: string(1..5).single(rs),8			rawText = string().single(rs),9			normalizedText = string().single(rs),10			range = int().take(2, rs).toList().sorted().let { (from, to) -> from..to }11	)12}13fun Arb.Companion.change(software: String? = null): Arb<Change> = arbitrary { rs ->14	val softwareName = software ?: string(1..5).single(rs)15	val changeType = enum<ChangeType>().single(rs)16	val code = when(changeType) {17		ChangeType.CHANGE -> pair(code(softwareName), code(softwareName)).single(rs)18		ChangeType.ADD -> null to code(softwareName).single(rs)19		ChangeType.DELETE -> code(softwareName).single(rs) to null20	}21	Change(22			softwareName = softwareName,23			filePath = file().map(File::toPath).single(rs),24			author = string(3..10).single(rs),25			beforeCode = code.first,26			afterCode = code.second,27			commitHash = string(40).single(rs),28			date = localDateTime().single(rs),29			changeType = changeType,30			diffType = enum<DiffType>().single(rs)31	)32}...

Full Screen

Full Screen

Arb.Companion.file

Using AI Code Generation

copy

Full Screen

1    val file = Arb.file()2    val files = Arb.files()3    val fileTree = Arb.fileTree()4    val fileTrees = Arb.fileTrees()5    val fileContent = Arb.fileContent()6    val fileContents = Arb.fileContents()7    val fileContentAsString = Arb.fileContentAsString()8    val fileContentsAsString = Arb.fileContentsAsString()9    val fileContentAsLines = Arb.fileContentAsLines()10    val fileContentsAsLines = Arb.fileContentsAsLines()11    val fileContentAsBytes = Arb.fileContentAsBytes()12    val fileContentsAsBytes = Arb.fileContentsAsBytes()13    val fileContentAsBase64 = Arb.fileContentAsBase64()14    val fileContentsAsBase64 = Arb.fileContentsAsBase64()

Full Screen

Full Screen

Arb.Companion.file

Using AI Code Generation

copy

Full Screen

1import io.kotest.property.arbitrary.file2import java.io.File3val fileArb = Arb.file()4import io.kotest.property.arbitrary.file5import java.io.File6val fileArb = Arb.file()7import io.kotest.property.arbitrary.file8import java.io.File9val fileArb = Arb.file()10import io.kotest.property.arbitrary.file11import java.io.File12val fileArb = Arb.file()13import io.kotest.property.arbitrary.file14import java.io.File15val fileArb = Arb.file()16import io.kotest.property.arbitrary.file17import java.io.File18val fileArb = Arb.file()19import io.kotest.property.arbitrary.file20import java.io.File21val fileArb = Arb.file()22import io.kotest.property.arbitrary.file23import java.io.File24val fileArb = Arb.file()25import io.kotest.property.arbitrary.file26import java.io.File27val fileArb = Arb.file()28import io.kotest.property.arbitrary.file29import java.io.File30val fileArb = Arb.file()31import io.kotest.property.arbitrary.file32import java.io.File33val fileArb = Arb.file()34import io.kotest.property.arbitrary.file35import java.io.File36val fileArb = Arb.file()

Full Screen

Full Screen

Arb.Companion.file

Using AI Code Generation

copy

Full Screen

1val arb = Arb.file()2val file = arb.sample()3println(file)4val arb = Arb.files()5val files = arb.sample()6println(files)7val arb = Arb.float()8val float = arb.sample()9println(float)10val arb = Arb.floats()11val floats = arb.sample()12println(floats)13val arb = Arb.floatRange()14val floatRange = arb.sample()15println(floatRange)16val arb = Arb.floatRanges()17val floatRanges = arb.sample()18println(floatRanges)19val arb = Arb.floats()20val floats = arb.sample()21println(floats)22val arb = Arb.floatRange()23val floatRange = arb.sample()24println(floatRange)25val arb = Arb.floatRanges()26val floatRanges = arb.sample()27println(floatRanges)28val arb = Arb.function()29val function = arb.sample()30println(function)31val arb = Arb.functions()32val functions = arb.sample()33println(functions)34val arb = Arb.int()35val int = arb.sample()36println(int)37val arb = Arb.ints()38val ints = arb.sample()39println(ints)40val arb = Arb.intRange()41val intRange = arb.sample()42println(intRange)

Full Screen

Full Screen

Arb.Companion.file

Using AI Code Generation

copy

Full Screen

1import io.kotest.property.Arb2import io.kotest.property.RandomSource3import io.kotest.property.arbitrary.file.FileGenerator4import java.io.File5fun Arb.Companion.file(6): Arb<File> = arb(FileGenerator(minDepth, maxDepth, minSize, maxSize, allowSpecial, allowLinks)) { it.next() }7import io.kotest.property.Arb8import io.kotest.property.RandomSource9import io.kotest.property.arbitrary.file.FileGenerator10import java.io.File11fun Arb.Companion.file(12): Arb<File> = arb(FileGenerator(minDepth, maxDepth, minSize, maxSize, allowSpecial, allowLinks)) { it.next() }13import io.kotest.property.Arb14import io.kotest.property.RandomSource15import io.kotest.property.arbitrary.file.FileGenerator16import java.io.File17fun Arb.Companion.file(18): Arb<File> = arb(FileGenerator(minDepth, maxDepth, minSize, maxSize, allowSpecial, allowLinks)) { it.next() }19import io.kotest.property.A

Full Screen

Full Screen

Arb.Companion.file

Using AI Code Generation

copy

Full Screen

1val arbFile = Arb.file(filename = Arb.string(5..10, Arb.alphanumeric()), content = Arb.string(5..10, Arb.alphanumeric()))2val arbFile = Arb.file(content = Arb.string(5..10, Arb.alphanumeric()))3val arbFile = Arb.file(content = Arb.string(5..10, Arb.alphanumeric()))4val arbFile = Arb.file(content = Arb.string(5..10, Arb.alphanumeric()))5val arbFile = Arb.file(content = Arb.string(5..10, Arb.alphanumeric()))6val arbFile = Arb.file(content = Arb.string(5..10, Arb.alphanumeric()))7val arbFile = Arb.file(content = Arb.string(5..10, Arb.alphanumeric()))8val arbFile = Arb.file(content = Arb.string(5..10, Arb.alphanumeric()))

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