github.com/hoop33/elvish@v0.0.0-20160801152013-6d25485beab4/util/deepprint_test.go (about)

     1  package util
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  type S struct {
     8  	I  int
     9  	S  string
    10  	Pt *T
    11  	G  G
    12  }
    13  
    14  type T struct {
    15  	M map[string]string
    16  }
    17  
    18  type G struct {
    19  }
    20  
    21  type U struct {
    22  	I int
    23  	S string
    24  }
    25  
    26  func (g G) GoString() string {
    27  	return "<G>"
    28  }
    29  
    30  var deepPrintTests = []struct {
    31  	in     interface{}
    32  	wanted string
    33  }{
    34  	{1, "1"},
    35  	{"foobar", `"foobar"`},
    36  	{map[string]int{"foobar": 42}, `map[string]int{"foobar": 42}`},
    37  	{[]int{42, 44}, `[]int{42, 44}`},
    38  	{[]int(nil), `nil`},
    39  	{(*int)(nil), `nil`},
    40  	{&S{42, "DON'T PANIC", &T{map[string]string{"foo": "bar"}}, G{}},
    41  		`&util.S{I: 42, S: "DON'T PANIC", Pt: &util.T{M: map[string]string{"foo": "bar"}}, G: <G>}`},
    42  	{[]interface{}{&U{42, "DON'T PANIC"}, 42, "DON'T PANIC"}, `[]interface {}{&util.U{I: 42, S: "DON'T PANIC"}, 42, "DON'T PANIC"}`},
    43  }
    44  
    45  func TestDeepPrint(t *testing.T) {
    46  	for _, tt := range deepPrintTests {
    47  		if out := DeepPrint(tt.in); out != tt.wanted {
    48  			t.Errorf("Deep(%v) => %#q, want %#q", tt.in, out, tt.wanted)
    49  		}
    50  	}
    51  }