-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract some stuff to make things more readable in the actual tests
- Loading branch information
Showing
2 changed files
with
160 additions
and
135 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
core/src/integration/kotlin/io/github/serpro69/kfaker/AbstractIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package io.github.serpro69.kfaker | ||
|
||
import io.github.serpro69.kfaker.provider.FakeDataProvider | ||
import io.github.serpro69.kfaker.provider.Money | ||
import io.github.serpro69.kfaker.provider.misc.RandomProvider | ||
import io.github.serpro69.kfaker.provider.misc.StringProvider | ||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.core.spec.style.scopes.DescribeSpecContainerScope | ||
import kotlin.reflect.KFunction | ||
import kotlin.reflect.KProperty | ||
import kotlin.reflect.KVisibility | ||
import kotlin.reflect.full.declaredMemberFunctions | ||
import kotlin.reflect.full.declaredMemberProperties | ||
import kotlin.reflect.full.isSubtypeOf | ||
import kotlin.reflect.full.starProjectedType | ||
|
||
abstract class AbstractIT : DescribeSpec { | ||
|
||
private constructor() : super() | ||
|
||
constructor(body: DescribeSpec.(AbstractIT) -> Unit) : super({ body(this, object : AbstractIT() {}) }) | ||
|
||
init { | ||
assertSoftly = true | ||
} | ||
|
||
val duplicatedValues = listOf( | ||
"Tiger! Tiger!", // book#title | ||
"Girls Girls", // kPop#girlsGroups | ||
"Two Two", // kPop#firstGroups | ||
"woof woof", // creature#dog#sound | ||
"Duran Duran", // rockBand#name | ||
"Li Li", // heroesOfTheStorm#heroes | ||
"Dee Dee", // theFreshPrinceOfBelAir#characters | ||
"Lola Lola", // cannabis#brands | ||
"Hail Hail", // pearlJam#songs | ||
"Help Help", // pearlJam#songs | ||
"Mr. Mr.", // kPop#thirdGroups | ||
"Chitty Chitty Bang Bang", // show#adultMusical | ||
"etc. etc.", // marketing#buzzwords | ||
"Ook Ook", // ventureBros#character | ||
"Mahi Mahi", // food#ingredients | ||
"Cous Cous", // food#ingredients | ||
"Boom Boom", // superMario#characters | ||
"Pom Pom", // superMario#characters | ||
"Min Min", // superSmashBros#fighter | ||
) | ||
|
||
val valuesWithHashKey = listOf( | ||
"A# .NET", // programmingLanguage#name | ||
"A# (Axiom)", // programmingLanguage#name | ||
"C# – ISO/I EC 23270", //programmingLanguage#name | ||
"F#", // programmingLanguage#name | ||
"J#", // programmingLanguage#name | ||
"M#", // programmingLanguage#name | ||
"P#", // programmingLanguage#name | ||
"Q# (Microsoft programming language)", // programmingLanguage#name | ||
"Visual J#", // programmingLanguage#name | ||
"Acoustic #1", // pearlJam#songs | ||
"I am downloading some NP# music.", // michaelScott#quotes | ||
"Cooler #6", // dragonBall#planets | ||
"Cooler #98", // dragonBall#planets | ||
"Cooler #256", // dragonBall#planets | ||
"Frieza #17", // dragonBall#planets | ||
"Frieza #79", // dragonBall#planets | ||
"Frieza #448", // dragonBall#planets | ||
"tL&^J@24CVF=zP46Lxixk`_a#=o6c5", // device#serial | ||
"S#arp", // kPop#firstGroups | ||
) | ||
} | ||
|
||
fun DescribeSpec.`describe all public generators`( | ||
test: suspend DescribeSpecContainerScope.(Faker, KProperty<*>, KFunction<*>) -> Unit | ||
) { | ||
val faker = Faker() | ||
|
||
// Get a list of all publicly visible providers | ||
val providers: List<KProperty<*>> = faker::class.declaredMemberProperties.filter { | ||
it.visibility == KVisibility.PUBLIC | ||
&& it.returnType.isSubtypeOf(FakeDataProvider::class.starProjectedType) | ||
&& it.returnType.classifier != Money::class // Ignore Money provider as it's a special case | ||
&& it.returnType.classifier != StringProvider::class // Ignore String provider | ||
&& it.returnType.classifier != RandomProvider::class // Ignore String provider | ||
} | ||
|
||
// Get a list of all publicly visible functions in each provider | ||
val providerFunctions: GeneratorFunctions = providers.associateBy { provider -> | ||
provider.getter.call(faker)!!::class.declaredMemberFunctions.filter { | ||
it.visibility == KVisibility.PUBLIC && !it.annotations.any { ann -> ann is Deprecated } | ||
} | ||
} | ||
describe("all public functions in each provider") { | ||
providerFunctions.forEach { (functions, provider) -> | ||
functions.forEach { | ||
context("result value for ${provider.name} ${it.name} is resolved correctly") { | ||
test(this, faker, provider, it) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
typealias GeneratorFunctions = Map<List<KFunction<*>>, KProperty<*>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters