2016-12-10 17:59:40 +02:00
|
|
|
package jsoniter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-01-05 15:23:08 +02:00
|
|
|
"testing"
|
2016-12-10 17:59:40 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_get_from_map(t *testing.T) {
|
2016-12-11 04:04:26 +02:00
|
|
|
any := Any{val: map[string]interface{}{
|
2016-12-10 17:59:40 +02:00
|
|
|
"hello": "world",
|
|
|
|
}}
|
2016-12-11 04:04:26 +02:00
|
|
|
if any.ToString("hello") != "world" {
|
2016-12-10 17:59:40 +02:00
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_get_from_array(t *testing.T) {
|
2016-12-11 04:04:26 +02:00
|
|
|
any := Any{val: []interface{}{
|
2016-12-10 17:59:40 +02:00
|
|
|
"hello", "world",
|
|
|
|
}}
|
2016-12-11 04:04:26 +02:00
|
|
|
if any.ToString(1) != "world" {
|
2016-12-10 17:59:40 +02:00
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_get_int(t *testing.T) {
|
2016-12-11 04:04:26 +02:00
|
|
|
any := Any{val: []interface{}{
|
2016-12-10 17:59:40 +02:00
|
|
|
1, 2, 3,
|
|
|
|
}}
|
2016-12-11 04:04:26 +02:00
|
|
|
if any.ToInt(1) != 2 {
|
2016-12-10 17:59:40 +02:00
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_is_null(t *testing.T) {
|
2016-12-11 04:04:26 +02:00
|
|
|
any := Any{val: []interface{}{
|
2016-12-10 17:59:40 +02:00
|
|
|
1, 2, 3,
|
|
|
|
}}
|
2017-01-05 15:23:08 +02:00
|
|
|
if any.IsNil() != false {
|
2016-12-10 17:59:40 +02:00
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_get_bool(t *testing.T) {
|
2016-12-11 04:04:26 +02:00
|
|
|
any := Any{val: []interface{}{
|
2016-12-10 17:59:40 +02:00
|
|
|
true, true, false,
|
|
|
|
}}
|
2016-12-11 04:04:26 +02:00
|
|
|
if any.ToBool(1) != true {
|
2016-12-10 17:59:40 +02:00
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_nested_read(t *testing.T) {
|
2016-12-11 04:04:26 +02:00
|
|
|
any := Any{val: []interface{}{
|
2016-12-10 17:59:40 +02:00
|
|
|
true, map[string]interface{}{
|
|
|
|
"hello": "world",
|
|
|
|
}, false,
|
|
|
|
}}
|
2016-12-11 04:04:26 +02:00
|
|
|
if any.ToString(1, "hello") != "world" {
|
2016-12-10 17:59:40 +02:00
|
|
|
fmt.Println(any.Error)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
2016-12-11 04:04:26 +02:00
|
|
|
|
|
|
|
func Test_int_to_string(t *testing.T) {
|
|
|
|
any := Any{val: []interface{}{
|
|
|
|
true, 5, false,
|
|
|
|
}}
|
|
|
|
if any.ToString(1) != "5" {
|
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|