github.com/pion/webrtc/v3@v3.2.24/pkg/null/null_test.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package null
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestNewBool(t *testing.T) {
    13  	value := bool(true)
    14  	nullable := NewBool(value)
    15  
    16  	assert.Equal(t,
    17  		true,
    18  		nullable.Valid,
    19  		"valid: Bool",
    20  	)
    21  
    22  	assert.Equal(t,
    23  		value,
    24  		nullable.Bool,
    25  		"value: Bool",
    26  	)
    27  }
    28  
    29  func TestNewByte(t *testing.T) {
    30  	value := byte('a')
    31  	nullable := NewByte(value)
    32  
    33  	assert.Equal(t,
    34  		true,
    35  		nullable.Valid,
    36  		"valid: Byte",
    37  	)
    38  
    39  	assert.Equal(t,
    40  		value,
    41  		nullable.Byte,
    42  		"value: Byte",
    43  	)
    44  }
    45  
    46  func TestNewComplex128(t *testing.T) {
    47  	value := complex128(-5 + 12i)
    48  	nullable := NewComplex128(value)
    49  
    50  	assert.Equal(t,
    51  		true,
    52  		nullable.Valid,
    53  		"valid: Complex128",
    54  	)
    55  
    56  	assert.Equal(t,
    57  		value,
    58  		nullable.Complex128,
    59  		"value: Complex128",
    60  	)
    61  }
    62  
    63  func TestNewComplex64(t *testing.T) {
    64  	value := complex64(-5 + 12i)
    65  	nullable := NewComplex64(value)
    66  
    67  	assert.Equal(t,
    68  		true,
    69  		nullable.Valid,
    70  		"valid: Complex64",
    71  	)
    72  
    73  	assert.Equal(t,
    74  		value,
    75  		nullable.Complex64,
    76  		"value: Complex64",
    77  	)
    78  }
    79  
    80  func TestNewFloat32(t *testing.T) {
    81  	value := float32(0.5)
    82  	nullable := NewFloat32(value)
    83  
    84  	assert.Equal(t,
    85  		true,
    86  		nullable.Valid,
    87  		"valid: Float32",
    88  	)
    89  
    90  	assert.Equal(t,
    91  		value,
    92  		nullable.Float32,
    93  		"value: Float32",
    94  	)
    95  }
    96  
    97  func TestNewFloat64(t *testing.T) {
    98  	value := float64(0.5)
    99  	nullable := NewFloat64(value)
   100  
   101  	assert.Equal(t,
   102  		true,
   103  		nullable.Valid,
   104  		"valid: Float64",
   105  	)
   106  
   107  	assert.Equal(t,
   108  		value,
   109  		nullable.Float64,
   110  		"value: Float64",
   111  	)
   112  }
   113  
   114  func TestNewInt(t *testing.T) {
   115  	value := int(1)
   116  	nullable := NewInt(value)
   117  
   118  	assert.Equal(t,
   119  		true,
   120  		nullable.Valid,
   121  		"valid: Int",
   122  	)
   123  
   124  	assert.Equal(t,
   125  		value,
   126  		nullable.Int,
   127  		"value: Int",
   128  	)
   129  }
   130  
   131  func TestNewInt16(t *testing.T) {
   132  	value := int16(1)
   133  	nullable := NewInt16(value)
   134  
   135  	assert.Equal(t,
   136  		true,
   137  		nullable.Valid,
   138  		"valid: Int16",
   139  	)
   140  
   141  	assert.Equal(t,
   142  		value,
   143  		nullable.Int16,
   144  		"value: Int16",
   145  	)
   146  }
   147  
   148  func TestNewInt32(t *testing.T) {
   149  	value := int32(1)
   150  	nullable := NewInt32(value)
   151  
   152  	assert.Equal(t,
   153  		true,
   154  		nullable.Valid,
   155  		"valid: Int32",
   156  	)
   157  
   158  	assert.Equal(t,
   159  		value,
   160  		nullable.Int32,
   161  		"value: Int32",
   162  	)
   163  }
   164  
   165  func TestNewInt64(t *testing.T) {
   166  	value := int64(1)
   167  	nullable := NewInt64(value)
   168  
   169  	assert.Equal(t,
   170  		true,
   171  		nullable.Valid,
   172  		"valid: Int64",
   173  	)
   174  
   175  	assert.Equal(t,
   176  		value,
   177  		nullable.Int64,
   178  		"value: Int64",
   179  	)
   180  }
   181  
   182  func TestNewInt8(t *testing.T) {
   183  	value := int8(1)
   184  	nullable := NewInt8(value)
   185  
   186  	assert.Equal(t,
   187  		true,
   188  		nullable.Valid,
   189  		"valid: Int8",
   190  	)
   191  
   192  	assert.Equal(t,
   193  		value,
   194  		nullable.Int8,
   195  		"value: Int8",
   196  	)
   197  }
   198  
   199  func TestNewRune(t *testing.T) {
   200  	value := rune('p')
   201  	nullable := NewRune(value)
   202  
   203  	assert.Equal(t,
   204  		true,
   205  		nullable.Valid,
   206  		"valid: Rune",
   207  	)
   208  
   209  	assert.Equal(t,
   210  		value,
   211  		nullable.Rune,
   212  		"value: Rune",
   213  	)
   214  }
   215  
   216  func TestNewString(t *testing.T) {
   217  	value := string("pion")
   218  	nullable := NewString(value)
   219  
   220  	assert.Equal(t,
   221  		true,
   222  		nullable.Valid,
   223  		"valid: String",
   224  	)
   225  
   226  	assert.Equal(t,
   227  		value,
   228  		nullable.String,
   229  		"value: String",
   230  	)
   231  }
   232  
   233  func TestNewUint(t *testing.T) {
   234  	value := uint(1)
   235  	nullable := NewUint(value)
   236  
   237  	assert.Equal(t,
   238  		true,
   239  		nullable.Valid,
   240  		"valid: Uint",
   241  	)
   242  
   243  	assert.Equal(t,
   244  		value,
   245  		nullable.Uint,
   246  		"value: Uint",
   247  	)
   248  }
   249  
   250  func TestNewUint16(t *testing.T) {
   251  	value := uint16(1)
   252  	nullable := NewUint16(value)
   253  
   254  	assert.Equal(t,
   255  		true,
   256  		nullable.Valid,
   257  		"valid: Uint16",
   258  	)
   259  
   260  	assert.Equal(t,
   261  		value,
   262  		nullable.Uint16,
   263  		"value: Uint16",
   264  	)
   265  }
   266  
   267  func TestNewUint32(t *testing.T) {
   268  	value := uint32(1)
   269  	nullable := NewUint32(value)
   270  
   271  	assert.Equal(t,
   272  		true,
   273  		nullable.Valid,
   274  		"valid: Uint32",
   275  	)
   276  
   277  	assert.Equal(t,
   278  		value,
   279  		nullable.Uint32,
   280  		"value: Uint32",
   281  	)
   282  }
   283  
   284  func TestNewUint64(t *testing.T) {
   285  	value := uint64(1)
   286  	nullable := NewUint64(value)
   287  
   288  	assert.Equal(t,
   289  		true,
   290  		nullable.Valid,
   291  		"valid: Uint64",
   292  	)
   293  
   294  	assert.Equal(t,
   295  		value,
   296  		nullable.Uint64,
   297  		"value: Uint64",
   298  	)
   299  }
   300  
   301  func TestNewUint8(t *testing.T) {
   302  	value := uint8(1)
   303  	nullable := NewUint8(value)
   304  
   305  	assert.Equal(t,
   306  		true,
   307  		nullable.Valid,
   308  		"valid: Uint8",
   309  	)
   310  
   311  	assert.Equal(t,
   312  		value,
   313  		nullable.Uint8,
   314  		"value: Uint8",
   315  	)
   316  }