1
0
mirror of https://github.com/json-iterator/go.git synced 2025-01-08 13:06:29 +02:00
json-iterator/jsoniter_reflect_native_test.go

155 lines
2.6 KiB
Go
Raw Normal View History

2017-01-06 14:17:47 +02:00
package jsoniter
import (
"fmt"
2017-06-06 17:27:00 +02:00
"testing"
2017-01-06 14:17:47 +02:00
)
func Test_reflect_str(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `"hello"`)
2017-01-06 14:17:47 +02:00
str := ""
2017-01-09 11:47:21 +02:00
iter.ReadVal(&str)
2017-01-06 14:17:47 +02:00
if str != "hello" {
fmt.Println(iter.Error)
t.Fatal(str)
}
}
func Test_reflect_ptr_str(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `"hello"`)
2017-01-06 14:17:47 +02:00
var str *string
2017-01-09 11:47:21 +02:00
iter.ReadVal(&str)
2017-01-06 14:17:47 +02:00
if *str != "hello" {
t.Fatal(str)
}
}
func Test_reflect_int(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := int(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_int8(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := int8(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_int16(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := int16(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_int32(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := int32(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_int64(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := int64(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_uint(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := uint(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_uint8(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := uint8(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_uint16(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := uint16(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_uint32(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := uint32(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_uint64(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := uint64(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_byte(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `123`)
2017-01-06 14:17:47 +02:00
val := byte(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 123 {
t.Fatal(val)
}
}
func Test_reflect_float32(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `1.23`)
2017-01-06 14:17:47 +02:00
val := float32(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 1.23 {
fmt.Println(iter.Error)
t.Fatal(val)
}
}
func Test_reflect_float64(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `1.23`)
2017-01-06 14:17:47 +02:00
val := float64(0)
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != 1.23 {
fmt.Println(iter.Error)
t.Fatal(val)
}
}
func Test_reflect_bool(t *testing.T) {
2017-06-17 04:21:37 +02:00
iter := ParseString(ConfigDefault, `true`)
2017-01-06 14:17:47 +02:00
val := false
2017-01-09 11:47:21 +02:00
iter.ReadVal(&val)
2017-01-06 14:17:47 +02:00
if val != true {
fmt.Println(iter.Error)
t.Fatal(val)
}
2017-06-06 17:27:00 +02:00
}