1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-24 08:22:14 +02:00
json-iterator/any_test.go
2017-01-05 21:23:08 +08:00

73 lines
1.1 KiB
Go

package jsoniter
import (
"fmt"
"testing"
)
func Test_get_from_map(t *testing.T) {
any := Any{val: map[string]interface{}{
"hello": "world",
}}
if any.ToString("hello") != "world" {
t.FailNow()
}
}
func Test_get_from_array(t *testing.T) {
any := Any{val: []interface{}{
"hello", "world",
}}
if any.ToString(1) != "world" {
t.FailNow()
}
}
func Test_get_int(t *testing.T) {
any := Any{val: []interface{}{
1, 2, 3,
}}
if any.ToInt(1) != 2 {
t.FailNow()
}
}
func Test_is_null(t *testing.T) {
any := Any{val: []interface{}{
1, 2, 3,
}}
if any.IsNil() != false {
t.FailNow()
}
}
func Test_get_bool(t *testing.T) {
any := Any{val: []interface{}{
true, true, false,
}}
if any.ToBool(1) != true {
t.FailNow()
}
}
func Test_nested_read(t *testing.T) {
any := Any{val: []interface{}{
true, map[string]interface{}{
"hello": "world",
}, false,
}}
if any.ToString(1, "hello") != "world" {
fmt.Println(any.Error)
t.FailNow()
}
}
func Test_int_to_string(t *testing.T) {
any := Any{val: []interface{}{
true, 5, false,
}}
if any.ToString(1) != "5" {
t.FailNow()
}
}