github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/val_encoder_native_int_test.go (about)

     1  package jzon
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  )
     7  
     8  func TestValEncoder_Int(t *testing.T) {
     9  	f := func(t *testing.T, i int) {
    10  		checkEncodeValueWithStandard(t, i, nil)
    11  	}
    12  	t.Run("test", func(t *testing.T) {
    13  		f(t, math.MaxInt32)
    14  	})
    15  	t.Run("nil pointer", func(t *testing.T) {
    16  		checkEncodeValueWithStandard(t, (*int)(nil), nil)
    17  	})
    18  	t.Run("pointer", func(t *testing.T) {
    19  		i := int(math.MaxInt32)
    20  		checkEncodeValueWithStandard(t, &i, nil)
    21  	})
    22  }
    23  
    24  func TestValEncoder_Int8(t *testing.T) {
    25  	f := func(t *testing.T, i int8) {
    26  		checkEncodeValueWithStandard(t, i, nil)
    27  	}
    28  	t.Run("test", func(t *testing.T) {
    29  		f(t, math.MaxInt8)
    30  	})
    31  	t.Run("nil pointer", func(t *testing.T) {
    32  		checkEncodeValueWithStandard(t, (*int8)(nil), nil)
    33  	})
    34  	t.Run("pointer", func(t *testing.T) {
    35  		i := int8(math.MaxInt8)
    36  		checkEncodeValueWithStandard(t, &i, nil)
    37  	})
    38  }
    39  
    40  func TestValEncoder_Int16(t *testing.T) {
    41  	f := func(t *testing.T, i int16) {
    42  		checkEncodeValueWithStandard(t, i, nil)
    43  	}
    44  	t.Run("test", func(t *testing.T) {
    45  		f(t, math.MaxInt16)
    46  	})
    47  	t.Run("nil pointer", func(t *testing.T) {
    48  		checkEncodeValueWithStandard(t, (*int16)(nil), nil)
    49  	})
    50  	t.Run("pointer", func(t *testing.T) {
    51  		i := int16(math.MaxInt16)
    52  		checkEncodeValueWithStandard(t, &i, nil)
    53  	})
    54  }
    55  
    56  func TestValEncoder_Int32(t *testing.T) {
    57  	f := func(t *testing.T, i int32) {
    58  		checkEncodeValueWithStandard(t, i, nil)
    59  	}
    60  	t.Run("test", func(t *testing.T) {
    61  		f(t, math.MaxInt32)
    62  	})
    63  	t.Run("nil pointer", func(t *testing.T) {
    64  		checkEncodeValueWithStandard(t, (*int32)(nil), nil)
    65  	})
    66  	t.Run("pointer", func(t *testing.T) {
    67  		i := int32(math.MaxInt32)
    68  		checkEncodeValueWithStandard(t, &i, nil)
    69  	})
    70  }
    71  
    72  func TestValEncoder_Int64(t *testing.T) {
    73  	f := func(t *testing.T, i int64) {
    74  		checkEncodeValueWithStandard(t, i, nil)
    75  	}
    76  	t.Run("test", func(t *testing.T) {
    77  		f(t, math.MaxInt64)
    78  	})
    79  	t.Run("nil pointer", func(t *testing.T) {
    80  		checkEncodeValueWithStandard(t, (*int64)(nil), nil)
    81  	})
    82  	t.Run("pointer", func(t *testing.T) {
    83  		i := int64(math.MaxInt64)
    84  		checkEncodeValueWithStandard(t, &i, nil)
    85  	})
    86  }
    87  
    88  func TestValEncoder_Int_OmitEmpty(t *testing.T) {
    89  	type st struct {
    90  		I   int   `json:",omitempty"`
    91  		I8  int8  `json:",omitempty"`
    92  		I16 int16 `json:",omitempty"`
    93  		I32 int32 `json:",omitempty"`
    94  		I64 int64 `json:",omitempty"`
    95  	}
    96  	checkEncodeValueWithStandard(t, st{}, nil)
    97  }