run.qontract.core.pattern.LookupRowPattern.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qontract-core Show documentation
Show all versions of qontract-core Show documentation
A Contract Testing Tool that leverages Gherkin to describe APIs in a human readable and machine enforceable manner
package run.qontract.core.pattern
import run.qontract.core.Resolver
import run.qontract.core.Result
import run.qontract.core.value.EmptyString
import run.qontract.core.value.Value
data class LookupRowPattern(override val pattern: Pattern, override val key: String? = null) : Pattern, Keyed {
override fun equals(other: Any?): Boolean = other is LookupRowPattern && resolvedHop(other.pattern, Resolver()) == resolvedHop(pattern, Resolver())
override fun hashCode(): Int = pattern.hashCode()
override fun matches(sampleData: Value?, resolver: Resolver): Result =
resolver.matchesPattern(key, pattern, sampleData ?: EmptyString)
override fun generate(resolver: Resolver): Value = when(key){
null -> pattern.generate(resolver)
else -> resolver.generate(key, pattern)
}
override fun newBasedOn(row: Row, resolver: Resolver): List {
return when(key) {
null -> pattern.newBasedOn(row, resolver)
else -> newBasedOn(row, key, pattern, resolver)
}
}
override fun parse(value: String, resolver: Resolver): Value = pattern.parse(value, resolver)
override fun encompasses(otherPattern: Pattern, thisResolver: Resolver, otherResolver: Resolver, typeStack: TypeStack): Result {
return pattern.encompasses(resolvedHop(otherPattern, otherResolver), thisResolver, otherResolver, typeStack)
}
override fun listOf(valueList: List, resolver: Resolver): Value {
return pattern.listOf(valueList, resolver)
}
override val typeAlias: String? = pattern.typeAlias
override fun patternSet(resolver: Resolver): List = pattern.patternSet(resolver)
override val typeName: String = pattern.typeName
}