Skip to content

Instantly share code, notes, and snippets.

@ntoskrnl
Last active May 22, 2017 16:36
Show Gist options
  • Save ntoskrnl/518a0978fb3a13f7e8bd6343530b438e to your computer and use it in GitHub Desktop.
Save ntoskrnl/518a0978fb3a13f7e8bd6343530b438e to your computer and use it in GitHub Desktop.
Python script that converts camel case unit test names a_b_c to `a - b - c`. Usage: `cat SomeTest.kt > testnames.py > SomeTest.kt`
import re
import sys
def convert(s):
parts = s.split('_')
r = []
for part in parts:
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1 \2', part)
s1 = re.sub('([a-z0-9])([A-Z])', r'\1 \2', s1).lower()
r.append(s1)
return (" - ").join(r)
s = ''
for line in sys.stdin:
s = s + line
p = re.compile(r'@(org\.junit\.)?Test(\n|\s|@[0-9A-Za-z_]+)+(fun\s+([0-9A-Za-z_]+)\()')
tickers = re.findall(p, s)
for x in tickers:
original = x[3]
target = convert(original)
# print original + ' => ' + target
s = re.sub('(' + original + ')', '`' + target + '`', s)
print '@file:Suppress("UnknownIdentifier")'
print s
@ntoskrnl
Copy link
Author

This script can make the following rename:

unsentMessage_onDeleteClick_deletesMessage => unsent message - on delete click - deletes message
attachView_loadSuccess_marksChannelAsRead => attach view - load success - marks channel as read
attachView_loadError_doesNotMarkChannelAsRead => attach view - load error - does not mark channel as read
attachView_showsActionsMenuWithItemActions_itemChannelContext => attach view - shows actions menu with item actions - item channel context
attachView_showsEmptyActionsMenu_unknownChannelContext => attach view - shows empty actions menu - unknown channel context
attachView_setsChannelContextInView_itemChannelContext => attach view - sets channel context in view - item channel context
attachView_showsChannelContextInView_itemChannelContext => attach view - shows channel context in view - item channel context
attachView_doesNotSetChannelContextInView_unknownChannelContext => attach view - does not set channel context in view - unknown channel context
attachView_hidesChannelContextInView_unknownChannelContext => attach view - hides channel context in view - unknown channel context
menuItemClick_blockUser_userBlocked => menu item click - block user - user blocked
menuItemClick_deleteChannel_channelDeleted => menu item click - delete channel - channel deleted
onCreateView_viewUpdateSubTitle_ifChannelDataLoad => on create view - view update sub title - if channel data load

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment