Skip to content

Commit ebc8096

Browse files
author
Jon Snyder
committed
remove Set from New constructors
1 parent 35b2f84 commit ebc8096

36 files changed

+195
-205
lines changed

bool.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ type Bool struct {
1717
}
1818

1919
// NewBool creates a new Bool
20-
func NewBool(b bool, valid, set bool) Bool {
20+
func NewBool(b, valid bool) Bool {
2121
return Bool{
2222
Bool: b,
2323
Valid: valid,
24-
Set: set,
24+
Set: true,
2525
}
2626
}
2727

2828
// BoolFrom creates a new Bool that will always be valid.
2929
func BoolFrom(b bool) Bool {
30-
return NewBool(b, true, true)
30+
return NewBool(b, true)
3131
}
3232

3333
// BoolFromPtr creates a new Bool that will be null if f is nil.
3434
func BoolFromPtr(b *bool) Bool {
3535
if b == nil {
36-
return NewBool(false, false, true)
36+
return NewBool(false, false)
3737
}
38-
return NewBool(*b, true, true)
38+
return NewBool(*b, true)
3939
}
4040

4141
func (b Bool) IsSet() bool {

bool_test.go

+10-16
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
)
77

88
var (
9-
boolJSON = []byte(`true`)
10-
falseJSON = []byte(`false`)
9+
boolJSON = []byte(`true`)
1110
)
1211

1312
func TestBoolFrom(t *testing.T) {
@@ -31,13 +30,8 @@ func TestBoolFromPtr(t *testing.T) {
3130
}
3231

3332
func TestUnmarshalBool(t *testing.T) {
34-
var b Bool
35-
err := json.Unmarshal(boolJSON, &b)
36-
maybePanic(err)
37-
assertBool(t, b, "bool json")
38-
3933
var null Bool
40-
err = json.Unmarshal(nullJSON, &null)
34+
err := json.Unmarshal(nullJSON, &null)
4135
maybePanic(err)
4236
assertNullBool(t, null, "null json")
4337
if !null.Set {
@@ -88,13 +82,13 @@ func TestMarshalBool(t *testing.T) {
8882
maybePanic(err)
8983
assertJSONEquals(t, data, "true", "non-empty json marshal")
9084

91-
zero := NewBool(false, true, true)
85+
zero := NewBool(false, true)
9286
data, err = json.Marshal(zero)
9387
maybePanic(err)
9488
assertJSONEquals(t, data, "false", "zero json marshal")
9589

9690
// invalid values should be encoded as null
97-
null := NewBool(false, false, true)
91+
null := NewBool(false, false)
9892
data, err = json.Marshal(null)
9993
maybePanic(err)
10094
assertJSONEquals(t, data, "null", "null json marshal")
@@ -106,13 +100,13 @@ func TestMarshalBoolText(t *testing.T) {
106100
maybePanic(err)
107101
assertJSONEquals(t, data, "true", "non-empty text marshal")
108102

109-
zero := NewBool(false, true, true)
103+
zero := NewBool(false, true)
110104
data, err = zero.MarshalText()
111105
maybePanic(err)
112106
assertJSONEquals(t, data, "false", "zero text marshal")
113107

114108
// invalid values should be encoded as null
115-
null := NewBool(false, false, true)
109+
null := NewBool(false, false)
116110
data, err = null.MarshalText()
117111
maybePanic(err)
118112
assertJSONEquals(t, data, "", "null text marshal")
@@ -125,7 +119,7 @@ func TestBoolPointer(t *testing.T) {
125119
t.Errorf("bad %s bool: %#v ≠ %v\n", "pointer", ptr, true)
126120
}
127121

128-
null := NewBool(false, false, true)
122+
null := NewBool(false, false)
129123
ptr = null.Ptr()
130124
if ptr != nil {
131125
t.Errorf("bad %s bool: %#v ≠ %s\n", "nil pointer", ptr, "nil")
@@ -138,19 +132,19 @@ func TestBoolIsZero(t *testing.T) {
138132
t.Errorf("IsZero() should be false")
139133
}
140134

141-
null := NewBool(false, false, true)
135+
null := NewBool(false, false)
142136
if !null.IsZero() {
143137
t.Errorf("IsZero() should be true")
144138
}
145139

146-
zero := NewBool(false, true, true)
140+
zero := NewBool(false, true)
147141
if zero.IsZero() {
148142
t.Errorf("IsZero() should be false")
149143
}
150144
}
151145

152146
func TestBoolSetValid(t *testing.T) {
153-
change := NewBool(false, false, true)
147+
change := NewBool(false, false)
154148
assertNullBool(t, change, "SetValid()")
155149
change.SetValid(true)
156150
assertBool(t, change, "SetValid()")

byte.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ type Byte struct {
1515
}
1616

1717
// NewByte creates a new Byte
18-
func NewByte(b byte, valid, set bool) Byte {
18+
func NewByte(b byte, valid bool) Byte {
1919
return Byte{
2020
Byte: b,
2121
Valid: valid,
22-
Set: set,
22+
Set: true,
2323
}
2424
}
2525

2626
// ByteFrom creates a new Byte that will always be valid.
2727
func ByteFrom(b byte) Byte {
28-
return NewByte(b, true, true)
28+
return NewByte(b, true)
2929
}
3030

3131
// ByteFromPtr creates a new Byte that be null if i is nil.
3232
func ByteFromPtr(b *byte) Byte {
3333
if b == nil {
34-
return NewByte(0, false, true)
34+
return NewByte(0, false)
3535
}
36-
return NewByte(*b, true, true)
36+
return NewByte(*b, true)
3737
}
3838

3939
func (b Byte) IsSet() bool {

byte_test.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import (
55
"testing"
66
)
77

8-
var (
9-
byteJSON = []byte(`"b"`)
10-
)
11-
128
func TestByteFrom(t *testing.T) {
139
i := ByteFrom('b')
1410
assertByte(t, i, "ByteFrom()")
@@ -80,7 +76,7 @@ func TestMarshalByte(t *testing.T) {
8076
assertJSONEquals(t, data, `"b"`, "non-empty json marshal")
8177

8278
// invalid values should be encoded as null
83-
null := NewByte(0, false, true)
79+
null := NewByte(0, false)
8480
data, err = json.Marshal(null)
8581
maybePanic(err)
8682
assertJSONEquals(t, data, "null", "null json marshal")
@@ -93,7 +89,7 @@ func TestMarshalByteText(t *testing.T) {
9389
assertJSONEquals(t, data, "b", "non-empty text marshal")
9490

9591
// invalid values should be encoded as null
96-
null := NewByte(0, false, true)
92+
null := NewByte(0, false)
9793
data, err = null.MarshalText()
9894
maybePanic(err)
9995
assertJSONEquals(t, data, "", "null text marshal")
@@ -106,7 +102,7 @@ func TestBytePointer(t *testing.T) {
106102
t.Errorf("bad %s int: %#v ≠ %d\n", "pointer", ptr, 'b')
107103
}
108104

109-
null := NewByte(0, false, true)
105+
null := NewByte(0, false)
110106
ptr = null.Ptr()
111107
if ptr != nil {
112108
t.Errorf("bad %s int: %#v ≠ %s\n", "nil pointer", ptr, "nil")
@@ -119,19 +115,19 @@ func TestByteIsZero(t *testing.T) {
119115
t.Errorf("IsZero() should be false")
120116
}
121117

122-
null := NewByte(0, false, true)
118+
null := NewByte(0, false)
123119
if !null.IsZero() {
124120
t.Errorf("IsZero() should be true")
125121
}
126122

127-
zero := NewByte(0, true, true)
123+
zero := NewByte(0, true)
128124
if zero.IsZero() {
129125
t.Errorf("IsZero() should be false")
130126
}
131127
}
132128

133129
func TestByteSetValid(t *testing.T) {
134-
change := NewByte(0, false, true)
130+
change := NewByte(0, false)
135131
assertNullByte(t, change, "SetValid()")
136132
change.SetValid('b')
137133
assertByte(t, change, "SetValid()")

bytes.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ type Bytes struct {
1919
}
2020

2121
// NewBytes creates a new Bytes
22-
func NewBytes(b []byte, valid, set bool) Bytes {
22+
func NewBytes(b []byte, valid bool) Bytes {
2323
return Bytes{
2424
Bytes: b,
2525
Valid: valid,
26-
Set: set,
26+
Set: true,
2727
}
2828
}
2929

3030
// BytesFrom creates a new Bytes that will be invalid if nil.
3131
func BytesFrom(b []byte) Bytes {
32-
return NewBytes(b, b != nil, true)
32+
return NewBytes(b, b != nil)
3333
}
3434

3535
// BytesFromPtr creates a new Bytes that will be invalid if nil.
3636
func BytesFromPtr(b *[]byte) Bytes {
3737
if b == nil {
38-
return NewBytes(nil, false, true)
38+
return NewBytes(nil, false)
3939
}
40-
n := NewBytes(*b, true, true)
40+
n := NewBytes(*b, true)
4141
return n
4242
}
4343

bytes_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestMarshalBytes(t *testing.T) {
8181
assertJSONEquals(t, data, string(b64BytesJSON), "non-empty json marshal")
8282

8383
// invalid values should be encoded as null
84-
null := NewBytes(nil, false, true)
84+
null := NewBytes(nil, false)
8585
data, err = json.Marshal(null)
8686
maybePanic(err)
8787
assertJSONEquals(t, data, "null", "null json marshal")
@@ -94,7 +94,7 @@ func TestMarshalBytesText(t *testing.T) {
9494
assertJSONEquals(t, data, `"hello"`, "non-empty text marshal")
9595

9696
// invalid values should be encoded as null
97-
null := NewBytes(nil, false, true)
97+
null := NewBytes(nil, false)
9898
data, err = null.MarshalText()
9999
maybePanic(err)
100100
assertJSONEquals(t, data, "", "null text marshal")
@@ -107,7 +107,7 @@ func TestBytesPointer(t *testing.T) {
107107
t.Errorf("bad %s []byte: %#v ≠ %s\n", "pointer", ptr, `"hello"`)
108108
}
109109

110-
null := NewBytes(nil, false, true)
110+
null := NewBytes(nil, false)
111111
ptr = null.Ptr()
112112
if ptr != nil {
113113
t.Errorf("bad %s []byte: %#v ≠ %s\n", "nil pointer", ptr, "nil")
@@ -120,19 +120,19 @@ func TestBytesIsZero(t *testing.T) {
120120
t.Errorf("IsZero() should be false")
121121
}
122122

123-
null := NewBytes(nil, false, true)
123+
null := NewBytes(nil, false)
124124
if !null.IsZero() {
125125
t.Errorf("IsZero() should be true")
126126
}
127127

128-
zero := NewBytes(nil, true, true)
128+
zero := NewBytes(nil, true)
129129
if zero.IsZero() {
130130
t.Errorf("IsZero() should be false")
131131
}
132132
}
133133

134134
func TestBytesSetValid(t *testing.T) {
135-
change := NewBytes(nil, false, true)
135+
change := NewBytes(nil, false)
136136
assertNullBytes(t, change, "SetValid()")
137137
change.SetValid(hello)
138138
assertBytes(t, change, "SetValid()")

float32.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ type Float32 struct {
1717
}
1818

1919
// NewFloat32 creates a new Float32
20-
func NewFloat32(f float32, valid, set bool) Float32 {
20+
func NewFloat32(f float32, valid bool) Float32 {
2121
return Float32{
2222
Float32: f,
2323
Valid: valid,
24-
Set: set,
24+
Set: true,
2525
}
2626
}
2727

2828
// Float32From creates a new Float32 that will always be valid.
2929
func Float32From(f float32) Float32 {
30-
return NewFloat32(f, true, true)
30+
return NewFloat32(f, true)
3131
}
3232

3333
// Float32FromPtr creates a new Float32 that be null if f is nil.
3434
func Float32FromPtr(f *float32) Float32 {
3535
if f == nil {
36-
return NewFloat32(0, false, true)
36+
return NewFloat32(0, false)
3737
}
38-
return NewFloat32(*f, true, true)
38+
return NewFloat32(*f, true)
3939
}
4040

4141
func (f Float32) IsSet() bool {

float32_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestMarshalFloat32(t *testing.T) {
7676
assertJSONEquals(t, data, "1.2345", "non-empty json marshal")
7777

7878
// invalid values should be encoded as null
79-
null := NewFloat32(0, false, true)
79+
null := NewFloat32(0, false)
8080
data, err = json.Marshal(null)
8181
maybePanic(err)
8282
assertJSONEquals(t, data, "null", "null json marshal")
@@ -89,7 +89,7 @@ func TestMarshalFloat32Text(t *testing.T) {
8989
assertJSONEquals(t, data, "1.2345", "non-empty text marshal")
9090

9191
// invalid values should be encoded as null
92-
null := NewFloat32(0, false, true)
92+
null := NewFloat32(0, false)
9393
data, err = null.MarshalText()
9494
maybePanic(err)
9595
assertJSONEquals(t, data, "", "null text marshal")
@@ -102,7 +102,7 @@ func TestFloat32Pointer(t *testing.T) {
102102
t.Errorf("bad %s float32: %#v ≠ %v\n", "pointer", ptr, 1.2345)
103103
}
104104

105-
null := NewFloat32(0, false, true)
105+
null := NewFloat32(0, false)
106106
ptr = null.Ptr()
107107
if ptr != nil {
108108
t.Errorf("bad %s float32: %#v ≠ %s\n", "nil pointer", ptr, "nil")
@@ -115,19 +115,19 @@ func TestFloat32IsZero(t *testing.T) {
115115
t.Errorf("IsZero() should be false")
116116
}
117117

118-
null := NewFloat32(0, false, true)
118+
null := NewFloat32(0, false)
119119
if !null.IsZero() {
120120
t.Errorf("IsZero() should be true")
121121
}
122122

123-
zero := NewFloat32(0, true, true)
123+
zero := NewFloat32(0, true)
124124
if zero.IsZero() {
125125
t.Errorf("IsZero() should be false")
126126
}
127127
}
128128

129129
func TestFloat32SetValid(t *testing.T) {
130-
change := NewFloat32(0, false, true)
130+
change := NewFloat32(0, false)
131131
assertNullFloat32(t, change, "SetValid()")
132132
change.SetValid(1.2345)
133133
assertFloat32(t, change, "SetValid()")

0 commit comments

Comments
 (0)