Created
May 22, 2017 16:33
-
-
Save ntoskrnl/1d7c837186c2263638c76d06389bad01 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`.
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