~samwhited/xmpp

xmpp/jid/unsafe_test.go -rw-r--r-- 1017 bytes
c9743d9fSam Whited docs: update changelog to include deprecations 9 days 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
// Copyright 2018 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

package jid_test

import (
	"fmt"
	"testing"

	"mellium.im/xmpp/jid"
)

func TestInvalidUnsafeParseJIDs(t *testing.T) {
	for i, tc := range invalidJIDs {
		t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
			_, err := jid.ParseUnsafe(tc)
			if err != nil {
				t.Errorf("Expected unsafe JID to be valid, got: %q", err)
			}
		})
	}
}

func TestInvalidUnsafeJIDs(t *testing.T) {
	for i, tc := range invalidParts {
		t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
			defer func() {
				if r := recover(); r != nil {
					t.Errorf("Unexpected panic in NewUnsafe: %q", r)
				}
			}()
			u := jid.NewUnsafe(tc.lp, tc.dp, tc.rp)
			if u.Localpart() != tc.lp {
				t.Errorf("Unexpected localpart")
			}
			if u.Domainpart() != tc.dp {
				t.Errorf("Unexpected domainpart")
			}
			if u.Resourcepart() != tc.rp {
				t.Errorf("Unexpected resourcepart")
			}
		})
	}
}