From bfffca845be49cc2a113602cd994a2f430b95f58 Mon Sep 17 00:00:00 2001 From: xengineering Date: Thu, 25 May 2023 18:57:36 +0200 Subject: Add unit test for xmpp.username() and fix it The second unit test detected a bug - they are worth the effort! --- xmpp/jid_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'xmpp/jid_test.go') diff --git a/xmpp/jid_test.go b/xmpp/jid_test.go index b900b9c..6f8b9fd 100644 --- a/xmpp/jid_test.go +++ b/xmpp/jid_test.go @@ -19,3 +19,20 @@ func TestDomainpart(t *testing.T) { } } } + +func TestUsername(t *testing.T) { + var data = map[string]string{ + "user@example.org/ressource": "user", + "example.org/ressource": "", + "user@example.org": "user", + "df%§df?LÖ@example.org": "df%§df?LÖ", + "example.org": "", + "test.eu": "", + } + + for k, v := range(data) { + if username(k) != v { + t.Fatalf("Username of JID '%s' is not '%s'!", k, v) + } + } +} -- cgit v1.2.3-70-g09d2