unit test

This commit is contained in:
李斌
2023-03-26 16:01:35 +08:00
parent 3afcc88a9a
commit e436397995
16 changed files with 430 additions and 152 deletions

View File

@@ -2,7 +2,6 @@ package jsonUtil
import (
"fmt"
"log"
"testing"
)
@@ -86,6 +85,8 @@ func TestJsonToStruct1(t *testing.T) {
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Source float64 `json:"source"`
Number int `json:"number"`
Address Address `json:"address"`
Emails []string `json:"emails"`
}
@@ -93,6 +94,7 @@ func TestJsonToStruct1(t *testing.T) {
jsonData := `{
"name": "John Doe",
"age": 30,
"source": "99.99",
"address": {
"city": "Shanghai",
"country": "China"
@@ -146,39 +148,6 @@ func TestJsonToStruct1(t *testing.T) {
}
}
func TestJsonToStruct2(t *testing.T) {
type Address struct {
City string `json:"city"`
Country string `json:"country"`
}
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Address Address `json:"address"`
Interests []string `json:"interests"`
}
jsonData1 := `{
"name": "Bob",
"age": 25,
"address": {
"city": "Shanghai",
"country": "China"
},
"interests": ["reading", "swimming"]
}`
var person1 Person
err := JsonToStruct(jsonData1, &person1)
if err != nil {
log.Fatal(err)
}
fmt.Printf("person1%+v \n", person1)
}
// 多层级json测试
func TestJsonToStruct4(t *testing.T) {
type Address struct {