package xmpp import ( "encoding/xml" "strings" "testing" ) type bufTest struct { xml string levels []int } func TestElementBuffer(t *testing.T) { var tests = []bufTest{ bufTest{``, []int{1, 0}}, bufTest{`testing`, []int{1, 2, 2, 1, 0}}, bufTest{`testing`, []int{1, 1, 2, 2, 1, 0}}, } for _, v := range tests { r := strings.NewReader(v.xml) d := xml.NewDecoder(r) b := newElementBuffer() for i, _ := range v.levels { token, err := d.Token() if err != nil { break } err = b.add(token) if err != nil { t.Fatalf("xmpp.elementBuffer.add() returned error: `%v`!\n", err) } if b.level != v.levels[i] { t.Fatalf("Indent level of xmpp.elementBuffer %d does not match value given by test data %d!\n", b.level, v.levels[i]) } } } }