|
Groovy example source code file (NodeAsHTMLPrinterTest.java)
The Groovy NodeAsHTMLPrinterTest.java source codepackage 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); } } |
... 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.