summaryrefslogtreecommitdiff
path: root/xmpp/element_buffer_test.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-04 22:10:55 +0200
committerxengineering <me@xengineering.eu>2023-07-04 22:15:17 +0200
commit48811e7d2487ebc3db49b8af7e20f57db4ac28f4 (patch)
treea317f8dc44ac9828ae5806e1fa1dee7547118619 /xmpp/element_buffer_test.go
parent5570ccd1d6b50042acbf2fad3793afa6dde79ca2 (diff)
parentd9fe0a4360770b1e4b6b4fb3686c3275ad1b6e6e (diff)
downloadlimox-48811e7d2487ebc3db49b8af7e20f57db4ac28f4.tar
limox-48811e7d2487ebc3db49b8af7e20f57db4ac28f4.tar.zst
limox-48811e7d2487ebc3db49b8af7e20f57db4ac28f4.zip
Merge branch 'element-handling'
This moves away from the concept to parse each individual XML token from the token and group them as a []xml.Token slice for further processing. While this is still possible, receiving aswell as sending has switched to define structs with XML tags which can be marshalled and unmarshalled with the xml.Encoder.EncodeElement() and xml.Decoder.DecodeElement() functions. Further documentation can be found at https://pkg.go.dev/encoding/xml#Unmarshal and https://pkg.go.dev/encoding/xml#Marshal. This merge reduces with its changes the number of code lines in the XMPP implementation by around 41 percent!
Diffstat (limited to 'xmpp/element_buffer_test.go')
-rw-r--r--xmpp/element_buffer_test.go55
1 files changed, 0 insertions, 55 deletions
diff --git a/xmpp/element_buffer_test.go b/xmpp/element_buffer_test.go
deleted file mode 100644
index af3d5c2..0000000
--- a/xmpp/element_buffer_test.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package xmpp
-
-import (
- "encoding/xml"
- "strings"
- "testing"
-)
-
-// bufTest is a struct containing a test point for the
-// xengineering.eu/limox/xmpp.elementBuffer. It contains a test XML string
-// which has to be exactly one XML element and an array of indentation levels
-// which have to be checked after each token which is parsed.
-type bufTest struct {
- xml string
- levels []int
-}
-
-func TestElementBuffer(t *testing.T) {
- tests := []bufTest{
- bufTest{`<stream></stream>`, []int{1, 0}},
- bufTest{`<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}},
- bufTest{`<!-- comment --><a><b>testing</b></a>`, []int{0, 1, 2, 2, 1, 0}},
- }
-
- for _, v := range tests {
- r := strings.NewReader(v.xml)
- d := xml.NewDecoder(r)
- b := newElementBuffer()
-
- i := 0
-
- for {
- token, err := d.Token()
- if err != nil {
- if i != len(v.levels) {
- t.Fatalf("Stopped parsing at unexpected index due to error `%v`!\n", err)
- }
- break
- }
-
- err = b.add(token)
- if err != nil {
- t.Fatalf("add(token) failed with 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])
- }
-
- i += 1
- }
- }
-}