-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamplex_test.go
More file actions
37 lines (35 loc) · 943 Bytes
/
examplex_test.go
File metadata and controls
37 lines (35 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package xjson
import (
"log"
"testing"
)
func ExampleEmptyArrayAndEmptyObject () {
response := struct {
Books []string `json:"books"`
Map map[string]string `json:"map"`
}{}
data, err := Marshal(response) ; if err != nil {panic(err)}
log.Print(string(data)) // {"books":null, map:{}}
}
func TestExampleEmptyArrayAndEmptyObject(t *testing.T) {
emptyObjectAndArrayNotNull = true
defer func() {
emptyObjectAndArrayNotNull = false
}()
ExampleEmptyArrayAndEmptyObject()
}
func ExampleIntFloatAutoConvertString () {
request := struct {
Page int `json:"page"`
Price float64 `json:"price"`
}{}
err := Unmarshal([]byte(`{"page":"1", "price": "1.05"}`), &request) ; if err != nil {panic(err)}
log.Printf("%+v", request) // {Page:1 Price:1.05}
}
func TestExampleIntFloatAutoConvertString(t *testing.T) {
autoNumberConvertString = true
defer func() {
autoNumberConvertString = false
}()
ExampleIntFloatAutoConvertString()
}