All Downloads are FREE. Search and download functionalities are using the official Maven repository.

run.qontract.core.pattern.Examples.kt Maven / Gradle / Ivy

Go to download

A Contract Testing Tool that leverages Gherkin to describe APIs in a human readable and machine enforceable manner

There is a newer version: 0.23.1
Show newest version
package run.qontract.core.pattern

import io.cucumber.messages.Messages
import io.cucumber.messages.Messages.GherkinDocument.Feature.Scenario.Examples
import java.util.*

data class Examples(val columnNames: List = emptyList(), val rows: List = listOf()) {
    val isEmpty: Boolean
        get() = rows.isEmpty()

    companion object {
        fun examplesFrom(examplesList: List): List = examplesList.map { examplesFrom(it) }

        fun examplesFrom(examples: Examples): run.qontract.core.pattern.Examples {
            val columns = getColumnNames(examples)
            val rows = examples.tableBodyList.map { Row(columns, getValues(it)) }

            return Examples(columns, rows)
        }

        private fun getColumnNames(examples: Examples) = getValues(examples.tableHeader)

        private fun getValues(row: Messages.GherkinDocument.Feature.TableRow): ArrayList = ArrayList(row.cellsList.map { it.value })

        private fun getValues(line: String): List {
            val values = " $line ".split("\\|".toRegex()).map { value -> value.trim()}
            return values.drop(1).dropLast(1)
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy