@@ -171,6 +171,48 @@ func TestBoolScan(t *testing.T) {
171171 assertNullBool (t , null , "scanned null" )
172172}
173173
174+ func TestBoolValueOrZero (t * testing.T ) {
175+ valid := NewBool (true , true )
176+ if valid .ValueOrZero () != true {
177+ t .Error ("unexpected ValueOrZero" , valid .ValueOrZero ())
178+ }
179+
180+ invalid := NewBool (true , false )
181+ if invalid .ValueOrZero () != false {
182+ t .Error ("unexpected ValueOrZero" , invalid .ValueOrZero ())
183+ }
184+ }
185+
186+ func TestBoolEqual (t * testing.T ) {
187+ b1 := NewBool (true , false )
188+ b2 := NewBool (true , false )
189+ assertBoolEqualIsTrue (t , b1 , b2 )
190+
191+ b1 = NewBool (true , false )
192+ b2 = NewBool (false , false )
193+ assertBoolEqualIsTrue (t , b1 , b2 )
194+
195+ b1 = NewBool (true , true )
196+ b2 = NewBool (true , true )
197+ assertBoolEqualIsTrue (t , b1 , b2 )
198+
199+ b1 = NewBool (true , false )
200+ b2 = NewBool (false , true )
201+ assertBoolEqualIsTrue (t , b1 , b2 )
202+
203+ b1 = NewBool (true , true )
204+ b2 = NewBool (true , false )
205+ assertBoolEqualIsFalse (t , b1 , b2 )
206+
207+ b1 = NewBool (true , false )
208+ b2 = NewBool (true , true )
209+ assertBoolEqualIsFalse (t , b1 , b2 )
210+
211+ b1 = NewBool (true , true )
212+ b2 = NewBool (false , true )
213+ assertBoolEqualIsFalse (t , b1 , b2 )
214+ }
215+
174216func assertBool (t * testing.T , b Bool , from string ) {
175217 if b .Bool != true {
176218 t .Errorf ("bad %s bool: %v ≠ %v\n " , from , b .Bool , true )
@@ -185,3 +227,17 @@ func assertNullBool(t *testing.T, b Bool, from string) {
185227 t .Error (from , "is valid, but should be invalid" )
186228 }
187229}
230+
231+ func assertBoolEqualIsTrue (t * testing.T , a , b Bool ) {
232+ t .Helper ()
233+ if ! a .Equal (b ) {
234+ t .Errorf ("Equal() of Bool{%t, Valid:%t} and Bool{%t, Valid:%t} should return true" , a .Bool , a .Valid , b .Bool , b .Valid )
235+ }
236+ }
237+
238+ func assertBoolEqualIsFalse (t * testing.T , a , b Bool ) {
239+ t .Helper ()
240+ if a .Equal (b ) {
241+ t .Errorf ("Equal() of Bool{%t, Valid:%t} and Bool{%t, Valid:%t} should return false" , a .Bool , a .Valid , b .Bool , b .Valid )
242+ }
243+ }
0 commit comments