github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/btcjson/helpers_test.go (about)

     1  // Copyright (c) 2014 The btcsuite developers
     2  // Copyright (c) 2016 The Dash developers
     3  // Use of this source code is governed by an ISC
     4  // license that can be found in the LICENSE file.
     5  
     6  package btcjson_test
     7  
     8  import (
     9  	"reflect"
    10  	"testing"
    11  
    12  	"github.com/BlockABC/godash/btcjson"
    13  )
    14  
    15  // TestHelpers tests the various helper functions which create pointers to
    16  // primitive types.
    17  func TestHelpers(t *testing.T) {
    18  	t.Parallel()
    19  
    20  	tests := []struct {
    21  		name     string
    22  		f        func() interface{}
    23  		expected interface{}
    24  	}{
    25  		{
    26  			name: "bool",
    27  			f: func() interface{} {
    28  				return btcjson.Bool(true)
    29  			},
    30  			expected: func() interface{} {
    31  				val := true
    32  				return &val
    33  			}(),
    34  		},
    35  		{
    36  			name: "int",
    37  			f: func() interface{} {
    38  				return btcjson.Int(5)
    39  			},
    40  			expected: func() interface{} {
    41  				val := int(5)
    42  				return &val
    43  			}(),
    44  		},
    45  		{
    46  			name: "uint",
    47  			f: func() interface{} {
    48  				return btcjson.Uint(5)
    49  			},
    50  			expected: func() interface{} {
    51  				val := uint(5)
    52  				return &val
    53  			}(),
    54  		},
    55  		{
    56  			name: "int32",
    57  			f: func() interface{} {
    58  				return btcjson.Int32(5)
    59  			},
    60  			expected: func() interface{} {
    61  				val := int32(5)
    62  				return &val
    63  			}(),
    64  		},
    65  		{
    66  			name: "uint32",
    67  			f: func() interface{} {
    68  				return btcjson.Uint32(5)
    69  			},
    70  			expected: func() interface{} {
    71  				val := uint32(5)
    72  				return &val
    73  			}(),
    74  		},
    75  		{
    76  			name: "int64",
    77  			f: func() interface{} {
    78  				return btcjson.Int64(5)
    79  			},
    80  			expected: func() interface{} {
    81  				val := int64(5)
    82  				return &val
    83  			}(),
    84  		},
    85  		{
    86  			name: "uint64",
    87  			f: func() interface{} {
    88  				return btcjson.Uint64(5)
    89  			},
    90  			expected: func() interface{} {
    91  				val := uint64(5)
    92  				return &val
    93  			}(),
    94  		},
    95  		{
    96  			name: "string",
    97  			f: func() interface{} {
    98  				return btcjson.String("abc")
    99  			},
   100  			expected: func() interface{} {
   101  				val := "abc"
   102  				return &val
   103  			}(),
   104  		},
   105  	}
   106  
   107  	t.Logf("Running %d tests", len(tests))
   108  	for i, test := range tests {
   109  		result := test.f()
   110  		if !reflect.DeepEqual(result, test.expected) {
   111  			t.Errorf("Test #%d (%s) unexpected value - got %v, "+
   112  				"want %v", i, test.name, result, test.expected)
   113  			continue
   114  		}
   115  	}
   116  }