Skip to content

Commit

Permalink
BREAKING: Remove ValidationBuilder.has (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoepelman authored Nov 11, 2024
1 parent 52ed85e commit d921b3a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
2 changes: 0 additions & 2 deletions api/konform.api
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public final class io/konform/validation/ValidationBuilder {
public fun <init> ()V
public final fun addConstraint (Ljava/lang/String;[Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lio/konform/validation/Constraint;
public final fun build ()Lio/konform/validation/Validation;
public final fun getHas (Lkotlin/reflect/KFunction;)Lio/konform/validation/ValidationBuilder;
public final fun getHas (Lkotlin/reflect/KProperty1;)Lio/konform/validation/ValidationBuilder;
public final fun hint (Lio/konform/validation/Constraint;Ljava/lang/String;)Lio/konform/validation/Constraint;
public final fun ifPresent (Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)V
public final fun ifPresent (Lkotlin/reflect/KFunction;Lkotlin/jvm/functions/Function1;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ public class ValidationBuilder<T> {
"'$name' is not a valid kotlin identifier or getter name."
}

public val <R> KProperty1<T, R>.has: ValidationBuilder<R>
get() = toPropKey(name, NonNull).getOrCreateBuilder()
public val <R> KFunction1<T, R>.has: ValidationBuilder<R>
get() = toPropKey(name, NonNull).getOrCreateBuilder()

public inline fun <reified SubT : T & Any> ifInstanceOf(init: ValidationBuilder<SubT>.() -> Unit): Unit =
run(IsClassValidation<SubT, T>(SubT::class, required = false, buildWithNew(init)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,6 @@ class ValidationBuilderTest {
"poweruser@".let { assertEquals(1, countErrors(nullableRequiredValidation(it))) }
}

@Test
fun alternativeSyntax() {
val splitDoubleValidation =
Validation<Register> {
Register::password.has.minLength(1)
Register::password.has.maxLength(10)
Register::email.has.matches(".+@.+".toRegex())
}

Register(email = "[email protected]", password = "a").let { assertEquals(Valid(it), splitDoubleValidation(it)) }
Register(
email = "[email protected]",
password = "",
).let { assertEquals(1, countErrors(splitDoubleValidation(it), Register::password)) }
Register(email = "[email protected]", password = "aaaaaaaaaaa").let {
assertEquals(1, countErrors(splitDoubleValidation(it), Register::password))
}
Register(email = "tester@").let { assertEquals(2, countFieldsWithErrors(splitDoubleValidation(it))) }
}

@Test
fun functionAccessorSyntax() {
val splitDoubleValidation =
Expand Down Expand Up @@ -479,7 +459,9 @@ class ValidationBuilderTest {
fun composeValidations() {
val addressValidation =
Validation<Address> {
Address::address.has.minLength(1)
Address::address {
minLength(1)
}
}

val validation =
Expand All @@ -496,7 +478,9 @@ class ValidationBuilderTest {
fun replacePlaceholderInString() {
val validation =
Validation<Register> {
Register::password.has.minLength(8)
Register::password {
minLength(8)
}
}
assertTrue(validation(Register(password = ""))[Register::password]!![0].contains("8"))
}
Expand Down

0 comments on commit d921b3a

Please sign in to comment.