Added input check for MatchIntegerBetween()

This commit is contained in:
Maurice Makaay 2019-06-05 22:21:34 +00:00
parent 3d791233e0
commit c0389283bd
2 changed files with 5 additions and 0 deletions

View File

@ -584,6 +584,9 @@ func MatchSigned(handler TokenHandler) TokenHandler {
// It uses an int64 for checking internally, so you can check values
// ranging from -9223372036854775808 to 9223372036854775807.
func MatchIntegerBetween(min int64, max int64) TokenHandler {
if max < min {
callerPanic(1, "TokenHandler: MatchIntegerBetween definition error at {caller}: max %d must not be < min %d", max, min)
}
digits := MatchSigned(MatchDigits())
return func(t *TokenAPI) bool {
fork := t.Fork()

View File

@ -82,6 +82,8 @@ func TestCombinatorPanics(t *testing.T) {
`TokenHandler: MatchMin definition error at /.*/tokenhandlers_builtin_test\.go:\d+: min must be >= 0`},
{func() { c.Max(-42, parsekit.A.Space) }, true,
`TokenHandler: MatchMax definition error at /.*/tokenhandlers_builtin_test\.go:\d+: max must be >= 0`},
{func() { a.IntegerBetween(10, -10) }, true,
`TokenHandler: MatchIntegerBetween definition error at /.*/tokenhandlers_builtin_test.go:\d+: max -10 must not be < min 10`},
})
}