diff --git a/tokenhandlers_builtin.go b/tokenhandlers_builtin.go index f2525d1..becf6aa 100644 --- a/tokenhandlers_builtin.go +++ b/tokenhandlers_builtin.go @@ -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() diff --git a/tokenhandlers_builtin_test.go b/tokenhandlers_builtin_test.go index 4b06b01..39ed4ba 100644 --- a/tokenhandlers_builtin_test.go +++ b/tokenhandlers_builtin_test.go @@ -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`}, }) }