jsoniter_any_test.go 506 B

123456789101112131415161718192021222324252627
  1. package jsoniter
  2. import "testing"
  3. func Test_read_string_as_any(t *testing.T) {
  4. iter := ParseString(`[1, {"hello": "world"}, 2]`)
  5. any := iter.ReadAny()
  6. if any.ToString(1, "hello") != "world" {
  7. t.FailNow()
  8. }
  9. }
  10. func Test_read_float64_as_any(t *testing.T) {
  11. iter := ParseString(`1.23`)
  12. any := iter.ReadAny()
  13. if any.ToFloat32() != 1.23 {
  14. t.FailNow()
  15. }
  16. }
  17. func Test_read_int_as_any(t *testing.T) {
  18. iter := ParseString(`123`)
  19. any := iter.ReadAny()
  20. if any.ToFloat32() != 123 {
  21. t.FailNow()
  22. }
  23. }