You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
1.6 KiB
87 lines
1.6 KiB
package Any
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func TestString(t *testing.T) {
|
|
fmt.Println(String("hello world!"))
|
|
fmt.Println(String(123))
|
|
fmt.Println(String(123.02))
|
|
bs := []byte("hello world!")
|
|
fmt.Println(String(bs))
|
|
}
|
|
func TestChannel(t *testing.T) {
|
|
var arr1 = []int{1, 2, 3, 4, 5}
|
|
ch := Channel(arr1)
|
|
fmt.Println(ch)
|
|
|
|
}
|
|
func TestBytes(t *testing.T) {
|
|
fmt.Println(Bytes("hello world!"))
|
|
fmt.Println(String("hello world!"))
|
|
}
|
|
func TestJson(t *testing.T) {
|
|
fmt.Println(Json("hello world!"))
|
|
fmt.Println(Json(123))
|
|
fmt.Println(Json(123.02))
|
|
bs := []byte("hello world!")
|
|
fmt.Println(Json(bs))
|
|
}
|
|
func TestFloat(t *testing.T) {
|
|
fmt.Println(Float(123))
|
|
fmt.Println(Float(123.02))
|
|
fmt.Println(Float("123.02"))
|
|
fmt.Println(Float("123.02f"))
|
|
}
|
|
|
|
func TestInt(t *testing.T) {
|
|
fmt.Println(Int(123))
|
|
fmt.Println(Int("123.005"))
|
|
fmt.Println(Int("123f"))
|
|
}
|
|
func TestPointer(t *testing.T) {
|
|
var a = 123
|
|
pa := Pointer(a)
|
|
fmt.Println(a)
|
|
fmt.Println(pa)
|
|
fmt.Println(*pa)
|
|
}
|
|
func TestMap(t *testing.T) {
|
|
type Message struct {
|
|
name string
|
|
code int
|
|
}
|
|
messages := []Message{
|
|
{name: "Hello", code: 100},
|
|
{name: "Hi", code: 101},
|
|
}
|
|
result := Map(messages, func(msg Message) (int, string) {
|
|
return msg.code, msg.name
|
|
})
|
|
fmt.Println(result)
|
|
|
|
}
|
|
|
|
func TestStructToMap(t *testing.T) {
|
|
type People struct {
|
|
Name string `json:"name"`
|
|
age int
|
|
}
|
|
p := People{
|
|
"test",
|
|
100,
|
|
}
|
|
result, _ := StructToMap(p)
|
|
fmt.Println(result)
|
|
}
|
|
func TestMapToSlice(t *testing.T) {
|
|
aMap := map[string]int{"a": 1, "b": 2, "c": 3}
|
|
result := MapToSlice(aMap, func(key string, value int) string {
|
|
return key + ":" + strconv.Itoa(value)
|
|
})
|
|
fmt.Println(result)
|
|
}
|