Created
May 28, 2015 11:14
-
-
Save paulk-asert/5d0ab5c91db3b32cfb22 to your computer and use it in GitHub Desktop.
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
@groovy.transform.TypeChecked | |
def myMethod() { | |
def s = 'The 3 quick\nbrown 4 fox' | |
def expected = 'The _ QUICK|brown _ FOX|' | |
def result = '' | |
new StringReader(s).splitEachLine(~/\d/){ result += "${it[0]}_${it[1].toUpperCase()}|" } | |
assert result == expected; result = '' | |
new StringReader(s).splitEachLine(~/\d/){ parts -> result += "${parts[0]}_${parts[1].toUpperCase()}|" } | |
assert result == expected; result = '' | |
new StringReader(s).splitEachLine(~/\d/){ List parts -> result += "${parts[0]}_${parts[1].toUpperCase()}|" } | |
assert result == expected; result = '' | |
new StringReader(s).splitEachLine(~/\d/){ p1, p2 -> result += "${p1}_${p2.toUpperCase()}|" } | |
assert result == expected; result = '' | |
new StringReader(s).splitEachLine(~/\d/){ String p1, String p2 -> result += "${p1}_${p2.toUpperCase()}|" } | |
assert result == expected; result = '' | |
new StringReader(s).splitEachLine(~/\d/){ String p1 -> result += "${p1.toUpperCase()}|" } | |
assert result == 'THE |BROWN |'; result = '' | |
} | |
myMethod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment