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

Groovy example source code file (NodeAsHTMLPrinterTest.java)

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

diff, exception, exception, foo, footer, footer, header, header, nodeashtmlprintertest, string, string, testcase, traversaltesthelper

The Groovy NodeAsHTMLPrinterTest.java source code

package org.codehaus.groovy.antlr.treewalker;

import junit.framework.TestCase;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;

/**
 * Testcases for the antlr AST visitor that prints groovy source code nodes as HTML.
 */
public class NodeAsHTMLPrinterTest extends TestCase {

    private static final String HEADER = "<html>
";
    private static final String FOOTER = "</pre>";

    protected void setUp() throws Exception {
        XMLUnit.setIgnoreWhitespace(true);
    }

    public void testAbstract() throws Exception {
        assertXmlEquals(
                HEADER +
                        "<code title='MODIFIERS'>" +
                        "  <code title='\"public\"'>" +
                        "</font>" +
                        "<code title='\"abstract\"'>" +
                        "<code title='CLASS_DEF'>" +
                        "<code title='an identifier'>" +
                        "<code title='EXTENDS_CLAUSE'>" +
                        "<code title='IMPLEMENTS_CLAUSE'>" +
                        "<code title='OBJBLOCK'>" +
                        FOOTER,
                pretty("public abstract class Foo{}"));

    }

    public void testArrayDeclarator() throws Exception {
        assertXmlEquals(
                HEADER +
                        "<code title='VARIABLE_DEF'>" +
                        "  <code title='TYPE'>" +
                        "    <code title='ARRAY_DECLARATOR'>" +
                        "      <code title='\"int\"'>" +
                        "    </font>" +
                        "  </font>" +
                        "  <code title='an identifier'>" +
                        "  <code title=\"'='\">" +
                        "    <code title='\"new\"'>" +
                        "      <code title='\"int\"'>" +
                        "      <code title='ARRAY_DECLARATOR'>" +
                        "        <code title='a numeric literal'>" +
                        "      </font>" +
                        "    </font>" +
                        "  </font>" +
                        "</font>" +
                        FOOTER,
                pretty("int[] primes = new int[5]"));
    }

    public void testRegexMatch() throws Exception {
        assertXmlEquals(
                HEADER +
                        "<code title='\"if\"'>" +
                        "  <code title='an identifier'>" +
                        "  <code title=\"'==~'\">" +
                        "  <code title='a string literal'>" +
                        "</font>" +
                        "<code title='SLIST'>" +
                        FOOTER,
                pretty("if (foo==~\"bar\"){}"));
    }

    private void assertXmlEquals(String expected, String actual) throws Exception {
        Diff diff = new Diff(expected, actual);
        assertTrue(diff.toString(), diff.similar());
    }

    private String pretty(String input) throws Exception {
        TraversalTestHelper traverser = new TraversalTestHelper();
        return traverser.traverse(input, NodeAsHTMLPrinter.class);
    }

}

Other Groovy examples (source code examples)

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