alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (ParsingTest.groovy)

This example Groovy source code file (ParsingTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

a, a, groovy2605, groovy2605, map, map, parsingtest, short, string, string

The Groovy ParsingTest.groovy source code

package gls.syntax

public class ParsingTest extends gls.CompilableTestSupport {
    void testExpressionParsingWithCastingInFrontOfAClosure() {
        int[] numbers = new int[3]

        shouldCompile """
            (String) {-> print ""}.call()
        """
    
        shouldCompile """
            (String[]) {-> print ""}.call()
        """

        shouldCompile """
            (short) {-> print numbers[0]}.call()
        """
        
        shouldCompile """
            (short[]) {-> print numbers}.call()
        """
        def testObj = new Groovy2605()

        def val1 = (Groovy2605) {-> return testObj}.call()
        assert val1 instanceof Groovy2605
        
        def val2 = (String){-> return testObj}.call()
        assert val2 instanceof String
        assert val2 == "[A Groovy2605 object]"

        def val3 = (short) {-> return numbers[0]}.call()
        assert val3 instanceof Short

        def val4 = (short[]) {-> return numbers}.call()
        assert val4.class.componentType == short
    }

    void testExpressionParsingWithCastInFrontOfAMap() {
        shouldCompile """
            def m = (Map)[a:{ "foo"; println 'bar' }]
        """
    }
}

class Groovy2605 {
    String toString(){
        return "[A Groovy2605 object]"
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy ParsingTest.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.