Last active
May 22, 2017 16:36
-
-
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`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script can make the following rename: