~samwhited/xmpp

fe8268521927881ec855b59ab3d1d1faa6498c8c — Sam Whited 5 years ago f332396
jid: Add more escape/unescape tests
1 files changed, 21 insertions(+), 7 deletions(-)

M jid/jid_test.go
M jid/jid_test.go => jid/jid_test.go +21 -7
@@ 169,16 169,30 @@ func TestCopy(t *testing.T) {
const allescaped = `\20\22\26\27\2f\3a\3c\3e\40\5c`

func TestEscape(t *testing.T) {
	if e := Escape(escape); e != allescaped {
		t.Errorf("Escaped localpart should be `%s` but got: `%s`", allescaped, e)
	for _, test := range []struct {
		unescaped, escaped string
	}{
		{escape, allescaped},
		{`nothingtodohere`, `nothingtodohere`},
		{"", ""},
	} {
		if e := Escape(test.unescaped); e != test.escaped {
			t.Errorf("Escaped localpart should be `%s` but got: `%s`", test.escaped, e)
		}
	}
}

func TestUnescape(t *testing.T) {
	if u := Unescape(allescaped); u != escape {
		t.Errorf("Unescaped localpart should be `%s` but got: `%s`", escape, u)
	}
	if u := Unescape(`\20\3c\3C\aa\\\`); u != ` <<\aa\\\` {
		t.Errorf("Unescaped localpart should be ` <<\\aa\\\\\\` but got: `%s`", u)
	for _, test := range []struct {
		escaped, unescaped string
	}{
		{allescaped, escape},
		{`\20\3c\3C\aa\\\`, ` <<\aa\\\`},
		{"nothingtodohere", "nothingtodohere"},
		{"", ""},
	} {
		if u := Unescape(test.escaped); u != test.unescaped {
			t.Errorf("Unescaped localpart should be `%s` but got: `%s`", test.unescaped, u)
		}
	}
}