mirror of
https://github.com/jlengrand/atrium.git
synced 2026-03-10 08:01:19 +00:00
draft multiple parameters
This commit is contained in:
@@ -22,13 +22,13 @@ def createGenerateLogicTask(Project project, String suffix = '') {
|
||||
def identifier = /[a-zA-Z0-9]+/
|
||||
def newLine = /(?:\r\n?|\n)/
|
||||
def newLineAndIndent = /$newLine\s*/
|
||||
def firstTypeParameter = /[A-Z][0-9]?/
|
||||
def firstBound = /(?: : $identifier(?:<.+?>)?\??)?/
|
||||
def firstTypeParameterWithBound = /$firstTypeParameter$firstBound/
|
||||
def firstTypeParameter = /[A-Za-z]+[0-9]?/
|
||||
def optionalBound = /(?: : $identifier(?:<.+?>)?\??)?/
|
||||
def firstTypeParameterWithBound = /$firstTypeParameter$optionalBound/
|
||||
def typeIdentifier = /fun (?:<${firstTypeParameterWithBound}(?:, )?(.*?)> )?($identifier)\((?:$newLineAndIndent)?container: (AssertionContainer<.+?>)/
|
||||
def parameter = /,(?: |$newLineAndIndent)($identifier): ([^:]+?)/
|
||||
def returnType = /(?:$newLineAndIndent)?\)(:.+)/
|
||||
|
||||
|
||||
def patterns = (6..0).collect {
|
||||
def steps = (0..<it * 2).findAll { it % 2 == 0 }
|
||||
new Tuple3<Pattern, String, String>(
|
||||
@@ -46,17 +46,26 @@ def createGenerateLogicTask(Project project, String suffix = '') {
|
||||
def interfaceName = "${type}Assertions"
|
||||
def implValName = "${type}Kt"
|
||||
|
||||
def arr = content.find(/fun <($firstTypeParameter)($firstBound)/) { match, typeParameter, upperBound ->
|
||||
return ["[$typeParameter${upperBound.replace(':', '<:').replace('<*>','[_]')}]", typeParameter]
|
||||
def firstMethod = content.find(/fun <.+?> /)
|
||||
String[] arr
|
||||
String typeParameters
|
||||
if (firstMethod != null) {
|
||||
typeParameters = firstMethod.substring(4, firstMethod.length() - 1)
|
||||
arr = [
|
||||
typeParameters
|
||||
.replaceAll(/ : Any\??/, '')
|
||||
.replaceAll(':', '<:')
|
||||
.replaceAll(/<\*>/,'[_]'),
|
||||
typeParameters.substring(1).find(identifier)
|
||||
]
|
||||
} else {
|
||||
def firstMethodWithoutTp = content.find(/fun $identifier\((?:$newLineAndIndent)?container: AssertionContainer<.+?>/)
|
||||
def a = 'AssertionContainer<'
|
||||
def match = firstMethodWithoutTp.find(/${a}.+?>/)
|
||||
arr = ['', match.substring(a.length(), match.length()-1)]
|
||||
}
|
||||
if (arr == null) {
|
||||
arr = content.find(/fun $identifier\((?:$newLineAndIndent)?container: AssertionContainer<(.+?)>/) { _, fixedType ->
|
||||
return ['', fixedType]
|
||||
}
|
||||
}
|
||||
println("$type arr $arr")
|
||||
|
||||
def (typeParameterList, containerParameter) = arr
|
||||
println("($typeParameterList, $containerParameter) == (${arr[0]}, ${arr[1]}")
|
||||
def classSignature = "class ${type}Logic$typeParameterList(container: AssertionContainer[$containerParameter]) {"
|
||||
String tmp = content
|
||||
.replaceAll("package ${kotlinPackagePath.replace('/','.')}", "package ${packagePath.replace('/', '.')}")
|
||||
@@ -73,8 +82,19 @@ def createGenerateLogicTask(Project project, String suffix = '') {
|
||||
tmp = tmp.replaceAll(triple.first, triple.second + implValName + triple.third)
|
||||
}
|
||||
|
||||
def afterFirstTp = ''
|
||||
if (typeParameters != null) {
|
||||
def firstLength = typeParameters.find(/<$identifier$optionalBound/).length()
|
||||
def length = typeParameters.length()
|
||||
def rest = typeParameters.substring(firstLength + 2 < length ? firstLength + 2 : firstLength, length - 1)
|
||||
if (rest != '') {
|
||||
afterFirstTp = /(?:${rest})?/
|
||||
}
|
||||
}
|
||||
println("$type afterFirst $afterFirstTp")
|
||||
|
||||
String generatedContent = tmp
|
||||
.replaceAll(/(def $identifier)\[\]/, /$1/)
|
||||
.replaceAll(/(def $identifier)\[$afterFirstTp\]/, /$1/)
|
||||
.replaceAll(/ : Any/,'')
|
||||
.replaceAll(/(<|, )in ([A-Z])/, /$1$2/)
|
||||
.replaceAll(/\.\(\)/, '')
|
||||
|
||||
@@ -14,7 +14,7 @@ import kotlin.reflect.KClass
|
||||
import ch.tutteli.atrium.logic.AnyKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class AnyLogic[(container: AssertionContainer[[]) {
|
||||
class AnyLogic[T, T2, T3](container: AssertionContainer[T]) {
|
||||
|
||||
def toBe(expected: T): Assertion = AnyKt.toBe(container, expected)
|
||||
def notToBe(expected: T): Assertion = AnyKt.notToBe(container, expected)
|
||||
|
||||
@@ -11,7 +11,7 @@ import ch.tutteli.atrium.creating.AssertionContainer
|
||||
import ch.tutteli.atrium.logic.CharSequenceKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class CharSequenceLogic[(container: AssertionContainer[[]) {
|
||||
class CharSequenceLogic[T <: CharSequence](container: AssertionContainer[T]) {
|
||||
|
||||
//TODO add with 0.14.0
|
||||
// def containsBuilder(): CharSequenceContains.Builder[T, NoOpSearchBehaviour] = CharSequenceKt.containsBuilder(container)
|
||||
|
||||
@@ -12,7 +12,7 @@ import ch.tutteli.atrium.domain.creating.changers.ExtractedFeaturePostStep
|
||||
import ch.tutteli.atrium.logic.CollectionKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class CollectionLogic[(container: AssertionContainer[[]) {
|
||||
class CollectionLogic[T <: Collection[_]](container: AssertionContainer[T]) {
|
||||
|
||||
def isEmpty(): Assertion = CollectionKt.isEmpty(container)
|
||||
def isNotEmpty(): Assertion = CollectionKt.isNotEmpty(container)
|
||||
|
||||
@@ -11,7 +11,7 @@ import ch.tutteli.atrium.creating.AssertionContainer
|
||||
import ch.tutteli.atrium.logic.ComparableKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class ComparableLogic[(container: AssertionContainer[[]) {
|
||||
class ComparableLogic[T1 <: Comparable[T2], T2](container: AssertionContainer[T1]) {
|
||||
|
||||
def isLessThan[T2](expected: T2): Assertion = ComparableKt.isLessThan(container, expected)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import ch.tutteli.atrium.creating.AssertionContainer
|
||||
import ch.tutteli.atrium.logic.DoubleKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class DoubleLogic[(container: AssertionContainer[,]) {
|
||||
class DoubleLogic(container: AssertionContainer[Double]) {
|
||||
|
||||
def toBeWithErrorTolerance(expected: Double, tolerance: Double): Assertion =
|
||||
DoubleKt.toBeWithErrorTolerance(container, expected, tolerance)
|
||||
|
||||
@@ -13,10 +13,10 @@ import ch.tutteli.atrium.reporting.translating.Translatable
|
||||
import ch.tutteli.atrium.logic.FeatureKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class FeatureLogic[(container: AssertionContainer[[]) {
|
||||
class FeatureLogic[T, TProperty](container: AssertionContainer[T]) {
|
||||
|
||||
//@formatter:off
|
||||
def property[TProperty](property: Function1[T, TProperty]): ExtractedFeaturePostStep[T, TProperty] = FeatureKt.property(container, property)
|
||||
def property(property: Function1[T, TProperty]): ExtractedFeaturePostStep[T, TProperty] = FeatureKt.property(container, property)
|
||||
|
||||
def f0[R](f: Function1[T, R]): ExtractedFeaturePostStep[T, R] = FeatureKt.f0(container, f)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import ch.tutteli.atrium.creating.AssertionContainer
|
||||
import ch.tutteli.atrium.logic.FloatKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class FloatLogic[(container: AssertionContainer[,]) {
|
||||
class FloatLogic(container: AssertionContainer[Float]) {
|
||||
|
||||
def toBeWithErrorTolerance(expected: Float, tolerance: Float): Assertion =
|
||||
FloatKt.toBeWithErrorTolerance(container, expected, tolerance)
|
||||
|
||||
@@ -12,10 +12,10 @@ import kotlin.reflect.KClass
|
||||
import ch.tutteli.atrium.logic.Fun0Kt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class Fun0Logic[(container: AssertionContainer[[]) {
|
||||
class Fun0Logic[TExpected <: Throwable](container: AssertionContainer[TExpected]) {
|
||||
|
||||
|
||||
def toThrow[Expected : Throwable](expectedType: KClass[TExpected]): ChangedSubjectPostStep[*, TExpected] = Fun0Kt.toThrow(container, expectedType)
|
||||
def toThrow(expectedType: KClass[TExpected]): ChangedSubjectPostStep[*, TExpected] = Fun0Kt.toThrow(container, expectedType)
|
||||
|
||||
def notToThrow[T : () => R](): ChangedSubjectPostStep[*, R] = Fun0Kt.notToThrow(container)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import ch.tutteli.atrium.domain.creating.changers.ExtractedFeaturePostStep
|
||||
import ch.tutteli.atrium.logic.IterableLikeKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class IterableLikeLogic[(container: AssertionContainer[[]) {
|
||||
class IterableLikeLogic[T, E](container: AssertionContainer[T]) {
|
||||
|
||||
|
||||
//TODO add with 0.14.0
|
||||
@@ -30,9 +30,9 @@ class IterableLikeLogic[(container: AssertionContainer[[]) {
|
||||
def all[E](converter: (T) => Iterable[E], assertionCreatorOrNull: Expect[E] => Unit): Assertion =
|
||||
IterableLikeKt.all(container, converter, assertionCreatorOrNull)
|
||||
|
||||
def hasNext[E](converter: (T) => Iterable[E]): Assertion = IterableLikeKt.hasNext(container, converter)
|
||||
def hasNext(converter: (T) => Iterable[E]): Assertion = IterableLikeKt.hasNext(container, converter)
|
||||
|
||||
def hasNotNext[E](converter: (T) => Iterable[E]): Assertion = IterableLikeKt.hasNotNext(container, converter)
|
||||
def hasNotNext(converter: (T) => Iterable[E]): Assertion = IterableLikeKt.hasNotNext(container, converter)
|
||||
|
||||
def min[E : Comparable[E]](converter: (T) => Iterable[E]): ExtractedFeaturePostStep[T, E] = IterableLikeKt.min(container, converter)
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import ch.tutteli.atrium.creating.AssertionContainer
|
||||
import ch.tutteli.atrium.logic.IteratorKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class IteratorLogic[(container: AssertionContainer[[]) {
|
||||
class IteratorLogic[E, T <: Iterator[E]](container: AssertionContainer[E]) {
|
||||
|
||||
def hasNext[T : Iterator[E]](): Assertion = IteratorKt.hasNext(container)
|
||||
def hasNotNext[T : Iterator[E]](): Assertion = IteratorKt.hasNotNext(container)
|
||||
def hasNext(): Assertion = IteratorKt.hasNext(container)
|
||||
def hasNotNext(): Assertion = IteratorKt.hasNotNext(container)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import ch.tutteli.atrium.domain.creating.changers.ExtractedFeaturePostStep
|
||||
import ch.tutteli.atrium.logic.ListKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class ListLogic[(container: AssertionContainer[[]) {
|
||||
class ListLogic[E, T <: List[E]](container: AssertionContainer[E]) {
|
||||
|
||||
|
||||
def get[T : List[E]](index: Int): ExtractedFeaturePostStep[T, E] = ListKt.get(container, index)
|
||||
def get(index: Int): ExtractedFeaturePostStep[T, E] = ListKt.get(container, index)
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ import kotlin.reflect.KClass
|
||||
import ch.tutteli.atrium.logic.MapKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class MapLogic[(container: AssertionContainer[[]) {
|
||||
class MapLogic[K, V, T <: Map[out K, V]](container: AssertionContainer[K]) {
|
||||
|
||||
def contains[V, T : Map[out K, V]](keyValuePairs: List[Pair[K, V]]): Assertion = MapKt.contains(container, keyValuePairs)
|
||||
def contains(keyValuePairs: List[Pair[K, V]]): Assertion = MapKt.contains(container, keyValuePairs)
|
||||
|
||||
def containsKeyWithValueAssertions[V, T : Map[out K, V]](valueType: KClass[V], keyValues: List[Pair[K, Expect[V] => Unit]]): Assertion =
|
||||
MapKt.containsKeyWithValueAssertions(container, valueType, keyValues)
|
||||
@@ -28,7 +28,7 @@ class MapLogic[(container: AssertionContainer[[]) {
|
||||
def isEmpty(): Assertion = MapKt.isEmpty(container)
|
||||
def isNotEmpty(): Assertion = MapKt.isNotEmpty(container)
|
||||
|
||||
def getExisting[V, T : Map[out K, V]](key: K): ExtractedFeaturePostStep[T, V] = MapKt.getExisting(container, key)
|
||||
def getExisting(key: K): ExtractedFeaturePostStep[T, V] = MapKt.getExisting(container, key)
|
||||
|
||||
def size(): ExtractedFeaturePostStep[T, Int] = MapKt.size(container)
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ import ch.tutteli.atrium.domain.creating.changers.ExtractedFeaturePostStep
|
||||
import ch.tutteli.atrium.logic.MapEntryKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class MapEntryLogic[(container: AssertionContainer[[]) {
|
||||
class MapEntryLogic[K, V, T <: Map.Entry[K, V]](container: AssertionContainer[K]) {
|
||||
|
||||
def isKeyValue[V, T : Map.Entry[K, V]](key: K, value: V): Assertion =
|
||||
def isKeyValue(key: K, value: V): Assertion =
|
||||
MapEntryKt.isKeyValue(container, key, value)
|
||||
def key[T : Map.Entry[K, *>](): ExtractedFeaturePostStep[T, K] = MapEntryKt.key(container)
|
||||
def value[T : Map.Entry[*, V]](): ExtractedFeaturePostStep[T, V] = MapEntryKt.value(container)
|
||||
|
||||
@@ -11,7 +11,7 @@ import ch.tutteli.atrium.domain.creating.changers.ExtractedFeaturePostStep
|
||||
import ch.tutteli.atrium.logic.PairKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class PairLogic[(container: AssertionContainer[[]) {
|
||||
class PairLogic[K, T <: Pair[K, *>>(container: AssertionContainer[K]) {
|
||||
|
||||
def first[T : Pair[K, *>](): ExtractedFeaturePostStep[T, K] = PairKt.first(container)
|
||||
def second[T : Pair[*, V]](): ExtractedFeaturePostStep[T, V] = PairKt.second(container)
|
||||
|
||||
@@ -12,8 +12,8 @@ import kotlin.reflect.KClass
|
||||
import ch.tutteli.atrium.logic.ThrowableKt
|
||||
import ch.tutteli.atrium.scala2.logic._
|
||||
|
||||
class ThrowableLogic[(container: AssertionContainer[[]) {
|
||||
class ThrowableLogic[TExpected <: Throwable](container: AssertionContainer[TExpected]) {
|
||||
|
||||
|
||||
def cause[Expected : Throwable](expectedType: KClass[TExpected]): ChangedSubjectPostStep[Throwable, TExpected] = ThrowableKt.cause(container, expectedType)
|
||||
def cause(expectedType: KClass[TExpected]): ChangedSubjectPostStep[Throwable, TExpected] = ThrowableKt.cause(container, expectedType)
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@ package ch.tutteli.atrium.logic
|
||||
import ch.tutteli.atrium.assertions.Assertion
|
||||
import ch.tutteli.atrium.creating.AssertionContainer
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
annotation class TypeParametersScala(val c: Int)
|
||||
/**
|
||||
* Collection of assertion functions and builders which are applicable to subjects with a [Comparable] type.
|
||||
*/
|
||||
@TypeParametersScala(2)
|
||||
interface ComparableAssertions {
|
||||
fun <T1 : Comparable<T2>, T2 : Any?> isLessThan(container: AssertionContainer<T1>, expected: T2): Assertion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user