You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-21 23:07:33 +02:00
make any easier to work with
This commit is contained in:
31
any_test.go
31
any_test.go
@ -6,34 +6,34 @@ import (
|
||||
)
|
||||
|
||||
func Test_get_from_map(t *testing.T) {
|
||||
any := Any{Val: map[string]interface{}{
|
||||
any := Any{val: map[string]interface{}{
|
||||
"hello": "world",
|
||||
}}
|
||||
if any.GetString("hello") != "world" {
|
||||
if any.ToString("hello") != "world" {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func Test_get_from_array(t *testing.T) {
|
||||
any := Any{Val: []interface{}{
|
||||
any := Any{val: []interface{}{
|
||||
"hello", "world",
|
||||
}}
|
||||
if any.GetString(1) != "world" {
|
||||
if any.ToString(1) != "world" {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func Test_get_int(t *testing.T) {
|
||||
any := Any{Val: []interface{}{
|
||||
any := Any{val: []interface{}{
|
||||
1, 2, 3,
|
||||
}}
|
||||
if any.GetInt(1) != 2 {
|
||||
if any.ToInt(1) != 2 {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func Test_is_null(t *testing.T) {
|
||||
any := Any{Val: []interface{}{
|
||||
any := Any{val: []interface{}{
|
||||
1, 2, 3,
|
||||
}}
|
||||
if any.IsNull() != false {
|
||||
@ -42,22 +42,31 @@ func Test_is_null(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_get_bool(t *testing.T) {
|
||||
any := Any{Val: []interface{}{
|
||||
any := Any{val: []interface{}{
|
||||
true, true, false,
|
||||
}}
|
||||
if any.GetBool(1) != true {
|
||||
if any.ToBool(1) != true {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func Test_nested_read(t *testing.T) {
|
||||
any := Any{Val: []interface{}{
|
||||
any := Any{val: []interface{}{
|
||||
true, map[string]interface{}{
|
||||
"hello": "world",
|
||||
}, false,
|
||||
}}
|
||||
if any.GetString(1, "hello") != "world" {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user