1 16 package org.apache.commons.attributes.compiler.test; 17 18 import java.lang.reflect.Field ; 19 import java.lang.reflect.Method ; 20 import java.lang.reflect.Constructor ; 21 import java.io.File ; 22 import java.net.URL ; 23 import java.net.URLClassLoader ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import org.apache.commons.attributes.compiler.AttributeExpressionParser; 27 import junit.framework.TestCase; 28 29 public class AttributeExpressionParserTestCase extends TestCase { 30 31 private void singleTest (String expression, String className, AttributeExpressionParser.Argument[] args) { 32 AttributeExpressionParser.ParseResult result = AttributeExpressionParser.parse (expression, "noFile", 1); 33 AttributeExpressionParser.ParseResult expected = new AttributeExpressionParser.ParseResult (className); 34 for (int i = 0; i < args.length; i++) { 35 expected.arguments.add (args[i]); 36 } 37 38 assertEquals (expected, result); 39 } 40 41 public void testExpressions () throws Exception { 42 singleTest ("Inherited()", "Inherited", new AttributeExpressionParser.Argument[] {}); 43 44 singleTest ("AnAttribute(1,2)", "AnAttribute", new AttributeExpressionParser.Argument[] { 45 new AttributeExpressionParser.Argument(null, "1", 0), 46 new AttributeExpressionParser.Argument(null, "2", 0) 47 }); 48 49 singleTest ("AnAttribute(\"sometext,1,2\",'a',',')", "AnAttribute", new AttributeExpressionParser.Argument[] { 50 new AttributeExpressionParser.Argument(null, "\"sometext,1,2\"", 0), 51 new AttributeExpressionParser.Argument(null, "'a'", 0), 52 new AttributeExpressionParser.Argument(null, "','", 0) 53 }); 54 55 singleTest ("AnAttribute(\"sometext,1,2\",'a',',',alpha='\"',beta=\"\\\'\")", "AnAttribute", new AttributeExpressionParser.Argument[] { 56 new AttributeExpressionParser.Argument(null, "\"sometext,1,2\"", 0), 57 new AttributeExpressionParser.Argument(null, "'a'", 0), 58 new AttributeExpressionParser.Argument(null, "','", 0), 59 new AttributeExpressionParser.Argument("alpha", "'\"'", 0), 60 new AttributeExpressionParser.Argument("beta", "\"\\\'\"", 0) 61 }); 62 63 singleTest ("my.package. AnAttribute(\"sometext,1,2\",'a',',',alpha='\"',beta=\"\\\'\")", 64 "my.package. AnAttribute", new AttributeExpressionParser.Argument[] { 65 new AttributeExpressionParser.Argument(null, "\"sometext,1,2\"", 0), 66 new AttributeExpressionParser.Argument(null, "'a'", 0), 67 new AttributeExpressionParser.Argument(null, "','", 0), 68 new AttributeExpressionParser.Argument("alpha", "'\"'", 0), 69 new AttributeExpressionParser.Argument("beta", "\"\\\'\"", 0) 70 }); 71 } 72 73 } | Popular Tags |