jsoniter_reflect_native_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package jsoniter
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func Test_reflect_str(t *testing.T) {
  7. iter := ParseString(`"hello"`)
  8. str := ""
  9. iter.ReadVal(&str)
  10. if str != "hello" {
  11. fmt.Println(iter.Error)
  12. t.Fatal(str)
  13. }
  14. }
  15. func Test_reflect_ptr_str(t *testing.T) {
  16. iter := ParseString(`"hello"`)
  17. var str *string
  18. iter.ReadVal(&str)
  19. if *str != "hello" {
  20. t.Fatal(str)
  21. }
  22. }
  23. func Test_reflect_int(t *testing.T) {
  24. iter := ParseString(`123`)
  25. val := int(0)
  26. iter.ReadVal(&val)
  27. if val != 123 {
  28. t.Fatal(val)
  29. }
  30. }
  31. func Test_reflect_int8(t *testing.T) {
  32. iter := ParseString(`123`)
  33. val := int8(0)
  34. iter.ReadVal(&val)
  35. if val != 123 {
  36. t.Fatal(val)
  37. }
  38. }
  39. func Test_reflect_int16(t *testing.T) {
  40. iter := ParseString(`123`)
  41. val := int16(0)
  42. iter.ReadVal(&val)
  43. if val != 123 {
  44. t.Fatal(val)
  45. }
  46. }
  47. func Test_reflect_int32(t *testing.T) {
  48. iter := ParseString(`123`)
  49. val := int32(0)
  50. iter.ReadVal(&val)
  51. if val != 123 {
  52. t.Fatal(val)
  53. }
  54. }
  55. func Test_reflect_int64(t *testing.T) {
  56. iter := ParseString(`123`)
  57. val := int64(0)
  58. iter.ReadVal(&val)
  59. if val != 123 {
  60. t.Fatal(val)
  61. }
  62. }
  63. func Test_reflect_uint(t *testing.T) {
  64. iter := ParseString(`123`)
  65. val := uint(0)
  66. iter.ReadVal(&val)
  67. if val != 123 {
  68. t.Fatal(val)
  69. }
  70. }
  71. func Test_reflect_uint8(t *testing.T) {
  72. iter := ParseString(`123`)
  73. val := uint8(0)
  74. iter.ReadVal(&val)
  75. if val != 123 {
  76. t.Fatal(val)
  77. }
  78. }
  79. func Test_reflect_uint16(t *testing.T) {
  80. iter := ParseString(`123`)
  81. val := uint16(0)
  82. iter.ReadVal(&val)
  83. if val != 123 {
  84. t.Fatal(val)
  85. }
  86. }
  87. func Test_reflect_uint32(t *testing.T) {
  88. iter := ParseString(`123`)
  89. val := uint32(0)
  90. iter.ReadVal(&val)
  91. if val != 123 {
  92. t.Fatal(val)
  93. }
  94. }
  95. func Test_reflect_uint64(t *testing.T) {
  96. iter := ParseString(`123`)
  97. val := uint64(0)
  98. iter.ReadVal(&val)
  99. if val != 123 {
  100. t.Fatal(val)
  101. }
  102. }
  103. func Test_reflect_byte(t *testing.T) {
  104. iter := ParseString(`123`)
  105. val := byte(0)
  106. iter.ReadVal(&val)
  107. if val != 123 {
  108. t.Fatal(val)
  109. }
  110. }
  111. func Test_reflect_float32(t *testing.T) {
  112. iter := ParseString(`1.23`)
  113. val := float32(0)
  114. iter.ReadVal(&val)
  115. if val != 1.23 {
  116. fmt.Println(iter.Error)
  117. t.Fatal(val)
  118. }
  119. }
  120. func Test_reflect_float64(t *testing.T) {
  121. iter := ParseString(`1.23`)
  122. val := float64(0)
  123. iter.ReadVal(&val)
  124. if val != 1.23 {
  125. fmt.Println(iter.Error)
  126. t.Fatal(val)
  127. }
  128. }
  129. func Test_reflect_bool(t *testing.T) {
  130. iter := ParseString(`true`)
  131. val := false
  132. iter.ReadVal(&val)
  133. if val != true {
  134. fmt.Println(iter.Error)
  135. t.Fatal(val)
  136. }
  137. }