123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package jsoniter
- import (
- "fmt"
- "testing"
- )
- func Test_reflect_str(t *testing.T) {
- iter := ParseString(`"hello"`)
- str := ""
- iter.ReadVal(&str)
- if str != "hello" {
- fmt.Println(iter.Error)
- t.Fatal(str)
- }
- }
- func Test_reflect_ptr_str(t *testing.T) {
- iter := ParseString(`"hello"`)
- var str *string
- iter.ReadVal(&str)
- if *str != "hello" {
- t.Fatal(str)
- }
- }
- func Test_reflect_int(t *testing.T) {
- iter := ParseString(`123`)
- val := int(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_int8(t *testing.T) {
- iter := ParseString(`123`)
- val := int8(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_int16(t *testing.T) {
- iter := ParseString(`123`)
- val := int16(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_int32(t *testing.T) {
- iter := ParseString(`123`)
- val := int32(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_int64(t *testing.T) {
- iter := ParseString(`123`)
- val := int64(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_uint(t *testing.T) {
- iter := ParseString(`123`)
- val := uint(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_uint8(t *testing.T) {
- iter := ParseString(`123`)
- val := uint8(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_uint16(t *testing.T) {
- iter := ParseString(`123`)
- val := uint16(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_uint32(t *testing.T) {
- iter := ParseString(`123`)
- val := uint32(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_uint64(t *testing.T) {
- iter := ParseString(`123`)
- val := uint64(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_byte(t *testing.T) {
- iter := ParseString(`123`)
- val := byte(0)
- iter.ReadVal(&val)
- if val != 123 {
- t.Fatal(val)
- }
- }
- func Test_reflect_float32(t *testing.T) {
- iter := ParseString(`1.23`)
- val := float32(0)
- iter.ReadVal(&val)
- if val != 1.23 {
- fmt.Println(iter.Error)
- t.Fatal(val)
- }
- }
- func Test_reflect_float64(t *testing.T) {
- iter := ParseString(`1.23`)
- val := float64(0)
- iter.ReadVal(&val)
- if val != 1.23 {
- fmt.Println(iter.Error)
- t.Fatal(val)
- }
- }
- func Test_reflect_bool(t *testing.T) {
- iter := ParseString(`true`)
- val := false
- iter.ReadVal(&val)
- if val != true {
- fmt.Println(iter.Error)
- t.Fatal(val)
- }
- }
|