Fix unit tests
[govpp.git] / vendor / github.com / bennyscetbun / jsongo / debug.go
1 package jsongo
2
3 import (
4         "encoding/json"
5         "fmt"
6         "os"
7 )
8
9 //DebugPrint Print a JSONNode as json withindent
10 func (that *JSONNode) DebugPrint(prefix string) {
11         asJSON, err := json.MarshalIndent(that, "", "  ")
12         if err != nil {
13                 fmt.Printf("%s\n", err.Error())
14                 os.Exit(-1)
15         }
16         fmt.Printf("%s%s\n", prefix, asJSON)
17 }
18
19 func printfindent(indentlevel int, indentchar string, format string, args ...interface{}) {
20         for i := 0; i < indentlevel; i++ {
21                 fmt.Printf("%s", indentchar)
22         }
23         fmt.Printf(format, args...)
24 }
25
26 func (that *JSONNode) debugProspectValue(indentlevel int, indentchar string) {
27         printfindent(indentlevel, indentchar, "Is of Type: TypeValue\n")
28         printfindent(indentlevel, indentchar, "Value of type: %T\n", that.Get())
29         printfindent(indentlevel, indentchar, "%+v\n", that.Get())
30 }
31
32 func (that *JSONNode) debugProspectMap(indentlevel int, indentchar string) {
33         printfindent(indentlevel, indentchar, "Is of Type: TypeMap\n")
34         for key := range that.m {
35                 printfindent(indentlevel, indentchar, "%s:\n", key)
36                 that.m[key].DebugProspect(indentlevel+1, indentchar)
37         }
38 }
39
40 func (that *JSONNode) debugProspectArray(indentlevel int, indentchar string) {
41         printfindent(indentlevel, indentchar, "Is of Type: TypeArray\n")
42         for key := range that.a {
43                 printfindent(indentlevel, indentchar, "[%d]:\n", key)
44                 that.a[key].DebugProspect(indentlevel+1, indentchar)
45         }
46 }
47
48 //DebugProspect Print all the data the we ve got on a node and all it s children
49 func (that *JSONNode) DebugProspect(indentlevel int, indentchar string) {
50         switch that.t {
51         case TypeValue:
52                 that.debugProspectValue(indentlevel, indentchar)
53         case TypeMap:
54                 that.debugProspectMap(indentlevel, indentchar)
55         case TypeArray:
56                 that.debugProspectArray(indentlevel, indentchar)
57         case TypeUndefined:
58                 printfindent(indentlevel, indentchar, "Is of Type: TypeUndefined\n")
59         }
60 }