KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > attributes > compiler > test > AttributeExpressionParserTestCase


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.attributes.compiler.test;
17
18 import java.lang.reflect.Field JavaDoc;
19 import java.lang.reflect.Method JavaDoc;
20 import java.lang.reflect.Constructor JavaDoc;
21 import java.io.File JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.net.URLClassLoader JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
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 JavaDoc expression, String JavaDoc 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 JavaDoc {
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