KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > query > regexptrees > test > TestRegexpTrees


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: TestRegexpTrees.java,v 1.7 2005/02/21 11:52:31 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.graph.query.regexptrees.test;
8
9 import junit.framework.TestSuite;
10
11 import com.hp.hpl.jena.graph.test.GraphTestBase;
12
13 import com.hp.hpl.jena.graph.query.regexptrees.*;
14 /**
15      Test useful properties of regexp trees.
16      @author hedgehog
17 */

18 public class TestRegexpTrees extends GraphTestBase
19     {
20     public TestRegexpTrees( String JavaDoc name )
21         { super( name ); }
22     
23     public static TestSuite suite()
24         { return new TestSuite( TestRegexpTrees.class ); }
25     
26     protected Object JavaDoc [][] equalities =
27         {
28             { new EndOfLine(), "EOL" },
29             { new EndOfLine(), "EOL" },
30             { new StartOfLine(), "SOL" },
31             { new StartOfLine(), "SOL" },
32             { new AnySingle(), "ANY" },
33             { new AnySingle(), "ANY" },
34             { new Paren( new AnySingle() ), "(ANY)" },
35             { new Paren( new EndOfLine() ), "(EOL)" },
36             { Text.create( "hello" ), "hello" },
37             { Text.create( "goodbye" ), "goodbye" },
38             { new AnyOf( "abcde" ), "any[abcde]" },
39             { new AnyOf( "defgh" ), "any[defgh]" },
40             { new NoneOf( "pqrst" ), "none[pqrst]" },
41             { new NoneOf( "12345" ), "none[12345]" },
42             { new BackReference( 1 ), "back(1)" },
43             { new BackReference( 2 ), "back(2)" }
44         };
45     
46     public void testEqualities()
47         {
48         for (int i = 0; i < equalities.length; i += 1)
49             for (int j = 0; j < equalities.length; j += 1)
50                 {
51                 Object JavaDoc [] A = equalities[i], B = equalities[j];
52                 boolean equal = A[1].equals( B[1] );
53                 if (A[0].equals( B[0] ) != equal )
54                     fail( A[0] + " should be " + (equal ? "equal to " : "different from ") + B[0] );
55                 }
56         }
57     
58     public void testConstantsDefinition()
59         {
60         assertEquals( RegexpTree.EOL, new EndOfLine() );
61         assertEquals( RegexpTree.SOL, new StartOfLine() );
62         assertEquals( RegexpTree.ANY, new AnySingle() );
63         }
64     
65     public void testExtractOperandFromOneOrMore()
66         {
67         testExtractFromOneOrMore( RegexpTree.EOL );
68         testExtractFromOneOrMore( RegexpTree.SOL );
69         testExtractFromOneOrMore( RegexpTree.ANY );
70         }
71     
72     public void testExtractOperandFromZeroOrMore()
73         {
74         testExtractFromZeroOrMore( RegexpTree.EOL );
75         testExtractFromZeroOrMore( RegexpTree.SOL );
76         testExtractFromZeroOrMore( RegexpTree.ANY );
77         }
78     
79     public void testExtractOperandFromOptional()
80         {
81         testExtractFromOptional( RegexpTree.EOL );
82         testExtractFromOptional( RegexpTree.SOL );
83         testExtractFromOptional( RegexpTree.ANY );
84         }
85     
86     public void testLiteralContents()
87         { assertEquals( "hello", Text.create( "hello" ).getString() ); }
88     
89     public void testParenOperand()
90         { assertSame( RegexpTree.EOL, new Paren( RegexpTree.EOL ).getOperand() ); }
91     
92     public void testParenIndex()
93         { assertEquals( 0, new Paren( RegexpTree.EOL ).getIndex() );
94         assertEquals( 1, new Paren( RegexpTree.EOL, 1 ).getIndex() );
95         assertEquals( 17, new Paren( RegexpTree.NON, 17 ).getIndex() ); }
96     
97     public void testBackReference()
98         { assertEquals( 2, new BackReference( 2 ).getIndex() ); }
99
100     protected void testExtractFromOneOrMore( RegexpTree operand )
101         { assertSame( operand, new OneOrMore( operand ).getOperand() ); }
102     
103     protected void testExtractFromZeroOrMore( RegexpTree operand )
104         { assertSame( operand, new ZeroOrMore( operand ).getOperand() ); }
105     
106     protected void testExtractFromOptional( RegexpTree operand )
107         { assertSame( operand, new Optional( operand ).getOperand() ); }
108     }
109
110 /*
111     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
112     All rights reserved.
113     
114     Redistribution and use in source and binary forms, with or without
115     modification, are permitted provided that the following conditions
116     are met:
117     
118     1. Redistributions of source code must retain the above copyright
119        notice, this list of conditions and the following disclaimer.
120     
121     2. Redistributions in binary form must reproduce the above copyright
122        notice, this list of conditions and the following disclaimer in the
123        documentation and/or other materials provided with the distribution.
124     
125     3. The name of the author may not be used to endorse or promote products
126        derived from this software without specific prior written permission.
127     
128     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
129     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
130     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
131     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
132     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
133     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
134     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
135     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
136     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
137     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
138 */
Popular Tags