summaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-06-28 17:43:38 +0200
committerxengineering <me@xengineering.eu>2023-06-29 19:34:52 +0200
commit64d71d587eb618cb4490e51d4af48e9f374f7f8d (patch)
treea7d22d3a88057a594fcf21c217038e9492941532 /xmpp
parentd170626154a4853be386c7180050afe09be3ca0b (diff)
downloadlimox-64d71d587eb618cb4490e51d4af48e9f374f7f8d.tar
limox-64d71d587eb618cb4490e51d4af48e9f374f7f8d.tar.zst
limox-64d71d587eb618cb4490e51d4af48e9f374f7f8d.zip
xmpp: Add indent level test for elementBuffer
This tests if the indent level is correctly detected. This basic test can be extended to support invalid XML elements which should be refused to add to the element buffer.
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/element_buffer_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/xmpp/element_buffer_test.go b/xmpp/element_buffer_test.go
new file mode 100644
index 0000000..3d03f0b
--- /dev/null
+++ b/xmpp/element_buffer_test.go
@@ -0,0 +1,40 @@
+package xmpp
+
+import (
+ "encoding/xml"
+ "strings"
+ "testing"
+)
+
+type bufTest struct {
+ xml string
+ levels []int
+}
+
+func TestElementBuffer(t *testing.T) {
+ var tests = []bufTest{
+ bufTest{`<stream></stream>`, []int{1, 0}},
+ bufTest{`<a><b>testing</b></a>`, []int{1, 2, 2, 1, 0}},
+ bufTest{`<a><!-- comment --><b>testing</b></a>`, []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])
+ }
+ }
+ }
+}