renamed "NotEnoughArgumentsComplainer" to "NotEnoughArgumentsComplainerNotEnoughArguments"
parent
c3af48030e
commit
bc6870c371
|
@ -83,7 +83,7 @@ package pathmatch
|
|||
// }
|
||||
//
|
||||
// Note that one can get more specific than just a BadRequest. For example:
|
||||
// NotEnoughArgumentsComplainer, PatternSyntaxErrorComplainer, UnsupportedArgumentType,
|
||||
// NotEnoughArguments, PatternSyntaxErrorComplainer, UnsupportedArgumentType,
|
||||
// and StructFieldWrongType.
|
||||
//
|
||||
// To be able to detect those more specific error types, put them BEFORE the "case pathmatch.BadRequest:"
|
||||
|
|
|
@ -1,32 +1,28 @@
|
|||
package pathmatch
|
||||
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
|
||||
type NotEnoughArgumentsComplainer interface {
|
||||
type NotEnoughArguments interface {
|
||||
BadRequest
|
||||
NotEnoughArgumentsComplainer()
|
||||
NotEnoughArguments()
|
||||
|
||||
ExpectedAtLeast() int
|
||||
Actual() int
|
||||
}
|
||||
|
||||
|
||||
// internalNotEnoughArgumentsComplainer is the only underlying implementation that fits the
|
||||
// NotEnoughArgumentsComplainer interface, in this library.
|
||||
type internalNotEnoughArgumentsComplainer struct {
|
||||
// internalNotEnoughArguments is the only underlying implementation that fits the
|
||||
// NotEnoughArguments interface, in this library.
|
||||
type internalNotEnoughArguments struct {
|
||||
expectedAtLeast int
|
||||
actual int
|
||||
}
|
||||
|
||||
|
||||
// newNotEnoughArgumentsComplainer creates a new internalNotEnoughArgumentsComplainer (struct) and
|
||||
// returns it as a NotEnoughArgumentsComplainer (interface).
|
||||
func newNotEnoughArgumentsComplainer(expectedAtLeast int, actual int) NotEnoughArgumentsComplainer {
|
||||
err := internalNotEnoughArgumentsComplainer{
|
||||
// newNotEnoughArguments creates a new internalNotEnoughArguments (struct) and
|
||||
// returns it as a NotEnoughArguments (interface).
|
||||
func newNotEnoughArguments(expectedAtLeast int, actual int) NotEnoughArguments {
|
||||
err := internalNotEnoughArguments{
|
||||
expectedAtLeast:expectedAtLeast,
|
||||
actual:actual,
|
||||
}
|
||||
|
@ -34,10 +30,9 @@ func newNotEnoughArgumentsComplainer(expectedAtLeast int, actual int) NotEnoughA
|
|||
return &err
|
||||
}
|
||||
|
||||
|
||||
// Error method is necessary to satisfy the 'error' interface (and the
|
||||
// NotEnoughArgumentsComplainer interface).
|
||||
func (err *internalNotEnoughArgumentsComplainer) Error() string {
|
||||
// NotEnoughArguments interface).
|
||||
func (err *internalNotEnoughArguments) Error() string {
|
||||
plural := ""
|
||||
if 1 < err.expectedAtLeast {
|
||||
plural = "s"
|
||||
|
@ -45,25 +40,22 @@ func (err *internalNotEnoughArgumentsComplainer) Error() string {
|
|||
return fmt.Sprintf("Bad Request: Not enough arguments. Expected at least %d argument%s, but actually got %d.", err.expectedAtLeast, plural, err.actual)
|
||||
}
|
||||
|
||||
|
||||
// BadRequest method is necessary to satisfy the 'BadRequest' interface.
|
||||
// It exists to make this error type detectable in a Go type-switch.
|
||||
func (err *internalNotEnoughArgumentsComplainer) BadRequest() {
|
||||
func (err *internalNotEnoughArguments) BadRequest() {
|
||||
// Nothing here.
|
||||
}
|
||||
|
||||
|
||||
// NotEnoughArgumentsComplainer method is necessary to satisfy the 'NotEnoughArgumentsComplainer' interface.
|
||||
// NotEnoughArguments method is necessary to satisfy the 'NotEnoughArguments' interface.
|
||||
// It exists to make this error type detectable in a Go type-switch.
|
||||
func (err *internalNotEnoughArgumentsComplainer) NotEnoughArgumentsComplainer() {
|
||||
func (err *internalNotEnoughArguments) NotEnoughArguments() {
|
||||
// Nothing here.
|
||||
}
|
||||
|
||||
|
||||
func (err *internalNotEnoughArgumentsComplainer) ExpectedAtLeast() int {
|
||||
func (err *internalNotEnoughArguments) ExpectedAtLeast() int {
|
||||
return err.expectedAtLeast
|
||||
}
|
||||
|
||||
func (err *internalNotEnoughArgumentsComplainer) Actual() int {
|
||||
func (err *internalNotEnoughArguments) Actual() int {
|
||||
return err.actual
|
||||
}
|
||||
|
|
2
set.go
2
set.go
|
@ -17,7 +17,7 @@ func set(value string, argsIndex int, args ...interface{}) error {
|
|||
expectedAtLeast := 1+argsIndex
|
||||
actual := lenArgs
|
||||
|
||||
return newNotEnoughArgumentsComplainer(expectedAtLeast, actual)
|
||||
return newNotEnoughArguments(expectedAtLeast, actual)
|
||||
}
|
||||
|
||||
arg := args[argsIndex]
|
||||
|
|
|
@ -351,9 +351,9 @@ func TestSetFail(t *testing.T) {
|
|||
t.Errorf("For test #%d, did indeed expect an error, but did not expect it to fit the \"InternalError\" interface, but actually did: %T.", testNumber, err)
|
||||
continue
|
||||
}
|
||||
case NotEnoughArgumentsComplainer:
|
||||
case NotEnoughArguments:
|
||||
if expected, actual := notEnoughArguments, test.ExpectedFit; expected != actual {
|
||||
t.Errorf("For test #%d, did indeed expect an error, but did not expect it to fit the \"NotEnoughArgumentsComplainer\" interface, but actually did: %T.", testNumber, err)
|
||||
t.Errorf("For test #%d, did indeed expect an error, but did not expect it to fit the \"NotEnoughArguments\" interface, but actually did: %T.", testNumber, err)
|
||||
continue
|
||||
}
|
||||
case UnsupportedArgumentType:
|
||||
|
|
Loading…
Reference in New Issue