remove redundant bool arg
This commit is contained in:
@@ -36,15 +36,15 @@ func NewFormat(name string, opts ...Option) *Format {
|
|||||||
|
|
||||||
type Option func(*Format)
|
type Option func(*Format)
|
||||||
|
|
||||||
func WithRequireAll(require bool) Option {
|
func WithRequireAll() Option {
|
||||||
return func(f *Format) {
|
return func(f *Format) {
|
||||||
f.requireAll = require
|
f.requireAll = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithErrorOnExtra(errorOnExtra bool) Option {
|
func WithErrorOnExtra() Option {
|
||||||
return func(f *Format) {
|
return func(f *Format) {
|
||||||
f.errorOnExtra = errorOnExtra
|
f.errorOnExtra = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func TestRequireAll(t *testing.T) {
|
|||||||
B int32 `nbt:"B,omitempty"`
|
B int32 `nbt:"B,omitempty"`
|
||||||
C int32 `nbt:"C"`
|
C int32 `nbt:"C"`
|
||||||
}
|
}
|
||||||
f := NewFormat("nbt", WithRequireAll(true))
|
f := NewFormat("nbt", WithRequireAll())
|
||||||
data := map[string]any{"A": int32(1), "C": int32(3)}
|
data := map[string]any{"A": int32(1), "C": int32(3)}
|
||||||
var got Simple
|
var got Simple
|
||||||
if err := f.Decode(data, &got); err != nil {
|
if err := f.Decode(data, &got); err != nil {
|
||||||
@@ -83,7 +83,7 @@ func TestRequireAllMissing(t *testing.T) {
|
|||||||
A int32 `nbt:"A"`
|
A int32 `nbt:"A"`
|
||||||
B int32 `nbt:"B"`
|
B int32 `nbt:"B"`
|
||||||
}
|
}
|
||||||
f := NewFormat("nbt", WithRequireAll(true))
|
f := NewFormat("nbt", WithRequireAll())
|
||||||
data := map[string]any{"A": int32(1)}
|
data := map[string]any{"A": int32(1)}
|
||||||
var got Simple
|
var got Simple
|
||||||
if err := f.Decode(data, &got); err == nil {
|
if err := f.Decode(data, &got); err == nil {
|
||||||
@@ -96,7 +96,7 @@ func TestRequireAllOmitEmptyWins(t *testing.T) {
|
|||||||
A int32 `nbt:"A"`
|
A int32 `nbt:"A"`
|
||||||
B int32 `nbt:"B,omitempty"`
|
B int32 `nbt:"B,omitempty"`
|
||||||
}
|
}
|
||||||
f := NewFormat("nbt", WithRequireAll(true))
|
f := NewFormat("nbt", WithRequireAll())
|
||||||
data := map[string]any{"A": int32(1)}
|
data := map[string]any{"A": int32(1)}
|
||||||
var got Simple
|
var got Simple
|
||||||
if err := f.Decode(data, &got); err != nil {
|
if err := f.Decode(data, &got); err != nil {
|
||||||
@@ -117,7 +117,7 @@ func TestSkipTag(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestErrorOnExtra(t *testing.T) {
|
func TestErrorOnExtra(t *testing.T) {
|
||||||
f := NewFormat("nbt", WithErrorOnExtra(true))
|
f := NewFormat("nbt", WithErrorOnExtra())
|
||||||
data := map[string]any{"Name": "test", "Secret": "shh", "Unknown": "extra"}
|
data := map[string]any{"Name": "test", "Secret": "shh", "Unknown": "extra"}
|
||||||
var got Example
|
var got Example
|
||||||
if err := f.Decode(data, &got); err == nil {
|
if err := f.Decode(data, &got); err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user