github.com/gogf/gf/v2@v2.7.4/util/gconv/gconv_z_unit_rune_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gconv_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/gogf/gf/v2/container/gvar"
    13  	"github.com/gogf/gf/v2/test/gtest"
    14  	"github.com/gogf/gf/v2/util/gconv"
    15  )
    16  
    17  var runeTests = []struct {
    18  	value   interface{}
    19  	expect  rune
    20  	expects []rune
    21  }{
    22  	{true, 1, []rune("true")},
    23  	{false, 0, []rune("false")},
    24  
    25  	{int(0), 0, []rune("0")},
    26  	{int(123), 123, []rune("123")},
    27  	{int8(123), 123, []rune("123")},
    28  	{int16(123), 123, []rune("123")},
    29  	{int32(123123123), 123123123, []rune("123123123")},
    30  	{int64(123123123123123123), 23327667, []rune("123123123123123123")},
    31  
    32  	{uint(0), 0, []rune("0")},
    33  	{uint(123), 123, []rune("123")},
    34  	{uint8(123), 123, []rune("123")},
    35  	{uint16(123), 123, []rune("123")},
    36  	{uint32(123123123), 123123123, []rune("123123123")},
    37  	{uint64(123123123123123123), 23327667, []rune("123123123123123123")},
    38  
    39  	{uintptr(0), 0, []rune{48}},
    40  	{uintptr(123), 123, []rune{49, 50, 51}},
    41  
    42  	{rune(0), 0, []rune("0")},
    43  	{rune(49), 49, []rune("49")},
    44  
    45  	{float32(123), 123, []rune{49, 50, 51}},
    46  	{float64(123.456), 123, []rune{49, 50, 51, 46, 52, 53, 54}},
    47  
    48  	{[]rune(""), 0, []rune("")},
    49  
    50  	{"Uranus", 0, []rune("Uranus")},
    51  
    52  	{complex(1, 2), 0,
    53  		[]rune{40, 49, 43, 50, 105, 41}},
    54  
    55  	{[3]int{1, 2, 3}, 0, []rune{91, 49, 44, 50, 44, 51, 93}},
    56  	{[]int{1, 2, 3}, 0, []rune{91, 49, 44, 50, 44, 51, 93}},
    57  
    58  	{map[int]int{1: 1}, 0, []rune(`{"1":1}`)},
    59  	{map[string]string{"Earth": "印度洋"}, 0, []rune(`{"Earth":"印度洋"}`)},
    60  
    61  	{gvar.New(123), 123, []rune{49, 50, 51}},
    62  	{gvar.New(123.456), 123, []rune{49, 50, 51, 46, 52, 53, 54}},
    63  }
    64  
    65  func TestRune(t *testing.T) {
    66  	gtest.C(t, func(t *gtest.T) {
    67  		for _, test := range runeTests {
    68  			t.AssertEQ(gconv.Rune(test.value), test.expect)
    69  		}
    70  	})
    71  }
    72  
    73  func TestRunes(t *testing.T) {
    74  	gtest.C(t, func(t *gtest.T) {
    75  		for _, test := range runeTests {
    76  			t.AssertEQ(gconv.Runes(test.value), test.expects)
    77  		}
    78  	})
    79  }