github.com/go-email-validator/go-email-validator@v0.0.0-20230409163946-b8b9e6a0552e/pkg/presentation/mailboxvalidator/nullable_bool_test.go (about)

     1  package mailboxvalidator
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestEmptyBool_MarshalJSON(t *testing.T) {
     9  	tests := []struct {
    10  		name      string
    11  		emptyBool EmptyBool
    12  		want      []byte
    13  		wantErr   bool
    14  	}{
    15  		{name: "true", emptyBool: NewEmptyBool(true), want: []byte("true"), wantErr: false},
    16  	}
    17  	for _, tt := range tests {
    18  		t.Run(tt.name, func(t *testing.T) {
    19  			e := tt.emptyBool
    20  			got, err := e.MarshalJSON()
    21  			if (err != nil) != tt.wantErr {
    22  				t.Errorf("MarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
    23  				return
    24  			}
    25  			if !reflect.DeepEqual(got, tt.want) {
    26  				t.Errorf("MarshalJSON() got = %v, want %v", got, tt.want)
    27  			}
    28  		})
    29  	}
    30  }
    31  
    32  func TestEmptyBool_ToString(t *testing.T) {
    33  	tests := []struct {
    34  		name      string
    35  		emptyBool EmptyBool
    36  		want      string
    37  	}{
    38  		{name: "true", emptyBool: NewEmptyBool(true), want: "True"},
    39  		{name: "false", emptyBool: NewEmptyBool(false), want: "False"},
    40  		{name: "nil", emptyBool: NewEmptyBoolWithNil(), want: ""},
    41  	}
    42  	for _, tt := range tests {
    43  		t.Run(tt.name, func(t *testing.T) {
    44  			e := EmptyBool{
    45  				bool: tt.emptyBool.bool,
    46  			}
    47  			if got := e.ToString(); got != tt.want {
    48  				t.Errorf("ToString() = %v, want %v", got, tt.want)
    49  			}
    50  		})
    51  	}
    52  }
    53  
    54  func TestToBool(t *testing.T) {
    55  	type args struct {
    56  		value string
    57  	}
    58  	tests := []struct {
    59  		name       string
    60  		args       args
    61  		wantResult EmptyBool
    62  	}{
    63  		{name: "true", args: args{value: "True"}, wantResult: NewEmptyBool(true)},
    64  		{name: "false", args: args{value: "False"}, wantResult: NewEmptyBool(false)},
    65  		{name: "nil", args: args{value: ""}, wantResult: NewEmptyBoolWithNil()},
    66  	}
    67  	for _, tt := range tests {
    68  		t.Run(tt.name, func(t *testing.T) {
    69  			if gotResult := ToBool(tt.args.value); !reflect.DeepEqual(gotResult, tt.wantResult) {
    70  				t.Errorf("ToBool() = %v, want %v", gotResult, tt.wantResult)
    71  			}
    72  		})
    73  	}
    74  }