dave08
10/17/2023, 1:47 PMval validateInstallActionList = dev.nesk.akkurate.Validator<List<InstallAction>> {
// ....?
}
(notice that Intellij had troubles importing Validator
...?)Johann Pardanaud
10/17/2023, 1:54 PMJohann Pardanaud
10/17/2023, 1:54 PMJohann Pardanaud
10/17/2023, 1:56 PMval validateInstallActionList = Validator<List<InstallAction>> {
// ....?
}
to force the import, put everything after Validator
in comment:
val validateInstallActionList = Validator /* <List<InstallAction>> {
// ....?
} */
then you will be able to use automatic import 😅dave08
10/17/2023, 1:58 PMdave08
10/17/2023, 1:59 PMJohann Pardanaud
10/17/2023, 2:03 PMdave08
10/17/2023, 2:06 PMdave08
10/17/2023, 3:16 PMval validateInstallActionList = Validator<InstallAction> {
// ....?
}.forList()
validateInstallActionList.any(someResultList)
validateInstallActionList.contains(someResultList, expectedToHaveTheseEntries)
// etc...
Johann Pardanaud
10/17/2023, 3:44 PMInstallAction
? A sealed class/interface? An enum? Something else?
What do you want to assert on this value? Its equality to something else?Johann Pardanaud
10/17/2023, 3:45 PMInstallAction
?dave08
10/17/2023, 3:45 PMJohann Pardanaud
10/17/2023, 3:45 PMJohann Pardanaud
10/17/2023, 3:46 PMdave08
10/18/2023, 8:55 AMany
would be any elements fulfill the criteria and would result in success.
But now I'm rethinking things that in the context of ValidationResult what would be returned? It could be more practical to have some kind of result like Arrow's Ior.Both<Success.., Error...> in the case that some passed the validations and others didn't.
That's moving away from the unit tests use case, but I agree that the main purpose of this library is validation and not assertions for unit tests...
I'm still not sure how that would help in certain things in my case, though. But it might still be a good idea for the library.Johann Pardanaud
10/18/2023, 9:16 AMany
. However, you can this manually by creating a custom constraint, but this is probably not what you're searching for.dave08
10/18/2023, 9:21 AMforList()
could maybe turn Validator<InstallAction>
to some kind of Validator.List<InstallAction>
which could have special constraints for lists, that could be done for Maps or even Iteration (to include sets). Wouldn't this maybe be useful in the validation context too? There's also lists coming from dbs... and validation failures could encompass multiple entries, and some might also have no problems... this could allow to return exactly what was wrong and what was right.Johann Pardanaud
10/18/2023, 9:23 AMValidator.List
would provide? Do you have some examples?dave08
10/18/2023, 9:27 AMassertions
module...😉)dave08
10/18/2023, 9:50 AMJohann Pardanaud
10/18/2023, 10:12 PMval validate = Validator<List<String>> {
each { isNotEmpty() }
}
val strings = listOf("foo", "", "bar")
when (val result = validate(strings)) {
is ValidationResult.Success -> TODO()
is ValidationResult.Failure -> result.violations.forEach(::println)
}
It prints: ConstraintViolation(message='Must not be empty', path=[1])
, you can see the path is a list containing 1
, then you know the second element did not match the constraint.Johann Pardanaud
10/18/2023, 10:13 PMOne potentially good validation could be if there's no duplicates in the listGood idea! I was about to answer back "use a `Set`" but it might not be possible sometimes. I'm adding it to the roadmap 🙂