Skip to content

Commit

Permalink
Rename excludeFor* functions to excludeFrom{1}
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 committed Dec 13, 2020
1 parent 0288046 commit 4e9403a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* for example `Address::country` for [Address.country]
* @param values values that should not be generated when calling the [providerFunction] in provider [T]
*/
inline fun <reified T : FakeDataProvider> excludeForFunction(providerFunction: KFunction1<T, String>, values: List<String>) {
excludeForFunction<T>(providerFunction.name, values)
inline fun <reified T : FakeDataProvider> excludeFromFunction(providerFunction: KFunction1<T, String>, values: List<String>) {
excludeFromFunction<T>(providerFunction.name, values)
}

/**
Expand All @@ -199,8 +199,8 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* for example `"country"` for [Address.country]
* @param values values that should not be generated when calling the [funcName] function in provider [T]
*/
inline fun <reified T : FakeDataProvider> excludeForFunction(funcName: String, values: List<String>) {
excludeForFunction<T>(funcName, *values.toTypedArray())
inline fun <reified T : FakeDataProvider> excludeFromFunction(funcName: String, values: List<String>) {
excludeFromFunction<T>(funcName, *values.toTypedArray())
}

/**
Expand All @@ -211,7 +211,7 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* for example `"country"` for [Address.country]
* @param values values that should not be generated when calling the [funcName] function in provider [T]
*/
inline fun <reified T : FakeDataProvider> excludeForFunction(funcName: String, vararg values: String) {
inline fun <reified T : FakeDataProvider> excludeFromFunction(funcName: String, vararg values: String) {
if (markedUnique.contains(T::class)) {
usedProviderFunctionValues[T::class]?.merge(funcName, values.toMutableSet()) { oldSet, newSet ->
oldSet.apply { addAll(newSet) }
Expand All @@ -225,8 +225,8 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* @param T an implementation class of [FakeDataProvider], for example [Address]
* @param values values that should not be generated when calling any of the functions in provider [T]
*/
inline fun <reified T : FakeDataProvider> excludeForProvider(values: List<String>) {
excludeForProvider<T>(*values.toTypedArray())
inline fun <reified T : FakeDataProvider> excludeFromProvider(values: List<String>) {
excludeFromProvider<T>(*values.toTypedArray())
}

/**
Expand All @@ -235,7 +235,7 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* @param T an implementation class of [FakeDataProvider], for example [Address]
* @param values values that should not be generated when calling any of the functions in provider [T]
*/
inline fun <reified T : FakeDataProvider> excludeForProvider(vararg values: String) {
inline fun <reified T : FakeDataProvider> excludeFromProvider(vararg values: String) {
if (markedUnique.contains(T::class)) {
usedProviderValues[T::class]?.addAll(values.toList())
}
Expand All @@ -247,7 +247,7 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* @param T an implementation class of [FakeDataProvider], for example [Address]
* @param patterns a function that does not take any arguments and returns a [List] of [Regex]es
*/
inline fun <reified T : FakeDataProvider> excludeForProvider(patterns: () -> List<Regex>) {
inline fun <reified T : FakeDataProvider> excludeFromProvider(patterns: () -> List<Regex>) {
if (markedUnique.contains(T::class)) {
providerExclusionPatterns[T::class]?.addAll(patterns.invoke())
}
Expand All @@ -262,11 +262,11 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* for example `Address::country` for [Address.country]
* @param patterns a function that does not take any arguments and returns a [List] of [Regex]es
*/
inline fun <reified T : FakeDataProvider> excludeForFunction(
inline fun <reified T : FakeDataProvider> excludeFromFunction(
providerFunction: KFunction1<T, String>,
patterns: () -> List<Regex>
) {
excludeForFunction<T>(providerFunction.name, patterns)
excludeFromFunction<T>(providerFunction.name, patterns)
}

/**
Expand All @@ -278,8 +278,8 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* for example `Address::country` for [Address.country]
* @param patterns a function that does not take any arguments and returns a [List] of [Regex]es
*/
inline fun <reified T : FakeDataProvider> excludeForFunction(funcName: String, patterns: () -> List<Regex>) {
excludeForFunction<T>(funcName, *patterns.invoke().toTypedArray())
inline fun <reified T : FakeDataProvider> excludeFromFunction(funcName: String, patterns: () -> List<Regex>) {
excludeFromFunction<T>(funcName, *patterns.invoke().toTypedArray())
}

/**
Expand All @@ -291,7 +291,7 @@ class UniqueProviderConfiguration @PublishedApi internal constructor() {
* for example `Address::country` for [Address.country]
* @param patterns [Regex]es to use to exclude generated values
*/
inline fun <reified T : FakeDataProvider> excludeForFunction(funcName: String, vararg patterns: Regex) {
inline fun <reified T : FakeDataProvider> excludeFromFunction(funcName: String, vararg patterns: Regex) {
if (markedUnique.contains(T::class)) {
providerFunctionExclusionPatterns[T::class]?.merge(funcName, patterns.toMutableSet()) { oldSet, newSet ->
oldSet.apply { addAll(newSet) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ class UniqueDataProviderIT : DescribeSpec({
val excludedCountries = listOf(
"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola"
)
faker.unique.configuration { excludeForFunction(Address::country, excludedCountries) }
faker.unique.configuration { excludeFromFunction(Address::country, excludedCountries) }
val newCountries = (0..30).map { faker.address.country() }

val moreExcludedCountries = listOf(
"Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic"
)
faker.unique.configuration { excludeForProvider<Address>(moreExcludedCountries) }
faker.unique.configuration { excludeFromProvider<Address>(moreExcludedCountries) }
val moreCountries = (0..30).map { faker.address.country() }

val excludedCountryCodes = listOf("AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ")
faker.unique.configuration { excludeForProvider<Address>(excludedCountryCodes) }
faker.unique.configuration { excludeFromProvider<Address>(excludedCountryCodes) }
val countryCodes = (0..30).map { faker.address.countryCode() }

it("excluded values through config should not be included in the generation") {
Expand Down Expand Up @@ -177,8 +177,8 @@ class UniqueDataProviderIT : DescribeSpec({
faker.unique.configuration {
// Enable unique generation and exclude by patterns
enable(faker::address) {
excludeForProvider<Address> { listOf(Regex("^A")) }
excludeForFunction(Address::country) { listOf(Regex("^B")) }
excludeFromProvider<Address> { listOf(Regex("^A")) }
excludeFromFunction(Address::country) { listOf(Regex("^B")) }
}
}

Expand Down

0 comments on commit 4e9403a

Please sign in to comment.