Skip to content
Browse files

Fix mangle, add unit tests

  • Loading branch information...
1 parent 97105c2 commit 76383a2e2742f138a3852a2be4be919938eceff6 @richo richo committed Sep 26, 2011
Showing with 32 additions and 1 deletion.
  1. +5 −1 ircSocket.py
  2. +27 −0 test/unit/test_ircSocket.py
View
6 ircSocket.py
@@ -43,7 +43,11 @@ def mangle(name):
if len(name) < 8:
name += "_"
else:
- name = name[:6] + "00"
+ try:
+ myno = int(name[7:])+1
+ name = "%s%.2i" % (name[:6], myno)
+ except ValueError:
+ name = name[:6] + "00"
return name
def _load_modules():
View
27 test/unit/test_ircSocket.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+from helpers import *
+
+import ircSocket
+
+START("mangle")
+mangle = ircSocket.mangle
+
+nick = "richo"
+
+nick = mangle(nick)
+ASSERT(nick == "richo_", "Mangle should pad with underscores to 8 chars")
+
+for i in xrange(3):
+ nick = mangle(nick)
+
+ASSERT(nick == "richo_00", "Mangle should add numbers when nick length exceeded")
+
+for i in xrange(3):
+ nick = mangle(nick)
+
+ASSERT(nick == "richo_03", "Mangle should then increment those numerals")
+
+
+END()
+
+

0 comments on commit 76383a2

Please sign in to comment.
Something went wrong with that request. Please try again.