forked from jenkinsci/workflow-cps-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jenkinsci#70 from abayer/jenkins-46358
[FIXED JENKINS-46358] Add support for StringGroovyMethods w/closures
- Loading branch information
Showing
5 changed files
with
177 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
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
101 changes: 101 additions & 0 deletions
101
lib/src/test/groovy/com/cloudbees/groovy/cps/CpsStringGroovyMethodsTest.groovy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.cloudbees.groovy.cps | ||
|
||
import org.junit.Ignore | ||
import org.junit.Test | ||
|
||
|
||
class CpsStringGroovyMethodsTest extends AbstractGroovyCpsTest { | ||
@Test | ||
void eachMatch() { | ||
evalCPSAndSync(''' | ||
int matchCount = 0 | ||
"foobarfoooobar".eachMatch(~/foo/) { matchCount++ } | ||
return matchCount | ||
''', 2) | ||
|
||
evalCPSAndSync(''' | ||
int matchCount = 0 | ||
"foobarfoooobar".eachMatch('foo') { matchCount++ } | ||
return matchCount | ||
''', 2) | ||
} | ||
|
||
@Test | ||
void find() { | ||
evalCPSAndSync(''' | ||
return "foobar".find("oob") { it.reverse() } | ||
''', "raboof") | ||
|
||
evalCPSAndSync(''' | ||
return "foobar".find(~/oob/) { it.reverse() } | ||
''', "raboof") | ||
} | ||
|
||
@Test | ||
void findAll() { | ||
evalCPSAndSync(''' | ||
return "foobarfoobarfoo".findAll("foo") { it.reverse() } | ||
''', ['oof', 'oof', 'oof']) | ||
|
||
evalCPSAndSync(''' | ||
return "foobarfoobarfoo".findAll(~/foo/) { it.reverse() } | ||
''', ['oof', 'oof', 'oof']) | ||
} | ||
|
||
@Test | ||
void replaceAll() { | ||
evalCPSAndSync(''' | ||
return "foobarfoobarfoo".replaceAll("foo") { it.reverse() } | ||
''', "oofbaroofbaroof") | ||
|
||
evalCPSAndSync(''' | ||
return "foobarfoobarfoo".replaceAll(~/foo/) { it.reverse() } | ||
''', "oofbaroofbaroof") | ||
} | ||
|
||
@Test | ||
void replaceFirst() { | ||
evalCPSAndSync(''' | ||
return "foobarfoobarfoo".replaceFirst("foo") { it.reverse() } | ||
''', "oofbarfoobarfoo") | ||
|
||
evalCPSAndSync(''' | ||
return "foobarfoobarfoo".replaceFirst(~/foo/) { it.reverse() } | ||
''', "oofbarfoobarfoo") | ||
} | ||
|
||
@Ignore("Waiting for StringGroovyMethods.LineIterable translation") | ||
@Test | ||
void splitEachLine() { | ||
evalCPSAndSync(''' | ||
return """ | ||
abc|def | ||
ghi|jkl | ||
mno|pqr | ||
""".splitEachLine("|") { it.reverse() } | ||
''', "bob") | ||
} | ||
|
||
@Test | ||
void takeWhile() { | ||
evalCPSAndSync(''' | ||
return "Groovy".takeWhile{ it != 'v' } | ||
''', "Groo") | ||
|
||
evalCPSAndSync(''' | ||
def ovyStr = 'ovy' | ||
return "Gro${ovyStr}".takeWhile{ it != "v" } | ||
''', "Groo") | ||
} | ||
|
||
private void evalCPSAndSync(String script, Object value) { | ||
evalCPS(script) == value | ||
evalCPS(""" | ||
@NonCPS | ||
def someMethod() { | ||
${script} | ||
} | ||
someMethod() | ||
""") == value | ||
} | ||
} |