1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-21 23:07:33 +02:00

implement any api

This commit is contained in:
Tao Wen
2016-12-10 23:59:40 +08:00
parent f98c2a4150
commit aa42ac95c0
6 changed files with 508 additions and 7 deletions

63
any_test.go Normal file
View File

@ -0,0 +1,63 @@
package jsoniter
import (
"testing"
"fmt"
)
func Test_get_from_map(t *testing.T) {
any := Any{Val: map[string]interface{}{
"hello": "world",
}}
if any.GetString("hello") != "world" {
t.FailNow()
}
}
func Test_get_from_array(t *testing.T) {
any := Any{Val: []interface{}{
"hello", "world",
}}
if any.GetString(1) != "world" {
t.FailNow()
}
}
func Test_get_int(t *testing.T) {
any := Any{Val: []interface{}{
1, 2, 3,
}}
if any.GetInt(1) != 2 {
t.FailNow()
}
}
func Test_is_null(t *testing.T) {
any := Any{Val: []interface{}{
1, 2, 3,
}}
if any.IsNull() != false {
t.FailNow()
}
}
func Test_get_bool(t *testing.T) {
any := Any{Val: []interface{}{
true, true, false,
}}
if any.GetBool(1) != true {
t.FailNow()
}
}
func Test_nested_read(t *testing.T) {
any := Any{Val: []interface{}{
true, map[string]interface{}{
"hello": "world",
}, false,
}}
if any.GetString(1, "hello") != "world" {
fmt.Println(any.Error)
t.FailNow()
}
}