|
Groovy example source code file (ClosureExpressionTest.groovy)
The Groovy ClosureExpressionTest.groovy source codepackage org.codehaus.groovy.ast.expr import org.codehaus.groovy.ast.builder.AstBuilder /** * * @author Hamlet D'Arcy */ class ClosureExpressionTest extends GroovyTestCase { void testGetText_Simple() { def expression = buildFromString 'return { it * it }' assert expression.text == '{ -> ... }' } void testGetText_Parameter() { def expression = buildFromString 'return { x -> x * x }' assert expression.text == '{ java.lang.Object x -> ... }' } void testGetText_MultipleParameters() { def expression = buildFromString 'return { x, y -> x * y }' assert expression.text == '{ java.lang.Object x, java.lang.Object y -> ... }' } void testGetText_TypedParameter() { def expression = buildFromString 'return { String x -> x * x }' assert expression.text == '{ java.lang.String x -> ... }' } void testGetText_MultipleTypedParameters() { def expression = buildFromString 'return { String x, Integer y -> x * y }' assert expression.text == '{ java.lang.String x, java.lang.Integer y -> ... }' } private Expression buildFromString(String source) { def ast = new AstBuilder().buildFromString(source) ast[0].statements[0].expression } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy ClosureExpressionTest.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.