~samwhited/clarkns

clarkns/ns_test.go -rw-r--r-- 713 bytes
7eacd4eaSam Whited Add boilerplate documentation and CI config 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package clarkns_test

import (
	"encoding/xml"
	"errors"
	"strconv"
	"testing"

	"mellium.im/clarkns"
)

var nsTests = [...]struct {
	s    string
	name xml.Name
	err  error
}{
	0: {},
	1: {
		s:    "{foo}bar",
		name: xml.Name{Space: "foo", Local: "bar"},
	},
	2: {
		s:    "bar",
		name: xml.Name{Local: "bar"},
	},
	3: {
		s:   "{foo",
		err: clarkns.ErrUnclosedNS,
	},
}

func TestNS(t *testing.T) {
	for i, tc := range nsTests {
		t.Run(strconv.Itoa(i), func(t *testing.T) {
			name, err := clarkns.Name(tc.s)
			if !errors.Is(err, tc.err) {
				t.Errorf("wrong error: want=%v, got=%v", tc.err, err)
			}

			if tc.name != name {
				t.Errorf("wrong namespace: want=%v, got=%v", tc.name, name)
			}
		})
	}
}