// This example demonstrates how to use ConfigState.Dump to dump variables to // stdout func ExampleConfigState_Dump() { // See the top-level Dump example for details on the types used in this // example. // Create two ConfigState instances with different indentation. scs := spew.ConfigState{Indent: "\t"} scs2 := spew.ConfigState{Indent: " "} // Setup some sample data structures for the example. bar := Bar{uintptr(0)} s1 := Foo{bar, map[interface{}]interface{}{"one": true}} // Dump using the ConfigState instances. scs.Dump(s1) scs2.Dump(s1) // Output: // (spew_test.Foo) { // unexportedField: (spew_test.Bar) { // data: (uintptr) <nil> // }, // ExportedField: (map[interface {}]interface {}) (len=1) { // (string) (len=3) "one": (bool) true // } // } // (spew_test.Foo) { // unexportedField: (spew_test.Bar) { // data: (uintptr) <nil> // }, // ExportedField: (map[interface {}]interface {}) (len=1) { // (string) (len=3) "one": (bool) true // } // } // }
// This example demonstrates how to use a ConfigState. func ExampleConfigState() { // Modify the indent level of the ConfigState only. The global // configuration is not modified. scs := spew.ConfigState{Indent: "\t"} // Output using the ConfigState instance. v := map[string]int{"one": 1} scs.Printf("v: %v\n", v) scs.Dump(v) // Output: // v: map[one:1] // (map[string]int) (len=1) { // (string) (len=3) "one": (int) 1 // } }
func TestDecode(t *testing.T) { scs := spew.ConfigState{Indent: "\t", ContinueOnMethod: true} for i, tt := range decodeTests { if tt.ptr == nil { continue } // v = new(right-type) v := reflect.New(reflect.TypeOf(tt.ptr).Elem()) if err := Decode(v.Interface(), tt.in); !reflect.DeepEqual(err, tt.err) { t.Errorf("#%d: got error %v want %v", i, err, tt.err) continue } if !reflect.DeepEqual(v.Elem().Interface(), tt.out) { scs.Dump(v.Elem().Interface(), tt.out) t.Errorf("#%d: mismatch\nhave: %+v\nwant: %+v", i, v.Elem().Interface(), tt.out) continue } // Check round trip. if tt.err == nil { enc, err := Encode(v.Interface()) if err != nil { t.Errorf("#%d: error re-marshaling: %v", i, err) continue } vv := reflect.New(reflect.TypeOf(tt.ptr).Elem()) if err := Decode(vv.Interface(), enc); err != nil { t.Errorf("#%d: error re-decodeing: %v", i, err) continue } if !reflect.DeepEqual(v.Elem().Interface(), vv.Elem().Interface()) { t.Errorf("#%d: mismatch\nhave: %#+v\nwant: %#+v", i, v.Elem().Interface(), vv.Elem().Interface()) continue } } } }
func Test_quick(t *testing.T) { LogOn() unit := 32 plot := Plot{ File{"out.pdf"}, PageConfig{ Width: unit * 4, Height: unit * 3, NSubpageX: 1, NSubpageY: 2, }, LineWidth{0.2}, Subpage{ //Viewport{XMin: 0, XMax: 0.5, YMin: 0, YMax: 1}, Block{ PolyLine{[]float64{0, 3}, []float64{0, 3}}, }, Axis{Position: TOP | RIGHT | LEFT | BOTTOM}, Legend{ Option: LEGEND_BACKGROUND | LEGEND_BOUNDING_BOX, Position: TOP | RIGHT | INSIDE | VIEWPORT, Offset: LegendOffset{0.02, 0.02}, PlotWidth: 0.05, BackColor: 0, Box: BoundingBox{1, 1}, OptionArray: []LegendType{LEGEND_LINE, LEGEND_LINE, LEGEND_LINE, LEGEND_LINE}, Text: TextLegend{Offset: 0.5, Scale: 0.8, Spacing: 1.5, Justification: 1.0, Colors: []int{1, 1, 1, 1}, Texts: []string{"k=1", "k=2", "k=3", "k=4"}}, Line: LineLegend{Colors: []int{3, 5, 8, 11}, Styles: []int{1, 1, 1, 1}, Widths: []float64{0.2, 0.2, 0.2, 0.2}}, }, }, Subpage{}, } pp := spew.ConfigState{Indent: " "} prepared := plot.Prepare() pp.Dump(prepared) prepared.Do() }