github.com/agrea/ptr@v0.2.0/ptr_test.go (about)

     1  package ptr
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  )
     7  
     8  func TestBool(t *testing.T) {
     9  	var b bool = true
    10  
    11  	if *Bool(b) != b {
    12  		t.Error("did not get a pointer back")
    13  	}
    14  }
    15  
    16  func TestByte(t *testing.T) {
    17  	b := []byte{'a'}
    18  
    19  	if *Byte(b[0]) != b[0] {
    20  		t.Error("did not get a pointer back")
    21  	}
    22  }
    23  
    24  func TestFloat32(t *testing.T) {
    25  	var f float32 = 123.12
    26  
    27  	if *Float32(f) != f {
    28  		t.Error("did not get a pointer back")
    29  	}
    30  }
    31  
    32  func TestFloat64(t *testing.T) {
    33  	var f float64 = 123.12
    34  
    35  	if *Float64(f) != f {
    36  		t.Error("did not get a pointer back")
    37  	}
    38  }
    39  
    40  func TestInt(t *testing.T) {
    41  	var i int = 123
    42  
    43  	if *Int(i) != i {
    44  		t.Error("did not get a pointer back")
    45  	}
    46  }
    47  
    48  func TestInt8(t *testing.T) {
    49  	var i int8 = 123
    50  
    51  	if *Int8(i) != i {
    52  		t.Error("did not get a pointer back")
    53  	}
    54  }
    55  
    56  func TestInt16(t *testing.T) {
    57  	var i int16 = 123
    58  
    59  	if *Int16(i) != i {
    60  		t.Error("did not get a pointer back")
    61  	}
    62  }
    63  
    64  func TestInt32(t *testing.T) {
    65  	var i int32 = 123
    66  
    67  	if *Int32(i) != i {
    68  		t.Error("did not get a pointer back")
    69  	}
    70  }
    71  
    72  func TestInt64(t *testing.T) {
    73  	var i int64 = 123
    74  
    75  	if *Int64(i) != i {
    76  		t.Error("did not get a pointer back")
    77  	}
    78  }
    79  
    80  func TestRune(t *testing.T) {
    81  	var r rune = 1
    82  
    83  	if *Rune(r) != r {
    84  		t.Error("did not get a pointer back")
    85  	}
    86  }
    87  
    88  func TestString(t *testing.T) {
    89  	var i string = "What was the question to life, universe and everything?"
    90  
    91  	if *String(i) != i {
    92  		t.Error("did not get a pointer back")
    93  	}
    94  }
    95  
    96  func TestTime(t *testing.T) {
    97  	o := time.Now().UTC()
    98  
    99  	if *Time(o) != o {
   100  		t.Error("did not get a pointer back")
   101  	}
   102  }
   103  
   104  func TestUint(t *testing.T) {
   105  	var i uint = 123
   106  
   107  	if *Uint(i) != i {
   108  		t.Error("did not get a pointer back")
   109  	}
   110  }
   111  
   112  func TestUint8(t *testing.T) {
   113  	var i uint8 = 123
   114  
   115  	if *Uint8(i) != i {
   116  		t.Error("did not get a pointer back")
   117  	}
   118  }
   119  
   120  func TestUint16(t *testing.T) {
   121  	var i uint16 = 123
   122  
   123  	if *Uint16(i) != i {
   124  		t.Error("did not get a pointer back")
   125  	}
   126  }
   127  
   128  func TestUint32(t *testing.T) {
   129  	var i uint32 = 123
   130  
   131  	if *Uint32(i) != i {
   132  		t.Error("did not get a pointer back")
   133  	}
   134  }
   135  
   136  func TestUint64(t *testing.T) {
   137  	var i uint64 = 123
   138  
   139  	if *Uint64(i) != i {
   140  		t.Error("did not get a pointer back")
   141  	}
   142  }