github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/decode/bool_test.go (about)

     1  package decode
     2  
     3  import "testing"
     4  
     5  func TestDecodeBool(t *testing.T) {
     6  	type args struct {
     7  		hexStr string
     8  	}
     9  	tests := []struct {
    10  		name       string
    11  		args       args
    12  		wantResult bool
    13  		wantErr    bool
    14  	}{
    15  		{
    16  			name: "true",
    17  			args: args{
    18  				hexStr: "0x0000000000000000000000000000000000000000000000000000000000000001",
    19  			},
    20  			wantResult: true,
    21  		},
    22  		{
    23  			name: "false",
    24  			args: args{
    25  				hexStr: "0x0000000000000000000000000000000000000000000000000000000000000000",
    26  			},
    27  			wantResult: false,
    28  		},
    29  		{
    30  			name: "too short",
    31  			args: args{
    32  				hexStr: "0x000000000001",
    33  			},
    34  			wantErr: true,
    35  		},
    36  		{
    37  			name: "invalid hex",
    38  			args: args{
    39  				hexStr: "0x000z000000000000000000000000000000000000000000000000000000000001",
    40  			},
    41  			wantErr: true,
    42  		},
    43  	}
    44  	for _, tt := range tests {
    45  		t.Run(tt.name, func(t *testing.T) {
    46  			gotResult, err := ArticulateBool(tt.args.hexStr)
    47  			if (err != nil) != tt.wantErr {
    48  				t.Errorf("ArticulateBool() error = %v, wantErr %v", err, tt.wantErr)
    49  				return
    50  			}
    51  			if gotResult != tt.wantResult {
    52  				t.Errorf("ArticulateBool() = %v, want %v", gotResult, tt.wantResult)
    53  			}
    54  		})
    55  	}
    56  }