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

Groovy example source code file (LineColumnCheckTestSuite.java)

This example Groovy source code file (LineColumnCheckTestSuite.java) 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

filenotfoundexception, filereader, io, ioexception, linecolumnchecker, linecolumnchecktestsuite, linecolumnchecktestsuite, runtimeexception, string, string, stringbuffer, stringbuffer, test_file_path, testsuite, testsuite

The Groovy LineColumnCheckTestSuite.java source code

package org.codehaus.groovy.ast;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

import junit.framework.TestSuite;

/**
 * Tests the LineColumn information in file specified in TEST_FILE_PATH
 * 
 * The file in the specified path should look like:
 * 
 * ###<testname>:::
 * <source code from which the AST will be built>
 * :::<expected AST output>
 * 
 * The section above can be repeated for every new TestCase
 * 
 * The AST output from the visitor is quite big. Also for small source code snippets. Therefore
 * it is possible to only specify the nodes that you wan't to check and separate them with a semicolon.
 * A semicolon is also needed when you begin with a new line.
 * Bsp: 
 * [TryCatchStatement,(1:1),(9:2)][BlockStatement,(1:5),(3:3)];
 * [CatchStatement,(3:3),(5:3)][BlockStatement,(3:12),(5:3)];
 * [CatchStatement,(5:3),(7:3)][BlockStatement,(5:12),(7:3)];
 * [BlockStatement,(7:3),(9:2)][BlockStatement,(7:11),(9:2)]
 * 
 * [<NodeType>,(:),(:)]
 * 
 * @author <a href="mailto:martin.kempf@gmail.com">Martin Kempf
 *
 */
public class LineColumnCheckTestSuite extends TestSuite {

    public static final String TEST_FILE_PATH = "./src/test/org/codehaus/groovy/ast/LineColumnCheck.txt";

    public static TestSuite suite() {
        TestSuite ts = new TestSuite("LineColumnCheckTestSuite");
        String content;
        try {
            content = getContent(new FileReader(TEST_FILE_PATH));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        String[] tests = content.split("###");
        String testName = "";
        String source = "";
        String expected;
        for (String test : tests) {
            String[] slicedTests = test.split(":::");
            for (int ii = 0; ii < slicedTests.length; ii++) {
                if (ii % 3 == 0) {
                    testName = slicedTests[ii];
                } else if (ii % 3 == 1) {
                    source = slicedTests[ii].trim();
                } else if (ii % 3 == 2) {
                    expected = slicedTests[ii].trim();
                    ts.addTest(new LineColumnChecker(testName, source, expected));
                }
            }
        }
        return ts;
    }

    private static String getContent(Reader reader) {
        int character;
        StringBuffer content = new StringBuffer();
        try {
            while ((character = reader.read()) != -1) {
                content.append((char) character);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content.toString();
    }

}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy LineColumnCheckTestSuite.java 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.