|
Groovy example source code file (IndentPrinterTest.groovy)
The Groovy IndentPrinterTest.groovy source code
package groovy.util
/**
* Unit test for IndentPrinter.
* @author Hamlet D'Arcy
*/
class IndentPrinterTest extends GroovyTestCase {
public void testSimpleIndentation() {
def out = new StringWriter()
def printer = new IndentPrinter(new PrintWriter(out))
printer.printIndent()
printer.println 'parent'
printer.incrementIndent()
printer.printIndent()
printer.println 'child'
printer.decrementIndent()
printer.printIndent()
printer.println 'parent2'
printer.flush()
assert 'parent\n child\nparent2\n' == out.toString()
}
public void testInWithBlock() {
def out = new StringWriter()
new IndentPrinter(new PrintWriter(out)).with { p ->
p.printIndent()
p.println('parent1')
p.incrementIndent()
p.printIndent()
p.println('child 1')
p.printIndent()
p.println('child 2')
p.decrementIndent()
p.printIndent()
p.println('parent2')
p.flush()
}
assert 'parent1\n child 1\n child 2\nparent2\n' == out.toString()
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy IndentPrinterTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.