Skip to content

Instantly share code, notes, and snippets.

@ctoestreich
Created April 29, 2013 20:24
Show Gist options
  • Save ctoestreich/5484489 to your computer and use it in GitHub Desktop.
Save ctoestreich/5484489 to your computer and use it in GitHub Desktop.
Test for splitting grails params for scripts
assert doSplit('''-compile
-wsdl=some/path''') == ['-compile','-wsdl','some/path']
assert doSplit('-compile -wsdl=some/path') == ['-compile','-wsdl','some/path']
assert doSplit('''-compile -wsdl=some/path
-test ''') == ['-compile','-wsdl','some/path', '-test']
assert doSplit('''-compile
-wsdl=some/path/to/wsdl
-mark=12,123,123''') == ['-compile', '-wsdl', 'some/path/to/wsdl', '-mark', '12,123,123']
assert doSplit('-compile -wsdl=some/path/to/wsdl -mark=12,123,123') == ['-compile', '-wsdl', 'some/path/to/wsdl', '-mark', '12,123,123']
assert doSplit('-compile') == ['-compile']
private doSplit(string){
return string.split(/(\n|[ ]|=)/).collect{ it.trim() }.findResults { it && it != '' ? it : null }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment