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:
|
// Note that one can get more specific than just a BadRequest. For example:
|
||||||
// NotEnoughArgumentsComplainer, PatternSyntaxErrorComplainer, UnsupportedArgumentType,
|
// NotEnoughArguments, PatternSyntaxErrorComplainer, UnsupportedArgumentType,
|
||||||
// and StructFieldWrongType.
|
// and StructFieldWrongType.
|
||||||
//
|
//
|
||||||
// To be able to detect those more specific error types, put them BEFORE the "case pathmatch.BadRequest:"
|
// To be able to detect those more specific error types, put them BEFORE the "case pathmatch.BadRequest:"
|
||||||
|
|
|
@ -1,32 +1,28 @@
|
||||||
package pathmatch
|
package pathmatch
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type NotEnoughArguments interface {
|
||||||
type NotEnoughArgumentsComplainer interface {
|
|
||||||
BadRequest
|
BadRequest
|
||||||
NotEnoughArgumentsComplainer()
|
NotEnoughArguments()
|
||||||
|
|
||||||
ExpectedAtLeast() int
|
ExpectedAtLeast() int
|
||||||
Actual() int
|
Actual() int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// internalNotEnoughArguments is the only underlying implementation that fits the
|
||||||
// internalNotEnoughArgumentsComplainer is the only underlying implementation that fits the
|
// NotEnoughArguments interface, in this library.
|
||||||
// NotEnoughArgumentsComplainer interface, in this library.
|
type internalNotEnoughArguments struct {
|
||||||
type internalNotEnoughArgumentsComplainer struct {
|
|
||||||
expectedAtLeast int
|
expectedAtLeast int
|
||||||
actual int
|
actual int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newNotEnoughArguments creates a new internalNotEnoughArguments (struct) and
|
||||||
// newNotEnoughArgumentsComplainer creates a new internalNotEnoughArgumentsComplainer (struct) and
|
// returns it as a NotEnoughArguments (interface).
|
||||||
// returns it as a NotEnoughArgumentsComplainer (interface).
|
func newNotEnoughArguments(expectedAtLeast int, actual int) NotEnoughArguments {
|
||||||
func newNotEnoughArgumentsComplainer(expectedAtLeast int, actual int) NotEnoughArgumentsComplainer {
|
err := internalNotEnoughArguments{
|
||||||
err := internalNotEnoughArgumentsComplainer{
|
|
||||||
expectedAtLeast:expectedAtLeast,
|
expectedAtLeast:expectedAtLeast,
|
||||||
actual:actual,
|
actual:actual,
|
||||||
}
|
}
|
||||||
|
@ -34,10 +30,9 @@ func newNotEnoughArgumentsComplainer(expectedAtLeast int, actual int) NotEnoughA
|
||||||
return &err
|
return &err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Error method is necessary to satisfy the 'error' interface (and the
|
// Error method is necessary to satisfy the 'error' interface (and the
|
||||||
// NotEnoughArgumentsComplainer interface).
|
// NotEnoughArguments interface).
|
||||||
func (err *internalNotEnoughArgumentsComplainer) Error() string {
|
func (err *internalNotEnoughArguments) Error() string {
|
||||||
plural := ""
|
plural := ""
|
||||||
if 1 < err.expectedAtLeast {
|
if 1 < err.expectedAtLeast {
|
||||||
plural = "s"
|
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)
|
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.
|
// BadRequest method is necessary to satisfy the 'BadRequest' interface.
|
||||||
// It exists to make this error type detectable in a Go type-switch.
|
// It exists to make this error type detectable in a Go type-switch.
|
||||||
func (err *internalNotEnoughArgumentsComplainer) BadRequest() {
|
func (err *internalNotEnoughArguments) BadRequest() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotEnoughArguments method is necessary to satisfy the 'NotEnoughArguments' interface.
|
||||||
// NotEnoughArgumentsComplainer method is necessary to satisfy the 'NotEnoughArgumentsComplainer' interface.
|
|
||||||
// It exists to make this error type detectable in a Go type-switch.
|
// It exists to make this error type detectable in a Go type-switch.
|
||||||
func (err *internalNotEnoughArgumentsComplainer) NotEnoughArgumentsComplainer() {
|
func (err *internalNotEnoughArguments) NotEnoughArguments() {
|
||||||
// Nothing here.
|
// Nothing here.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (err *internalNotEnoughArguments) ExpectedAtLeast() int {
|
||||||
func (err *internalNotEnoughArgumentsComplainer) ExpectedAtLeast() int {
|
|
||||||
return err.expectedAtLeast
|
return err.expectedAtLeast
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err *internalNotEnoughArgumentsComplainer) Actual() int {
|
func (err *internalNotEnoughArguments) Actual() int {
|
||||||
return err.actual
|
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
|
expectedAtLeast := 1+argsIndex
|
||||||
actual := lenArgs
|
actual := lenArgs
|
||||||
|
|
||||||
return newNotEnoughArgumentsComplainer(expectedAtLeast, actual)
|
return newNotEnoughArguments(expectedAtLeast, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
arg := args[argsIndex]
|
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)
|
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
|
continue
|
||||||
}
|
}
|
||||||
case NotEnoughArgumentsComplainer:
|
case NotEnoughArguments:
|
||||||
if expected, actual := notEnoughArguments, test.ExpectedFit; expected != actual {
|
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
|
continue
|
||||||
}
|
}
|
||||||
case UnsupportedArgumentType:
|
case UnsupportedArgumentType:
|
||||||
|
|
Loading…
Reference in New Issue