valiktor icon indicating copy to clipboard operation
valiktor copied to clipboard

hasSize not working as expected

Open 1gravity opened this issue 4 years ago • 0 comments

Is your feature request related to a problem? Please describe.

I used hasSize(100) expecting the validation to be at most 100 characters long which isn't what's happening though. The function is defined as: hasSize(min: Int = Int.MIN_VALUE, max: Int = Int.MAX_VALUE) which translates to hasSize(100, Int.MAX_VALUE).

Describe the solution you'd like

I think there should be a one parameter function hasSize(size: Int) to prevent these misunderstandings and the two parameter function should not have default values for min/max.

  • hasSize(size: Int) -> matches exact size / length
  • hasSize(min: Int, max: Int) -> matches size in [min, max]

Describe alternatives you've considered

To be even clearer with the intention I suggest:

  • hasSize(size: Int) -> matches exact size / length
  • hasSize(range: IntRange) -> matches size defined by IntRange

1gravity avatar Apr 29 '21 13:04 1gravity