Added input check for MatchIntegerBetween()
This commit is contained in:
parent
3d791233e0
commit
c0389283bd
|
@ -584,6 +584,9 @@ func MatchSigned(handler TokenHandler) TokenHandler {
|
||||||
// It uses an int64 for checking internally, so you can check values
|
// It uses an int64 for checking internally, so you can check values
|
||||||
// ranging from -9223372036854775808 to 9223372036854775807.
|
// ranging from -9223372036854775808 to 9223372036854775807.
|
||||||
func MatchIntegerBetween(min int64, max int64) TokenHandler {
|
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())
|
digits := MatchSigned(MatchDigits())
|
||||||
return func(t *TokenAPI) bool {
|
return func(t *TokenAPI) bool {
|
||||||
fork := t.Fork()
|
fork := t.Fork()
|
||||||
|
|
|
@ -82,6 +82,8 @@ func TestCombinatorPanics(t *testing.T) {
|
||||||
`TokenHandler: MatchMin definition error at /.*/tokenhandlers_builtin_test\.go:\d+: min must be >= 0`},
|
`TokenHandler: MatchMin definition error at /.*/tokenhandlers_builtin_test\.go:\d+: min must be >= 0`},
|
||||||
{func() { c.Max(-42, parsekit.A.Space) }, true,
|
{func() { c.Max(-42, parsekit.A.Space) }, true,
|
||||||
`TokenHandler: MatchMax definition error at /.*/tokenhandlers_builtin_test\.go:\d+: max must be >= 0`},
|
`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`},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue